独墅湖高教创新区危化品智慧管控平台(新危化品)
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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<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="companyName" >
          <el-select
              clearable
              v-model="state.form.companyName"
              filterable
              remote
              @change="selectValue"
              reserve-keyword
              placeholder="请输入企业名称"
              remote-show-suffix
              :remote-method="getCompanyList"
              style="width: 100%"
          >
            <el-option
                v-for="item in state.companyList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="是否使用成品:" prop="useProd" >
          <el-radio-group v-model="state.form.useProd">
            <el-radio :label="0">不使用</el-radio>
            <el-radio :label="1">使用</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="logo:" prop="logoPath" >
          <el-upload accept="image/*" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.imgLimit' v-model:file-list="state.imgList" list-type="picture-card" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" >
            <el-icon><Plus /></el-icon>
            <template #tip>
              <div class="el-upload__tip">上传jpg/png图片尺寸小于5M,最多可上传1张,建议宽度30px左右。</div>
            </template>
          </el-upload>
        </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 {addConfig, editConfig} from "@/api/hazardousChemicals/config";
import {getCompany} from "@/api/hazardousChemicals/company";
import {getToken} from "@/utils/auth";
import {delPic} from "@/api/hazardousChemicals/config";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const state = reactive({
  form: {
    id: '',
    companyId: null,
    companyName: '',
    logoPath: '',
    useProd: 0
 
  },
  companyList: [],
  formRules:{
    companyName: [{ required: true, message: '请选择企业', trigger: 'blur' }],
    useProd: [{ required: true, message: '请选择是否使用成品', trigger: 'blur' }],
  },
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
  header: {
    Authorization:getToken()
  },
  imgList: [],
  imgLimit: 1,
})
 
 
const openDialog = async (type, value) => {
  await getCompanyList("")
  title.value = type === 'add' ? '新增配置' : type ==='edit' ? '编辑配置':'' ;
  if(type === 'edit' ) {
    state.form = JSON.parse(JSON.stringify(value));
    if(value.logoPath) {
      const obj = {
        url: import.meta.env.VITE_APP_BASE_API + "/" +  value.logoPath,
        name: ''
      }
      state.imgList = [obj]
    }
  }
  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 addConfig(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 {...data} = JSON.parse(JSON.stringify(state.form))
      const res = await editConfig(data)
      if(res.code === 200){
        ElMessage({
          type: 'success',
          message: '编辑成功'
        });
      }else{
        ElMessage.warning(res.message)
      }
      emit("getList")
      busRef.value.clearValidate();
      reset();
      dialogVisible.value = false;
    }
  }
}
 
const selectValue =  (val) => {
  state.companyList.forEach(item => {
    if(item.name === val){
      state.form.companyId = item.id
    }
  })
}
const getCompanyList = async (val)=>{
  if(val != ""){
    const queryParams = {
      name: val
    }
    const res = await getCompany(queryParams)
    if (res.code == 200) {
      state.companyList = res.data.list
 
    } else {
      ElMessage.warning(res.message)
    }
  }else {
 
    const queryParams = {
      pageNum: 1,
      pageSize: 10
    }
    const res = await getCompany(queryParams)
    if (res.code == 200) {
      state.companyList = res.data.list
 
    } else {
      ElMessage.warning(res.message)
    }
  }
}
const handleClose = () => {
  busRef.value.clearValidate();
  reset();
  dialogVisible.value = false;
  emit("getList")
}
 
const showTip =()=>{
  ElMessage({
    type: 'warning',
    message: '超出文件上传数量'
  });
}
const picSize = async (rawFile) => {
  if(rawFile.size / 1024 / 1024 > 5){
    ElMessage({
      type: 'warning',
      message: '文件大小不能超过5M'
    });
    return false
  }
};
const handleAvatarSuccess = (res, uploadFile) => {
  if(res.code == 200){
    state.form.logoPath = res.data.path
  }else{
    state.imgList = []
    ElMessage({
      type: 'warning',
      message: '文件上传失败'
    })
  }
}
const handleRemove = async (file, uploadFiles) => {
  let path = state.form.logoPath;
  await delPic({path: path}).then(res => {
    if(res.code == 200){
      // ElMessage({
      //   type: 'success',
      //   message: '文件已删除'
      // })
      state.form.logoPath = ''
    }else{
      ElMessage({
        type: 'warning',
        message: res.message
      })
    }
  }).catch(() => {
    state.form.logoPath = ''
  });
}
const reset = () => {
  state.form = {
    id: '',
    name: '',
    remark: '',
  }
}
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>