From dd159ea51a7a77bd8cc00c70c0e900f472fb3395 Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期四, 05 六月 2025 18:00:17 +0800
Subject: [PATCH] 完善基础管理 供应商、客户、煤种等功能

---
 src/views/basicInformation/mould/coal.vue |  279 +++++++++++++++++++++++++++++++------------------------
 1 files changed, 157 insertions(+), 122 deletions(-)

diff --git a/src/views/basicInformation/mould/coal.vue b/src/views/basicInformation/mould/coal.vue
index 0a999c2..ae905ed 100644
--- a/src/views/basicInformation/mould/coal.vue
+++ b/src/views/basicInformation/mould/coal.vue
@@ -1,131 +1,166 @@
 <template>
-  <div>
-    <el-dialog
-      v-model="dialogVisible"
-      :title="title"
-      width="800"
-      :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="supplierName">
-          <el-input
-            v-model="formData.supplierName"
-            placeholder="璇疯緭鍏ヤ緵璐у晢鍚嶇О"
-          />
-        </el-form-item>
-        <el-form-item label="绾崇◣浜鸿瘑鍒彿" prop="identifyNumber">
-          <el-input
-            v-model="formData.identifyNumber"
-            placeholder="璇疯緭鍏ョ撼绋庝汉璇嗗埆鍙�"
-          />
-        </el-form-item>
-        <el-form-item label="缁忚惀鍦板潃" prop="address">
-          <el-select v-model="formData.address" placeholder="璇烽�夋嫨缁忚惀鍦板潃">
-            <el-option label="Zone one" value="shanghai" />
-            <el-option label="Zone two" value="beijing" />
-          </el-select>
-        </el-form-item>
-        <el-form-item label="閾惰璐︽埛" prop="bankAccount">
-          <el-input
-            v-model="formData.bankAccount"
-            placeholder="璇疯緭鍏ラ摱琛岃处鎴�"
-          />
-        </el-form-item>
-        <el-form-item>
-          <el-button type="primary" @click="submitForm"> 纭畾 </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 { 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: "",
-  },
-});
-
-const emit = defineEmits([
-  "submit",
-  "handleBeforeClose",
-  "update:coalDialogFormVisible",
-]);
-
-// 琛ㄥ崟寮曠敤
-const formRef = ref(null);
-// 琛ㄥ崟鏁版嵁
-const formData = ref({ ...props.form });
-// 寮圭獥鍙鎬�
-const dialogVisible = defineModel("coalDialogFormVisible", {
+    beforeClose: {
+        type: Function,
+        default: () => {}
+    },
+    form: {
+        type: Object,
+        default: () => ({})
+    },
+    addOrEdit: {
+        type: String,
+        default: 'add'
+    },
+    title: {
+        type: String,
+        default: ''
+    },
+})
+const copyForm = defineModel("copyForm", {
   required: true,
-  type: Boolean,
+  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 formRef = ref(null)
+// 琛ㄥ崟鏁版嵁
+const formData = ref({ ...props.form })
+// 寮圭獥鍙鎬�
+const dialogVisible = defineModel("coalDialogFormVisible",{required:true,type:Boolean})
 
 // 鐩戝惉澶栭儴浼犲叆鐨勮〃鍗曟暟鎹彉鍖�
-watch(
-  () => props.form,
-  (newVal) => {
-    formData.value = { ...newVal };
-  },
-  { deep: true }
-);
+watch(() => props.form, (newVal) => {
+    formData.value = { ...newVal }
+    // 濡傛灉鏄柊澧炴ā寮忥紝璁剧疆缁存姢浜�
+    if (props.addOrEdit === 'add' && userStore.id) {
+        formData.value.maintainerId = userStore.id
+    }
+}, { deep: true })
 
 // 鐩戝惉鍐呴儴寮圭獥鐘舵�佸彉鍖�
-watch(
-  () => dialogVisible.value,
-  (newVal) => {
-    emit("update:coalDialogFormVisible", newVal);
-  }
-);
+watch(() => dialogVisible.value, (newVal) => {
+    emit('update:coalDialogFormVisible', newVal)
+})
 
 // 鎻愪氦琛ㄥ崟
 const submitForm = async () => {
-  if (!formRef.value) return;
-  await formRef.value.validate((valid, fields) => {
-    if (valid) {
-      emit("submit", formData.value);
-    }
-  });
-};
+    if (!formRef.value) return
+    await formRef.value.validate(async (valid, fields) => {
+        if (valid) {
+            delete formData.value.createTime
+            delete formData.value.updateTime
+            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" },
@@ -134,22 +169,22 @@
     { 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" },
-  ],
 });
+// 鑾峰彇褰撳墠鏃ユ湡骞舵牸寮忓寲涓� 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