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
| import {
| ref,
| onMounted,
| reactive,
| computed,
| Ref,
| watch,
| SetupContext,
| h,
| } from 'vue'
| import { injectModel } from '@/libs/Provider/Provider'
| import { WmsInOutStockRecordDrawer } from '../Models/WmsInOutStockRecordDrawer'
| import { ElMessage } from 'element-plus'
| import isEqual from 'lodash/isEqual'
| import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox'
| import { cloneDeep } from 'lodash'
|
| export const useWmsInOutStockRecordDrawer = (props: any, ctx?: any) => {
| const wmsInOutStockRecordDrawer = injectModel<WmsInOutStockRecordDrawer>(
| 'wmsInOutStockRecordDrawer'
| )
| /**
| * 用来对比的初始化数据
| */
| const initiateData: Ref<Record<string, any>> = ref({})
| const formData = ref<Record<string, any>>({})
| // ref
| const formRef = ref()
|
| const disabled = ref(false)
|
| const current = computed(() => {
| return props.row || null
| })
|
| const inputNumber = (attrs) => {
| return (
| <el-input-number
| min="1"
| step="1"
| precision="0"
| {...attrs}
| ></el-input-number>
| )
| }
|
| const visible = computed({
| get() {
| return props.modelValue
| },
| set(val) {
| ctx.emit('update:modelValue', val)
| },
| })
| /**
| * 添加的form字段
| */
| const formItems = reactive([
| {
| label: '单据编号',
| prop: 'orderNo',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入单据编号',
| rules: [{ required: true, message: '单据编号不能为空', trigger: 'blur' }],
| },
| {
| label: '物料名称',
| prop: 'materialName',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入物料名称',
| },
| {
| label: '物料件号',
| prop: 'materialNo',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入物料件号',
| rules: [{ required: true, message: '物料件号不能为空', trigger: 'blur' }],
| },
| {
| label: '操作类型',
| prop: 'stockType',
| el: 'select',
| //disabled: disabled,
| placeholder: '请输入操作类型',
| rules: [{ required: true, message: '操作类型不能为空', trigger: 'blur' }],
| },
| {
| label: '容器编号',
| prop: 'containerNo',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入容器编号',
| },
| {
| label: '机型',
| prop: 'materialModel',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入机型',
| },
| {
| label: '操作时间',
| prop: 'operateTime',
| type: 'datetimerange',
| el: 'date-picker',
| //disabled: disabled,
| placeholder: '请输入操作时间',
| },
| {
| label: '备注',
| prop: 'remark',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入备注',
| },
| {
| label: '物料ID',
| prop: 'materialId',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入物料ID',
| rules: [{ required: true, message: '物料ID不能为空', trigger: 'blur' }],
| },
| {
| label: '任务号',
| prop: 'taskNo',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入任务号',
| rules: [{ required: true, message: '任务号不能为空', trigger: 'blur' }],
| },
| {
| label: '起始库位',
| prop: 'sourcePlace',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入起始库位',
| },
| {
| label: '目标库位',
| prop: 'toPlace',
| el: 'input',
| //disabled: disabled,
| placeholder: '请输入目标库位',
| },
| ])
| /**
| * 校验是否有数据变化
| */
| const checkIsEqualObject = () => {
| const data = {
| formData: formData.value,
| }
| const check = isEqual(initiateData.value, data)
| return check
| }
|
| const onClose = (done: () => void) => {
| if (visible.value) {
| if (checkIsEqualObject()) {
| visible.value = false
| done && done()
| } else {
| ConfirmBox('是否保存设置?')
| .then(() => {
| onConfirm()
| })
| .catch(() => {
| visible.value = false
| done && done()
| })
| }
| }
| }
| /**
| * 保存
| */
| const onConfirm = async () => {
| await formRef.value?.validate()
| const data = {
| orderNo: formData.value.orderNo,
| materialName: formData.value.materialName,
| materialNo: formData.value.materialNo,
| stockType: formData.value.stockType,
| containerNo: formData.value.containerNo,
| materialModel: formData.value.materialModel,
| operateTime: formData.value.operateTime,
| remark: formData.value.remark,
| materialId: formData.value.materialId,
| taskNo: formData.value.taskNo,
| sourcePlace: formData.value.sourcePlace,
| toPlace: formData.value.toPlace,
| }
| if (!current.value) {
| await wmsInOutStockRecordDrawer.addWmsInOutStockRecord(data)
| } else {
| const id = current.value.id
| await wmsInOutStockRecordDrawer.updateWmsInOutStockRecord(id, data)
| }
| ElMessage.success('保存成功')
| ctx.emit('confirm')
| }
|
| const updateCheckData = () => {
| initiateData.value = {
| formData: {
| ...formData.value,
| },
| }
| }
| const updateFormItemOptions = (propName: string, enumData: any[]) => {
| const item = formItems.find((item) => item.prop === propName)
| if (item && enumData) {
| item.options = enumData.map((item) => ({
| label: item.description,
| value: item.value,
| }))
| }
| }
| /**
| * 通用查询枚举
| */
| const commonQueryEnumForFrom = async () => {
| const stockTypeEnumEnum = await wmsInOutStockRecordDrawer.getWmsEnumData({
| EnumName: 'StockTypeEnum',
| })
| updateFormItemOptions('stockType', stockTypeEnumEnum)
| }
| commonQueryEnumForFrom()
| /**
| * 弹窗打开获取详情
| */
| const onOpen = async () => {
| if (current.value) {
| const res = await wmsInOutStockRecordDrawer.getWmsInOutStockRecordDetail(
| current.value
| )
|
| formData.value = {
| orderNo: res.orderNo,
| materialName: res.materialName,
| materialNo: res.materialNo,
| stockType: res.stockType,
| containerNo: res.containerNo,
| materialModel: res.materialModel,
| operateTime: res.operateTime,
| remark: res.remark,
| materialId: res.materialId,
| taskNo: res.taskNo,
| sourcePlace: res.sourcePlace,
| toPlace: res.toPlace,
| id: res.id,
| }
| disabled.value = true
| updateCheckData()
| } else {
| formData.value = {}
|
| disabled.value = false
| updateCheckData()
| }
| }
|
| watch(() => current.value, onOpen)
|
| return {
| formItems,
| formData,
| visible,
| formRef,
| onOpen,
| onClose,
| onConfirm,
| }
| }
|
|