zhouwx
2025-02-26 e29932c247871e8921b210e311c8ea4a57d721ce
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
<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="basicName" >
          <el-input disabled v-model.trim="state.form.basicName" ></el-input>
        </el-form-item>
        <el-form-item label="相忌危化品:" prop="hazmatBasicName" >
          <el-input disabled v-model.trim="state.form.tabooBasicName" ></el-input>
        </el-form-item>
        <el-form-item label="仓库:" prop="warehouseName" >
          <el-select
              clearable
              v-model="state.form.warehouseName"
              filterable
              remote
              reserve-keyword
              placeholder="请输入所入仓库"
              remote-show-suffix
              :remote-method="getWareHouseList"
              style="width: 100%"
              @change="selectWareValue"
          >
            <el-option
                v-for="item in state.wareHouseList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="存储柜:" prop="cupboardId" >
          <el-select
              v-model="state.form.cupboardId"
              placeholder="请选择存储柜"
              style="width: 100%"
          >
            <el-option
                v-for="item in state.cupList"
                :key="item.id"
                :label="item.cupboardName"
                :value="item.id"
            />
          </el-select>
        </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 {getCupById, getWarehouse} from "@/api/hazardousChemicals/warehouse";
import {handleAvoid} from "@/api/hazardousChemicals/avoid";
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const state = reactive({
  form: {
    id: '',
    tabooBasicName: '',
    warehouseName: '',
    warehouseId: '',
    cupboardId: ''
  },
  formRules:{
    warehouseName: [{ required: true, trigger: "blur", message: '请选择仓库' }],
    cupboardId: [{ required: true, trigger: "blur", message: '请选择存储柜' }],
  },
})
 
 
const openDialog = async (value) => {
  await getWareHouseList("")
  await getCupList(value.warehouseId)
  title.value = '相忌报警处理'
  state.form = JSON.parse(JSON.stringify(value));
  dialogVisible.value = true;
}
 
const onSubmit = async () => {
  const valid = await busRef.value.validate();
  if(valid){
    const param = {
      cupboardId: state.form.cupboardId,
      id: state.form.id,
      warehouseId:state.form.warehouseId
    }
    const res = await handleAvoid(param)
    if(res.code === 200){
      ElMessage({
        type: 'success',
        message: '处理成功'
      });
    }else{
      ElMessage.warning(res.message)
    }
    emit("getList")
    busRef.value.clearValidate();
    reset();
    dialogVisible.value = false;
  }
}
const getWareHouseList = async (val) => {
  let param = {}
  if(val != ""){
    param = {
      name: val
    }
  }else {
    param = {
      pageNum: 1,
      pageSize: 10
    }
  }
  const res = await getWarehouse(param)
  if(res.code == 200){
    state.wareHouseList = res.data.list.map(item => {
      return {
        ...item,
        children: item.warehouseCupboards && item.warehouseCupboards.length>0 ? item.warehouseCupboards : null
      }
    })
  }else{
    ElMessage.warning(res.message)
  }
}
const selectWareValue = (val) => {
  state.form.cupboardId = null
  state.wareHouseList.forEach(item => {
    if(item.name === val){
      state.form.warehouseId = item.id
      getCupList(item.id)
    }
  })
}
const getCupList = async (val) => {
  const res = await getCupById(val)
  if(res.code == 200) {
    state.cupList = res.data
  }else {
    ElMessage.warning(res.message)
  }
}
 
const handleClose = () => {
  busRef.value.clearValidate();
  reset();
  dialogVisible.value = false;
  emit("getList")
}
const reset = () => {
  state.form = {
    id: '',
    hazmatBasicName: '',
    warehouseName: '',
    cupboardId: ''
  }
}
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>