<template>
    <!-- 档案移交申请审核 -->
    <div class="app-container">
        <TableModel :formLabel="formLabel" :showOperation="true" :showRightTools="true" ref="auditTableRef"
            :columnsList="columnsList" :request-api="getTransferAuditListApi">
            <template slot="auditStatus" slot-scope="{ data }">
                <el-tag size="mini" :type="getStatusType(data.auditStatus)">
                    {{ getStatusText(data.auditStatus) }}
                </el-tag>
            </template>

            <template slot="handle" slot-scope="{ data }">
                <el-button plain size="mini" type="success" icon="el-icon-warning-outline" v-hasPermi="['transfer:apply:query']"
                    @click="handleDetail(data)">
                    详情
                </el-button>
            </template>
        </TableModel>
    </div>
</template>

<script>
import TableModel from '@/components/TableModel'
import { columnsList, formLabel } from './config'
import {
    getTransferAuditListApi,
} from '@/api/filesTransfer/audit.js'
import { encryptWithSM4 } from '@/utils/sm'


export default {
    name: 'Audit',
    dicts: ['pro_type', 'voltage_level'],
    components: {
        TableModel,
    },
    data() {
        return {
            formLabel,
            columnsList,
            getTransferAuditListApi,
            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: {
        // 详情
        handleDetail(row) {
            this.$router.push({
                name: 'DetailData2',
                query: {
                    id: encryptWithSM4(row.id ?? '0'),
                    viewStatus: encryptWithSM4('audit'),
                    auditStatus: encryptWithSM4(this.getStatusText2(row.auditStatus)),
                }
            })
        },
        /* 搜索操作 */
        handleQuery() {
            this.$refs.auditTableRef.getTableList()
        },
        
        // 获取状态
        getStatusText(status) {
            switch (status) {
                case '0':
                    return '待审批'
                case '1':
                    return '审批通过'
                case '2':
                    return '审批驳回'
                default:
                    return '未知状态'
            }
        },

        // 获取状态标签类型
        getStatusType(status) {
            switch (status) {
                case '0':
                    return 'danger'
                case '1':
                    return 'warning'
                case '2':
                    return 'success'
                default:
                    return 'info'
            }
        },
        getStatusText2(status) {
            switch (status) {
                case '0':
                    return 'approving'
                case '1':
                    return 'approved'
                case '2':
                    return 'rejected'
                default:
                    return 'approving'
            }
        },
    },
}
</script>
