MaterialTaskModal2.vue
6.1 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
<template>
<a-modal
:title="title"
:width="800"
:visible="visible"
:maskClosable="false"
:confirmLoading="confirmLoading"
@ok="handleOk"
@cancel="handleCancel">
<a-spin :spinning="confirmLoading">
<a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol" :model="model">
<!-- 主表单区域 -->
<a-row class="form-row" :gutter="0">
<a-col :lg="8">
<a-form-model-item label="托盘号" :rules="[{ required: true, message: '请输入托盘号!' }]">
<a-input placeholder="请输入托盘号" v-model="model.containerCode"/>
</a-form-model-item>
</a-col>
<a-col :lg="8">
<a-form-model-item label="入库口">
<a-input placeholder="请输入入库口" v-model="model.toPort"/>
</a-form-model-item>
</a-col>
</a-row>
</a-form-model>
<!-- 子表单区域 -->
<a-tabs v-model="activeKey">
<a-tab-pane tab="物料信息" key="1" :forceRender="true">
<j-editable-table
ref="editableTable1"
:loading="table1.loading"
:columns="table1.columns"
:dataSource="table1.dataSource"
:maxHeight="300"
:rowNumber="true"
:rowSelection="true"
:actionButton="true"/>
</a-tab-pane>
</a-tabs>
</a-spin>
</a-modal>
</template>
<script>
import JEditableTable from '@/components/jeecg/JEditableTable'
import {FormTypes, VALIDATE_NO_PASSED, getRefPromise, validateFormModelAndTables} from '@/utils/JEditableTableUtil'
import {httpAction, getAction} from '@/api/manage'
import {execute, quickReceipt} from '@/api/api'
import JDate from '@/components/jeecg/JDate'
export default {
name: 'MaterialTaskModal',
components: {
JDate, JEditableTable
},
data() {
return {
title: '操作',
visible: false,
confirmLoading: false,
model: {},
labelCol: {
xs: {span: 24},
sm: {span: 6}
},
wrapperCol: {
xs: {span: 24},
sm: {span: 24 - 6}
},
activeKey: '1',
// 客户信息
table1: {
loading: false,
dataSource: [],
columns: [
{
title: '物料编码',
key: 'materialCode',
width: '24%',
type: FormTypes.sel_search,
defaultValue: '',
dictCode:'material,name,code',
placeholder: '请输入${title}',
validateRules: [{required: true, message: '${title}不能为空'}]
},
{
title: '数量',
key: 'qty',
type: FormTypes.inputNumber,
width: '80px',
}
]
},
url: {
add: '/test/jeecgOrderMain/add',
edit: '/test/jeecgOrderMain/edit',
orderCustomerList: '/test/jeecgOrderMain/queryOrderCustomerListByMainId',
orderTicketList: '/test/jeecgOrderMain/queryOrderTicketListByMainId'
}
}
},
created() {
},
methods: {
// 获取所有的editableTable实例
getAllTable() {
return Promise.all([
getRefPromise(this, 'editableTable1')
])
},
add() {
// 默认新增一条数据
this.getAllTable().then(editableTables => {
editableTables[0].add()
})
this.edit({})
},
edit(record) {
this.visible = true
this.activeKey = '1'
this.model = Object.assign({}, record)
},
close() {
this.visible = false
this.getAllTable().then(editableTables => {
editableTables[0].initialize()
})
this.$emit('close')
this.$refs.form.resetFields();
},
/** 查询某个tab的数据 */
requestTableData(url, params, tab) {
tab.loading = true
getAction(url, params).then(res => {
tab.dataSource = res.result || []
}).finally(() => {
tab.loading = false
})
},
handleOk() {
this.validateFields()
},
handleCancel() {
this.close()
},
/** 触发表单验证 */
validateFields() {
this.getAllTable().then(tables => {
/** 一次性验证主表和所有的次表 */
return validateFormModelAndTables(this.$refs.form, this.model, tables)
}).then(allValues => {
let formData = this.classifyIntoFormData(allValues)
console.log("输出数据:")
console.log(formData)
this.receipt(formData);
// 发起请求
// return this.requestAddOrEdit(formData)
}).catch(e => {
if (e.error === VALIDATE_NO_PASSED) {
// 如果有未通过表单验证的子表,就自动跳转到它所在的tab
this.activeKey = e.index == null ? this.activeKey : (e.index + 1).toString()
} else {
console.error(e)
}
})
},
/** 整理成formData */
classifyIntoFormData(allValues) {
let orderMain = Object.assign(this.model, allValues.formValue)
return {
...orderMain, // 展开
receiptEntityList: allValues.tablesValue[0].values,
}
},
/** 发起新增或修改的请求 */
requestAddOrEdit(formData) {
alert(JSON.stringify(formData))
let url = this.url.add, method = 'post'
if (this.model.id) {
url = this.url.edit
method = 'put'
}
this.confirmLoading = true
httpAction(url, formData, method).then((res) => {
if (res.success) {
this.$message.success(res.message)
this.$emit('ok')
this.close()
} else {
this.$message.warning(res.message)
}
}).finally(() => {
this.confirmLoading = false
})
},
receipt(record) {
this.confirmLoading = true
this.model = Object.assign({}, record);
quickReceipt(this.model).then((res) => {
this.loading = false;
if (res.success) {
this.$message.success(res.message);
this.$emit('ok');
this.close();
} else {
this.$message.error(res.message);
}
this.confirmLoading = false
});
},
}
}
</script>
<style scoped>
</style>