vips.vue
10 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
<template>
<layout-body>
<layout-filter>
<filter-item :label="filters.sknCode.label">
<Input v-model.trim.number="filters.sknCode.model"
:placeholder="filters.sknCode.holder" :maxlength="9"></Input>
</filter-item>
<filter-item :label="filters.prodCode.label">
<Input v-model.trim="filters.prodCode.model"
:placeholder="filters.prodCode.holder"></Input>
</filter-item>
<filter-item :label="filters.prodBarCode.label">
<Input v-model.trim="filters.prodBarCode.model"
:placeholder="filters.prodBarCode.holder"></Input>
</filter-item>
<filter-item :label="filters.priceStatus.label">
<Select v-model.trim="filters.priceStatus.model" clearable>
<Option v-for="option in filters.priceStatus.options"
:value="option.value"
:key="option.value">{{option.label}}</Option>
</Select>
</filter-item>
<filter-item :label="filters.saleStatus.label">
<Select v-model.trim="filters.saleStatus.model" clearable>
<Option v-for="option in filters.saleStatus.options"
:value="option.value"
:key="option.value">{{option.label}}</Option>
</Select>
</filter-item>
<filter-item :label="filters.stockStatus.label">
<Select v-model.trim="filters.stockStatus.model" clearable>
<Option v-for="option in filters.stockStatus.options"
:value="option.value"
:key="option.value">{{option.label}}</Option>
</Select>
</filter-item>
<filter-item label="选择类目">
<select-category :value="categoryValue"
@select-change="sortChange"></select-category>
</filter-item>
<filter-item>
<Button type="primary" @click="filterSearch">筛选</Button>
<Button @click="clearFilter">清空条件</Button>
</filter-item>
</layout-filter>
<layout-action>
<Button type="primary" @click="batchSetVip(1)">启用</Button>
<Button type="error" @click="batchSetVip(2)">禁用</Button>
</layout-action>
<layout-list>
<Table border :columns="columns"
@on-selection-change="selectChange" :data="dataList"></Table>
<Page :total="page.total" :current="page.current"
@on-change="pageChange" :page-size="20" show-total></Page>
</layout-list>
</layout-body>
</template>
<script>
import _ from 'lodash';
import ProductService from 'services/product/product-service';
import {SelectCategory} from 'components/select';
import {CellImage, CellInfo, CellPrice} from 'components/cell';
import vipStore from './store';
export default {
data() {
return {
columns: [],
dataList: {},
page: {},
filters: {},
batchRows: [],
submitting: false,
enableFilter: false,
categoryValue: []
};
},
created() {
this.productService = new ProductService();
const vip = vipStore.apply(this);
const params = this.filterValues();
this.productList(params);
this.filters = vip.filterFields;
this.columns = vip.tableCols;
this.dataList = vip.tableData;
this.page = vip.pageData;
},
methods: {
filterValues() {
const values = {
page: 1,
size: 20
};
const fields = this.filters;
const keyMap = {
productSkn: 'sknCode',
sknFactoryCode: 'prodCode',
status: 'saleStatus',
productVipStatus: 'priceStatus',
skuFactoryCode: 'prodBarCode',
stock: 'stockStatus',
maxSortId: 'maxSort',
middleSortId: 'midSort',
smallSortId: 'minSort'
};
const selectKeys = ['status', 'stock', 'productVipStatus'];
if (this.enableFilter) {
_.each(keyMap, (val, key) => {
values[key] = fields[val].model;
});
_.each(selectKeys, key => {
const val = values[key];
if (!(val + '').length || _.isNull(val)) {
values[key] = null;
}
});
}
return values;
},
filterSearch() {
let params = {};
this.enableFilter = true;
params = this.filterValues();
this.productList(params);
this.page.current = 1;
},
clearFilter() {
let params = {};
const store = vipStore.apply(this);
this.filters = store.filterFields;
this.enableFilter = false;
params = this.filterValues();
this.productList(params);
this.page.current = 1;
this.categoryValue = [];
},
productList(params) {
if (_.isObject(params) &&
typeof params.productSkn !== 'undefined' &&
!_.isFinite(+params.productSkn)) {
this.$Message.error('SKN编码只能是数字', 3);
return;
}
this.$Loading.start();
this.productService.vipProductList(params)
.then(res => {
this.$Loading.finish();
if (res.code === 200) {
this.resolveData(res.data);
}
});
},
reloadList() {
let params = {};
if (this.enableFilter) {
params = this.filterValues();
}
_.merge(params, {
page: 1,
size: 20
});
this.productList(params);
this.page.current = 1;
},
resolveData(data) {
this.dataList = data.list;
this.page.total = data.total;
},
enableVipPrice(row) {
const skn = row.productSKN;
const canOpen = row.canOpenFlag;
if (canOpen) {
this.setPriceStatus([{
skn
}], 1);
} else {
this.$Message
.error('与平台签订vip会员价格相关合同后,才能开启', 3);
}
},
disableVipPrice(row) {
const skn = row.productSKN;
this.setPriceStatus([{
skn
}], 2);
},
batchSetVip(status) {
let list = [];
const vsMap = {
1: '启用',
2: '禁用'
};
const len = this.batchRows.length;
if (len) {
_.each(this.batchRows, item => {
list.push({
skn: item.productSKN,
status: item.productVipStatus
});
});
this.setPriceStatus(list, status);
} else {
this.$Message.error(`请先勾选要${vsMap[status]}的商品`, 3);
}
},
setPriceStatus(list, status) {
let sknList = [];
let params = {};
const vsMap = {
1: '启用',
2: '禁用'
};
list = _.filter(list, item => {
return item.status !== status;
});
if (!list.length) {
this.$Message.error(`当前选中的商品中,不包含要${vsMap[status]}的商品`, 3);
return;
}
_.each(list, item => {
sknList.push(item.skn);
});
params.productSknList = sknList;
params.productVipStatus = status;
if (sknList.length) {
if (this.submitting) {
return;
}
this.submitting = true;
this.productService.setVipPriceStatus(params)
.then(() => {
this.reloadList();
this.submitting = false;
this.$Message.success('VIP价格状态变更成功');
});
}
},
sortChange({max, mid, min}) {
this.filters.maxSort.model = max || null;
this.filters.midSort.model = mid || null;
this.filters.minSort.model = min || null;
},
pageChange(page) {
let params = this.filterValues();
params.page = page;
this.page.current = page;
this.productList(params);
},
selectChange(rows) {
this.batchRows = rows;
}
},
components: {
SelectCategory,
CellImage,
CellInfo,
CellPrice
}
};
</script>
<style lang="scss">
</style>