-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathindex.html
539 lines (507 loc) · 17.9 KB
/
index.html
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://cdn.bootcss.com/vue/2.4.2/vue.min.js"></script>
<!-- 引入样式 -->
<link href="https://cdn.bootcss.com/element-ui/1.4.2/theme-default/index.css" rel="stylesheet">
<!-- 引入组件库 -->
<script src="https://cdn.bootcss.com/element-ui/1.4.2/index.js"></script>
<style lang="">
#app {
margin: 0 200px;
}
.tip {
color: red;
font-size: 12px;
}
#app input[type="text"] {
width: 280px;
}
#app .price-wra input[type="text"] {
width: 80px;
}
#app .el-input {
width: auto;
}
.must-fill {
color: red;
}
.el-row {
margin-top: 15px;
}
.spec-table {
margin-top: 15px;
}
{
border-bottom: 1px solid #535353;
}
.spec {
padding-bottom: 20px;
border-bottom: 1px solid #535353;
}
.mar-t {
margin-top: 20px;
}
.price-modi {
width: 70px
}
</style>
</head>
<body>
<div id="app">
<!-- <h3>二、规格参数</h3> -->
<p>1、商品规格</p>
<el-row>
<el-checkbox v-model="enableSpec" size="large">启用规格</el-checkbox>
<span class="tip">* 启用商品规格后,商品的价格及库存以商品规格为准</span>
</el-row>
<div class="specs">
<!-- specs不存在直接不渲染 -->
<template v-if="specs.length != 0">
<div class="spec" v-for="(spec,index) in specs" v-show="enableSpec">
<p>* 规格{{index+1}}
<el-button type="primary" @click="deleteType(index)" size="mini">删除规格</el-button>
</p>
<div>
<el-row>
规格名:
<el-input placeholder="请输入规格名,例如:尺寸" class="spec-type" v-model.trim.lazy="spec.type"></el-input>
</el-row>
<el-row>
规格项:
<el-input placeholder="请输入规格项,例如:XXL" class="spec-type" v-model.trim.lazy="newSpecName[index]"></el-input>
</el-row>
<!-- <p>{{newSpecName[index]}}</p> -->
<el-row>
规格项:
<el-row v-for="(specName,index) in spec.children">
<el-input placeholder="" class="spec-type" v-model.lazy="specName" @blur="modiSpec(specName,spec.children,index)" :disabled="true"></el-input>
<el-button @click="deleteSpec(index,spec.children)">删除</el-button>
</el-row>
<br>
<el-button @click="addSpec(spec.children, newSpecName[index], index)" size="small">+添加</el-button>
<br>
</el-row>
</div>
</div>
</template>
</div>
<el-button type="primary" :disabled="this.specs.length === 2" v-if="enableSpec" @click="addType" size="small" class="mar-t">添加规格</el-button>
<!-- <div v-for="item in arr">
<input type="text" v-model="item">
</div>
<button @click="arrTest">test</button> -->
<div class="price-wra">
<br>
<p>2、商品价格</p>
<p v-show="enableSpec" class="mar-t">批量填写</p>
<el-row class="price-wra">
<b class="must-fill">*</b>市场价(元):
<el-input v-model="displayedPrices.marketPrice" class="goods-price"></el-input>
<b class="must-fill">*</b>享买价(元):
<el-input v-model="displayedPrices.advicePrice" class="goods-price"></el-input> 供货价(元):
<el-input v-model="displayedPrices.cost" class="goods-price"></el-input> <b class="must-fill">*</b>商品库存 :
<el-input v-model="displayedPrices.amount" class="goods-price"></el-input>
<!-- <el-button type="primary">确定</el-button> -->
</el-row>
<!-- <h4>{{displayedPrices.amount}}</h4> -->
<br>
<template v-if="enableSpec">
<!-- specs不存在直接不渲染 -->
<template v-if="specs.length != 0">
<el-table :data="tableData" border :style="{width:specs.length*100+402+'px'}" key='aTable'>
<el-table-column prop="spec0" :label="specs[0].type" width="100">
<input type="text" value="123">
</el-table-column>
<el-table-column prop="spec1" :label="specs[1].type" width="100" v-if="specs.length == 2">
</el-table-column>
<el-table-column label="市场价" width="100" min-width="200">
<template scope="scope">
<el-popover trigger="click" placement="top">
<p>市场价:
<el-input size="mini" class="price-modi" v-model.number="scope.row.prices.marketPrice"></el-input>
</p>
<div style="text-align: right; margin: 0">
<!-- <el-button size="mini" type="text" @click="visible2 = false">取消</el-button> -->
<!-- <el-button type="primary" size="mini" @click="visible2 = false">确定</el-button> -->
</div>
<div slot="reference" class="name-wrapper">
{{ scope.row.prices.marketPrice }}
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="prices.advicePrice" label="建议售价" width="100">
<template scope="scope">
<el-popover trigger="click" placement="top">
<p>市场价:
<el-input size="mini" class="price-modi" v-model.number="scope.row.prices.advicePrice"></el-input>
</p>
<div style="text-align: right; margin: 0">
<!-- <el-button size="mini" type="text" @click="visible2 = false">取消</el-button> -->
<!-- <el-button type="primary" size="mini" @click="visible2 = false">确定</el-button> -->
</div>
<div slot="reference" class="name-wrapper">
{{ scope.row.prices.advicePrice }}
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="prices.cost" label="供货价" width="100">
<template scope="scope">
<el-popover trigger="click" placement="top">
<p>市场价:
<el-input size="mini" class="price-modi" v-model.number="scope.row.prices.cost"></el-input>
</p>
<div style="text-align: right; margin: 0">
<!-- <el-button size="mini" type="text" @click="visible2 = false">取消</el-button> -->
<!-- <el-button type="primary" size="mini" @click="visible2 = false">确定</el-button> -->
</div>
<div slot="reference" class="name-wrapper">
{{ scope.row.prices.cost }}
</div>
</el-popover>
</template>
</el-table-column>
<el-table-column prop="prices.amount" label="库存" width="100">
<template scope="scope">
<el-popover trigger="click" placement="top">
<p>市场价:
<el-input size="mini" class="price-modi" v-model.number="scope.row.prices.amount"></el-input>
</p>
<div style="text-align: right; margin: 0">
<!-- <el-button size="mini" type="text" @click="visible2 = false">取消</el-button> -->
<!-- <el-button type="primary" size="mini" @click="visible2 = false">确定</el-button> -->
</div>
<div slot="reference" class="name-wrapper">
{{ scope.row.prices.amount }}
</div>
</el-popover>
</template>
</el-table-column>
</el-table>
</template>
</template>
<template v-else>
<!-- <el-table :data="originalPrices" style="width: 401px" border>
<el-table-column prop="marketPrice" label="市场价" width="100">
</el-table-column>
<el-table-column prop="advicePrice" label="建议售价" width="100">
</el-table-column>
<el-table-column prop="cost" label="供货价" width="100">
</el-table-column>
<el-table-column prop="amount" label="库存" width="100">
</el-table-column>
</el-table> -->
</template>
<!-- <p>{{originalPrices}}</p>
<p>{{defaultAddPrices}}</p>
<p>{{specCombinations}}</p>
<p>{{mySpecPrices}}</p>
<p>{{specPrices}}</p>
<p>{{tableData}}</p>
<p>{{enableSpec}}</p>
<p>{{arr}}</p> -->
</div>
</div>
<script>
new Vue({
el: '#app',
data: function () {
return {
arr: [1, 3, 5],
visible2: false,
// local
// __flag
// 规格种类的数量
typesLength: null,
enableSpec: null,
// __data
// 注意此项为数组 type Array
originalPrices: [{
marketPrice: 110,
advicePrice: 100,
cost: 90,
amount: 110
}],
// 批量填写价格
defaultAddPrices: {
marketPrice: 100,
advicePrice: 90,
cost: 80,
amount: 50
},
// from backend
specs: [{
type: '颜色',
children: ['红', '蓝']
},
{
type: '尺寸',
children: ['大', '中']
}
],
// from backend
_specs: [{
type: '颜色',
children: ['红', '蓝']
},
{
type: '尺寸',
children: ['大', '中']
}
],
// from backend
specPrices: [{
specs: ['红', '大'],
prices: {
marketPrice: 90,
advicePrice: 60,
cost: 40,
amount: 10
}
},
{
specs: ['红', '中'],
prices: {
marketPrice: 30,
advicePrice: 70,
cost: 30,
amount: 10
}
},
{
specs: ['蓝', '大'],
prices: {
marketPrice: 20,
advicePrice: 10,
cost: 30,
amount: 10
}
},
{
specs: ['蓝', '中'],
prices: {
marketPrice: 50,
advicePrice: 40,
cost: 30,
amount: 10
}
}
],
newSpecName: ['', '']
}
},
methods: {
arrTest() {
this.arr = 0
var t = 0;
var _t = '0';
console.log('Boolean(t)')
console.log(Boolean(t))
console.log(Boolean(_t))
},
test() {
console.log(this.specs)
},
deleteType(index) {
var r = confirm('确定删除规格名么?')
if (r) {
console.log('......' + r)
this.specs.splice(index, 1)
// 刷新 mySpecPrices
var myDefaultAddPrices = JSON.parse(JSON.stringify(this.defaultAddPrices));
this.mySpecPrices(this.specCombinations(), myDefaultAddPrices)
} else {
return
}
},
deleteSpec(index, spec) {
spec.splice(index, 1)
// 刷新 mySpecPrices
var myDefaultAddPrices = JSON.parse(JSON.stringify(this.defaultAddPrices));
this.mySpecPrices(this.specCombinations(), myDefaultAddPrices)
},
modiSpec(specName, spec, index) {
spec[index] = specName;
console.log(this.specs)
},
addType() {
// alert()
var obj = {}
obj.type = "";
obj.children = []
this.specs.push(obj)
},
addSpec(spec, newSpecName, index) {
console.log(newSpecName + '111')
// 检测新规格名是否规范 1, 不为空. 2,不重复
if (!newSpecName) {
alert('规格项名称不能为空')
return
} else if (spec.includes(newSpecName)) {
alert('规格项名称不能为重复')
return
}
spec.push(newSpecName)
console.log(spec)
// 每次点击添加, 保存一个defaultAddPrices的深拷贝副本, 防止数据关联
var myDefaultAddPrices = JSON.parse(JSON.stringify(this.defaultAddPrices));
var specCombinations = this.specCombinations()
this.mySpecPrices(specCombinations, myDefaultAddPrices)
this.newSpecName[index] = ''
// console.log(this.specs)
},
modiPrice() {
},
// 规格组合数组
specCombinations() {
console.log(this.specs)
var arrWra = [];
// 有2个规格type
if (this.specs.length == 2) {
var arr1 = this.specs[0].children
var arr2 = this.specs[1].children
// 判断arr1是否为[], 如果是 为其添加个空字符串占位
if (arr1.length == 0) {
arr1 = ['']
}
if (arr2.length == 0) {
arr2 = ['']
}
var arr = []
for (var t = 0; t < arr1.length; t++) {
for (var i = 0; i < arr2.length; i++) {
arr = []
arr.push(arr1[t])
arr.push(arr2[i])
arrWra.push(arr)
}
}
console.log(arrWra)
return arrWra
// 只有1个规格type
} else if (this.specs.length == 1) {
var arr = this.specs[0].children
if (arr.length == 0) {
arr = ['']
}
for (var i = 0; i < arr.length; i++) {
var _arr = []
_arr.push(arr[i])
arrWra.push(_arr)
}
console.log(arrWra)
console.log('arrWra............')
return arrWra
}
},
// 规格价格数据 local
// 数据更新
mySpecPrices(specCombinations, myDefaultAddPrices) {
// function sameSpecs(element) {
// return element.specs == arr[i];
// }
var arrWra = []
// 规格组合 数组
var arr = specCombinations
console.log(arr)
for (var i = 0; i < arr.length; i++) {
// 新增 规格价格 项
var obj = {};
obj.specs = arr[i];
// !注意 a类型为数组
// 对比 新的 规格组合数组 与原价格数组
var oldItem = this.specPrices.filter((element) => {
return element.specs + "" === arr[i] + "";
})
var newItem = this.specPrices.filter((element) => {
return element.specs + "" != arr[i] + "";
})
// 注意这里用的是length因为 空数组,空对象的布尔值为true
// 旧规各项价格
if (oldItem.length) {
obj.prices = oldItem[0].prices
console.log(oldItem[0])
// 新规各项价格
} else {
console.log(newItem)
console.log('_____')
// if (newItem.length != 0) {
// 这里用深拷贝否则各新项目的价格数据会关联
newItem[0].prices = JSON.parse(JSON.stringify(myDefaultAddPrices));
obj.prices = newItem[0].prices
// }
}
arrWra.push(obj)
}
console.log(arrWra)
this.specPrices = arrWra
},
// spec type 只有一个时, 检查重复 并 去重
// checkDuplicate() {
// console.log(this.specPrices)
// }
},
computed: {
displayedPrices() {
// console.log(this.enableSpec ? this.defaultAddPrices : this.originalPrices[0])
return this.enableSpec ? this.defaultAddPrices : this.originalPrices[0]
},
// 表格数据
tableData() {
var arr = this.specPrices;
console.log(arr)
for (var i = 0; i < arr.length; i++) {
arr[i].spec0 = arr[i].specs[0]
arr[i].spec1 = arr[i].specs[1]
}
// console.log(this.mySpecPrices)
return arr
}
},
created() {
// this.defaultAddPrices = this.goodsData.defaultAddPrices
// this.originalPrices = this.goodsData.originalPrices
this.specs = this._specs
this.specs = []
this.specPrices = []
if (this.specs.length == 0) {
// 初始化规格数据
var obj = {}
obj.type = "";
obj.children = []
this.specs.push(obj)
// console.log(this.specs)
// 初始化价格数据
var _obj = [{}]
_obj[0].specs = ['']
_obj[0].prices = {
marketPrice: 0,
advicePrice: 0,
cost: 0,
amount: 0
}
this.specPrices = _obj
}
this.typesLength = this.specs.length
this.enableSpec = this.typesLength ? true : false
this.enableSpec = false
console.log(this.enableSpec)
console.log(this.typesLength)
console.log(this.specCombinations)
console.log('this.specCombinations')
if (this.typesLength === 2) {
this.typeName1 = this.goodsData[0].type
this.typeName2 = this.goodsData[0].type
}
}
})
</script>
</body>
</html>
<!-- obj = JSON.parse(JSON.stringify(obj)); -->