<!-- 溯源计划管理 基本信息 -->
<script name="ResultCompleteApproveBasic" lang="ts" setup>
import type { Ref } from 'vue'
import { ElLoading, ElMessage, ElMessageBox } from 'element-plus'
import type { FormInstance, FormRules } from 'element-plus'
import dayjs from 'dayjs'
import type { IForm, IResultConfirmList } from '../resultComplete-interface'
import selectResultConfirmDialog from '../dialog/selectResultConfirmDialog.vue'
import type { dictType } from '@/global'
import { getDictByCode } from '@/api/system/dict'
import { SCHEDULE } from '@/utils/scheduleDict'
import ApprovalDialog from '@/components/Approval/ApprovalDialog.vue'
import useUserStore from '@/store/modules/user'
import { useCheckList } from '@/commonMethods/useCheckList'
import { getInfo as getResultConfirmDetail } from '@/api/equipment/source/resultConfirm'
import { useDoubleClickTableRow, useSetAllRowReadable } from '@/commonMethods/useSetAllRowReadable'
import { addResultCompleteList, failUpdateResultCompleteList, getInfo, submit, updateResultCompleteList } from '@/api/equipment/source/resultComplete'
const props = defineProps({
pageType: { // 页面类型 add新建 edit编辑 detail详情
type: String,
requre: true,
default: 'detail',
},
id: {
type: String,
requre: true,
},
approvalStatusName: { // 审批状态名称
type: String,
requre: true,
},
processId: {
type: String,
},
})
const emits = defineEmits(['addSuccess', 'submitSuccess'])
const user = useUserStore() // 用户信息
const form = ref<IForm>({
id: '', // 列表id
labCode: '', // 实验室代码
groupCode: '', // 组别代码
formNo: '', // 情况表编号
formName: '', // 情况表名称
createUserId: '', // 创建人id
createUserName: '', // 创建人
createTime: '', // 创建时间
formGroup: '', // 计划表组别
formYear: '', // 计划表年份
})
const ruleFormRef = ref() // 表单ref
const certFormRef = ref() // 证书要素确认ref
const resultRulesRef = ref() // 结果确认ref
const equipmentRef = ref() // 设备ref
const loading = ref(false) // loading
const infoId = ref('') // id
const rules = ref<FormRules>({ // 校验规则
labCode: [{ required: true, message: '实验室代码不能为空', trigger: ['blur', 'change'] }],
groupCode: [{ required: true, message: '组别代码不能为空', trigger: ['blur', 'change'] }],
formYear: [{ required: true, message: '年不能为空', trigger: ['blur', 'change'] }],
formGroup: [{ required: true, message: '组不能为空', trigger: ['blur', 'change'] }],
})
// -----------------------------------------字典--------------------------------------------------------------
const labCodeList = ref<dictType[]>([]) // 实验室代码
const groupCodeList = ref<dictType[]>([]) // 组别代码
const meterIdentifyMap = ref<dictType[]>([]) as any // 计量标识
// 查询字典
const getDict = async () => {
// 计量标识
const res = await getDictByCode('bizMeterIdentify')
res.data.forEach((item: { value: string; name: string }) => {
meterIdentifyMap.value[`${item.value}`] = item.name
})
// 实验室代码
getDictByCode('bizLabCode').then((response) => {
labCodeList.value = response.data
})
// 组别代码
getDictByCode('bizGroupCode').then((response) => {
groupCodeList.value = response.data
})
}
// ------------------------------------------溯源结果确认情况------------------------------------------------
const resultConfirmColumns = ref([ // 表头
{ text: '统一编号', value: 'equipmentNo', align: 'center', width: '240', required: true },
{ text: '设备名称', value: 'equipmentName', align: 'center', required: true },
{ text: '型号规格', value: 'model', align: 'center', required: true },
{ text: '溯源机构', value: 'traceCompany', align: 'center', required: true },
{ text: '测试、校准/检定时间', value: 'traceDate', align: 'center', required: true },
{ text: '检定有效期', value: 'validDate', align: 'center', required: true, width: '120' },
{ text: '检定结果', value: 'conclusion', align: 'center', required: true },
{ text: '限用范围', value: 'limitScope', align: 'center', required: true },
{ text: '备注', value: 'remark', align: 'center', required: true },
])
const resultConfirmList = ref<IResultConfirmList[]>([]) // 溯源结果确认情况列表
const checkoutList = ref<IResultConfirmList[]>([]) // 量传指标选中
const selectResultConfirmRef = ref() // 选择溯源结果确认情况组件ref
const selectIndex = ref(0) // 选择的第几行
// 点击结果确认
const selectResultConfirm = (index: number) => {
selectIndex.value = index
selectResultConfirmRef.value.initDialog()
}
// 确定选择结果确认情况
const confirmSelectResultConfirm = (val: any) => {
console.log(val)
if (val.length) {
const index = resultConfirmList.value.findIndex((i: IResultConfirmList) => val[0].id === i.confirmId)
if (index !== -1) {
ElMessage.warning('此结果确认情况已添加过')
return
}
let param
getResultConfirmDetail({ id: val[0].id }).then((res) => {
param = {
confirmId: val[0].id, // 主键
equipmentId: res.data.equipmentId,
equipmentNo: res.data.equipmentNo, // 统一编号
equipmentName: res.data.equipmentName, // 设备名称
model: res.data.model, // 型号规格
traceCompany: res.data.traceCompany, // 溯源机构名称
limitScope: res.data.limitScope, // 限用范围
remark: res.data.remark, // 备注
traceDate: dayjs(res.data.traceDate).format('YYYY-MM-DD'), // 测试、校准或检定日期
validDate: dayjs(res.data.validDate).format('YYYY-MM-DD'), // 有效期
conclusion: meterIdentifyMap.value[res.data.meterIdentify], // 结论
editable: true,
}
resultConfirmList.value.splice(selectIndex.value, 1, param)
})
}
}
// 溯源结果确认选中
const handleSelectionChange = (e: any) => {
checkoutList.value = e
}
// 点击增加行
const addRow = () => {
const checkResult = useCheckList(resultConfirmList.value, resultConfirmColumns.value, '溯源结果确认情况', 'reason') // 检查表格
if (checkResult) {
useSetAllRowReadable(resultConfirmList.value)
resultConfirmList.value.push({
conclusion: '', // 结论
confirmId: '', // 溯源结果确认id
equipmentId: '', // 测量设备id
equipmentName: '', // 设备名称
equipmentNo: '', // 设备编号
limitScope: '', // 限用范围
model: '', // 型号规格
remark: '', // 备注
traceCompany: '', // 溯源机构名称
traceDate: '', // 测试、校准或检定日期
validDate: '', // 有效期
editable: true,
})
}
}
// 删除行
const deleteRow = () => {
if (!checkoutList.value.length) {
ElMessage({
message: '请选中要删除的行',
type: 'warning',
})
return false
}
resultConfirmList.value = resultConfirmList.value.filter((item: any) => {
return !checkoutList.value.includes(item)
})
}
// 双击行--量传指标
const rowDblclick = (row: any) => {
if (props.pageType !== 'detail') {
useDoubleClickTableRow(row, resultConfirmList.value)
}
}
// -----------------------------------------------保存----------------------------------------------
/**
* 点击保存
* @param formEl 基本信息表单ref
*/
const saveForm = () => {
if (!useCheckList(resultConfirmList.value, resultConfirmColumns.value, '溯源结果确认情况')) {
return false
}
if (!resultConfirmList.value.length) {
ElMessage.warning('溯源结果确认情况不能为空')
return false
}
ruleFormRef.value.validate((valid: boolean) => {
if (valid) { // 基本信息表单通过校验
ElMessageBox.confirm(
'确认保存吗?',
'提示',
{
confirmButtonText: '确认',
cancelButtonText: '取消',
type: 'warning',
},
).then(() => {
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.8)',
})
const params = {
...form.value,
id: infoId.value,
formName: `${form.value.formYear}年${form.value.formGroup}组测量设备溯源完成情况表`,
processId: props.processId,
resultConfirmIdList: resultConfirmList.value.map(item => item.confirmId),
}
if (props.pageType === 'add') { // 新建
addResultCompleteList(params).then((res) => {
loading.close()
form.value.formNo = res.data.formNo // 情况表编号
infoId.value = res.data.id // id
emits('addSuccess', infoId.value)
ElMessage.success('已保存')
}).catch(() => {
loading.close()
})
}
else if (props.pageType === 'edit') { // 编辑
console.log(props.approvalStatusName)
if (props.approvalStatusName === '草稿箱' || props.approvalStatusName === '全部') {
updateResultCompleteList(params).then((res) => {
loading.close()
emits('addSuccess', infoId.value)
ElMessage.success('已保存')
}).catch(() => {
loading.close()
})
}
else { // '未通过' || '已取消'
failUpdateResultCompleteList(params).then((res) => {
loading.close()
emits('submitSuccess')
fetchInfo()
ElMessage.success('已保存')
}).catch(() => {
loading.close()
})
}
}
})
}
})
}
// ----------------------------------------------提交--------------------------------------------
// 提交
/**
*
* @param processId 流程实例id
* @param id
*/
const submitForm = (processId: string, id: string) => {
const loading = ElLoading.service({
lock: true,
text: '加载中...',
background: 'rgba(255, 255, 255, 0.6)',
})
submit({ id, formId: SCHEDULE.TRACE_RESULT_PERFORMANCE_APPROVAL }).then((res) => {
ElMessage.success('已提交')
emits('submitSuccess')
loading.close()
})
}
// -----------------------------------------获取详情------------------------------------------
// 获取详情
function fetchInfo() {
loading.value = true
getInfo({ id: infoId.value }).then((res) => {
loading.value = false
form.value = res.data
form.value.formYear = `${res.data.formYear}`
resultConfirmList.value = res.data.confirmEquipmentList.map((item: any) => {
return {
...item,
traceDate: dayjs(item.traceDate).format('YYYY-MM-DD'), // 测试、校准或检定日期
validDate: dayjs(item.validDate).format('YYYY-MM-DD'), // 有效期
conclusion: meterIdentifyMap.value[item.conclusion], // 结论
}
})
})
}
// ---------------------------------------------钩子----------------------------------------------
watch(() => props.id, (newValue) => {
infoId.value = newValue!
if (infoId.value) {
fetchInfo() // 获取详情信息
}
}, { immediate: true })
onMounted(() => {
getDict().then(() => {
form.value.createUserId = user.id// 创建人id
form.value.createUserName = user.name // 创建人名字
form.value.createTime = dayjs().format('YYYY-MM-DD HH:mm:ss')// 创建时间
if (props.pageType !== 'add' && infoId.value) {
fetchInfo() // 获取详情信息
}
})
})
defineExpose({ saveForm, submitForm, fetchInfo })
</script>
<template>
<detail-block v-loading="loading" title="">
<el-form
ref="ruleFormRef"
:model="form"
:label-width="120"
label-position="right"
:rules="rules"
>
<el-row :gutter="24">
<el-col :span="6">
<el-form-item label="申请表编号:" prop="formNo">
<el-input v-model="form.formNo" disabled placeholder="系统自动生成" />
</el-form-item>
</el-col>
<el-col :span="12" style="display: flex;line-height: 32px;">
<el-form-item label="申请表名称:" />
<el-form-item label-width="0" prop="formYear" style="width: 90px;">
<el-date-picker
v-model="form.formYear"
type="year"
placeholder="选择年"
format="YYYY"
value-format="YYYY"
:disabled="pageType === 'detail'"
/>
</el-form-item>
<span style="margin: 0 8px;font-size: 14px;color: #606266;">年</span>
<el-form-item label-width="0" prop="formGroup" style="width: 90px;">
<!-- <el-select v-model="form.formGroup" placeholder="选择组">
<el-option
v-for="item in formGroupList"
:key="item.value"
:value="item.value"
:label="item.name"
/>
</el-select> -->
<el-input v-model="form.formGroup" :disabled="pageType === 'detail'" placeholder="输入组" />
</el-form-item>
<span style="margin: 0 8px;font-size: 14px;color: #606266;">组测量设备溯源完成情况表</span>
</el-col>
<el-col :span="6">
<el-form-item label="实验室代码" prop="labCode">
<el-select
v-model="form.labCode"
:placeholder="pageType === 'detail' ? ' ' : '请选择实验室代码'"
:disabled="pageType === 'detail'"
class="full-width-input"
>
<el-option
v-for="item in labCodeList"
:key="item.id"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="组别代码" prop="groupCode">
<el-select
v-model="form.groupCode"
:placeholder="pageType === 'detail' ? ' ' : '请选择组别代码'"
:disabled="pageType === 'detail'"
class="full-width-input"
>
<el-option
v-for="item in groupCodeList"
:key="item.id"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="创建人:">
<el-input
v-model="form.createUserName" disabled
/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item label="创建时间:" prop="createTime">
<el-date-picker
v-model="form.createTime"
type="datetime"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
disabled
/>
</el-form-item>
</el-col>
</el-row>
</el-form>
</detail-block>
<detail-block v-loading="loading" title="溯源结果确认情况">
<template v-if="pageType !== 'detail'" #btns>
<el-button type="primary" @click="addRow">
增加行
</el-button>
<el-button type="info" @click="deleteRow">
删除行
</el-button>
</template>
<el-table
ref="table"
:data="resultConfirmList"
border
style="width: 100%;"
@selection-change="handleSelectionChange"
@row-dblclick="rowDblclick"
>
<el-table-column v-if="pageType !== 'detail'" type="selection" width="38" />
<el-table-column align="center" label="序号" width="80" type="index" />
<el-table-column
v-for="item in resultConfirmColumns"
:key="item.value"
:prop="item.value"
:label="item.text"
:width="item.width"
align="center"
>
<template #header>
<span v-show="item.required" style="color: red;">*</span><span>{{ item.text }}</span>
</template>
<template #default="scope">
<span v-if="!scope.row.editable">{{ scope.row[item.value] }}</span>
<el-input v-if="scope.row.editable && item.value === 'equipmentNo'" v-model="scope.row[item.value]" :disabled="true" :autofocus="true" :placeholder="`${item.text}`" class="input">
<template v-if="pageType !== 'detail'" #append>
<el-button size="small" @click="selectResultConfirm(scope.$index)">
选择
</el-button>
</template>
</el-input>
</template>
</el-table-column>
</el-table>
</detail-block>
<select-result-confirm-dialog ref="selectResultConfirmRef" @confirm="confirmSelectResultConfirm" />
</template>
<style lang="scss" scoped>
.tech-file {
display: flex;
align-items: center;
margin-left: 20px;
margin-bottom: 10px;
.file-text {
white-space: nowrap;
margin-right: 10px;
font-size: 14px;
color: #60627f;
}
}
</style>