modal-size-edit.vue
8.07 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>
<Modal
class="size-modal"
width="auto"
v-model="showModal"
:saveLoading="saveLoading"
@on-ok="modalOK"
@on-cancel="modalCancel"
:title="title"
ok-text="保存">
<div class="size-edit">
<Checkbox v-model="sizeImgFlag">隐藏测量方式图</Checkbox>
<Table ref="tableSize" v-if="loadingOk" :row-class-name="rowClassName" :show-header="false" :data="data" :columns="columns">
</Table>
</div>
</Modal>
</template>
<script>
import ProductService from 'services/product/product-service';
import _ from 'lodash';
export default {
name: 'modal-size-edit',
created() {
this.productService = new ProductService();
},
data() {
return {
showModal: false,
saveLoading: true,
title: '编辑尺码信息',
sizeImgFlag: false,
skn: 0,
gender: '',
data: [],
columns: [{}],
noMeasureIds: {},
loadingOk: false,
};
},
watch: {
columns: {
handler(col) {
if (_.get(this.$refs, 'tableSize.rebuildData.length')) {
this.data = this.$refs.tableSize.rebuildData;
let noMeasureIds = _.filter(col, c => c.noMeasure).map(c => {
return c.sizeAttributeId;
});
_.each(this.data, row => {
_.each(row.prdSizeAttributeBoList, attr => {
if (_.some(noMeasureIds, id => id === attr.sizeAttributeId)) {
attr.sizeValue = '';
}
});
});
}
},
deep: true
}
},
methods: {
show(skn) {
let columns = [];
this.skn = skn;
this.showModal = true;
this.productService.queryProdSize(this.skn).then(sizeInfo => {
if (_.get(sizeInfo, 'sizeRelationsList.length', 0)) {
let noMeasureIds = sizeInfo.noMeasureIds;
let attrs = sizeInfo.sizeRelationsList[0].prdSizeAttributeBoList;
columns.push({
width: 70,
render: (h, params) => {
if (params.index === 0) {
return <span>尺码</span>;
}
return <span>{params.row.sizeName}</span>;
},
fixed: 'left'
});
columns.push({
width: 220,
render: (h, params) => {
if (params.index === 0) {
return <span>参考尺码({sizeInfo.genderName})</span>;
}
return (
<div>
<i-input
class="size-inpt"
value={params.row.referenceNameA}
onInput={val => (params.row.referenceNameA = val)} />
/
<i-input
class="size-inpt"
value={params.row.referenceNameB}
onInput={val => (params.row.referenceNameB = val)} />
</div>
);
},
fixed: 'left'
});
_.each(attrs, (attr, colIndex) => {
columns.push({
width: 120,
noMeasure: _.some(noMeasureIds, id => +id === attr.sizeAttributeId),
sizeAttributeId: attr.sizeAttributeId,
render: (h, params) => {
if (params.index === 0) {
return h('div', {}, [
h('span', {}, attr.sizeAttributeName),
h('Checkbox', {
props: {
value: params.column.noMeasure
},
on: {
input: val => (params.column.noMeasure = val)
}
}, '无需测量')]);
}
return (
<i-input
class="size-inpt"
value={params.row.prdSizeAttributeBoList[colIndex].sizeValue}
onInput={val => (params.row.prdSizeAttributeBoList[colIndex].sizeValue = val)}
disabled={params.column.noMeasure}></i-input>
);
}
});
});
this.columns = columns;
this.data = _.concat({}, sizeInfo.sizeRelationsList);
this.sizeImgFlag = sizeInfo.sizeImgFlag !== 0;
this.gender = sizeInfo.gender;
this.loadingOk = true;
}
});
},
getColumns() {
},
rowClassName(row, index) {
if (index === 0) {
return 'table-header';
}
},
modalOK() {
let data = _.drop(this.$refs.tableSize.rebuildData, 1);
let columns = this.$refs.tableSize.cloneColumns;
let noMeasureIds = [],
sizeInfoList = [],
productSizeReferList = [];
_.each(columns, col => {
if (col.sizeAttributeId && col.noMeasure) {
noMeasureIds.push(col.sizeAttributeId);
}
});
sizeInfoList = _.concat([], ..._.map(data, row => {
return _.map(row.prdSizeAttributeBoList, size => {
return {
productSkn: this.skn,
sizeId: row.sizeId,
sizeAttributeId: size.sizeAttributeId,
sizeValue: size.sizeValue
};
});
}));
productSizeReferList = _.map(data, row => {
return {
sizeId: row.sizeId,
gender: this.gender,
referenceName: `${row.referenceNameA}/${row.referenceNameB}`
};
});
let postData = {
productSkn: this.skn,
noMeasureIds: JSON.stringify(noMeasureIds),
sizeInfoList: JSON.stringify(sizeInfoList),
productSizeReferList: JSON.stringify(productSizeReferList),
sizeImgFlag: this.sizeImgFlag ? 1 : 0
};
this.productService.saveProdSizeInfo(postData).then(result => {
if (result.code === 200) {
this.loadingOk = false;
this.showModal = false;
this.$Message.success('尺码保存成功!');
} else {
this.$Message.error('尺码保存失败!');
}
});
},
modalCancel() {
this.loadingOk = false;
this.showModal = false;
}
}
};
</script>
<style lang="scss">
.size-edit {
min-height: 200px;
position: relative;
display: inline-block;
width: 100%;
.ivu-spin {
margin-top: 50px;
}
.size-inpt {
width: 70px;
}
}
.size-modal {
.ivu-modal {
width: 90%;
}
}
</style>