<template>
    <!-- 项目管理 -->
    <div class="app-container">
        <TableModel :formLabel="formLabel" :showOperation="true" :showRightTools="true" ref="proTableRef"
            :columnsList="columnsList" :request-api="getProListAPI">
            <template slot="fileStatus" slot-scope="{ data }">
                <el-tag
                    size="mini"
                    :type="getFileStatusType(data.fileStatus)"
                >
                    {{ getFileStatusText(data.fileStatus) }}
                </el-tag>
            </template>
            <template slot="handle" slot-scope="{ data }">
                <el-tag v-if="!data.contentsName"
                    size="mini"
                    type="danger"
                >
                    未配置档案类型
                </el-tag>
                <el-button plain size="mini" type="primary" icon="el-icon-document" v-hasPermi="['file:manage:set']"
                    @click="openFileManager(data)" v-if="data.contentsName">
                    档案管理
                </el-button>
            </template>
        </TableModel>
    </div>
</template>

<script>
import TableModel from '@/components/TableModel'
import { columnsList, formLabel } from './config'
import { encryptWithSM4 } from '@/utils/sm'
import {
    getProListAPI
} from '@/api/archivesManagement/fileManager/fileManager.js'


export default {
    name: 'ProManager',
    dicts:['pro_type','voltage_level'],
    components: {
        TableModel,
    },
    data() {
        return {
            formLabel,
            columnsList,
            getProListAPI,
            title: "",
            isflag: false,
            isAdd: '',
            row: {},
            loading: false,
        }
    },

    created() {
        // 将字典数据填充到表单配置的下拉选项中
        if (Array.isArray(this.formLabel)) {
            this.formLabel.forEach((item) => {
                if (item.f_dict && this.dict && this.dict.type && this.dict.type[item.f_dict]) {
                    this.$set(item, 'f_selList', this.dict.type[item.f_dict])
                }
            })
        }
    },

    methods: {
        closeDialog() {
            this.isflag = false;
        },
        showColose() {
            this.isflag = false;
        },
        /** 配置档案类型 */
        handleUpdate(row) {
            this.title = "配置档案类型";
            this.isAdd = 'edit';
            this.row = row;
            this.isflag = true;
        },
        /* 搜索操作 */
        handleQuery() {
            this.$refs.proTableRef.getTableList()
        },
        /* 打开档案管理 */
        openFileManager(row) {
            this.$router.push({
                name: 'FileData',
                query: {
                    id: encryptWithSM4(row.id),
                    fileStatus: encryptWithSM4(row.fileStatus)
                }
            })
        },
        
        // 获取文件状态文本
        getFileStatusText(status) {
            switch (status) {
                case '0':
                    return '未归档移交'
                case '1':
                    return '已确认完整性'
                case '2':
                    return '已归档移交'
                default:
                    return '未知状态'
            }
        },
        
        // 获取文件状态标签类型
        getFileStatusType(status) {
            switch (status) {
                case '0':
                    return 'danger'
                case '1':
                    return 'warning'
                case '2':
                    return 'success'
                default:
                    return 'info'
            }
        }
    },
}
</script>
