zhouwx
2026-06-18 5612bbd431d10589a06c7ed3584de2cad1b5ea0a
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<template>
  <div class="notice">
    <el-dialog
        v-model="dialogVisible"
        :title="title"
        width="850px"
        :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="subscribeNum">
          <el-select
              clearable
              v-model="state.form.subscribeNum"
              filterable
              remote
              reserve-keyword
              placeholder="请输入申购订单"
              remote-show-suffix
              :remote-method="getOrderList"
              style="width: 50%;margin-bottom:5px"
              @change="selectValue"
          >
            <el-option
                v-for="item in state.orderList"
                :key="item.id"
                :label="item.subscribeNum"
                :value="item.subscribeNum"
            />
          </el-select>
          <div style="display: flex;width: 100%;margin-top: 5px">
            <el-table :data="state.form.subscribeHazmats" :border="true">
              <el-table-column type="index" label="序号" width="80" align="center"></el-table-column>
              <el-table-column label="危化品名称" align="center"  >
                <template #default="{row,$index}">
                  <el-form-item align="center" :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatName'" :rules="state.formRules.hazmatName">
                    <span>{{row.hazmatName}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
              <el-table-column label="数量" align="center"  >
                <template #default="{row,$index}">
                  <el-form-item :prop="'subscribeHazmats.' + '[' + $index + ']' + '.hazmatCount'" :rules="state.formRules.hazmatCount">
                    <span>{{row.hazmatCount}}</span>
                  </el-form-item>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </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: 50%"
              @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
              clearable
              v-model="state.form.cupboardId"
              placeholder="请选择副柜"
              style="width: 50%"
          >
            <el-option
 
                v-for="item in state.cupList"
                :key="item.id"
                :label="item.cupboardName"
                :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="批号:" prop="batchNo" >
          <el-input v-model.trim="state.form.batchNo"  style="width: 50%" placeholder="请输入批号"></el-input>
        </el-form-item>
      </el-form>
      <template #footer v-if="title !=='查看'">
        <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, ElMessageBox} from "element-plus";
import {addCompany, checkName, distributeCompany, editCompany} from "@/api/hazardousChemicals/company";
import {verifyPhone, verifyPwd} from "@/utils/validate";
import {getUser} from "@/api/hazardousChemicals/user";
import {getToken} from "@/utils/auth";
import {renderAsync} from "docx-preview";
import {addSubscribe, editSubscribe, getSubscribeList} from "@/api/hazardousChemicals/subscribeApply";
import {getCupById, getWarehouse} from "@/api/hazardousChemicals/warehouse";
import moment from "moment";
import Cookies from "js-cookie";
import {addOrder, editOrder} from "@/api/hazardousChemicals/orderWarehouse";
 
const dialogVisible = ref(false);
const title = ref("");
const busRef = ref();
const length = ref()
const emit = defineEmits(["getList"]);
const state = reactive({
  form: {
    id: '',
    companyId:null,
    cupboardId: null,
    warehouseId:null,
    batchNo:'',
    subscribeNum:'',
    num:'',
    warehouseName:'',
    subscribeHazmats:[]
  },
  orderName:'',
  orderList:[],
  wareHouseList: [],
  cupList: [],
  subscribePersonId:null,
  formRules:{
    warehouseName: [{ required: true, message: '请选择主柜', trigger: 'blur' }],
    cupboardId:[{ required: true, message: '请选择副柜', trigger: 'blur' }],
    subscribeNum: [{ required: true, message: '请选择申购订单', trigger: 'blur' }],
  },
 
})
const openDialog = async (type, value) => {
  await getOrderList("")
  await getWareHouseList("")
  const userInfo= JSON.parse(Cookies.get('userInfo'))
  state.subscribePersonId = userInfo.id
  title.value = type === 'add' ? '订单入库' : type ==='edit' ? '编辑' : '查看' ;
  if(type === 'edit' || type === 'view') {
    Object.keys(value).forEach(key => key in state.form && (state.form[key] = value[key]));
    state.form.subscribeHazmats = value.subscribe.subscribeHazmats
    state.form.warehouseName = value.warehouse.name
    state.form.companyId = userInfo.companyId
    await getCupList(state.form.warehouseId)
  }
  state.form.batchNo = moment(new Date()).format("YYYYMMDD")
  dialogVisible.value = true;
}
 
const onSubmit = async () => {
  const valid = await busRef.value.validate();
  if(valid){
    state.form.num = state.form.subscribeHazmats.reduce((sum, item) => sum + item.hazmatCount, 0)
    if(title.value === '订单入库'){
      const {id,subscribeHazmats,warehouseName,companyId, ...data} = JSON.parse(JSON.stringify(state.form))
      const res = await addOrder(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 {subscribeHazmats,warehouseName,...data} = JSON.parse(JSON.stringify(state.form))
      const res = await editOrder(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: '',
    companyId:null,
    cupboardId: null,
    warehouseId:null,
    batchNo:'',
    subscribeNum:'',
    num:'',
    subscribeHazmats:[],
    warehouseName:''
  }
  state.subscribePersonId = null
  state.orderName = ''
}
const selectValue = (val) => {
  if(!val){
    state.form.subscribeHazmats = []
    return
  }
  const match  = state.orderList.find(i => i.subscribeNum == val)
  if(match){
    state.form.subscribeHazmats = match.subscribeHazmats
  }
}
const getOrderList = async (val) => {
  let param = {}
  if(val != ""){
    param = {
      subscribeNum: val,
      status: 1,
      subscribePersonId:state.subscribePersonId
    }
  }else {
    param = {
      pageNum: 1,
      pageSize: 10,
      status: 1,
      subscribePersonId:state.subscribePersonId
    }
  }
  const res = await getSubscribeList(param)
  if(res.code == 200){
    state.orderList = res.data.list
  }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 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
  }else{
    ElMessage.warning(res.message)
  }
}
 
 
 
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>