From 7619d415522ab3dc3299d6a2a9f5c9964a692d3f Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期三, 18 六月 2025 17:58:53 +0800
Subject: [PATCH] 添加生产管理接口及优化表格字段
---
src/views/basicInformation/mould/coal.vue | 277 +++++++++++++++++++++++++++++++------------------------
1 files changed, 155 insertions(+), 122 deletions(-)
diff --git a/src/views/basicInformation/mould/coal.vue b/src/views/basicInformation/mould/coal.vue
index 0a999c2..a0454a3 100644
--- a/src/views/basicInformation/mould/coal.vue
+++ b/src/views/basicInformation/mould/coal.vue
@@ -1,131 +1,164 @@
<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.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 +167,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