BatchModal.vue
11.6 KB
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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<template>
<j-modal
:title="title"
:width="width"
:visible="visible"
:confirmLoading="confirmLoading"
switchFullscreen
@ok="handleCancel"
okText="取消"
@cancel="handleCancel"
cancelText="关闭"
>
<a-spin :spinning="confirmLoading">
<a-form-model ref="form" :model="model" :rules="validatorRules">
<!-- <a-row>-->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="单据号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="code">-->
<!-- <a-input ref="code" v-model="model.code" placeholder="请输入单据号" style="width: 100%"/>-->
<!-- </a-form-model-item>-->
<!-- </a-col> -->
<!-- -->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="单据时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiptDate"-->
<!-- >-->
<!-- <j-date :show-time="true" date-format="YYYY-MM-DD" placeholder="请选择单据时间"-->
<!-- class="query-group-cust" v-model="model.receiptDate"></j-date>-->
<!-- </a-form-model-item>-->
<!-- </a-col>-->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="仓库" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zoneCode">-->
<!-- <j-search-select-tag v-model="model.zoneCode" dict="product_area,name,code" />-->
<!-- </a-form-model-item>-->
<!-- </a-col>-->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="部门" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departName">-->
<!-- <j-search-select-tag v-model="model.departName" dict="sys_depart,depart_name,depart_name,parent_id='2'" />-->
<!-- </a-form-model-item>-->
<!-- </a-col>-->
<!-- -->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="保管人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="preserver">-->
<!-- <j-search-select-tag v-model="model.preserver" dict="fp_user,username,username, type = 0" />-->
<!-- </a-form-model-item>-->
<!-- </a-col>-->
<!-- <a-col :span="24">-->
<!-- <a-form-model-item label="收料人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="receiver">-->
<!-- <j-search-select-tag v-model="model.receiver" dict="fp_user,username,username, type = 0" />-->
<!-- </a-form-model-item>-->
<!-- </a-col>-->
<!-- </a-row>-->
</a-form-model>
</a-spin>
<!-- <a-table ref="table" rowKey="id" size="middle" :columns="columns" :dataSource="dataSource" :pagination="false">-->
<!-- <span slot="action" slot-scope="text, record">-->
<!-- <a-input-number placeholder="" v-model="record.qty" :value="text" />-->
<!-- </span> -->
<!-- </a-table> -->
<j-vxe-table
toolbar
:toolbarConfig="toolbarConfig"
row-number
row-selection
keep-source
async-remove
:height="340"
:loading="loading"
:columns="columns"
:dataSource="dataSource"
:pagination="pagination"
@save="handleTableSave"
@remove="handleTableRemove"
@edit-closed="handleEditClosed"
@pageChange="handlePageChange"
@selectRowChange="handleSelectRowChange"
/>
</j-modal>
</template>
<script>
import {getAction, httpAction, postAction} from '@/api/manage'
import {purchaseDerailList, ajaxGetDictItems} from '@/api/api'
import {JVXETypes} from "@comp/jeecg/JVxeTable";
export default {
name: 'BatchModal',
components: {},
props: {
mainId: {
type: String,
required: false,
default: ''
}
},
data() {
return {
title: '操作',
width: 1200,
visible: false,
materialList: {},
querySource: {},
// 工具栏的按钮配置
toolbarConfig: {
// add 新增按钮;remove 删除按钮;clearSelection 清空选择按钮
btn: ['save', 'remove', 'clearSelection']
},
// 是否正在加载
loading: false,
dataSource: [],
invStatus:[],
pagination: {
// 当前页码
current: 1,
// 每页的条数
pageSize: 200,
// 可切换的条数
pageSizeOptions: ['10', '20', '30', '100', '200'],
// 数据总数(目前并不知道真实的总数,所以先填写0,在后台查出来后再赋值)
total: 0,
},
model: {},
labelCol: {
xs: { span: 24 },
sm: { span: 5 }
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 }
},
validatorRules: {
code: [
{ required: true, message: '请输入单据号!'},
],
receiptDate: [
{ required: true, message: '请输入单据日期!'},
],
zoneCode: [
{ required: true, message: '请选择仓库!'},
],
departName: [
{ required: true, message: '请选择部门!'},
],
qty: [
{ required: true, message: '请输入数量!'},
{ pattern: /^(([1-9][0-9]*)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/, message: '请输入正确的数量!'},
],
preserver: [
{ required: true, message: '请选择保管人!'},
],
receiver: [
{ required: true, message: '请选择收料人!'},
],
},
columns: [
{key: 'id', title: 'id'},
{key: 'mapName', title: '物料名称'},
{key: 'mapNumber', title: '物料代码'},
{key: 'note', title: '备注'},
{key: 'qty', title: '订货数量'},
{key: 'commitQty', title: '到货数量',type: JVXETypes.input},
{key: 'furnaceNumber', title: '炉号', type: JVXETypes.input},
{key: 'batchNumber', title: '批号', type: JVXETypes.input},
{
title: '图片上传',
key: 'image',
type: JVXETypes.image,
width: '180px',
token: true,
},
],
confirmLoading: false,
dictOptions: {},
superFieldList:[],
url: {
getData: '/purchase_order/purchaseOrder/listPurchaseOrderDetailsByMainId',
// 模拟保存单行数据(即时保存)
saveRow: '/mock/vxe/immediateSaveRow',
// 模拟保存整个表格的数据
saveAll: '/purchase_order/purchaseOrder/yjbatchEdit',
},
}
},
created() {
//备份model原始值
//this.getSuperFieldList()
// this.modelDefault = JSON.parse(JSON.stringify(this.model))
//this.loadFrom();
},
methods: {
loadFrom(){
ajaxGetDictItems('inventory_status').then((res) => {
if (res.success) {
this.invStatus = res.result
}
})
},
handleTableSave({$table, target}) {
// 校验整个表格
$table.validate().then((errMap) => {
// 校验通过
if (!errMap) {
// 获取所有数据
let tableData = target.getTableData()
console.log('当前保存的数据是:', tableData)
// 获取新增的数据
let newData = target.getNewData()
console.log('-- 新增的数据:', newData)
// 获取删除的数据
let deleteData = target.getDeleteData()
console.log('-- 删除的数据:', deleteData)
// 【模拟保存】
this.loading = true
postAction(this.url.saveAll, tableData).then(res => {
if (res.success) {
this.$message.success(`保存成功!`)
} else {
this.$message.warn(`保存失败:` + res.message)
}
}).finally(() => {
this.loading = false
})
}
})
},
loadData(id) {
// 封装查询条件
let formData = {
pageNo: this.pagination.current,
pageSize: this.pagination.pageSize,
headId:id
}
// 调用查询数据接口
this.loading = true
getAction(this.url.getData, formData).then(res => {
if (res.success) {
// 后台查询回来的 total,数据总数量
this.pagination.total = res.result.total
// 将查询的数据赋值给 dataSource
this.dataSource = res.result.records
// 重置选择
this.selectedRows = []
} else {
this.$error({title: '主表查询失败', content: res.message})
}
}).finally(() => {
// 这里是无论成功或失败都会执行的方法,在这里关闭loading
this.loading = false
})
},
getStatusColor(status) {
const colors = {
'good ': 'green',
'defective': 'red',
'discussed ': 'grey',
'scrap': 'purple',
default: 'blue'
};
return colors[status] || colors.default;
},
getContainerCode(e){
this.$nextTick(function (){
let record={containerCode: e}
this.model = Object.assign({}, record)
})
},
// 当分页参数变化时触发的事件
handlePageChange(event) {
// 重新赋值
this.pagination.current = event.current
this.pagination.pageSize = event.pageSize
// 查询数据
this.loadData()
},
// 当选择的行变化时触发的事件
handleSelectRowChange(event) {
this.selectedRows = event.selectedRows
},
solutionInvStatus(value) {
var actions = []
Object.keys(this.invStatus).some(key => {
if (this.invStatus[key].value == '' + value) {
actions.push(this.invStatus[key].text)
return true
}
})
return actions.join('')
},
// add() {
// this.edit(this.modelDefault)
// this.model.inventoryStatus = 'good'
// },
edit(ids) {
this.visible = true
this.loadData(ids);
},
// show(record) {
// this.model = Object.assign({}, record)
// this.visible = true
// },
selectContainer(record){
this.$refs.selectContainerForm.edit(record);
},
close() {
this.$emit('close')
this.visible = false
this.$refs.form.clearValidate()
},
selectList(ids) {
const that = this
that.querySource.headId = ids;
purchaseDerailList(that.querySource).then(res => {
that.dataSource = res
})
},
handleOk() {
const that = this
// 触发表单验证
this.$refs.form.validate(valid => {
if (valid) {
that.confirmLoading = true
let httpurl = ''
let method = ''
httpurl += this.url.add
method = 'post'
this.dataSource.forEach((item, index) => {
this.$set(this.dataSource[index], 'code', this.model.code)
this.$set(this.dataSource[index], 'receiptDate', this.model.receiptDate)
this.$set(this.dataSource[index], 'zoneCode', this.model.zoneCode)
this.$set(this.dataSource[index], 'departName', this.model.departName)
this.$set(this.dataSource[index], 'preserver', this.model.preserver)
this.$set(this.dataSource[index], 'receiver', this.model.receiver)
})
httpAction(httpurl, this.dataSource, method)
.then(res => {
if (res.success) {
that.$message.success(res.message)
that.$emit('refash')
that.close()
} else {
that.$message.warning(res.message)
}
})
.finally(() => {
that.confirmLoading = false
})
} else {
return false
}
})
},
handleCancel() {
this.close()
}
}
}
</script>