supplement.vue
7.98 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
<template>
<layout-body class="supplement">
<layout-filter ref="filter" :model="query">
<filter-item label="SKN编码">
<Input v-model.trim="query.productSkn" :maxlength="9"></Input>
</filter-item>
<filter-item label="商家编码">
<Input v-model.trim="query.sknFactoryCode"></Input>
</filter-item>
<filter-item label="商品名称">
<Input v-model.trim="query.productName"></Input>
</filter-item>
<filter-item label="商品条码">
<Input v-model.trim="query.skuFactoryCode"></Input>
</filter-item>
<filter-item label="选择类目">
<select-category v-model="category"></select-category>
</filter-item>
<filter-item label="选择品牌">
<select-brand v-model="query.brandId"></select-brand>
</filter-item>
<filter-item label="库存情况">
<select-stock-status v-model="query.stockStatus"></select-stock-status>
</filter-item>
<filter-item>
<Button type="primary" @click="toSearch">筛选</Button>
<Button @click="reset">清空条件</Button>
</filter-item>
</layout-filter>
<layout-action>
<Button type="primary" @click="openInvoice">添加到入库单</Button>
<span class="brand-info" v-if="selectBrand.brandId">当前选择的品牌:{{selectBrand.brandName}}</span>
</layout-action>
<layout-list>
<Table border
ref="table"
:columns="tableCols"
:data="tableData"
@on-selection-change="selectChange"
@on-select="selectSingle"></Table>
<Page
:total="pageData.total"
:current="pageData.pageNo"
@on-change="pageChange"
:page-size="pageData.pageSize"
show-total></Page>
</layout-list>
<modal-invoice ref="modalInvoice" @save="saveInvoice" :brand="selectBrand.brandId"></modal-invoice>
</layout-body>
</template>
<script>
import _ from 'lodash';
import {SelectBrand, SelectCategory, SelectStockStatus} from 'components/select';
import {ModalInvoice} from './components';
import {InvoiceService} from 'services/repository';
import store from './store';
export default {
data() {
return store.apply(this);
},
created() {
this.invoiceService = new InvoiceService();
return this.toSearch();
},
methods: {
toSearch() {
this.pageData.pageNo = 1;
return this.search();
},
search() {
this.$Loading.start();
this.resetSelectBrand();
return this.invoiceService.supplementProductList(this.getParams()).then(res => {
this.$Loading.finish();
this.tableData = res.records;
this.pageData.total = res.totalCount;
}, () => {
this.$Loading.finish();
});
},
pageChange(page) {
this.pageData.pageNo = page;
return this.search();
},
getParams() {
let params = Object.assign(this.query, {
maxSortId: _.get(this.category, '[0].value'),
middleSortId: _.get(this.category, '[1].value'),
smallSortId: _.get(this.category, '[2].value')
}, this.pageData);
delete params.total;
return _.pickBy(params, val => val);
},
reset() {
this.category = [];
this.$refs.filter.reset();
this.toSearch();
},
resetSelectBrand() {
this.selectBrand.brandId = 0;
this.selectBrand.brandName = '';
},
selectChange(selection) {
_.each(this.$refs.table.rebuildData, row => { // 更新rebuildData不会导致页面重新刷新
if (_.some(selection, item => item.id === row.id)) {
if (row.num <= 0) {
row.num = 1;
}
row._checked = true;
} else {
row.num = 0;
row._checked = false;
}
});
this.checkBrand();
},
numChange(row, num) {
if ((row.num > 0 && !row._checked) ||
(row.num === 0 && row._checked)) {
if (row.brandId !== this.selectBrand.brandId && this.selectBrand.brandId) { // 如果品牌不同就直接操作table的rebuilddata不会导致表格刷新
row.num = 0;
this.$Message.warning(`请选择品牌为:${this.selectBrand.brandName}的商品补货`);
return;
}
this.syncData();
row._checked = num > 0;
this.checkBrand();
}
},
checkBrand() {
let selection = _.filter(this.$refs.table.rebuildData, row => row._checked);
if (selection.length > 0) {
if (!this.selectBrand.brandId) {
this.selectBrand.brandId = _.head(selection).brandId;
this.selectBrand.brandName = _.head(selection).brandName;
}
let rmRows = _.remove(selection, row => row.brandId !== this.selectBrand.brandId);
if (rmRows.length) {
this.syncData(); // 同步rebuildData和数据data,然后修改_checked重新渲染表格
_.each(this.tableData, row => {
if (_.some(rmRows, rmRow => rmRow.id === row.id)) {
row._checked = false;
row.num = 0;
}
});
this.$Message.warning(`请选择品牌为:${this.selectBrand.brandName}的商品补货`);
}
} else {
this.resetSelectBrand();
}
},
openInvoice() {
if (!this.selectBrand.brandId) {
this.$Message.warning('请先选择要补货的商品');
return;
}
this.$refs.modalInvoice.show();
},
syncData() {
this.tableData = this.$refs.table.rebuildData;
},
saveInvoice(invoiceId) {
this.syncData();
let goodsList = this.tableData.filter(row => row._checked).map(row => {
return {
productSku: row.productSku,
num: row.num
};
});
if (goodsList.length && invoiceId) {
this.$Loading.start();
return this.invoiceService.addGoods({
proRequisitionFormId: invoiceId,
goodsList
}).then(res => {
this.$Loading.finish();
if (res.code === 200) {
this.$Notice.success({
title: '保存成功'
});
this.saveInvoiceAfter();
} else {
this.$Notice.error({
title: res.message
});
}
}, () => {
this.$Loading.finish();
});
}
this.$Message.warning('请选择商品和入库单');
},
saveInvoiceAfter() {
this.resetSelectBrand();
_.each(this.tableData, row => {
row.num = 0;
row._checked = false;
});
}
},
components: {
SelectBrand,
SelectCategory,
SelectStockStatus,
ModalInvoice
}
};
</script>
<style lang="scss">
.supplement {
.brand-info {
color: #f90;
font-size: 14px;
margin-left: 20px;
}
}
</style>