Browse Source

[Mod 0000] 更新瓦斯评判参数的api调用逻辑

houzekong 8 months ago
parent
commit
9964bdb5e5

+ 4 - 4
src/views/vent/gas/gasPumpSetting/components/settingForm.vue

@@ -33,7 +33,7 @@
       </BasicForm>
     </div>
     <div class="text-right">
-      <Button class="mr-10px setting-form__button" type="primary" ghost @click="cancel">取消</Button>
+      <!-- <Button class="mr-10px setting-form__button" type="primary" ghost @click="cancel">取消</Button> -->
       <Button class="mr-10px setting-form__button" type="primary" ghost @click="calculate">计算</Button>
       <Button class="mr-10px setting-form__button" type="primary" ghost @click="submit">提交</Button>
     </div>
@@ -72,9 +72,9 @@
     };
   }
 
-  function cancel() {
-    emit('cancel');
-  }
+  // function cancel() {
+  //   emit('cancel');
+  // }
   function calculate() {
     Promise.all([submitWSForm(), submitEUForm()]).then(() => {
       emit('calculate', { ...props.model, ...formData.value });

+ 20 - 6
src/views/vent/gas/gasPumpSetting/index.vue

@@ -7,24 +7,38 @@
 <script lang="ts" setup>
   import CustomHeader from '/@/components/vent/customHeader.vue';
   import SettingForm from './components/settingForm.vue';
-  import { getGasDrainageParamList, updateGasDrainageParam, createParam } from './gasPumpSetting.api';
+  import { getGasDrainageParamList, updateGasDrainageParam, createParam, addGasDrainageParam } from './gasPumpSetting.api';
   import { ref } from 'vue';
   import { message } from 'ant-design-vue';
   import { onMounted } from 'vue';
 
   const formModel = ref<any>({});
+  // 判断是否已经存在评判参数,没有的话需要新建
+  let paramsExists = true;
 
   function refresh() {
     getGasDrainageParamList({}).then(({ records }) => {
-      formModel.value = records[0];
+      if (records[0]) {
+        formModel.value = records[0];
+      } else {
+        paramsExists = false;
+      }
     });
   }
 
   function submit(formData) {
-    updateGasDrainageParam(formData).then(() => {
-      message.success('修改成功');
-      refresh();
-    });
+    if (paramsExists) {
+      updateGasDrainageParam(formData).then(() => {
+        message.success('修改成功');
+        refresh();
+      });
+    } else {
+      addGasDrainageParam(formData).then(() => {
+        message.success('新建成功');
+        paramsExists = true;
+        refresh();
+      });
+    }
   }
 
   function calculate(formData) {