<template>
    <!-- 档案多维度管理 -->
    <div class="app-container">
        <TableModel :formLabel="formLabel" :showOperation="true" :showRightTools="true" ref="customClassificationTableRef"
            :columnsList="columnsList" :request-api="getKyFilesCustomizeClassifyListAPI">
            <template slot="btn">
                <el-button plain size="mini" type="primary" icon="el-icon-plus" v-hasPermi="['files:customize:add']"
                    @click="handleAdd">
                    新增
                </el-button>
            </template>

            <template slot="handle" slot-scope="{ data }">
                <el-button plain size="mini" type="primary" icon="el-icon-edit" v-hasPermi="['files:customize:list']"
                           @click="handleDetail(data)">
                  详情
                </el-button>
                <el-button plain size="mini" type="primary" icon="el-icon-edit" v-hasPermi="['files:customize:update']"
                    @click="handleUpdate(data)">
                    修改
                </el-button>
                <el-button plain size="mini" type="danger" icon="el-icon-delete" v-hasPermi="['files:customize:del']"
                    @click="handleDelete(data)">
                    删除
                </el-button>
            </template>
        </TableModel>
        <!-- 新增/编辑 -->
        <CustomizeForm v-if="isflag" :isAdd="isAdd" :rowData="row" @handleQuery="handleQuery" :title="title"
            @closeDialog="closeDialog" @showColose="showColose" :dataForm="row" :disabled="isAdd === 'detail'" :width="600" />
    </div>
</template>

<script>
import TableModel from '@/components/TableModel'
import { columnsList, formLabel } from './config'
import {
    delKyFilesCustomizeClassifyAPI,
    getKyFilesCustomizeClassifyListAPI,
} from '@/api/archivesManagement/archCustomClassification'
import CustomizeForm from './prop/customizeForm'


export default {
    name: 'ArchClassification',
    components: {
        TableModel,
        CustomizeForm
    },
    data() {
        return {
            formLabel,
            columnsList,
            getKyFilesCustomizeClassifyListAPI,
            title: "",
            isflag: false,
            isAdd: '',
            row: {},
            loading: false,
        }
    },

    created() {

    },

    methods: {
        /** 新增按钮操作 */
        handleAdd() {
            this.title = "新增";
            this.isAdd = 'add';
            this.isflag = true;
        },
        closeDialog() {
            this.isflag = false;
        },
        showColose() {
            this.isflag = false;
        },
      /** 详情操作 */
      handleDetail(row) {
        this.title = "详情";
        this.isAdd = 'detail'; // 标记为详情模式
        this.row = row;
        this.isflag = true;
      },
        /** 修改操作 */
        handleUpdate(row) {
            this.title = "修改";
            this.isAdd = 'edit';
            this.row = row;
            this.isflag = true;
        },
        /* 搜索操作 */
        handleQuery() {
            this.$refs.customClassificationTableRef.getTableList()
        },
        /** 删除操作 */
        handleDelete(row) {
            this.$modal.confirm(`是否确认删除自定义名称为"${row.customizeClassifyName}"的数据项？`).then(() => {
                // 显示加载遮罩
                this.$modal.loading("正在删除，请稍候...");
                delKyFilesCustomizeClassifyAPI({ id: row.id }).then(res => {
                    this.$modal.closeLoading();
                    if (res.code === 200) {
                        this.$modal.msgSuccess("删除成功");
                        this.handleQuery();
                    } else {
                        this.$modal.msgError(res.msg);
                    }
                }).catch(error => {
                    this.$modal.closeLoading();
                    this.$modal.msgError(error);
                });
            }).catch(() => {
                // 用户取消删除，不需要处理
            });
        },
    },
}
</script>
