<template>
    <hc-card>
        <template #header>
            <div class="w-40">
                <el-select v-model="searchForm.fileStorageType" filterable clearable block placeholder="文件存储类型">
                    <el-option v-for="item in fileStorageTypeData" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
            </div>
            <div class="ml-14px">
                <el-button hc-btn type="warning">配置</el-button>
            </div>
        </template>
        <template #extra>
            <el-button hc-btn type="primary" @click="addClick">新增</el-button>
        </template>
        <hc-table :column="tableColumn" :datas="tableData" :loading="tableLoading" :index-style="{ width: 60 }" :is-current-row="false">
            <template #fieldType="{ row }">{{ getFieldType(row.fieldType) }}</template>
            <template #containerType="{ row }">{{ getContainerType(row.containerType) }}</template>
            <template #captureMode="{ row }">{{ getCaptureMode(row.captureMode) }}</template>
            <template #mandatoryType="{ row }">{{ getMandatoryType(row.mandatoryType) }}</template>
            <template #action="{ row }">
                <el-link type="warning" @click="editRowClick(row)">修改</el-link>
                <el-link type="danger" @click="delRowClick(row)">删除</el-link>
            </template>
        </hc-table>
        <template #action>
            <hc-pages :pages="searchForm" @change="pageChange" />
        </template>
    </hc-card>
</template>

<script setup>
import { nextTick, onActivated, onDeactivated, onUnmounted, ref } from 'vue'
import { deepClone, formValidate, getArrValue } from 'js-fast-way'
import { HcDelMsg } from 'hc-vue3-ui'
import mainApi from '~api/desk/meta'

//激活
onActivated(() => {
    searchClick()
})

//搜索表单
const searchForm = ref({ fileStorageType: '', current: 1, size: 30, total: 0 })
const searchClick = () => {
    searchForm.value.current = 1
    getTableData()
}

//分页
const pageChange = ({ current, size }) => {
    searchForm.value.current = current
    searchForm.value.size = size
    getTableData()
}

//表格数据
const tableColumn = ref([
    { key: 'containerName', name: '元数据项' },
    { key: 'code', name: '编号', align: 'center' },
    { key: 'fieldType', name: '数据类型', align: 'center' },
    { key: 'containerType', name: '所属容器分类', align: 'center' },
    { key: 'captureMode', name: '捕获方式', align: 'center' },
    { key: 'mandatoryType', name: '是否必选', align: 'center' },
    { key: 'action', name: '操作', width: 110, align: 'center' },
])
const tableData = ref([{}])

//获取表格数据
const tableLoading = ref(true)
const getTableData = async () => {
    tableData.value = []
    tableLoading.value = true
    const { data } = await mainApi.page({
        ...searchForm.value,
        total: null,
    })
    tableLoading.value = false
    tableData.value = getArrValue(data?.records)
    searchForm.value.total = data?.total || 0
}

//文件存储类型
const fileStorageTypeData = [
    { value: '', label: '元数据表' }, { value: 'a', label: '普通' }, { value: 'b', label: '竣工图' },
    { value: 'c', label: '计量' }, { value: 'd', label: '质检' }, { value: 'e', label: '声像' },
    { value: 'f', label: '隐蔽' }, { value: 'g', label: '试验' }, { value: 'h', label: '管理文件' },
    { value: 'i', label: '变更令' },
]

//数据类型
const fieldTypeData = [{ label: '字符串', value: 1 }, { label: '日期', value: 4 }]
const getFieldType = (val) => {
    return fieldTypeData.find(({ value }) => value == val)?.label || ''
}

//所属容器分类
const containerTypeData = [
    { label: '无', value: 100 }, { label: '来源', value: 0 }, { label: '文件联', value: 1 },
    { label: '内容描述', value: 2 }, { label: '文件标识码', value: 3 }, { label: '照片文件', value: 4 },
    { label: '电子属性', value: 5 }, { label: '数字化属性', value: 6 }, { label: '电子签名', value: 7 },
    { label: '竣工图', value: 8 }, { label: '业务层级', value: 9 },
]
const getContainerType = (val) => {
    return containerTypeData.find(({ value }) => value == val)?.label || ''
}

//捕获方式
const captureModeData = [{ label: '手动', value: 0 }, { label: '自动', value: 1 }, { label: '手动/自动', value: 2 }]
const getCaptureMode = (val) => {
    return captureModeData.find(({ value }) => value == val)?.label || ''
}

//是否必选
const mandatoryTypeData = [{ label: '可选', value: 0 }, { label: '必选', value: 1 }, { label: '条件选', value: 2 }]
const getMandatoryType = (val) => {
    return mandatoryTypeData.find(({ value }) => value == val)?.label || ''
}

//新增
const addClick = async () => {
    //formModel.value = {}
    //await nextTick()
    //isDialogShow.value = true
}

//修改
const editRowClick = async (row) => {
    //formModel.value = deepClone(row)
    // await nextTick()
    //isDialogShow.value = true
}

//删除
const delRowClick = (row) => {

}

//关闭
onDeactivated(() => {
    //isTempShow.value = false
    //isDialogShow.value = false
})

//卸载
onUnmounted(()=> {
    //isTempShow.value = false
    //isDialogShow.value = false
})
</script>

<style lang="scss">

</style>
