zhouwx
2024-12-25 c53fc4edf8587a1ba44d5a57139baee3dcaba0b0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
  <div class="system-add-gas-container">
    <el-dialog
        :title="state.title"
        v-model="state.isShowUserDialog"
        width="500px"
    >
      <el-form :model="state.gasForm" size="default" ref="gasRef" :rules="state.gasFormRules" label-width="110px">
        <el-form-item label="方位:" prop="orientation">
          <el-select
              v-model="state.gasForm.orientation"
              class="w100"
              style="width: 100%"
              size="default"
          >
            <el-option v-for="item in state.positionList" :key="item.label" :label="item.value" :value="item.label"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="本底浓度:" prop="concentration">
          <el-input v-model.trim="state.gasForm.concentration" placeholder="请输入本底浓度" :disabled="state.disabled" @input="checkTextInput($event)"></el-input>
        </el-form-item>
        <el-form-item label="倍增系数:" prop="multiplication">
          <el-input v-model.trim="state.gasForm.multiplication" placeholder="请输入倍增系数" :disabled="state.disabled"  @input="state.gasForm.multiplication= state.gasForm.multiplication.replace(/[^0-9]/g,'')"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
            <el-button @click="handleClose" size="default">取 消</el-button>
            <el-button type="primary"  @click="onSubmit" size="default">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
 
<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";
import {verifyAndSpace, verifyNumberIntegerAndFloat} from "/@/utils/toolsValidate";
 
const gasRef = ref();
const emit = defineEmits(["getGasData"]);
const state = reactive<GasState>({
  disabled: false,
  title: '',
  isShowUserDialog: false,
  gasForm: {
    id: null,
    gasCategoryId: null,
    orientation: '',
    concentration: '',
    multiplication: '',
  },
  gasFormRules:{
    concentration: [{ required: true, message: '请填写本底浓度', trigger: 'blur' }],
    multiplication: [{ required: true, message: '请填写倍增系数', trigger: 'blur' }],
    orientation: [{ required: true, message: '请选择方位', trigger: 'blur' }],
  },
  positionList: [
    {
      value: '方位1',
      label: 1
    },
    {
      value: '方位2',
      label: 2
    },
    {
      value: '方位3',
      label: 3
    },
  ],
});
const openDialog = (type: string, value: any) => {
  state.isShowUserDialog = true;
  state.gasForm.gasCategoryId = value.id
  if (type === '新增') {
    state.disabled = false;
    state.title = '新增参数配置';
    state.gasForm = {
      id: null,
      gasCategoryId: value.id,
      orientation: '',
      concentration: '',
      multiplication: '',
    };
  } else if (type === '编辑'){
    state.disabled = false;
    state.title = '编辑参数配置';
    state.gasForm = JSON.parse(JSON.stringify(value));
  }
};
const onSubmit = async () => {
  if(state.title == '新增参数配置'){
    const valid = await gasRef.value.validate();
    if(valid) {
      const {id,...data} = state.gasForm
      let res = await gasManageApi().addGasConfig(data);
      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 {...data} = state.gasForm
      let res = await gasManageApi().editGasConfig(data);
      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 = () => {
  gasRef.value.clearValidate();
  state.isShowUserDialog = false;
  emit('getGasData');
}
 
const  checkTextInput = (val:any) => {
  state.gasForm.concentration = verifyNumberIntegerAndFloat(val);
}
defineExpose({
  openDialog
});
</script>
<style scoped lang="scss">
 
</style>