cb_wayadd.js
5.47 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
//logs.js
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
Page({
data: {
wlist:[],
selectunitindex:0,
specs :[],
wayindex : '',
first:'1',
buttonhide:true,
atn_ishidden:true,
auto_focus:false,
inputvalue:'',
dtn_ishidden:true
},
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("practice") && this.data.optid){
util.cache('wayadd',true)
this.cookdetail()
}else{
this.waylist();
}
var that=this;
util.postSuccessFun=function(json,uri_code){
switch(uri_code){
case uri.CGI__USER_GETSELLERPRACTICEBYID__CODE: //做法列表
if(json.ret==200){
var list=json.data[0];
if(util.cache('practice')){
var cachelist=util.cache('practice');
cachelist.forEach(function(v,i){
list.forEach(function(r,n){
if(v.id==r.id){
r.status=true
}
})
})
}
that.setData({
waylist:list,
})
console.log(list)
}
break
case uri.CGI__USER_GETCOOKBOOKBYID__CODE: //详情
var kindlist=json.data.data.practice;
var cachelist=[];
kindlist.forEach(function(v,i){
cachelist.push({
id:v.practice,
name:v.name,
})
})
if(cachelist.length>0){
util.cache('practice',cachelist)
}
that.waylist();
break;
case uri.CGI__USER_ADDPRACTICE__CODE: //添加做法
console.log(json)
if(json.ret==200){
that.setData({
atn_ishidden:true,
auto_focus:true,
inputvalue:''
})
that.waylist();
}else{
that.setData({
dtn_ishidden:false,
reminderInfo:json.msg.split(':')[1]
})
}
break;
}
}
},
waylist:function(){
util.post(uri.CGI__USER_GETSELLERPRACTICEBYID,{sellerid:this.data.sellerid},uri.CGI__USER_GETSELLERPRACTICEBYID__CODE)
},
cookdetail:function(){
util.post(uri.CGI__USER_GETCOOKBOOKBYID,{id:this.data.optid},uri.CGI__USER_GETCOOKBOOKBYID__CODE);
},
switch1Change:function(e){
var id=e.currentTarget.dataset.id;
var waylist=this.data.waylist;
var cachelist=util.cache('practice');
waylist.forEach(function(v,i){
if(v.id==id) {
v.status=false
}
})
cachelist.forEach(function(v,i){
if(v.id==id){
cachelist.splice(i,1)
}
})
if(cachelist.length==0){
wx.removeStorage({key:'practice'})
}else{
util.cache('practice',cachelist)
}
this.setData({
waylist:waylist
})
},
switch2Change:function(e){
console.log('开',e)
var id=e.currentTarget.dataset.id;
var name=e.currentTarget.dataset.name;
var waylist=this.data.waylist;
var cachelist=util.cache('practice') ? util.cache('practice') : [];
waylist.forEach(function(v,i){
if(v.id==id) {
v.status=true
}
})
cachelist.push({
id:id,
name:name
})
util.cache('practice',cachelist)
this.setData({
waylist:waylist
})
},
//添加做法
addWayName:function(){
this.setData({
atn_ishidden:false,
auto_focus:true
})
},
//做法去除空格
modalInput:function(e){
var val=''
//32为空格code码
if(e.detail.keyCode==32){
val=''
}else{
val=e.detail.value
}
this.setData({
inputvalue:val
})
},
//取消弹框
cancelModel:function(){
this.setData({
atn_ishidden:true,
auto_focus:true
})
},
//确认添加做法
confirmModel:function(){
if(this.data.inputvalue!=''){
util.post(uri.CGI__USER_ADDPRACTICE,{sellerid:this.data.sellerid,name:this.data.inputvalue},uri.CGI__USER_ADDPRACTICE__CODE);
}else{
this.setData({
dtn_ishidden:false,
reminderInfo:'菜品做法不能为空'
})
}
},
confirm:function(){
this.setData({
dtn_ishidden:true,
})
},
netchange:function(){
this.onShow();
}
});