From 19520d076777a22f76477c4b29e1a6e7a3891196 Mon Sep 17 00:00:00 2001 From: 张诺 <zhang_12370@163.com> Date: 星期二, 10 六月 2025 11:48:32 +0800 Subject: [PATCH] 修改方案字段以及接口上传 --- src/views/basicInformation/index.vue | 10 +- src/views/basicInformation/mould/coalQualityMaintenance.vue | 133 ++++++++++++++++++++++++-------------------- 2 files changed, 78 insertions(+), 65 deletions(-) diff --git a/src/views/basicInformation/index.vue b/src/views/basicInformation/index.vue index 9f5927e..c8be716 100644 --- a/src/views/basicInformation/index.vue +++ b/src/views/basicInformation/index.vue @@ -23,16 +23,16 @@ <div> <data-table :loading="loading" :table-data="tableData" :columns="columns" @selection-change="handleSelectionChange" @edit="handleEdit" :show-selection="true" :border="true"> <!-- 瀛楁鍚嶇О鍒楃殑鑷畾涔夋彃妲� - 鏄剧ず涓烘爣绛� --> - <template v-if="tabName === 'coalQualityMaintenance'" #coalFields="{ row }"> - <template v-if="typeof row.coalFields === 'string' && row.coalFields.includes(',')"> - <el-tag v-for="(field, index) in row.coalFields.split(',')" :key="index" type="primary" size="small" + <template v-if="tabName === 'coalQualityMaintenance'" #fieldIds="{ row }"> + <template v-if="typeof row.fieldIds === 'string' && row.fieldIds.includes(',')"> + <el-tag v-for="(field, index) in row.fieldIds.split(',')" :key="index" type="primary" size="small" style="margin-right: 4px; margin-bottom: 2px;"> {{ getFieldDisplayName(field.trim()) }} </el-tag> </template> <template v-else> <el-tag type="primary" size="small"> - {{ getFieldDisplayName(row.coalFields) || '--' }} + {{ getFieldDisplayName(row.fieldIds) || '--' }} </el-tag> </template> </template> @@ -380,7 +380,7 @@ const coalQualityMaintenanceColumns = ref([ { prop: "plan", label: "鏂规鍚嶇О", minWidth: 100 }, { - prop: "coalFields", + prop: "fieldIds", label: "瀛楁鍚嶇О", minWidth: 200, showOverflowTooltip: true, diff --git a/src/views/basicInformation/mould/coalQualityMaintenance.vue b/src/views/basicInformation/mould/coalQualityMaintenance.vue index 4f3dd9f..26fe0ac 100644 --- a/src/views/basicInformation/mould/coalQualityMaintenance.vue +++ b/src/views/basicInformation/mould/coalQualityMaintenance.vue @@ -1,55 +1,25 @@ <!-- 鐓よ川鏂规缁存姢寮圭獥缁勪欢 --> <template> - <el-dialog - v-model="dialogVisible" - :title="title" - width="600" - :close-on-click-modal="false" - :before-close="handleClose" - > + <el-dialog v-model="dialogVisible" :title="title" width="600" :close-on-click-modal="false" + :before-close="handleClose"> <!-- 琛ㄥ崟鍖哄煙 --> - <el-form - ref="formRef" - :model="formData" - :rules="formRules" - label-width="120px" - style="max-width: 400px; margin: 0 auto" - > + <el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px" + style="max-width: 400px; margin: 0 auto"> <!-- 鏂规鍚嶇О杈撳叆妗� --> <el-form-item label="鐓よ川鏂规鍚嶇О" prop="plan"> - <el-input - v-model="formData.plan" - placeholder="璇疯緭鍏ョ叅璐ㄦ柟妗堝悕绉�" - clearable - /> + <el-input v-model="formData.plan" placeholder="璇疯緭鍏ョ叅璐ㄦ柟妗堝悕绉�" clearable /> </el-form-item> <!-- 鐓よ川瀛楁澶氶�変笅鎷夋 --> - <el-form-item label="鐓よ川鏂规绫诲瀷" prop="coalFields"> - <el-select - v-model="formData.coalFields" - placeholder="璇烽�夋嫨鐓よ川鏂规绫诲瀷" - style="width: 100%" - clearable - multiple - > - <el-option - v-for="item in fieldOptions" - :key="item.value" - :label="item.label" - :value="item.value" - /> + <el-form-item label="鐓よ川鏂规绫诲瀷" prop="coalFieldList"> + <el-select v-model="formData.coalFieldList" placeholder="璇烽�夋嫨鐓よ川鏂规绫诲瀷" style="width: 100%" clearable multiple> + <el-option v-for="item in fieldOptions" :key="item.id" :label="item.label" :value="item" /> </el-select> </el-form-item> <!-- 鏂规鎻忚堪鏂囨湰鍩� --> <el-form-item label="鐓よ川鏂规鎻忚堪" prop="schemeDesc"> - <el-input - v-model="formData.schemeDesc" - type="textarea" - placeholder="璇疯緭鍏ョ叅璐ㄦ柟妗堟弿杩�" - :rows="3" - /> + <el-input v-model="formData.schemeDesc" type="textarea" placeholder="璇疯緭鍏ョ叅璐ㄦ柟妗堟弿杩�" :rows="3" /> </el-form-item> <!-- 鎿嶄綔鎸夐挳鍖哄煙 --> @@ -70,7 +40,7 @@ /** 鍏抽棴寮圭獥鍓嶇殑鍥炶皟鍑芥暟 */ beforeClose: { type: Function, - default: () => {}, + default: () => { }, }, /** 琛ㄥ崟鏁版嵁 */ form: { @@ -117,7 +87,7 @@ plan: [ { required: true, message: "璇疯緭鍏ユ柟妗堝悕绉�", trigger: "blur" }, ], - coalFields: [ + coalFieldList: [ { required: true, message: "璇烽�夋嫨鏂规绫诲瀷", trigger: "blur" }, ], }); @@ -148,17 +118,32 @@ */ const initFormData = (newForm) => { formData.value = { ...newForm }; - - // 澶勭悊coalFields瀛楁锛氱紪杈戞椂闇�瑕佸皢瀛楃涓茶浆鎹负鏁扮粍渚涘閫夌粍浠朵娇鐢� + console.log(formData.value) + // 澶勭悊 coalFieldList 瀛楁锛氱紪杈戞椂闇�瑕佸皢瀛楃涓茶浆鎹负鏁扮粍渚涘閫夌粍浠朵娇鐢� if (newForm.coalFields) { if (typeof newForm.coalFields === 'string') { - formData.value.coalFields = parseCoalFields(newForm.coalFields); - } else if (Array.isArray(newForm.coalFields)) { - // 纭繚鏁扮粍涓殑鍊奸兘鏄暟瀛楃被鍨� - formData.value.coalFields = newForm.coalFields - .map(id => parseInt(id)) - .filter(id => !isNaN(id)); + // 灏嗗瓧绗︿覆杞崲涓篒D鏁扮粍锛岀劧鍚庡尮閰嶅搴旂殑閫夐」瀵硅薄 + const ids = parseCoalFields(newForm.coalFields); + formData.value.coalFieldList = ids.map(id => { + const option = fieldOptions.find(opt => opt.value === id); + return option || { fields: `瀛楁${id}`, value: id }; + }); + } else if (Array.isArray(newForm.coalFieldList)) { + // 纭繚鏁扮粍涓殑鍊奸兘鏄纭殑瀵硅薄鏍煎紡 + formData.value.coalFieldList = newForm.coalFieldList.map(item => { + if (typeof item === 'object' && item.value !== undefined) { + return item; + } else { + // 濡傛灉鏄函ID锛岄渶瑕佸尮閰嶅搴旂殑閫夐」 + const id = parseInt(item); + const option = fieldOptions.find(opt => opt.value === id); + return option || { fields: `瀛楁${id}`, value: id }; + } + }); } + } else { + // 濡傛灉娌℃湁 coalFieldList锛屽垵濮嬪寲涓虹┖鏁扮粍 + formData.value.coalFieldList = []; } }; @@ -174,6 +159,7 @@ fieldOptions.push(...data.map(item => ({ label: item.fieldName, value: item.id, + fields:item.fields }))); } else { console.error("鑾峰彇鐓よ川瀛楁鍒楄〃澶辫触", data); @@ -187,9 +173,9 @@ /** * 鐩戝惉琛ㄥ崟鏁版嵁鍙樺寲锛屽疄鐜版暟鎹洖鏄� */ -watch(() => props.form, initFormData, { - deep: true, - immediate: true +watch(() => props.form, initFormData, { + deep: true, + immediate: true }); // ===== 浜嬩欢澶勭悊鍑芥暟 ===== @@ -198,15 +184,43 @@ */ const submitForm = async () => { if (!formRef.value) return; - - try { - const isValid = await formRef.value.validate(); - if (!isValid) return; - // 鍑嗗鎻愪氦鏁版嵁锛氬皢coalFields鏁扮粍杞崲涓哄瓧绗︿覆 - const submitData = { + // 鍒濆鍖栧瓧娈垫暟缁� + formData.value.fieldIds = []; + formData.value.coalFields = []; + + // 瀹夊叏澶勭悊 coalFieldList 鏁版嵁 + if (formData.value.coalFieldList && Array.isArray(formData.value.coalFieldList)) { + formData.value.coalFieldList.forEach((element) => { + // 妫�鏌ュ厓绱犳槸鍚︿负瀵硅薄骞朵笖鏈夊繀瑕佺殑灞炴�� + if (element && typeof element === 'object') { + if (element.value !== undefined) { + formData.value.fieldIds.push(element.value); + } + if (element.fields !== undefined) { + formData.value.coalFields.push(element.fields); + } + } else { + // 濡傛灉鍏冪礌鏄畝鍗曞�硷紝鐩存帴浣跨敤 + formData.value.fieldIds.push(element); + // 灏濊瘯浠� fieldOptions 涓壘鍒板搴旂殑 label + const option = fieldOptions.find(opt => opt.value === element); + if (option) { + formData.value.coalFields.push(option.fields); + } + } + }); + } + + // 鍒犻櫎涓存椂瀛楁 + delete formData.value.coalFieldList; + + try { + // 鍑嗗鎻愪氦鏁版嵁锛氬皢鏁扮粍杞崲涓哄瓧绗︿覆 + const submitData = { ...formData.value, - coalFields: stringifyCoalFields(formData.value.coalFields) + coalFields: stringifyCoalFields(formData.value.coalFields), + fieldIds: stringifyCoalFields(formData.value.fieldIds) }; // 鍒犻櫎涓嶉渶瑕佺殑鏃堕棿瀛楁锛堢紪杈戞椂锛� @@ -224,7 +238,6 @@ ...submitData, result }; - emit("submit", responseData); } catch (error) { console.error("琛ㄥ崟鎻愪氦澶辫触", error); -- Gitblit v1.9.3