cb_ggadd.js
9.19 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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
Page({
data: {
specs:[],
slist:[],
},
onLoad:function(opt){
var that=this;
console.log('opt:',opt);
util.setBarTitle('添加规格')
this.setData({
sellerid: util.cache("sellerid"),
optid:opt.id
})
},
onShow:function(){
if(!util.cache('spec') && this.data.optid){
this.cookdetail();
util.cache('ggadd',true)
}else{
this.gglist();
}
var that=this;
util.postSuccessFun=function(json,uri_code){
switch(uri_code){
case uri.CGI__USER_GETSELLERSPECIFICATIONSBYID__CODE:
if(json.ret==200){
var list=json.data[0];
list.forEach(function(v,i){
v.status=0
})
}
if(util.cache('spec')){
var spec=util.cache('spec');
spec.forEach(function(v,i){
list.forEach(function(r,n){
if(v.id==r.id){
r.status=1;
r.price=v.price;
r.member_price=v.member_price;
}
})
})
}
that.setData({
gglist:list,
})
break
case uri.CGI__USER_GETCOOKBOOKBYID__CODE: //详情
var spec=json.data.data.spec;
var cachelist=[];
spec.forEach(function(v,i){
cachelist.push({
id:v.specid,
specs:v.specs,
price:v.price,
member_price:v.member_price!=0 ? v.member_price : ''
})
})
if(cachelist.length>0){
util.cache('spec',cachelist)
}
that.gglist();
break;
}
}
},
cookdetail:function(){
util.post(uri.CGI__USER_GETCOOKBOOKBYID,{id:this.data.optid},uri.CGI__USER_GETCOOKBOOKBYID__CODE)
},
gglist:function(){
util.post(uri.CGI__USER_GETSELLERSPECIFICATIONSBYID,{sellerid:this.data.sellerid},uri.CGI__USER_GETSELLERSPECIFICATIONSBYID__CODE)
},
//填写规格普通价
priceModalInput:function(e){
var id=e.currentTarget.dataset.id;
var price=e.detail.value;
if(e.detail.value!=''){
if(price.indexOf('.')!=-1){
if(price[0]=='.'){
if(price.length==1){
price='0'+price;
}else{
var arr=price.split('.');
if(arr[arr.length-1]!=''){
if(arr[0]=='' && arr[1]==''){
price='.'+arr[arr.length-1]
}
}else{
price='0.'+arr[1]
}
}
}else{
var temp=price.slice(0,-1)
if(temp.indexOf('.')!=-1){
if(price[price.length-1]=='.'){
price=price.slice(0,-1);
}
if(price[price.length-1]!='.'){
var arr=price.split('.');
if(arr[1].length>2){
price=arr[0]+'.'+arr[1].slice(0,2)
}
}
}
}
}
}
var gglist=this.data.gglist;
var cachelist=util.cache('spec');
if(price!=''){
if(price.indexOf('.')==-1 && Number(price)==0){
price=0
}
}
cachelist.forEach(function(v,i){
if(v.id==id){
v.price=price;
}
})
gglist.forEach(function(v,i){
if(v.id==id){
v.price=price;
}
})
this.setData({
gglist:gglist
})
util.cache('spec',cachelist)
},
//价格判断
condition:function(e){
var _key = e.currentTarget.dataset.id;
var _name = e.currentTarget.dataset.name;
var _value = e.detail.value;
if(_value.indexOf('.')!=-1){
if(_value[_value[_value.length-1]]=='.'){
_value+='00'
}else{
if(Number(_value)==0){
_value=0
}
}
}else{
if(Number(_value)==0){
_value=0
}
}
var gglist=this.data.gglist;
var cachelist=util.cache('spec');
cachelist.forEach(function(v,i){
if(v.id==_key){
v[_name]=_value;
}
})
gglist.forEach(function(v,i){
if(v.id==_key){
v[_name]=_value;
}
})
this.setData({
gglist:gglist
})
util.cache('spec',cachelist)
if(_value==0){
this.setData({
dtn_ishidden:false,
reminderInfo:_name+'价格不能为0'
})
}else if(_value==''){
this.setData({
dtn_ishidden:false,
reminderInfo:_name+'价格不能为空'
})
}
},
confirm:function(){
this.setData({
dtn_ishidden:true,
})
},
//填写规格会员价
memberpriceModalInput:function(e){
var id=e.currentTarget.dataset.id;
var member_price=e.detail.value;
if(e.detail.value!=''){
if(member_price.indexOf('.')!=-1){
if(member_price[0]=='.'){
console.log('xxxx')
if(member_price.length==1){
member_price='0'+member_price;
}else{
var arr=member_price.split('.');
if(arr[arr.length-1]!=''){
if(arr[0]=='' && arr[1]==''){
member_price='.'+arr[arr.length-1]
}
}else{
member_price='0.'+arr[1]
}
}
}else{
var temp=member_price.slice(0,-1)
if(temp.indexOf('.')!=-1){
if(member_price[member_price.length-1]=='.'){
member_price=member_price.slice(0,-1);
}
if(member_price[member_price.length-1]!='.'){
var arr=member_price.split('.');
if(arr[1].length>2){
member_price=arr[0]+'.'+arr[1].slice(0,2)
}
}
}
}
}
}
if(member_price.indexOf('.')==-1 && Number(member_price)==0){
member_price=0
}
var gglist=this.data.gglist;
var cachelist=util.cache('spec');
cachelist.forEach(function(v,i){
if(v.id==id){
v.member_price=member_price;
}
})
gglist.forEach(function(v,i){
if(v.id==id){
v.member_price=member_price;
}
})
this.setData({
gglist:gglist
})
util.cache('spec',cachelist)
},
//关闭规格选项
switch1Change: function (e) {
var id=e.currentTarget.dataset.id;
var gglist=this.data.gglist;
var cachelist=util.cache('spec');
gglist.forEach(function(v,i){
if(v.id==id){
v.status=0
}
})
cachelist.forEach(function(v,i){
if(v.id==id){
cachelist.splice(i,1)
}
})
if(cachelist.length>0){
util.cache('spec',cachelist)
}else{
wx.removeStorage({key:'spec'})
}
this.setData({
gglist:gglist
})
},
//开启规格项
switch2Change:function(e){
var id=e.currentTarget.dataset.id;
var name=e.currentTarget.dataset.name;
var gglist=this.data.gglist;
var cachelist=util.cache('spec') ? util.cache('spec') : [];
var price=0;
var member_price=0;
gglist.forEach(function(v,i){
if(v.id==id){
v.status=1;
price=v.price ? v.price : 0
member_price=v.member_price ? v.member_price : 0
}
})
cachelist.push({
id:id,
specs:name,
price:price,
member_price:member_price
})
util.cache('spec',cachelist)
this.setData({
gglist:gglist
})
},
netchange:function(){
this.onShow();
}
});