-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprod-list.js
More file actions
153 lines (125 loc) · 3.13 KB
/
prod-list.js
File metadata and controls
153 lines (125 loc) · 3.13 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
import $ from 'jquery'
import Pagination from './scripts/pagination.js'
class Production {
constructor(opts) {
let {
id,
pic,
code,
content,
unit,
price,
price1,
store,
state
} = opts
this.id = id
this.pic = pic
this.code = code
this.content = content
this.unit = unit
this.price = price
this.price1 = price1
this.store = store
this.state = state
}
}
Production.of = opts => new Production(opts)
const productionTpl = (prod) => `
<tr>
<td>
<div class="list-checkbox">
<input name="" type="checkbox" class="" value=""/>
</div>
</td>
<td>
<div class="row">
<div class="grid width--3">
<div class="list-pic">
<img alt="" src="/images/${prod.pic}"/>
</div>
</div>
<div class="grid width--9">
<div class="list-id">${prod.code}</div>
<div class="list-content">
${prod.content}
</div>
</div>
</div>
</td>
<td class="list-nth-1">${prod.unit}</td>
<td class="list-nth-1">¥${prod.price}</td>
<td class="list-nth-1">¥${prod.price1}</td>
<td class="list-nth-1">${prod.store}</td>
<td class="list-nth-1">${prod.state}</td>
<td>
<div class="list-actions">
<div class="list-action">
<a href="#">修改</a>
</div>
<div class="list-action">
<a href="#">删除</a>
</div>
</div>
</td>
</tr>
`
const productionView = (prod) => {
let tpl = productionTpl(prod)
let $tpl = $(tpl)
$tpl.on('click.prodremove', function() {
console.log(prod.id)
})
return $tpl
}
const appendToContainer = $con => views => {
$con.empty()
views.forEach(n => n.appendTo($con))
}
const sendRequest = (page) => {
/**
商品列表
GET /
200:
{
msg: 'ok',
code: '200',
data: [{
id: 1,
code: 'PC12345',
content: '唯品会-007 【规格1:1:100*200*300,规格2:200*100*300】',
unit: '件',
price: '100.000',
price1: '120.000',
store: 600,
state: '上架'
}]
}
*/
console.log(page)
let rd = Math.floor(Math.random() * 10) + 1
let prods = Array(rd).fill({
id: 1,
code: 'PC12345',
content: '唯品会-007 【规格1:1:100*200*300,规格2:200*100*300】',
unit: '件',
price: '100.000',
price1: '120.000',
store: 600,
state: '上架'
})
return $.get('')
.then(_ => prods)
.then(prods => prods.map(Production.of).map(productionView))
.then(appendToContainer($('.js-listcontainer')))
}
const main = _ => {
sendRequest()
.then(data => {
Pagination.of({ $el: $('.js-pagination'), sum: 10, curr: 5 })
.on('pagination.export', function(evt, page) {
sendRequest(page)
})
})
}
main()