From 29be8639dc16b5d82bddc6099b1fa5cdca75f77a Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 20 十月 2026 16:28:22 +0800
Subject: [PATCH] feat(import): 统一导入弹框与模板,修复模板日期格式及上传报错

---
 src/views/CNAS/process/ensureResults/ensureResultsValidity/components/detailFormDialog.vue |  183 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 161 insertions(+), 22 deletions(-)

diff --git a/src/views/CNAS/process/ensureResults/ensureResultsValidity/components/detailFormDialog.vue b/src/views/CNAS/process/ensureResults/ensureResultsValidity/components/detailFormDialog.vue
index 62415a7..88318c1 100644
--- a/src/views/CNAS/process/ensureResults/ensureResultsValidity/components/detailFormDialog.vue
+++ b/src/views/CNAS/process/ensureResults/ensureResultsValidity/components/detailFormDialog.vue
@@ -1,45 +1,80 @@
 <template>
   <div>
-    <el-dialog title="缂栬緫" v-model="formDia"
+    <el-dialog :title="operationType === 'add' ? '鏂板璐ㄦ帶椤圭洰' : '缂栬緫璐ㄦ帶椤圭洰'" v-model="formDia"
                :close-on-click-modal="false"
                :close-on-press-escape="false"
                width="80%" @close="closeDia">
       <el-form :model="form" :rules="rules" ref="form" label-width="140px">
         <el-col :span="12">
-          <el-form-item label="鐩戞帶鐩殑" prop="monitorPurpose">
-            <el-input v-model="form.monitorPurpose" size="small" clearable></el-input>
+          <el-form-item label="搴忓彿" prop="sortNo">
+            <el-input-number v-model="form.sortNo" :min="1" style="width:100%" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item label="璁″垝寮�灞曟椂闂�" prop="plannedTime">
-            <el-input v-model="form.plannedTime" size="small" clearable></el-input>
-          </el-form-item>
-        </el-col>
-        <el-col :span="12">
-          <el-form-item label="鐩戞帶椤圭洰" prop="monitorProject">
+          <el-form-item label="璐ㄦ帶椤圭洰" prop="monitorProject">
             <el-input v-model="form.monitorProject" size="small" clearable></el-input>
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item label="鍙傚姞鍗曚綅锛堜汉鍛橈級" prop="participant">
-            <el-input v-model="form.participant" size="small" clearable></el-input>
+          <el-form-item label="鎶�鏈爣鍑�" prop="technicalStandardText">
+            <el-input v-model="form.technicalStandardText" size="small" clearable placeholder="鏍囧噯缂栧彿鍙婂悕绉帮紱闈炴娴嬬被鍙~鍐欑▼搴忔枃浠舵垨/" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item label="棰勭畻锛堝厓锛�" prop="budget">
-            <el-input v-model="form.budget" size="small" clearable></el-input>
+          <el-form-item label="璐ㄦ帶鏂瑰紡" prop="monitorWay">
+            <el-input v-model="form.monitorWay" size="small" clearable placeholder="濡傜洸鏍锋娴嬨�佷汉鍛樻瘮瀵广�佺洃鐫f鏌�" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item label="缁勭粐浜哄憳" prop="organization">
-            <el-input v-model="form.organization" size="small" clearable></el-input>
+          <el-form-item label="瀹屾垚鏃堕檺" prop="completionMonth">
+            <el-date-picker v-model="form.completionMonth" type="month" value-format="YYYY-MM" format="YYYY.MM" style="width:100%" />
           </el-form-item>
         </el-col>
         <el-col :span="12">
-          <el-form-item label="鐩戞帶鏂瑰紡" prop="monitorWay">
-            <el-input v-model="form.monitorWay" size="small" clearable></el-input>
+          <el-form-item label="璐熻矗浜�" prop="responsibleUserId">
+            <el-select v-model="form.responsibleUserId" filterable style="width:100%">
+              <el-option v-for="item in userOptions" :key="item.id" :value="item.id" :label="item.name" />
+            </el-select>
           </el-form-item>
         </el-col>
+        <el-col :span="12">
+          <el-form-item label="浜嬮」绫诲埆" prop="itemKind">
+            <el-select v-model="form.itemKind" style="width: 100%">
+              <el-option label="闈炴娴嬬被" value="OTHER" />
+              <el-option label="妫�娴嬬被" value="INSPECTION" />
+            </el-select>
+          </el-form-item>
+        </el-col>
+        <template v-if="form.itemKind === 'INSPECTION'">
+          <el-col :span="12"><el-form-item label="妫�娴嬫爣鍑�" prop="standardMethodId">
+            <el-select v-model="form.standardMethodId" filterable style="width: 100%" placeholder="璇烽�夋嫨妫�娴嬫爣鍑�" @change="handleStandardChange">
+              <el-option v-for="item in standardOptions" :key="item.id" :value="item.id" :label="`${item.code || ''} ${item.name || ''}`" />
+            </el-select>
+          </el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="鍘熷璁板綍妯℃澘" prop="templateIds">
+            <el-select v-model="form.templateIds" multiple collapse-tags filterable style="width: 100%"
+              :loading="templateBindingLoading" :disabled="!form.standardMethodId"
+              :placeholder="form.standardMethodId ? '璇烽�夋嫨鍘熷璁板綍妯℃澘' : '璇峰厛閫夋嫨妫�娴嬫爣鍑�'"
+              :no-data-text="form.standardMethodId ? '璇ユ娴嬫爣鍑嗘殏鏈粦瀹氬師濮嬭褰曟ā鏉�' : '璇峰厛閫夋嫨妫�娴嬫爣鍑�'">
+              <el-option v-for="item in templateOptions" :key="item.id" :value="item.id" :label="item.name" />
+            </el-select>
+            <div v-if="form.standardMethodId && !templateBindingLoading && templateOptions.length === 0"
+              style="font-size: 12px; line-height: 18px; color: var(--el-color-warning); margin-top: 4px;">
+              璇ユ娴嬫爣鍑嗗湪鏍囧噯搴撲腑灏氭湭缁戝畾鍘熷璁板綍妯℃澘锛岃鍏堝湪鏍囧噯搴撲腑瀹屾垚缁戝畾銆�
+            </div>
+          </el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="鏍峰搧鍚嶇О"><el-input v-model="form.sampleName" /></el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="鏍峰搧瑙勬牸"><el-input v-model="form.sampleSpec" /></el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="妫�娴嬪憳"><el-select v-model="form.inspectorUserId" filterable style="width: 100%">
+            <el-option v-for="item in userOptions" :key="item.id" :value="item.id" :label="item.name" />
+          </el-select></el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="璇勪环浜�"><el-select v-model="form.evaluatorUserId" filterable style="width: 100%">
+            <el-option v-for="item in userOptions" :key="item.id" :value="item.id" :label="item.name" />
+          </el-select></el-form-item></el-col>
+          <el-col :span="12"><el-form-item label="浠诲姟鎴鏃�">
+            <el-date-picker v-model="form.dueDate" type="date" value-format="YYYY-MM-DD" style="width: 100%" />
+          </el-form-item></el-col>
+        </template>
       </el-form>
       <template #footer><span  class="dialog-footer">
 					<el-button @click="closeDia">鍙� 娑�</el-button>
@@ -54,6 +89,10 @@
   addQualityMonitorDetail,
   updateQualityMonitorDetail
 } from "@/api/cnas/process/ensureResults/qualityMonitor";
+import { selectStandardMethodList } from '@/api/cnas/process/method/standardMethod';
+import { selectStandardTemplatePageList } from '@/api/standard/model';
+import { selectTemplateBindingsByStandardMethod } from '@/api/standard/standardLibrary';
+import { selectUserCondition } from '@/api/performance/class';
 
 export default {
   name: 'detailFormDialog',
@@ -66,6 +105,10 @@
       formDia: false,
       form: {
         qualityMonitorDetailsId: '',
+        sortNo: null,
+        technicalStandardText: '',
+        completionMonth: '',
+        responsibleUserId: null,
         monitorPurpose: '',
         plannedTime: '',
         monitorProject: '',
@@ -73,10 +116,28 @@
         budget: '',
         organization: '',
         monitorWay: '',
+        itemKind: 'OTHER',
+        standardMethodId: null,
+        templateId: null,
+        templateIds: [],
+        sampleName: '',
+        sampleSpec: '',
+        inspectorUserId: null,
+        evaluatorUserId: null,
+        dueDate: null,
       },
+      standardOptions: [],
+      allTemplateOptions: [],
+      templateOptions: [],
+      templateBindingLoading: false,
+      userOptions: [],
       rules: {
-        monitorPurpose: [{ required: true, message: '璇疯緭鍏ョ洃鎺х洰鐨�', trigger: 'blur' }],
-        monitorProject: [{ required: true, message: '璇疯緭鍏ョ洃鎺ч」鐩�', trigger: 'blur' }],
+        monitorProject: [{ required: true, message: '璇疯緭鍏ヨ川鎺ч」鐩�', trigger: 'blur' }],
+        technicalStandardText: [{ required: true, message: '璇疯緭鍏ユ妧鏈爣鍑�', trigger: 'blur' }],
+        monitorWay: [{ required: true, message: '璇疯緭鍏ヨ川鎺ф柟寮�', trigger: 'blur' }],
+        completionMonth: [{ required: true, message: '璇烽�夋嫨瀹屾垚鏃堕檺', trigger: 'change' }],
+        responsibleUserId: [{ required: true, message: '璇烽�夋嫨璐熻矗浜�', trigger: 'change' }],
+        templateIds: [{ required: true, type: 'array', min: 1, message: '璇疯嚦灏戦�夋嫨涓�涓師濮嬭褰曟ā鏉�', trigger: 'change' }],
       },
       upLoad: false,
       operationType: '',
@@ -87,17 +148,95 @@
     openDia(type, row) {
       this.formDia = true
       this.operationType = type
+      this.templateOptions = []
+      this.allTemplateOptions = []
+      this.templateBindingLoading = false
+      selectStandardMethodList({ current: 1, size: 1000 }).then(res => { this.standardOptions = res.data?.records || res.data || [] })
+      selectStandardTemplatePageList({ current: 1, size: 1000 }).then(res => { this.allTemplateOptions = res.data?.records || res.data || [] })
+      selectUserCondition({ type: 1 }).then(res => { this.userOptions = res.data || [] })
       if (type === 'edit') {
         this.searchInfo(row)
+        if (row.itemKind === 'INSPECTION' && row.standardMethodId) {
+          this.loadBoundTemplates(row.standardMethodId, this.form.templateIds)
+        }
       }
     },
     searchInfo (row) {
-      this.form = {...row}
+      const templateIds = row.templateIds
+        ? String(row.templateIds).split(',').filter(Boolean).map(id => Number(id))
+        : (row.templateId ? [Number(row.templateId)] : [])
+      this.form = {...row, itemKind: row.itemKind || 'OTHER', templateIds}
+    },
+    handleStandardChange(id) {
+      const standard = this.standardOptions.find(item => Number(item.id) === Number(id))
+      if (standard) this.form.technicalStandardText = `${standard.code || ''} ${standard.name || ''}`.trim()
+      this.form.templateIds = []
+      this.form.templateId = null
+      // 鍜屽鎵樹笅鍗曚繚鎸佷竴鑷达細閫夋嫨妫�娴嬫爣鍑嗗悗锛屽彧灞曠ず璇ユ爣鍑嗗湪鏍囧噯搴撲腑宸茬粦瀹氱殑鍘熷璁板綍妯℃澘
+      this.loadBoundTemplates(id)
+    },
+    loadBoundTemplates(standardMethodId, selectedIds = null) {
+      const currentIds = Array.isArray(selectedIds) ? selectedIds.map(Number) : null
+      this.templateOptions = []
+      if (currentIds === null) this.form.templateIds = []
+      if (!standardMethodId) return
+      this.templateBindingLoading = true
+      selectTemplateBindingsByStandardMethod({ standardMethodId }).then(res => {
+        const bound = (res.data || []).map(item => ({ id: Number(item.templateId), name: item.name }))
+        this.templateOptions = bound
+        if (currentIds === null) {
+          // 鏂板鎴栧垏鎹㈡娴嬫爣鍑嗘椂锛岄粯璁ら�変腑璇ユ爣鍑嗗凡缁戝畾鐨勫叏閮ㄦā鏉�
+          this.form.templateIds = bound.map(item => item.id)
+          return
+        }
+        // 缂栬緫鏃朵繚鐣欏師閫夋嫨锛涜嫢妯℃澘鍚庢潵琚В缁戯紝琛ュ厖鍚嶇О閬垮厤涓嬫媺妗嗗彧鏄剧ず ID
+        const boundIds = new Set(bound.map(item => item.id))
+        currentIds.forEach(id => {
+          if (!boundIds.has(id)) {
+            const template = this.allTemplateOptions.find(item => Number(item.id) === id)
+            if (template) this.templateOptions.push({ id: Number(template.id), name: template.name })
+          }
+        })
+        this.form.templateIds = currentIds
+      }).catch(() => {
+        this.templateOptions = []
+      }).finally(() => {
+        this.templateBindingLoading = false
+      })
+    },
+    buildEntity () {
+      const entity = this.HaveJson(this.form)
+      const templateIds = Array.isArray(this.form.templateIds)
+        ? this.form.templateIds.map(id => Number(id)).filter(id => Number.isInteger(id) && id > 0)
+        : []
+      entity.templateIds = templateIds.join(',') || null
+      entity.templateId = templateIds.length ? templateIds[0] : null
+      entity.reviewerUserId = null
+      return entity
     },
     // 鎻愪氦琛ㄥ崟
     submitForm () {
       this.$refs['form'].validate((valid) => {
         if (valid) {
+          if (this.form.itemKind === 'INSPECTION') {
+            const required = ['standardMethodId','sampleName','inspectorUserId','evaluatorUserId','dueDate']
+            if (required.some(key => !this.form[key])) {
+              this.$message.warning('璇疯ˉ榻愭娴嬫爣鍑嗐�佹ā鏉裤�佹牱鍝併�佹娴嬪憳銆佽瘎浠蜂汉鍜屼换鍔℃埅姝㈡棩')
+              return
+            }
+            if (!Array.isArray(this.form.templateIds) || !this.form.templateIds.length) {
+              this.$message.warning('璇疯嚦灏戦�夋嫨涓�涓師濮嬭褰曟ā鏉�')
+              return
+            }
+            if (this.form.inspectorUserId === this.form.evaluatorUserId) {
+              this.$message.warning('妫�娴嬪憳涓嶈兘鍚屾椂鎷呬换璇勪环浜�')
+              return
+            }
+            if (this.form.dueDate.slice(0, 7) > this.form.completionMonth) {
+              this.$message.warning('浠诲姟鎴鏃ヤ笉鑳芥櫄浜庤鍒掑畬鎴愭湀浠�')
+              return
+            }
+          }
           if (this.operationType === 'add') {
             this.handleAdd()
           } else {
@@ -108,7 +247,7 @@
     },
     // 鎻愪氦鏂板
     handleAdd () {
-      let entity = this.HaveJson(this.form)
+      let entity = this.buildEntity()
       entity.qualityMonitorId = this.qualityMonitorId
       this.upLoad = true
       addQualityMonitorDetail(entity).then(res => {
@@ -122,7 +261,7 @@
     },
     // 鎻愪氦淇敼
     handleEdit () {
-      const entity = this.HaveJson(this.form)
+      const entity = this.buildEntity()
       this.upLoad = true
       updateQualityMonitorDetail(entity).then(res => {
         this.upLoad = false

--
Gitblit v1.9.3