<script lang="ts" setup name="DeviceReportList"> import { ElMessage, ElMessageBox } from 'element-plus' import showPhoto from './showPhotoSinge.vue' import { useCheckList } from '@/utils/useCheckList' import detailDialog from '@/views/tested/device/certificate/components/detailDialog.vue' const $props = defineProps({ data: { type: Array, default: () => ([]), }, }) const $route = useRoute() // 表头显示标题 const columns = ref([ { text: '证书编号', value: 'certificateNo', required: true, isSelect: false, // 是否下拉框 }, { text: '证书名称', value: 'certificateName', required: true, isSelect: false, // 是否下拉框 }, { text: '校准(检定)单位', value: 'checkOrganization', required: true, isSelect: false, // 是否下拉框 }, { text: '证书日期', value: 'checkDate', required: true, isSelect: false, // 是否下拉框 }, { text: '证书有效期', value: 'certificateValid', required: true, isSelect: false, // 是否下拉框 }, { text: '证书附件', value: 'minioFileName', required: true, isSelect: false, // 是否下拉框 isUpload: true, }, ]) const list = ref<any[]>([]) // 检查数据列表 function checkCertificateList() { return useCheckList(list.value, columns.value as any, '证书报告') } // 将列表置为不可编辑状态 function setAllRowReadable() { for (const item of list.value) { item.editable = false } } // 双击行显示输入框 const dblclickRow = (row: any) => { if ($route.path.includes('detail')) { return } setAllRowReadable() row.editable = true } const SelectionList = ref() // 表格选中 const handleSelectionChange = (e: any[]) => { SelectionList.value = e } // 添加行 const addRow = () => { // certificateRef.value.initDialog({ title: '添加' }) if (checkCertificateList()) { setAllRowReadable() list.value.push({ name: '', information: '', location: '', editable: true, }) } } // 删除行 const removeRow = () => { list.value = list.value.filter((item) => { return !SelectionList.value.includes(item) }) } watch(() => $props.data, (newVal) => { if (newVal) { list.value = newVal } }) const initDialog = () => { list.value = $props.data } initDialog() defineExpose({ list, }) const detailRef = ref() const handler = (row: any) => { if (!row.minioFileName) { ElMessage.warning('暂无文件') return } detailRef.value.initDialog(row.minioFileName) // getPhotoUrl(row.minioFileName).then((res) => { // window.open(res.data, '_blank') // }) } </script> <template> <detail-block-switch title="证书报告"> <detail-dialog ref="detailRef" /> <template v-if="!$route.path.includes('detail')" #btns> <el-button type="primary"> 扫描增加 </el-button> <el-button type="primary" @click="addRow"> 增加行 </el-button> <el-button type="info" @click="removeRow"> 删除行 </el-button> </template> <el-table ref="multipleTableRef" :data="list" style="width: 100%;" border @selection-change="handleSelectionChange" @row-dblclick="dblclickRow" > <el-table-column v-if="!$route.path.includes('detail')" type="selection" width="38" /> <el-table-column align="center" label="序号" width="80" type="index" /> <el-table-column v-for="item in columns" :key="item.value" :prop="item.value" :label="item.text" align="center" > <template #header> <span v-show="item.required && !$route.path.includes('detail')" style="color: red;">*</span><span>{{ item.text }}</span> </template> <template #default="scope"> <span v-if="!scope.row.editable && !item.isUpload">{{ scope.row[item.value] }}</span> <el-input v-if="scope.row.editable && !item.isSelect" v-model="scope.row[item.value]" :autofocus="true" :placeholder="`${item.text}`" class="input" /> <el-date-picker v-if="scope.row.editable && item.isSelect" v-model="scope.row[item.value]" type="date" format="YYYY-MM-DD" value-format="YYYY-MM-DD HH:mm:ss" :placeholder="`${item.text}`" /> <span v-if="item.isUpload"> <el-button link type="primary" size="small" @click="handler(scope.row)"> 查看 </el-button> </span> </template> </el-table-column> </el-table> </detail-block-switch> </template> <style lang="scss" scoped> .el-dialog { width: 700px; } .el-select { width: 100%; } </style>