<template>
    <!-- 测试项日志 -->
    <div :style="{ height: height }">
        <vxe-table height="auto" auto-resize :data="dataList" v-bind="defaultAttribute" :key="key">
            <vxe-column v-for="item in column" :field="item.field" :title="item.title" :formatter="formatter"
                :min-width="item.width" :sortable="item.sortable"></vxe-column>
            <vxe-column title="操作" fixed="right" width="100">
                <template v-slot:default="scoped">
                    <el-button link type="danger" @click="remove(scoped.row)">删除</el-button>
                </template>
            </vxe-column>

        </vxe-table>
    </div>

</template>
<script setup lang='ts'>
import { mainHeight } from '@/utils/layout'
import { ref, reactive } from 'vue'
import { defaultAttribute } from '@/components/table/defaultAttribute'
import { ElMessageBox, ElMessage } from 'element-plus'
import { activateUser, deluser, passwordConfirm } from '@/api/user-boot/user'
import { useDictData } from '@/stores/dictData'
const dictData = useDictData()
const voltageLevelList: any = dictData.getBasicData('Dev_Voltage_Stand')
import { deleteItem } from '@/api/cs-device-boot/csGroup'
const volConTypeList = dictData.getBasicData('Dev_Connect')
const emit = defineEmits(['onSubmit'])
const height = mainHeight(295).height
const dataList = ref([])
const key: any = ref(0)
const column: any = ref([
    { field: 'startTime', title: '数据起始时间', width: '140px', sortable: true },
    { field: 'endTime', title: '数据结束时间', width: '140px', sortable: true },
    { field: 'itemName', title: '数据来源', width: '100px' },
    { field: 'statisticalInterval', title: '统计间隔', width: '100px', },
    { field: '', title: '时间间隔', width: '140px', },
    { field: 'voltageLevel', title: '电压等级', width: '100px',sortable: true  },
    { field: 'volConType', title: '	电压接线方式', width: '100px', sortable: true },
    { field: 'capacitySi', title: '用户协议容量(MVA)', width: '140px', },
    { field: 'capacitySscb', title: '基准短路容量(MVA)', width: '140px', },
    { field: 'capacitySscmin', title: '最小短路容量(MVA)', width: '140px', },
    { field: 'capacitySt', title: '供电设备容量(MVA)', width: '140px', },
    { field: 'location', title: '	测试位置', width: '100px', },

    { field: 'ct', title: 'CT', width: '70px', },
    { field: 'pt', title: 'PT', width: '70px', },

])
const setData = (data: any) => {
    dataList.value = JSON.parse(JSON.stringify(data))
    key.value += 1
}
const formatter = (row: any) => {
    if (row.column.field == 'voltageLevel') {
        return row.cellValue == null ? '/' : voltageLevelList.filter((item: any) => item.id == row.cellValue)[0]?.name
    } else if (row.column.field == 'volConType') {
        return row.cellValue == null ? '/' : volConTypeList.filter((item: any) => item.id == row.cellValue)[0]?.name
    } else {
        return row.cellValue == null ? '/' : row.cellValue

    }


}
// 删除
const remove = (row: any) => {
    ElMessageBox.prompt('二次校验密码确认', '', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        customClass: 'customInput',
        inputType: 'text'
    }).then(({ value }) => {
        passwordConfirm(value).then(res => {
            console.log('密码正确');

            deleteItem({ id: row.id }).then(() => {
                ElMessage.success('删除成功')
                emit('onSubmit')
            })
        })
    })




}

defineExpose({ setData })
</script>
<style lang="scss">
.customInput {
    .el-input__inner {
        -webkit-text-security: disc !important;
    }
}
</style>
