cb_label.js
5.91 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
// pages/cookbook/cb_label.js
//logs.js
var util = require('../../utils/util.js')
var uri = require('../../utils/uri.js')
Page({
data: {
loading: true,
sellerid: '',
},
onLoad:function (options) {
util.setBarTitle('标签库')
console.log("foodid", options.foodid)
this.setData({
classid: options.classid ? options.classid:'',
foodid: options.foodid ? options.foodid:'',
sellerid: util.cache("sellerid")
})
if(this.data.foodid!='') {
this.getcookdetail();
}else if(this.data.classid!=''){
this.getcook()
}else{
this.getLabelList()
}
},
getLabelList:function () { // 获取标签数据
util.post(uri.CGI__USER_GETSELLERLABELBYID, { sellerid: this.data.sellerid }, uri.CGI__USER_GETSELLERLABELBYID__CODE)
},
onReady: function () {
this.setData({ loading:false })
},
onShow: function () {
var that = this;
util.postSuccessFun = function(json, uri_code) {
switch (uri_code) {
case uri.CGI__USER_GETSELLERLABELBYID__CODE:
if (json.ret == 200) {
var thisdata = json.data[0];
console.log(thisdata)
if(that.data.select){
var select=that.data.select;
thisdata.forEach(function(v,i){
v.item.forEach(function(r,n){
select.forEach(function(o,k){
console.log(o)
if(o==r.id){
r.state=true
}
})
})
})
}
that.setData({
dataList:thisdata
})
}
break;
case uri.CGI__USER_GETCOOKBOOKBYID__CODE: //获取菜品标签
console.log(json.data.data)
if(json.ret==200){
if(json.data.data.lid){
console.log(json.data.data.lid.split(','))
that.setData({
select:json.data.data.lid.split(',')
})
}
}
that.getLabelList()
break;
case uri.CGI__USER_GETCLASSBYID__CODE:
if(json.ret==200){
if(json.data[0].class_label!=null){
that.setData({
select:json.data[0].class_label.split(',')
})
}
}
that.getLabelList()
break;
}
}
},
radioChange (e) { // 单选框方法
var index = e.currentTarget.dataset.index
var dataList = this.data.dataList
dataList.forEach((key, num) => {
if (key.type == '2') {
if (key.item[index].state) {
key.item[index].state = false
} else {
key.item.forEach((Son, k) => {
Son.state = false
})
key.item[index].state = true
}
}
})
this.setData({ dataList: dataList })
},
checkbox (e) { // 复选框方法
var title = e.currentTarget.dataset.title
var index = e.currentTarget.dataset.index
var dataList = this.data.dataList
dataList.forEach((key, num) => {
if (title == key.title) {
key.item[index].state = !key.item[index].state
}
})
this.setData({ dataList: dataList })
},
okButtonClick () { // 提交方法
var dataList = this.data.dataList
var classid = this.data.classid
var foodid = this.data.foodid
var slist = []
dataList.forEach((key, num) => {
key.item.forEach((item, j) => {
if (item.state) {
console.log(item.state)
slist.push(item.id)
}
})
})
var ssid = slist.toString();
console.log(ssid)
if (ssid) {
if (classid) {
console.log("调用分类提交方法")
this.SetClassLabel(classid, ssid) // 调用分类提交方法
} else if (foodid) {
console.log("调用菜品提交方法")
console.log(foodid)
this.SetCookbookLabel(foodid, ssid) // 调用菜品提交方法
}
} else {
wx.showToast({
title: '请选择',
icon: 'none'
})
throw new Error('报错')
}
},
// 提交分类标签
SetClassLabel (id, data) {
util.post(uri.CGI__USER_SETCLASSLABEL, {
classid: id,
id: data
},
uri.CGI__USER_SETCLASSLABEL__CODE)
util.postSuccessFun = (json, uri_code) => {
switch (uri_code) {
case uri.CGI__USER_SETCLASSLABEL__CODE:
console.log(json)
if (json.ret == 200) {
wx.showToast({
title: '保存成功',
})
setTimeout(() => {
wx.navigateBack({})
}, 1000)
}
break
}
}
},
// 提交菜品标签
SetCookbookLabel (id, data) {
util.post(uri.CGI__USER_SETCOOKBOOKLABEL, {
cid: id,
id: data
},
uri.CGI__USER_SETCOOKBOOKLABEL__CODE)
util.postSuccessFun = (json, uri_code) => {
switch (uri_code) {
case uri.CGI__USER_SETCOOKBOOKLABEL__CODE:
console.log(json)
if (json.ret == 200) {
wx.showToast({
title: '保存成功',
})
setTimeout(() => {
wx.navigateBack({})
}, 1000)
}
break
}
}
},
// 获取单条菜品信息
getcookdetail:function(){
util.post(uri.CGI__USER_GETCOOKBOOKBYID,{id:this.data.foodid},uri.CGI__USER_GETCOOKBOOKBYID__CODE)
},
// 获取分类信息
getcook:function(){
util.post(uri.CGI__USER_GETCLASSBYID,{id:this.data.classid},uri.CGI__USER_GETCLASSBYID__CODE)
},
netchange:function(){
this.onShow();
}
})