From 4076c14a8eac96cd716522f2cb15dcda0eb4fcef Mon Sep 17 00:00:00 2001
From: 马宇豪 <978517621@qq.com>
Date: 星期三, 10 四月 2024 08:37:53 +0800
Subject: [PATCH] 新修改

---
 src/views/basicDataManage/gasManage/component/gasDialog.vue |   73 +++++++++++++++++++++++++++++++++---
 1 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/src/views/basicDataManage/gasManage/component/gasDialog.vue b/src/views/basicDataManage/gasManage/component/gasDialog.vue
index 1878d0a..b392507 100644
--- a/src/views/basicDataManage/gasManage/component/gasDialog.vue
+++ b/src/views/basicDataManage/gasManage/component/gasDialog.vue
@@ -5,7 +5,7 @@
             v-model="state.isShowUserDialog"
             width="500px"
         >
-            <el-form :model="state.gasForm" size="default" ref="gasRef" :rules="state.gasFormRules" label-width="110px">
+            <el-form :model="state.gasForm" size="default" ref="gasRef" :rules="state.title == '新增气体'  || state.title == '编辑气体'? state.gasFormRules : ''" label-width="110px">
                 <el-form-item label="气体名称:" prop="gasName">
                     <el-input v-model.trim="state.gasForm.gasName" :disabled="state.disabled" ></el-input>
                 </el-form-item>
@@ -32,6 +32,8 @@
 <script setup lang="ts">
 import {reactive, ref} from "vue";
 import { GasState } from "/@/types/gasManage";
+import {gasManageApi} from "/@/api/basicDataManage/gasManage";
+import {ElMessage} from "element-plus";
 
 const gasRef = ref();
 const emit = defineEmits(["getGasData"]);
@@ -40,6 +42,7 @@
     title: '',
     isShowUserDialog: false,
     gasForm: {
+        id: '',
         gasName: '',
         gasMolecularFormula: '',
         gasThreshold: '',
@@ -58,21 +61,79 @@
         state.disabled = false;
         state.title = '新增气体';
         state.gasForm = {
+            id: '',
             gasName: '',
             gasMolecularFormula: '',
             gasThreshold: '',
             gasUnit: ''
         };
+    } else if (type === '编辑'){
+        state.disabled = false;
+        state.title = '编辑气体';
+        state.gasForm = JSON.parse(JSON.stringify(value));
     } else {
         state.disabled = true;
         state.title = '查看气体';
         state.gasForm = JSON.parse(JSON.stringify(value));
     }
 };
-const onSubmit = () => {
-    gasRef.value.clearValidate();
-    state.isShowUserDialog = false;
-    emit('getGasData');
+const onSubmit = async () => {
+        if(state.title == '新增气体'){
+            const valid = await gasRef.value.validate();
+            if(valid) {
+                const param = {
+                    molecularFormula: state.gasForm.gasMolecularFormula,
+                    name: state.gasForm.gasName,
+                    unit: state.gasForm.gasUnit,
+                    threshold: state.gasForm.gasThreshold
+                }
+                let res = await gasManageApi().addGas(param);
+                if (res.data.code === 100) {
+                    ElMessage({
+                        type: 'success',
+                        message: '新增成功'
+                    });
+                    gasRef.value.clearValidate();
+                    state.isShowUserDialog = false;
+                    emit('getGasData');
+                } else {
+                    ElMessage({
+                        type: 'warning',
+                        message: res.data.msg
+                    });
+                }
+            }
+        }else if(state.title == '编辑气体') {
+          const valid = await gasRef.value.validate();
+          if(valid) {
+            const param = {
+              id: state.gasForm.id,
+              molecularFormula: state.gasForm.gasMolecularFormula,
+              name: state.gasForm.gasName,
+              unit: state.gasForm.gasUnit,
+              threshold: state.gasForm.gasThreshold
+            }
+            let res = await gasManageApi().editGas(param);
+            if (res.data.code === 100) {
+              ElMessage({
+                type: 'success',
+                message: '编辑成功'
+              });
+              gasRef.value.clearValidate();
+              state.isShowUserDialog = false;
+              emit('getGasData');
+            } else {
+              ElMessage({
+                type: 'warning',
+                message: res.data.msg
+              });
+            }
+          }
+        } else {
+            gasRef.value.clearValidate();
+            state.isShowUserDialog = false;
+            emit('getGasData');
+        }
 };
 
 const handleClose = () => {
@@ -87,4 +148,4 @@
 </script>
 <style scoped lang="scss">
 
-</style>
\ No newline at end of file
+</style>

--
Gitblit v1.9.2