Skip to content

Instantly share code, notes, and snippets.

@interjc
Created August 23, 2016 06:16
Show Gist options
  • Select an option

  • Save interjc/e3cb46e718d0946d73d35d0d905bc53f to your computer and use it in GitHub Desktop.

Select an option

Save interjc/e3cb46e718d0946d73d35d0d905bc53f to your computer and use it in GitHub Desktop.

Revisions

  1. interjc created this gist Aug 23, 2016.
    101 changes: 101 additions & 0 deletions remove.vue
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,101 @@
    <script>
    import Vue from 'vue';
    import Ajax from '../utils/ajax';
    import Modal from './modal.vue';
    let httpRes = {};
    export default {
    props: {
    modal: {
    type: Object,
    default: null
    }
    },
    data(){
    return{
    title: '删除',
    okText: '删除',
    okClass: 'btn btn-danger',
    cancelText: '取消',
    cancelClass: 'btn btn-default',
    small: true,
    method: 'delete'
    };
    },
    computed: {
    itemType(){
    let self = this,
    modal = self.modal,
    ret = '本条';
    if(modal.item){
    if(modal.item.type == 2){
    ret = '此评论';
    } else {
    ret = '此回复';
    }
    }
    return ret;
    }
    },
    components: {
    Modal
    },
    methods: {
    remove(){
    let self = this,
    modal = self.modal,
    page = modal.page,
    item = modal.item,
    parent = modal.parent,
    top = modal.top,
    path = modal.path + item.id,
    method = self.method;
    // delete
    httpRes.removeReply = new Ajax({
    path,
    method,
    success(response) {
    if(item && parent){
    parent.$remove(item);
    if(page){
    page.totalRecord--;
    }
    if(top){
    Vue.nextTick(() => {
    top.replyCount = parent.length;
    });
    }
    }
    },
    beforeSend(){
    modal.processing = true;
    modal.okText = '删除中…';
    },
    complete(){
    modal.processing = false;
    modal.okText = '删除';
    modal.show = false;
    }
    });
    httpRes.removeReply.fetch();
    },
    cancel(){
    let self = this,
    modal = self.modal;
    modal.show = false;
    modal.item = null;
    modal.parent = null;
    modal.processing = false;
    modal.okText = '删除';
    }
    }
    };
    </script>

    <template>
    <modal :title="title" :small="small" :ok-text="okText" :ok-class="okClass" :cancel-text="cancelText" :cancel-class="cancelClass" :ok-disabled="modal.processing" :show.sync="modal.show" @ok="remove" @cancel="cancel">
    <div>您确定要删除<span v-text="itemType"></span>?</div>
    </modal>
    </template>