import { Component, Vue } from 'vue-property-decorator';
import { State, Action, namespace } from 'vuex-class';
const Template = namespace('template');
@Component
export default class Index extends Vue {
    @Template.State('sysTemplateList') protected systemList!: [];
    protected ActionList: any = {
        rename: {
            key: 'rename',
            icon: 'zhongmingming2x',
            text: '重命名',
            callback: this.renameFolder,
        },
        del: {
          key: 'del',
          icon: 'shanchu2x',
          text: '删除',
          callback: this.delFolder,
        },
    };
    @Template.Action('getSysTemplateList') private getSysTemplateList!: () => void;
    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: any) => {
            this.$dialog.confirm({
            message: '您确定要删除该文件夹吗？',
            beforeClose: (action, done) => {
                if ( action === 'confirm' ) {
                    this.$api.template.delete(folder_id).then((res: any) => {
                            resolve();
                            this.$toast.success('删除成功');
                            done();
                        }).catch((err: any) => {
                            done();
                        });
                    } else {
                        done();
                    }
                },
            });
        });
    }
}
