Commit e093fb40963a90f68b111b878bce8573abc8b9ff

Authored by wangfan
1 parent 6642a3b0

快速预定

@@ -3,452 +3,453 @@ import util from '../../../utils/util'; @@ -3,452 +3,453 @@ import util from '../../../utils/util';
3 import App from '../../../utils/api'; 3 import App from '../../../utils/api';
4 const {regeneratorRuntime} = global 4 const {regeneratorRuntime} = global
5 Component({ 5 Component({
6 - /**  
7 - * 组件的属性列表  
8 - */  
9 - properties: {  
10 - item:{  
11 - type:Object // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)  
12 - },  
13 - type:{  
14 - type:String,  
15 - default:'+'  
16 - },  
17 - sellerid:{  
18 - type:Number  
19 - },  
20 - orderid:{  
21 - type:Number  
22 - },  
23 - fromSoucre:{  
24 - type:Number,  
25 - value:0  
26 - },  
27 - request_uri:{  
28 - type:Boolean,  
29 - value:false,  
30 - },  
31 - identity:{  
32 - type:String,  
33 - value:"",  
34 - }  
35 - 6 + /**
  7 + * 组件的属性列表
  8 + */
  9 + properties: {
  10 + item: {
  11 + type: Object // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
36 }, 12 },
37 -  
38 - /**  
39 - * 组件的初始数据  
40 - */  
41 - data: {  
42 - hiddenFoodSpec:true,//加菜规格  
43 - hiddenFoodSpecReduce:true,//减菜规格  
44 - selectKind:[{title:'xxxxx'},{title:'yyyyy'}], 13 + type: {
  14 + type: String,
  15 + default: '+'
45 }, 16 },
46 - ready () {  
47 - 17 + sellerid: {
  18 + type: Number
48 }, 19 },
49 - detached(){  
50 - 20 + orderid: {
  21 + type: Number
51 }, 22 },
52 - /**  
53 - * 组件的方法列表  
54 - */  
55 - methods: {  
56 - init(){  
57 - console.log('food-spec init');  
58 - this.setData({  
59 - hiddenFoodSpec:false  
60 - })  
61 - },  
62 - //关闭规格框  
63 - close:function(){  
64 - this.setData({  
65 - hiddenFoodSpec:true,  
66 - hiddenFoodSpecReduce:true,  
67 - })  
68 - //关闭了规格窗口  
69 - this.triggerEvent('foodSpecCallback',{  
70 - type:'specWin',  
71 - value:'hide'  
72 - });  
73 - },  
74 - //构造KindMenu  
75 - initKindMenu(){  
76 - return new Promise((success,fail)=>{  
77 - let price=this.data.item.price;  
78 - let hasSpec = this.data.item.spec.length>0;  
79 - let hasPractice = this.data.item.practice.length>0;  
80 - if(hasSpec || hasPractice){  
81 - var specs = this.data.item.spec//规格  
82 - var practice = this.data.item.practice//做法  
83 - var kind = []  
84 - var foodMenu=[]  
85 - if(this.data.type=='-'){  
86 - if(specs){  
87 - specs.map(function(r,n){  
88 - if(r.id){//某规格卖光了 就不显示 && r.clear_num>1  
89 - kind.push({id:r.id,price:r.price,title:r.specs,iskind:false})  
90 - }  
91 - })  
92 - } 23 + fromSoucre: {
  24 + type: Number,
  25 + value: 0
  26 + },
  27 + request_uri: {
  28 + type: Boolean,
  29 + value: false,
  30 + },
  31 + identity: {
  32 + type: String,
  33 + value: "",
  34 + }
93 35
94 - if(practice) {  
95 - practice.map(function (r, n) {  
96 - if (r.id) {  
97 - foodMenu.push({id: r.id, price: r.price, title: r.name, iskind: false})  
98 - }  
99 - })  
100 - }  
101 - App.Advance.GetCookbookSelBySpecsId({  
102 - sellerid:this.data.sellerid,  
103 - orderid: this.data.orderid,  
104 - cookbookid: this.data.item.id,  
105 - status:this.data.fromSoucre!=''?2:'',//只查没有下单的  
106 - }).then(res=>{  
107 - this.setData({  
108 - selectKind:res.data[0],  
109 - hiddenFoodSpecReduce:false,  
110 - kind:kind?kind:'',  
111 - foodMenu:foodMenu,  
112 - })  
113 - })  
114 - }else{  
115 - specs.map(function(r,n){  
116 - if ((r.id && r.clear_num > 0) || r.clear_num==null){//某规格卖光了 就不显示 && r.clear_num>1  
117 - kind.push({id:r.id,price:r.price,title:r.specs,iskind:false})  
118 - }  
119 - })  
120 - if(kind.length>0){  
121 - kind[0].iskind=true;  
122 - var kindPrice=kind[0].price;  
123 - var specs_id=kind[0].id;  
124 - } 36 + },
125 37
126 - practice.map(function(r,n){  
127 - if(r.id){  
128 - foodMenu.push({id:r.id,price:price,title:r.name,iskind:false})  
129 - }  
130 - }) 38 + /**
  39 + * 组件的初始数据
  40 + */
  41 + data: {
  42 + hiddenFoodSpec: true,//加菜规格
  43 + hiddenFoodSpecReduce: true,//减菜规格
  44 + selectKind: [{title: 'xxxxx'}, {title: 'yyyyy'}],
  45 + },
  46 + ready () {
131 47
132 - if(foodMenu.length>0){  
133 - foodMenu[0].iskind=true;  
134 - var foodMenuPrice=foodMenu[0].price;  
135 - var practice_id=foodMenu[0].id;  
136 - }  
137 - App.Advance.GetCookbookSelBySpecsId({  
138 - sellerid:this.data.sellerid,  
139 - orderid: this.data.orderid,  
140 - cookbookid: this.data.item.id,  
141 - status:this.data.fromSoucre!=''?2:'',//只查没有下单的  
142 - }).then(res=>{  
143 - this.setData({  
144 - selectKind:res.data[0],  
145 - hiddenFoodSpec:false,  
146 - kind:kind,  
147 - foodMenu:foodMenu,  
148 - showSpecsPrice:false,  
149 - cookbook_name:this.data.item.name,  
150 - cookbook_id:this.data.item.id,  
151 - specs_id:specs_id ? specs_id :'',  
152 - practice_id:practice_id ? practice_id : '',  
153 - selectPrice:kindPrice>0 ? kindPrice : foodMenuPrice,  
154 - add_target:''  
155 - })  
156 - })  
157 - }  
158 - success();  
159 - }else{  
160 - fail();  
161 - }  
162 - });  
163 - },  
164 - //选择规格  
165 - kindSelect: function (e) {  
166 - var index = e.currentTarget.dataset.key  
167 - var specsid = e.currentTarget.id  
168 - var price = e.currentTarget.dataset.price  
169 - for (var i = 0; i < this.data.kind.length; i++) {  
170 - if (i == index) {  
171 - this.data.kind[i].iskind = true;  
172 - } else {  
173 - this.data.kind[i].iskind = false; 48 + },
  49 + detached(){
  50 +
  51 + },
  52 + /**
  53 + * 组件的方法列表
  54 + */
  55 + methods: {
  56 + init(){
  57 + console.log('food-spec init');
  58 + this.setData({
  59 + hiddenFoodSpec: false
  60 + })
  61 + },
  62 + //关闭规格框
  63 + close: function () {
  64 + this.setData({
  65 + hiddenFoodSpec: true,
  66 + hiddenFoodSpecReduce: true,
  67 + })
  68 + //关闭了规格窗口
  69 + this.triggerEvent('foodSpecCallback', {
  70 + type: 'specWin',
  71 + value: 'hide'
  72 + });
  73 + },
  74 + //构造KindMenu
  75 + initKindMenu(){
  76 + return new Promise((success, fail) => {
  77 + let price = this.data.item.price;
  78 + let hasSpec = this.data.item.spec.length > 0;
  79 + let hasPractice = this.data.item.practice.length > 0;
  80 + if (hasSpec || hasPractice) {
  81 + var specs = this.data.item.spec//规格
  82 + var practice = this.data.item.practice//做法
  83 + var kind = []
  84 + var foodMenu = []
  85 + if (this.data.type == '-') {
  86 + if (specs) {
  87 + specs.map(function (r, n) {
  88 + if (r.id) {//某规格卖光了 就不显示 && r.clear_num>1
  89 + kind.push({id: r.id, price: r.price, title: r.specs, iskind: false})
174 } 90 }
  91 + })
175 } 92 }
176 - var is_show = ''  
177 - if(this.data.foodMenu==''){  
178 - is_show=1  
179 - }else if(specsid && this.data.practice_id){  
180 - is_show=1  
181 - }  
182 - this.setData({  
183 - kind: this.data.kind,  
184 - selectPrice:price,  
185 - specs_id:specsid,  
186 - foodMenu:this.data.foodMenu?this.data.foodMenu:'',  
187 - showSpecsPrice:price?false:true,  
188 - showAdd:is_show?false:true//showAdd:specsid?false:true  
189 - });  
190 - },  
191 - //选择做法  
192 - menuSelect: function (e) {  
193 - var index = e.currentTarget.dataset.key  
194 - var practiceid = e.currentTarget.id  
195 - var price = e.currentTarget.dataset.price  
196 - for (var i = 0; i < this.data.foodMenu.length; i++) {  
197 - if (i == index) {  
198 - this.data.foodMenu[i].iskind = true;  
199 - } else {  
200 - this.data.foodMenu[i].iskind = false; 93 +
  94 + if (practice) {
  95 + practice.map(function (r, n) {
  96 + if (r.id) {
  97 + foodMenu.push({id: r.id, price: r.price, title: r.name, iskind: false})
201 } 98 }
  99 + })
202 } 100 }
203 - var is_show = ''  
204 - if(this.data.kind==''){  
205 - is_show=1  
206 - }else if(this.data.specs_id && practiceid){  
207 - is_show=1 101 + App.Advance.GetCookbookSelBySpecsId({
  102 + sellerid: this.data.sellerid,
  103 + orderid: this.data.orderid,
  104 + cookbookid: this.data.item.id,
  105 + status: this.data.fromSoucre != '' ? 2 : '',//只查没有下单的
  106 + }).then(res => {
  107 + this.setData({
  108 + selectKind: res.data[0],
  109 + hiddenFoodSpecReduce: false,
  110 + kind: kind ? kind : '',
  111 + foodMenu: foodMenu,
  112 + })
  113 + })
  114 + } else {
  115 + specs.map(function (r, n) {
  116 + if ((r.id && r.clear_num > 0) || r.clear_num == null) {//某规格卖光了 就不显示 && r.clear_num>1
  117 + kind.push({id: r.id, price: r.price, title: r.specs, iskind: false})
  118 + }
  119 + })
  120 + if (kind.length > 0) {
  121 + kind[0].iskind = true;
  122 + var kindPrice = kind[0].price;
  123 + var specs_id = kind[0].id;
208 } 124 }
209 - this.setData({  
210 - foodMenu: this.data.foodMenu,  
211 - foodMenuPrice:price,  
212 - practice_id:practiceid,  
213 - showAdd:is_show?false:true  
214 - });  
215 - },  
216 - //加菜面板  
217 - addCook:function(e){  
218 - console.log('addCook',this.data.item,e);  
219 - var cookbookid = this.data.item.cookbookid  
220 - var price=this.data.item.price;  
221 125
222 - this.initKindMenu().then(res=>{  
223 - //打开了规格窗口  
224 - this.triggerEvent('foodSpecCallback',{  
225 - type:'specWin',  
226 - value:'show'  
227 - });  
228 - }).catch(res=>{  
229 - console.log('initKindMenu',res);  
230 - if( this.data.item.clear_num && this.data.item.clear_num>0  
231 - && this.data.item.num+1 > this.data.item.clear_num){  
232 - wx.showToast({  
233 - title:'该菜品最多能点'+this.data.item.clear_num+'份',  
234 - duration:2000,  
235 - mask:true,  
236 - icon:'none'  
237 - });  
238 - return;  
239 - }  
240 - //通知  
241 - this.triggerEvent('foodSpecCallback',{  
242 - cookbookid:cookbookid,  
243 - type:1,  
244 - });  
245 - //this.matchArray(cookbookid,1,countTotal,countPirce)  
246 - App.Advance.AddCart({  
247 - orderid: this.data.orderid,  
248 - openid:util.cache('openid'),  
249 - cookbookid:cookbookid,  
250 - price: price,  
251 - source: 1,  
252 - request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识  
253 - fromSoucre:this.data.fromSoucre?this.data.fromSoucre:'',  
254 - identity:this.data.identity  
255 - });  
256 - });  
257 - },  
258 - //减菜面板  
259 - subtractCook(){  
260 - console.log('addFunction',this.data.item);  
261 - var cookbookid = this.data.item.cookbookid  
262 - var price=this.data.item.price;  
263 - this.initKindMenu().then(res=>{  
264 - //打开了规格窗口  
265 - this.triggerEvent('foodSpecCallback',{  
266 - type:'specWin',  
267 - value:'show'  
268 - });  
269 - }).catch(res=>{  
270 - //通知  
271 - this.triggerEvent('foodSpecCallback',{  
272 - cookbookid:cookbookid,  
273 - type:-1,  
274 - });  
275 -  
276 - App.Advance.ReduceOrder({  
277 - orderid: this.data.orderid,  
278 - openid: getApp().openid,  
279 - cookbookid: cookbookid,  
280 - //specid: specid ? specid : '',  
281 - //practiceid: specid ? specid : '',  
282 - fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',  
283 - request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识  
284 - status:this.data.fromSoucre!=''?2:'',//只查没有下单的  
285 - source: 2,  
286 - });  
287 - });  
288 - },  
289 - //减菜面板加菜按钮  
290 - add:function(e){  
291 - console.log('add',util.attr(e,'cookbookid'),e);  
292 - let index=util.attr(e,'index');  
293 - let selectKind=this.data.selectKind;  
294 -  
295 - console.log('selectKind',selectKind,index);  
296 - let specs=this.data.item.spec;  
297 - let clear_num=null;  
298 - specs.forEach(spec=>{  
299 - if(spec.id==selectKind[index].specid){  
300 - clear_num=spec.clear_num;  
301 - } 126 + practice.map(function (r, n) {
  127 + if (r.id) {
  128 + foodMenu.push({id: r.id, price: price, title: r.name, iskind: false})
  129 + }
302 }) 130 })
303 - if( clear_num && clear_num>0  
304 - && selectKind[index].foodNum+1 > clear_num){  
305 - wx.showToast({  
306 - title:'该菜品最多能点'+clear_num+'份',  
307 - duration:2000,  
308 - mask:true,  
309 - icon:'none'  
310 - });  
311 - return; 131 +
  132 + if (foodMenu.length > 0) {
  133 + foodMenu[0].iskind = true;
  134 + var foodMenuPrice = foodMenu[0].price;
  135 + var practice_id = foodMenu[0].id;
312 } 136 }
  137 + App.Advance.GetCookbookSelBySpecsId({
  138 + sellerid: this.data.sellerid,
  139 + orderid: this.data.orderid,
  140 + cookbookid: this.data.item.id,
  141 + status: this.data.fromSoucre != '' ? 2 : '',//只查没有下单的
  142 + }).then(res => {
  143 + this.setData({
  144 + selectKind: res.data[0],
  145 + hiddenFoodSpec: false,
  146 + kind: kind,
  147 + foodMenu: foodMenu,
  148 + showSpecsPrice: false,
  149 + cookbook_name: this.data.item.name,
  150 + cookbook_id: this.data.item.id,
  151 + specs_id: specs_id ? specs_id : '',
  152 + practice_id: practice_id ? practice_id : '',
  153 + selectPrice: kindPrice > 0 ? kindPrice : foodMenuPrice,
  154 + add_target: ''
  155 + })
  156 + })
  157 + }
  158 + success();
  159 + } else {
  160 + fail();
  161 + }
  162 + });
  163 + },
  164 + //选择规格
  165 + kindSelect: function (e) {
  166 + var index = e.currentTarget.dataset.key
  167 + var specsid = e.currentTarget.id
  168 + var price = e.currentTarget.dataset.price
  169 + for (var i = 0; i < this.data.kind.length; i++) {
  170 + if (i == index) {
  171 + this.data.kind[i].iskind = true;
  172 + } else {
  173 + this.data.kind[i].iskind = false;
  174 + }
  175 + }
  176 + var is_show = ''
  177 + if (this.data.foodMenu == '') {
  178 + is_show = 1
  179 + } else if (specsid && this.data.practice_id) {
  180 + is_show = 1
  181 + }
  182 + this.setData({
  183 + kind: this.data.kind,
  184 + selectPrice: price,
  185 + specs_id: specsid,
  186 + foodMenu: this.data.foodMenu ? this.data.foodMenu : '',
  187 + showSpecsPrice: price ? false : true,
  188 + showAdd: is_show ? false : true//showAdd:specsid?false:true
  189 + });
  190 + },
  191 + //选择做法
  192 + menuSelect: function (e) {
  193 + var index = e.currentTarget.dataset.key
  194 + var practiceid = e.currentTarget.id
  195 + var price = e.currentTarget.dataset.price
  196 + for (var i = 0; i < this.data.foodMenu.length; i++) {
  197 + if (i == index) {
  198 + this.data.foodMenu[i].iskind = true;
  199 + } else {
  200 + this.data.foodMenu[i].iskind = false;
  201 + }
  202 + }
  203 + var is_show = ''
  204 + if (this.data.kind == '') {
  205 + is_show = 1
  206 + } else if (this.data.specs_id && practiceid) {
  207 + is_show = 1
  208 + }
  209 + this.setData({
  210 + foodMenu: this.data.foodMenu,
  211 + foodMenuPrice: price,
  212 + practice_id: practiceid,
  213 + showAdd: is_show ? false : true
  214 + });
  215 + },
  216 + //加菜面板
  217 + addCook: function (e) {
  218 + console.log('addCook', this.data.item, e);
  219 + var cookbookid = this.data.item.identity>=0?this.data.item.cookbookid:this.data.item.id
  220 + var price = this.data.item.price;
313 221
314 - selectKind[index].foodNum=parseInt(selectKind[index].foodNum)+1;  
315 - this.setData({selectKind:selectKind});  
316 - this.formSubmit(e,true);  
317 - },  
318 - //减菜面板减菜按钮  
319 - reduce(e){  
320 - console.log('reduce',util.attr(e,'cookbookid'),e);  
321 - var cookbookid = util.attr(e,'cookbookid')  
322 - var specid = util.attr(e,'specid')  
323 - var practice_id = util.attr(e,'practiceid')  
324 - var price = util.attr(e,'price') 222 + this.initKindMenu().then(res => {
  223 + //打开了规格窗口
  224 + this.triggerEvent('foodSpecCallback', {
  225 + type: 'specWin',
  226 + value: 'show'
  227 + });
  228 + }).catch(res => {
  229 + console.log('initKindMenu', res);
  230 + if (this.data.item.clear_num && this.data.item.clear_num > 0
  231 + && this.data.item.num + 1 > this.data.item.clear_num) {
  232 + wx.showToast({
  233 + title: '该菜品最多能点' + this.data.item.clear_num + '份',
  234 + duration: 2000,
  235 + mask: true,
  236 + icon: 'none'
  237 + });
  238 + return;
  239 + }
  240 + //通知
  241 + this.triggerEvent('foodSpecCallback', {
  242 + cookbookid: cookbookid,
  243 + type: 1,
  244 + });
  245 + //this.matchArray(cookbookid,1,countTotal,countPirce)
  246 + App.Advance.AddCart({
  247 + orderid: this.data.orderid,
  248 + openid: util.cache('openid'),
  249 + cookbookid: cookbookid,
  250 + price: price,
  251 + source: 1,
  252 + request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
  253 + fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
  254 + identity: this.data.identity
  255 + });
  256 + });
  257 + },
  258 + //减菜面板
  259 + subtractCook(){
  260 + console.log('addFunction', this.data.item);
  261 + var cookbookid = this.data.item.identity>=0?this.data.item.cookbookid:this.data.item.id
  262 + var price = this.data.item.price;
  263 + this.initKindMenu().then(res => {
  264 + //打开了规格窗口
  265 + this.triggerEvent('foodSpecCallback', {
  266 + type: 'specWin',
  267 + value: 'show'
  268 + });
  269 + }).catch(res => {
  270 + //通知
  271 + this.triggerEvent('foodSpecCallback', {
  272 + cookbookid: cookbookid,
  273 + type: -1,
  274 + });
325 275
326 - let index=util.attr(e,'index');  
327 - let selectKind=this.data.selectKind;  
328 - selectKind[index].foodNum-=1;  
329 - if(selectKind[index].foodNum<=0){  
330 - selectKind.splice(index,1);  
331 - }  
332 - this.setData({selectKind:selectKind});  
333 - if(selectKind.length<1){  
334 - this.close();  
335 - } 276 + App.Advance.ReduceOrder({
  277 + orderid: this.data.orderid,
  278 + openid: getApp().openid,
  279 + cookbookid: cookbookid,
  280 + //specid: specid ? specid : '',
  281 + //practiceid: specid ? specid : '',
  282 + fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
  283 + request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
  284 + status: this.data.fromSoucre != '' ? 2 : '',//只查没有下单的
  285 + source: 2,
  286 + });
  287 + });
  288 + },
  289 + //减菜面板加菜按钮
  290 + add: function (e) {
  291 + console.log('add', util.attr(e, 'cookbookid'), e);
  292 + let index = util.attr(e, 'index');
  293 + let selectKind = this.data.selectKind;
336 294
337 - this.triggerEvent('foodSpecCallback',{  
338 - cookbookid:cookbookid,  
339 - type:-1  
340 - }); 295 + console.log('selectKind', selectKind, index);
  296 + let specs = this.data.item.spec;
  297 + let clear_num = null;
  298 + specs.forEach(spec => {
  299 + if (spec.id == selectKind[index].specid) {
  300 + clear_num = spec.clear_num;
  301 + }
  302 + })
  303 + if (clear_num && clear_num > 0
  304 + && selectKind[index].foodNum + 1 > clear_num) {
  305 + wx.showToast({
  306 + title: '该菜品最多能点' + clear_num + '份',
  307 + duration: 2000,
  308 + mask: true,
  309 + icon: 'none'
  310 + });
  311 + return;
  312 + }
341 313
342 - //执行删除操作  
343 - let params={  
344 - orderid: this.data.orderid,  
345 - openid: getApp().openid,  
346 - cookbookid: cookbookid,  
347 - fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',  
348 - status:this.data.fromSoucre?2:'',//只查没有下单的  
349 - request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识  
350 - source: 2,  
351 - };  
352 - if(specid>0){  
353 - params.specid=specid;  
354 - }  
355 - if(practice_id>0){  
356 - params.practiceid=practice_id;  
357 - }  
358 - App.Advance.ReduceOrder(params);  
359 - },  
360 - /**  
361 - *  
362 - * @param e  
363 - * @param subtractCook 减菜面板  
364 - */  
365 - formSubmit(e,subtractCook=false){  
366 - if(subtractCook){//减菜面板  
367 - var cookbookid = util.attr(e,'cookbookid')  
368 - var specid = util.attr(e,'specid')  
369 - var practice_id = util.attr(e,'practiceid')  
370 - var price = util.attr(e,'price')  
371 - }else{  
372 - var cookbookid = util.val(e,'cookbookid')  
373 - var specid = util.val(e,'specs_id')  
374 - var practice_id = util.val(e,'practice_id')  
375 - var price = util.val(e,'price')  
376 - if(this.data.selectPrice){  
377 - console.log(666666,this.data.selectPrice)  
378 - price=this.data.selectPrice  
379 - }else{  
380 - console.log('yyyyyy',this.data.foodMenuPrice)  
381 - price=this.data.foodMenuPrice  
382 - }  
383 - this.close();  
384 - }  
385 - console.log('formSubmit',specid,practice_id,price) 314 + selectKind[index].foodNum = parseInt(selectKind[index].foodNum) + 1;
  315 + this.setData({selectKind: selectKind});
  316 + this.formSubmit(e, true);
  317 + },
  318 + //减菜面板减菜按钮
  319 + reduce(e){
  320 + console.log('reduce', util.attr(e, 'cookbookid'), e);
  321 + var cookbookid = util.attr(e, 'cookbookid')
  322 + var specid = util.attr(e, 'specid')
  323 + var practice_id = util.attr(e, 'practiceid')
  324 + var price = util.attr(e, 'price')
386 325
  326 + let index = util.attr(e, 'index');
  327 + let selectKind = this.data.selectKind;
  328 + selectKind[index].foodNum -= 1;
  329 + if (selectKind[index].foodNum <= 0) {
  330 + selectKind.splice(index, 1);
  331 + }
  332 + this.setData({selectKind: selectKind});
  333 + if (selectKind.length < 1) {
  334 + this.close();
  335 + }
387 336
388 - let selectKindNum=0;  
389 - if(this.data.selectKind){  
390 - this.data.selectKind.forEach((kind)=>{  
391 - if(kind.specid==specid){  
392 - selectKindNum=kind.foodNum  
393 - }  
394 - })  
395 - }  
396 - console.log('selectKindNum',this.data.selectKind,selectKindNum);  
397 - if(selectKindNum>0){  
398 - let clear_num=null;  
399 - let specs=this.data.item.spec;  
400 - specs.forEach(spec=>{  
401 - if(spec.id==specid){  
402 - clear_num=spec.clear_num;  
403 - }  
404 - })  
405 - if( clear_num && clear_num>0  
406 - && selectKindNum+1 > clear_num){  
407 - wx.showToast({  
408 - title:'该菜品最多能点'+clear_num+'份',  
409 - duration:2000,  
410 - mask:true,  
411 - icon:'none'  
412 - });  
413 - return;  
414 - }  
415 - } 337 + this.triggerEvent('foodSpecCallback', {
  338 + cookbookid: cookbookid,
  339 + type: -1
  340 + });
416 341
  342 + //执行删除操作
  343 + let params = {
  344 + orderid: this.data.orderid,
  345 + openid: getApp().openid,
  346 + cookbookid: cookbookid,
  347 + fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
  348 + status: this.data.fromSoucre ? 2 : '',//只查没有下单的
  349 + request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
  350 + source: 2,
  351 + };
  352 + if (specid > 0) {
  353 + params.specid = specid;
  354 + }
  355 + if (practice_id > 0) {
  356 + params.practiceid = practice_id;
  357 + }
  358 + App.Advance.ReduceOrder(params);
  359 + },
  360 + /**
  361 + *
  362 + * @param e
  363 + * @param subtractCook 减菜面板
  364 + */
  365 + formSubmit(e, subtractCook = false){
  366 + if (subtractCook) {//减菜面板
  367 + var cookbookid = util.attr(e, 'cookbookid')
  368 + var specid = util.attr(e, 'specid')
  369 + var practice_id = util.attr(e, 'practiceid')
  370 + var price = util.attr(e, 'price')
  371 + } else {
  372 + var cookbookid = util.val(e, 'cookbookid')
  373 + var specid = util.val(e, 'specs_id')
  374 + var practice_id = util.val(e, 'practice_id')
  375 + var price = util.val(e, 'price')
  376 + if (this.data.selectPrice) {
  377 + console.log(666666, this.data.selectPrice)
  378 + price = this.data.selectPrice
  379 + } else {
  380 + console.log('yyyyyy', this.data.foodMenuPrice)
  381 + price = this.data.foodMenuPrice
  382 + }
  383 + this.close();
  384 + }
  385 + console.log('formSubmit', cookbookid,specid, practice_id, price)
  386 + //return;
417 387
418 - this.triggerEvent('foodSpecCallback',{  
419 - cookbookid:cookbookid,  
420 - type:1  
421 - });  
422 - let param={  
423 - orderid: this.data.orderid,  
424 - openid:util.cache('openid'),  
425 - cookbookid:this.data.item.id,  
426 - price: price,  
427 - source: 1,  
428 - request_uri: this.data.request_uri==true?1:'',//服务员通过消息通知进来 又加菜的标识  
429 - fromSoucre:this.data.fromSoucre?this.data.fromSoucre:'',  
430 - identity:this.data.identity  
431 - }  
432 - if(specid>0){  
433 - param.specid=specid;  
434 - }  
435 - if(practice_id>0){  
436 - param.practiceid=practice_id;  
437 - }  
438 - App.Advance.AddCart(param);  
439 - },  
440 - //清除订单下某菜品所有数量  
441 - clean(){  
442 - let cookbookid=this.data.item.id  
443 - this.triggerEvent('foodSpecCallback',{  
444 - cookbookid:cookbookid,  
445 - type:this.data.item.num*-1  
446 - });  
447 - App.Advance.ClearCookById({  
448 - orderid: this.data.orderid,  
449 - sellerid: this.data.sellerid,  
450 - cookbookid:cookbookid  
451 - }); 388 + let selectKindNum = 0;
  389 + if (this.data.selectKind) {
  390 + this.data.selectKind.forEach((kind) => {
  391 + if (kind.specid == specid) {
  392 + selectKindNum = kind.foodNum
  393 + }
  394 + })
  395 + }
  396 + console.log('selectKindNum', this.data.selectKind, selectKindNum);
  397 + if (selectKindNum > 0) {
  398 + let clear_num = null;
  399 + let specs = this.data.item.spec;
  400 + specs.forEach(spec => {
  401 + if (spec.id == specid) {
  402 + clear_num = spec.clear_num;
  403 + }
  404 + })
  405 + if (clear_num && clear_num > 0
  406 + && selectKindNum + 1 > clear_num) {
  407 + wx.showToast({
  408 + title: '该菜品最多能点' + clear_num + '份',
  409 + duration: 2000,
  410 + mask: true,
  411 + icon: 'none'
  412 + });
  413 + return;
452 } 414 }
  415 + }
  416 +
  417 +
  418 + this.triggerEvent('foodSpecCallback', {
  419 + cookbookid: cookbookid,
  420 + type: 1
  421 + });
  422 +
  423 + let param = {
  424 + orderid: this.data.orderid,
  425 + openid: util.cache('openid'),
  426 + cookbookid: cookbookid,
  427 + price: price,
  428 + source: 1,
  429 + request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
  430 + fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
  431 + identity: this.data.identity
  432 + }
  433 + if (specid > 0) {
  434 + param.specid = specid;
  435 + }
  436 + if (practice_id > 0) {
  437 + param.practiceid = practice_id;
  438 + }
  439 + App.Advance.AddCart(param);
  440 + },
  441 + //清除订单下某菜品所有数量
  442 + clean(){
  443 + let cookbookid = this.data.item.id
  444 + this.triggerEvent('foodSpecCallback', {
  445 + cookbookid: cookbookid,
  446 + type: this.data.item.num * -1
  447 + });
  448 + App.Advance.ClearCookById({
  449 + orderid: this.data.orderid,
  450 + sellerid: this.data.sellerid,
  451 + cookbookid: cookbookid
  452 + });
453 } 453 }
  454 + }
454 }) 455 })
@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 <block wx:if="{{foodMenu.length>0}}"> 20 <block wx:if="{{foodMenu.length>0}}">
21 <view class="toast-content-kind" style="margin-bottom:{{kind.length==0 ? '235rpx' : '40rpx'}};"> 21 <view class="toast-content-kind" style="margin-bottom:{{kind.length==0 ? '235rpx' : '40rpx'}};">
22 <view class="toast-kind-title">做法</view> 22 <view class="toast-kind-title">做法</view>
23 - <view class="toast-kind-menu"> 23 + <view class="toast-kind-menu flex-ll">
24 <view class="toast-kind-single {{item.iskind==true?'kind-active':''}}" wx:for="{{foodMenu}}" wx:key="foodmenu-key" data-key="{{index}}" id="{{item.id}}" data-price="{{item.price}}" bindtap='menuSelect'>{{item.title}}</view> 24 <view class="toast-kind-single {{item.iskind==true?'kind-active':''}}" wx:for="{{foodMenu}}" wx:key="foodmenu-key" data-key="{{index}}" id="{{item.id}}" data-price="{{item.price}}" bindtap='menuSelect'>{{item.title}}</view>
25 <input value="{{practice_id}}" name="practice_id" hidden="true"/> 25 <input value="{{practice_id}}" name="practice_id" hidden="true"/>
26 </view> 26 </view>
@@ -124,7 +124,7 @@ export default { @@ -124,7 +124,7 @@ export default {
124 //菜品列表 124 //菜品列表
125 'App.Advance.GetCookbookByClass': null, 125 'App.Advance.GetCookbookByClass': null,
126 //菜品规格 126 //菜品规格
127 - ' App.Advance.GetCookbookSelBySpecsId': null, 127 + 'App.Advance.GetCookbookSelBySpecsId': null,
128 //添加到购物车 128 //添加到购物车
129 'App.Advance.AddCart': null, 129 'App.Advance.AddCart': null,
130 //减菜 130 //减菜
@@ -440,7 +440,8 @@ module.exports = { @@ -440,7 +440,8 @@ module.exports = {
440 html=html.replace(/&quot;/ig,''); 440 html=html.replace(/&quot;/ig,'');
441 return html; 441 return html;
442 }, 442 },
443 - val:function(e){ 443 + val:function(e,key=''){
  444 + if(key!='') return e.detail.value[key]||'';
444 return e.detail.value; 445 return e.detail.value;
445 }, 446 },
446 attr:function(e,key=''){ 447 attr:function(e,key=''){