ck_list.js
6.93 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
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
Page({
data: {
loading: true,
scrollHeight: 0,
isscroll: true,
atn_ishidden: true,
specs: [],
// 搜索框宽度
searchWidth: '',
inputKey: '',
sellerid: '',
auto_focus: false
},
onLoad: function () {
var that=this;
//获取系统信息
var sys=wx.getSystemInfo({
success:function(res){
that.setData({
scrollHeight:res.windowHeight,
scrollHeight1:res.windowHeight-93,
scrollHeight2:res.windowHeight-200,
windowWidth:res.windowWidth,
margin:(res.windowWidth*0.92-228)/10,
searchWidth:res.windowWidth*0.84-35,
topheight:util.cache('headerHeight')
});
}
});
wx.setNavigationBarTitle({
title:'我的菜品' ,
})
this.setData({
sellerid: util.cache("sellerid"),
});
},
onShow:function(){
var that=this;
this.cookList();
util.postSuccessFun=function(json,uri_code){
switch(uri_code){
case uri.CGI__USER_GETCOOKBOOKBYCLASS__CODE: //获取所有分类下所有菜品列表(估清管理)
console.log(json.data[0]['list']);
if(json.ret==200){
var arr=json.data[0]['list'];
if(typeof arr!='string' && arr.length>0){
arr.forEach(function(v,i){
if(i==0){
v.isactive=true;
}else{
v.isactive=false;
}
if(typeof v.cookbooklist[0]!='string' && v.cookbooklist[0].length>0){
v.cookbooklist[0].forEach(function(r,n){
if(r.name.length>6){
r.name=r.name.slice(0,6)+'...'
}
r.isactive=false;
if(n%2==0){
r.bg_color='bg-pink'
}else{
r.bg_color='bg-blue'
}
})
}
})
var thislist=[];
arr.forEach(function(v,i){
if(v.class_type!=1){
if(typeof v.cookbooklist[0]!='string' && v.cookbooklist[0].length>0){
thislist.push(v);
}
}
})
arr=thislist;
}
var mtop=0;
if(arr.length>0){
arr[0].isactive=true;
mtop=Math.ceil(arr.length/3)*90+30
}
that.setData({
classlist:arr.length>0 ? arr : null,
cooklist:arr.length>0 ? arr[0] : null,
mtop:mtop
})
}
break
case uri.CGI__USER_SETCLEARCOOKBOOKBYID__CODE: //设置商家菜品估清(估清管理)
console.log(json)
if(json.ret==200){
wx.navigateBack({
url: 'ck_list',
})
}
break
case uri.CGI__USER_SEARCHCOOKBOOK__CODE:
if(json.ret==200){
console.log(66666,json.data[0])
if(json.data[0].length>0){
json.data[0].forEach(function(v,i){
if(i%2==0){
v.bg_color='bg-pink'
}else{
v.bg_color='bg-blue'
}
})
}
that.setData({
newlist:json.data[0].length>0 ? json.data[0] : null
})
}
break
}
}
},
getcooklist:function(e){
var classid=e.detail;
var classlist=this.data.classlist;
var cooklist=[];
classlist.forEach(function(v,i){
if(v.id==classid){
cooklist=v;
}
})
this.setData({
cooklist:cooklist
})
},
selectcook:function(e){
var cookid=e.detail.id;
var cooklist=this.data.cooklist;
var title='';
var clear_num='';
cooklist.cookbooklist[0].forEach(function (v,i) {
if(v.id==cookid){
title=v.name;
clear_num=v.clear_num ? v.clear_num : null
}
})
this.setData({
auto_focus:true,
atn_ishidden:false,
title:title,
cookbookid:cookid,
clear_num:clear_num
})
},
cookList:function(){
util.post(uri.CGI__USER_GETCOOKBOOKBYCLASS,{sellerid:this.data.sellerid},uri.CGI__USER_GETCOOKBOOKBYCLASS__CODE)
},
searchsubmit:function(e){
console.log(e.detail.value)
this.setData({
inputKey:e.detail.value
})
util.post(uri.CGI__USER_SEARCHCOOKBOOK,{sellerid:this.data.sellerid,name:e.detail.value},uri.CGI__USER_SEARCHCOOKBOOK__CODE)
},
//对无规格菜品的点击事件,有弹出框
onlyClear:function(e){
console.log(e);
this.setData({
auto_focus:true,
atn_ishidden:false,
title:e.currentTarget.dataset.name,
cookbookid:e.currentTarget.dataset.id,
clear_num:e.currentTarget.dataset.num
})
console.log('无规格:',this.data.cookbookid)
},
//对无规格菜品的弹出框取消
onlyCancelModel:function(){
this.setData({
atn_ishidden:true,
})
},
//对无规格菜品的弹出框确认
onlyConfirmModel:function(e){
util.post(uri.CGI__USER_SETCLEARCOOKBOOKBYID,{cookbookid:this.data.cookbookid,clear_num:this.data.clear_num},uri.CGI__USER_SETCLEARCOOKBOOKBYID__CODE)
},
//获取无规格菜品输入框数据
onlyModalInput:function(e){
console.log(e);
this.setData({
clear_num:e.detail.value
})
},
netchange:function(){
this.onShow();
}
})