import { Component, Vue } from 'vue-property-decorator';
import { State, Action } from 'vuex-class';
@Component
export default class Index extends Vue {
    @Action('getSysTemplateList') private getSysTemplateList!: () => void;
    protected ActionList: any = {
        rename: {
            key: 'rename',
            icon: 'shanchu3',
            text: '重命名',
            callback: this.renameFolder,
        },
        del: {
          key: 'del',
          icon: 'shanchu3',
          text: '删除',
          callback: this.delFolder,
        },
    };
    protected mounted() {
        this.getSysTemplateList();
    }
    private renameFolder(folder: any) {
        const { folder_name } = folder;
        return true
    }
    private delFolder(folder: any) {
        const { folder_id} = folder;
        return new Promise(resolve=>{
            this.$dialog.confirm({
            message: '您确定要删除该文件夹吗？',
            beforeClose: (action, done) => {
                if ( action === 'confirm' ) {
                    this.$api.template.delete(folder_id).then((res: any) => {
                            resolve()
                            this.$toast.success('删除成功');
                            this.resetList();
                            done();
                        }).catch((err: any) => {
                            done();
                        });
                    } else {
                        done();
                    }
                },
            });
        }) 
    }
    protected resetList() {
        throw Error('resetList 在列表实现');
    }
}
