独墅湖高教创新区危化品智慧管控平台(新危化品)
zhouwx
2025-04-17 a8593f5ca77a934b31bbdd3b919d8e41796cb920
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
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="500px"
        :before-close="handleClose"
        :close-on-press-escape="false"
        :close-on-click-modal="false"
    >
      <el-form :model="state.form" size="default" ref="busRef" :rules="state.formRules" label-width="150px" >
        <el-form-item label="种类:" prop="peculiarityType" >
          <el-input v-model.trim="state.form.peculiarityType" placeholder="请输入种类"></el-input>
        </el-form-item>
        <el-form-item label="编号:" prop="peculiarityNumber" >
          <el-input v-model.trim="state.form.peculiarityNumber" oninput="value=value.replace(/^\.+|[^\d]/g,'')" placeholder="请输入编号"></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" v-preReClick>确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>
<script setup>
import {reactive, ref, toRefs} from 'vue'
import {ElMessage} from "element-plus";
import {addWarehouse, checkName, editWarehouse} from "@/api/hazardousChemicals/warehouse";
import {verifyPhone} from "@/utils/validate";
import {checkBasicName} from "@/api/hazardousChemicals/basicInfo";
import {addCharacteristic, editCharacteristic} from "@/api/hazardousChemicals/characteristic";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const startUsername = ref('');
const state = reactive({
  form: {
    id: '',
    peculiarityType: '',
    peculiarityNumber: null
 
  },
  formRules:{
    peculiarityType: [{ required: true, trigger: "blur", message: '请输入种类', }],
    peculiarityNumber: [{ required: true, message: '请输入编号', trigger: 'blur' }],
  },
})
 
 
const openDialog = async (type, value) => {
 
  title.value = type === 'add' ? '新增种类' : type ==='edit' ? '编辑种类':'' ;
  if(type === 'edit' ) {
    state.form = JSON.parse(JSON.stringify(value));
    startUsername.value = value.username
  }
  dialogVisible.value = true;
}
 
const onSubmit = async () => {
  const valid = await busRef.value.validate();
  if(valid){
    if(title.value === '新增种类'){
      const {id, ...data} = JSON.parse(JSON.stringify(state.form))
      const res = await addCharacteristic(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '新增成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }else if(title.value === '编辑种类'){
      const {createBy,createTime,delFlag,...data} = JSON.parse(JSON.stringify(state.form))
      const res = await editCharacteristic(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }
  }
}
 
const handleClose = () => {
  busRef.value.clearValidate();
  reset();
  dialogVisible.value = false;
  emit("getList")
}
const reset = () => {
  state.form = {
    id: '',
    peculiarityType: '',
    peculiarityNumber: null
  }
}
defineExpose({
  openDialog
});
 
</script>
 
<style scoped lang="scss">
.notice{
  :deep(.el-form .el-form-item__label) {
    font-size: 15px;
  }
  .file {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
}
</style>