ShipmentPickDetailModal.vue
5.53 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
<template>
<j-modal
:title="title"
:width="modalWidth"
:visible="visible"
:confirmLoading="confirmLoading"
switchFullscreen
@ok="handleOk"
@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="matnr">
<a-input v-model="model.matnr" disabled />
</a-form-model-item>
</a-col>
<a-col :span="24">
<a-form-model-item label="计划批次" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zcharg">
<a-input
v-model="model.zcharg"
readonly
placeholder="点击选择计划批次"
@click="openBatchModal" />
</a-form-model-item>
</a-col>
</a-row>
</a-form-model>
</a-spin>
<!-- 批次选择弹窗 -->
<a-modal
v-model:visible="batchModalVisible"
title="选择计划批次"
:width="modalWidth"
@ok="handleBatchConfirm"
@cancel="batchModalVisible = false">
<a-table
:rowSelection="rowSelection"
:columns="batchColumns"
:dataSource="batchList"
rowKey="id"
bordered />
</a-modal>
</j-modal>
</template>
<script>
import { httpAction } from '@/api/manage';
export default {
name: 'ShipmentPickDetailModal',
props: {
mainId: {
type: String,
required: false,
default: '',
},
},
data() {
return {
title: '操作',
visible: false,
confirmLoading: false,
batchModalVisible: false,
model: {},
labelCol: { xs: { span: 24 }, sm: { span: 5 } },
wrapperCol: { xs: { span: 24 }, sm: { span: 16 } },
validatorRules: {},
batchList: [],
selectedBatchIds: [], // 存储选中的批次ID
batchColumns: [],
rowSelection: {
selectedRowKeys: [], // 与表格的行选择绑定
onChange: this.handleRowSelect, // 行选择事件
},
url: {
add: "/shipment/pick/header/addShipmentPickDetail",
edit: "/shipment/pick/header/editShipmentPickDetail",
}
};
},
computed: {
modalWidth() {
const columnCount = this.batchColumns.length;
const maxColumnWidth = 150;
const minWidth = 800;
return Math.max(minWidth, columnCount * maxColumnWidth);
},
},
methods: {
handleRowSelect(selectedRowKeys, selectedRows) {
this.rowSelection.selectedRowKeys = selectedRowKeys; // 更新选中行的键
this.selectedBatchIds = selectedRows.map(row => row.id); // 更新选中批次ID
},
add() {
this.edit(this.modelDefault);
},
edit(record) {
this.model = Object.assign({}, record);
this.visible = true;
},
close() {
this.$emit('close');
this.visible = false;
this.$refs.form.clearValidate();
},
handleOk() {
this.$refs.form.validate(valid => {
if (valid) {
this.confirmLoading = true;
const httpurl = this.model.id ? this.url.edit : this.url.add;
const method = this.model.id ? 'put' : 'post';
this.model['shipmentPickId'] = this.mainId;
httpAction(httpurl, this.model, method)
.then(res => {
if (res.success) {
this.$message.success(res.message);
this.$emit('ok');
} else {
this.$message.warning(res.message);
}
})
.finally(() => {
this.confirmLoading = false;
this.close();
});
}
});
},
handleCancel() {
this.close();
},
openBatchModal() {
this.loadBatchList();
this.batchModalVisible = true;
},
handleBatchConfirm() {
const selectedBatches = this.batchList.filter(batch =>
this.selectedBatchIds.includes(batch.id)
);
this.model.zcharg = selectedBatches.map(batch => batch.batch).join(',');
this.batchModalVisible = false;
},
loadBatchList() {
const params = this.model.matnr;
if (!params) {
this.$message.warning('物料编码不能为空');
return;
}
const url = `/inventory/inventoryDetail/getInventoryListByMaterialCode?materialCode=${encodeURIComponent(params)}`;
httpAction(url, {}, 'get')
.then(res => {
if (res.success) {
this.batchList = res.result;
this.batchColumns = [
{title: '批次', dataIndex: 'batch', key: 'batch'},
{title: '库房地点', dataIndex: 'lgort', key: 'lgort'},
{title: '库位号', dataIndex: 'locationCode', key: 'locationCode'},
{title: '物料编码', dataIndex: 'materialCode', key: 'materialCode'},
{title: '物料名称', dataIndex: 'materialName', key: 'materialName'},
{title: '物料规格', dataIndex: 'materialSpec', key: 'materialSpec'},
{title: '物料单位', dataIndex: 'materialUnit', key: 'materialUnit'},
{title: '数量', dataIndex: 'qty', key: 'qty'},
{title: '明细id', dataIndex: 'id', key: 'id'},
];
} else {
this.$message.warning('加载批次数据失败:' + res.message);
}
})
.catch(() => {
this.$message.error('接口请求失败,请检查网络连接');
});
},
},
};
</script>