From 3d9d458e631d8d6a070d579b2e3e260aea45ac58 Mon Sep 17 00:00:00 2001
From: zhang_12370 <z2864490065@outlook.com>
Date: 星期二, 24 六月 2025 13:54:51 +0800
Subject: [PATCH] 优化文档管理 优化采购管理渲染数据匹配接口字段 上传第一版主页

---
 src/views/basicInformation/mould/coal.vue |  256 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 152 insertions(+), 104 deletions(-)

diff --git a/src/views/basicInformation/mould/coal.vue b/src/views/basicInformation/mould/coal.vue
index b31e8bb..36e599e 100644
--- a/src/views/basicInformation/mould/coal.vue
+++ b/src/views/basicInformation/mould/coal.vue
@@ -1,145 +1,193 @@
 <template>
-    <div>
-        <el-dialog
-            v-model="dialogVisible"
-            :title="title"
-            width="500"
-            :close-on-click-modal="false"
-            :before-close="handleClose"
-        >
-            <el-form
-                ref="formRef"
-                style="max-width: 600px; margin: 0 auto"
-                :model="formData"
-                :rules="rules"
-                label-width="auto"
-            >
-                <el-form-item label="鐓ょ鍚嶇О" prop="coal">
-                    <el-input
-                        v-model="formData.coal"
-                        placeholder="璇疯緭鍏ョ叅绉嶅悕绉�"
-                    />
-                </el-form-item>
-                <el-form-item label="缁存姢浜哄鍚�" prop="maintainerId">
-                    <el-input
-                        v-model="formData.maintainerId"
-                        placeholder="璇疯緭鍏ョ淮鎶や汉濮撳悕"
-                    />
-                </el-form-item>
-                <el-form-item label="缁存姢鏃ユ湡" prop="maintenanceDate">
-                    <el-input v-model="formData.maintenanceDate" placeholder="璇疯緭鍏ラ摱琛岃处鎴�" />
-                </el-form-item>
-                <el-form-item>
-                    <el-button type="primary" @click="submitForm">
-                        纭畾
-                    </el-button>
-                    <el-button v-if="addOrEdit === 'edit'" @click="resetForm">閲嶇疆</el-button>
-                    <el-button v-if="addOrEdit === 'add'" @click="cancelForm">鍙栨秷</el-button>
-                </el-form-item>
-            </el-form>
-        </el-dialog>
-    </div>
+  <div>
+    <el-dialog
+        v-model="dialogVisible"
+        :title="title"
+        width="500"
+        :close-on-click-modal="false"
+        :before-close="handleClose"
+    >
+      <el-form
+          ref="formRef"
+          style="max-width: 600px; margin: 0 auto"
+          :model="formData"
+          :rules="rules"
+          label-width="120px"
+      >
+        <el-form-item label="鐓ょ鍚嶇О" prop="coal">
+          <el-input
+              v-model="formData.coal"
+              placeholder="璇疯緭鍏ョ叅绉嶅悕绉�"
+          />
+        </el-form-item>
+        <el-form-item label="缁存姢浜哄鍚�" prop="maintainerId">
+          <el-input
+              :value="userStore.name || ''"
+              placeholder="缁存姢浜哄鍚�"
+              disabled
+          />
+        </el-form-item>
+        <el-form-item label="缁存姢鏃ユ湡" prop="maintenanceDate">
+          <el-input
+              :value="getCurrentDate()"
+              placeholder="缁存姢鏃ユ湡"
+              disabled
+          />
+        </el-form-item>
+
+        <el-form-item class="dialog-footer">
+          <el-button v-if="addOrEdit === 'edit'" @click="resetForm">閲嶇疆</el-button>
+          <el-button v-if="addOrEdit === 'add'" @click="cancelForm">鍙栨秷</el-button>
+          <el-button type="primary" @click="submitForm">
+            纭畾
+          </el-button>
+        </el-form-item>
+      </el-form>
+    </el-dialog>
+  </div>
 </template>
 
 <script setup>
-import { ref, watch ,defineProps } from 'vue'
-import { addOrEditCoalInfo } from '@/api/basicInformation/coal'
+import {ref, watch, defineProps, reactive, onMounted} from 'vue'
+import {addOrEditCoalInfo} from '@/api/basicInformation/coal'
+import useUserStore from '@/store/modules/user'
+
+const userStore = useUserStore()
 
 const props = defineProps({
-    beforeClose: {
-        type: Function,
-        default: () => {}
-    },
-    form: {
-        type: Object,
-        default: () => ({})
-    },
-    addOrEdit: {
-        type: String,
-        default: 'add'
-    },
-    title: {
-        type: String,
-        default: ''
-    },
+  beforeClose: {
+    type: Function,
+    default: () => {
+    }
+  },
+  form: {
+    type: Object,
+    default: () => ({})
+  },
+  addOrEdit: {
+    type: String,
+    default: 'add'
+  },
+  title: {
+    type: String,
+    default: ''
+  },
+})
+const copyForm = defineModel("copyForm", {
+  required: true,
+  type: Object,
+});
+// 鍦ㄧ粍浠舵寕杞芥椂鑾峰彇鐢ㄦ埛淇℃伅
+onMounted(async () => {
+  // 濡傛灉store涓病鏈夌敤鎴蜂俊鎭紝鍒欒幏鍙栫敤鎴蜂俊鎭�
+  if (!userStore.name) {
+    try {
+      await userStore.getInfo()
+      // 鑷姩濉厖缁存姢浜篒D
+      if (props.addOrEdit === 'add') {
+        formData.value.maintainerId = userStore.id
+      }
+    } catch (error) {
+      console.error('鑾峰彇鐢ㄦ埛淇℃伅澶辫触:', error)
+    }
+  } else {
+    // 鑷姩濉厖缁存姢浜篒D
+    if (props.addOrEdit === 'add') {
+      formData.value.maintainerId = userStore.id
+    }
+  }
 })
 
-const emit = defineEmits(['submit', 'handleBeforeClose','update:coalDialogFormVisible'])
-
+const emit = defineEmits(['submit', 'handleBeforeClose', 'update:coalDialogFormVisible'])
 // 琛ㄥ崟寮曠敤
 const formRef = ref(null)
 // 琛ㄥ崟鏁版嵁
-const formData = ref({ ...props.form })
+const formData = ref({...props.form})
 // 寮圭獥鍙鎬�
-const dialogVisible = defineModel("coalDialogFormVisible",{required:true,type:Boolean})
+const dialogVisible = defineModel("coalDialogFormVisible", {required: true, type: Boolean})
 
 // 鐩戝惉澶栭儴浼犲叆鐨勮〃鍗曟暟鎹彉鍖�
 watch(() => props.form, (newVal) => {
-    formData.value = { ...newVal }
-}, { deep: true })
+  formData.value = {...newVal}
+  // 濡傛灉鏄柊澧炴ā寮忥紝璁剧疆缁存姢浜�
+  if (props.addOrEdit === 'add' && userStore.id) {
+    formData.value.maintainerId = userStore.id
+  }
+}, {deep: true})
 
 // 鐩戝惉鍐呴儴寮圭獥鐘舵�佸彉鍖�
 watch(() => dialogVisible.value, (newVal) => {
-    emit('update:coalDialogFormVisible', newVal)
+  emit('update:coalDialogFormVisible', newVal)
 })
 
 // 鎻愪氦琛ㄥ崟
 const submitForm = async () => {
-    if (!formRef.value) return
-    await formRef.value.validate(async (valid, fields) => {
-        if (valid) {
-            formData.value.maintenanceDate = "2023-10-01" // 绀轰緥鏃ユ湡
-            let result = await addOrEditCoalInfo({
-                ...formData.value,
-            })
-            let obj = {
-                title: props.title,
-                result,
-            }
-            emit('submit', obj)
-        }
-    })
+  if (!formRef.value) return
+  await formRef.value.validate(async (valid, fields) => {
+    if (valid) {
+      delete formData.value.maintainerName // 鍒犻櫎鏄剧ず鐢ㄧ殑瀛楁锛屽彧淇濈暀ID
+
+      // 纭繚maintainerId鏈夊��
+      if (!formData.value.maintainerId) {
+        formData.value.maintainerId = userStore.id
+      }
+
+      // 璁剧疆缁存姢鏃ユ湡
+      formData.value.maintenanceDate = getCurrentDate()
+
+      let result = await addOrEditCoalInfo({
+        ...formData.value,
+      })
+      let obj = {
+        title: props.title,
+        result,
+      }
+      emit('submit', obj)
+    }
+  })
 }
 // 鍙栨秷琛ㄥ崟
 const cancelForm = () => {
-    emit('update:coalDialogFormVisible', false)
-    formData.value = {}
+  emit('update:coalDialogFormVisible', false)
+  formData.value = {}
 }
 // 閲嶇疆琛ㄥ崟
 const resetForm = () => {
-    if (!formRef.value) return
-    formRef.value.resetFields()
+  if (!formRef.value) return
+  formData.value = JSON.parse(JSON.stringify(copyForm.value));
+  // formRef.value.resetFields()
 }
 // 鍏抽棴寮圭獥
 const handleClose = () => {
-    // 瑙﹀彂鐖剁粍浠剁殑鍏抽棴鍑芥暟
-    emit("handleBeforeClose")
-    emit('update:coalDialogFormVisible', false)
+  // 瑙﹀彂鐖剁粍浠剁殑鍏抽棴鍑芥暟
+  emit("handleBeforeClose")
+  emit('update:coalDialogFormVisible', false)
 }
 const rules = reactive({
   supplierName: [
-    { required: true, message: "璇疯緭鍏ヤ緵璐у晢鍚嶇О", trigger: "blur" },
+    {required: true, message: "璇疯緭鍏ヤ緵璐у晢鍚嶇О", trigger: "blur"},
   ],
   identifyNumber: [
-    { required: true, message: "璇锋纭緭鍏ョ撼绋庝汉璇嗗埆鍙�", trigger: "blur" },
-    { min: 17, max: 20, message: "璇疯緭鍏�17-20浣嶇撼绋庝汉璇嗗埆鍙�", trigger: "blur" },
-  ],
-  address: [
-    {
-      required: true,
-      message: "璇烽�夋嫨缁忚惀鍦板潃",
-      trigger: "change",
-    },
-  ],
-  bankAccount: [{ required: true, message: "璇疯緭鍏ラ摱琛岃处鎴�", trigger: "blur" }],
-  bank: [{ required: true, message: "璇疯緭鍏ュ紑鎴疯", trigger: "blur" }],
-  contacts: [{ required: true, message: "璇疯緭鍏ュ紑鎴疯", trigger: "blur" }],
-  contactsPhone: [
-    { required: true, message: "璇疯緭鍏ヨ仈绯讳汉", trigger: "blur" },
-    { min: 11, max: 11, message: "璇疯緭鍏�11浣嶈仈绯讳汉鐢佃瘽", trigger: "blur" },
+    {required: true, message: "璇锋纭緭鍏ョ撼绋庝汉璇嗗埆鍙�", trigger: "blur"},
+    {min: 17, max: 20, message: "璇疯緭鍏�17-20浣嶇撼绋庝汉璇嗗埆鍙�", trigger: "blur"},
   ],
 });
+
+// 鑾峰彇褰撳墠鏃ユ湡骞舵牸寮忓寲涓� YYYY-MM-DD
+function getCurrentDate() {
+  const today = new Date();
+  const year = today.getFullYear();
+  const month = String(today.getMonth() + 1).padStart(2, '0'); // 鏈堜唤浠�0寮�濮�
+  const day = String(today.getDate()).padStart(2, '0');
+  return `${year}-${month}-${day}`;
+}
 </script>
 
-<style lang="sass" scoped>
+<style lang="scss" scoped>
+.dialog-footer {
+  display: flex;
+  margin-top: 20px;
+  flex-direction: column;
+  align-items: flex-end;
+}
 </style>
\ No newline at end of file

--
Gitblit v1.9.3