Commit 3b36561a3e28e9e9f156cfffaed74536d3d2c66d

Authored by yiren
1 parent 055f15a2

提前点餐

@@ -32,92 +32,20 @@ Page({ @@ -32,92 +32,20 @@ Page({
32 this.setData({ 32 this.setData({
33 options: obj, 33 options: obj,
34 }) 34 })
35 - this.setData({  
36 - options: obj,  
37 - })  
38 - this.getCheckCookList(obj); 35 + this.getCheckCookList(obj)
39 }, 36 },
40 // 获取点菜列表 37 // 获取点菜列表
41 - getCheckCookList(obj) { 38 + getCheckCookList(options) {
42 let param = { 39 let param = {
43 - sellerid: obj.sid,  
44 - identity: obj.identity,  
45 - orderid: obj.oid, 40 + sellerid: options.sid,
  41 + identity: options.identity,
  42 + orderid: options.oid,
46 status: '0,1', 43 status: '0,1',
47 }; 44 };
48 - let probablyPrice = 0;  
49 - let vipProbablyPrice = 0;  
50 App.Cookbook.GetCookbookByClass(param).then(json => { 45 App.Cookbook.GetCookbookByClass(param).then(json => {
51 let cookbooklist = this.formatCookList(json.data[0].list) 46 let cookbooklist = this.formatCookList(json.data[0].list)
52 - let newArr = JSON.parse(JSON.stringify(cookbooklist))  
53 - let num = 0  
54 - for (let i = 0; i < newArr.length; i++) {  
55 - if (newArr[i].cookbooklist.length == 0) {  
56 - continue;  
57 - }  
58 - for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {  
59 - let cook_style = newArr[i].cookbooklist[0][j].cook_style  
60 - if (cook_style.image_type == 2) {  
61 - num++  
62 - } else {  
63 - if (num % 2 != 0) {  
64 - let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {  
65 - return newArr[i].cookbooklist[0][j].id == item.id  
66 - })  
67 - if (k != -1) {  
68 - let temp = {  
69 - boderNone: true,  
70 - image_type: '2',  
71 - }  
72 - cookbooklist[i].cookbooklist[0].splice(k, 0, temp)  
73 - }  
74 - }  
75 - num = 0  
76 - }  
77 - }  
78 - }  
79 - cookbooklist.forEach(item => {  
80 - item.normsLen = 0  
81 - item.cookbooklist[0].forEach((cooks, idx) => {  
82 - if (cooks.order_xx && cooks.order_xx.length > 0) {  
83 - let arr = cooks.order_xx  
84 - let result = arr.reduce((obj, item) => {  
85 - let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));  
86 - let _d = {  
87 - ...item,  
88 - count: 1  
89 - };  
90 - find ? find.count++ : obj.push(_d);  
91 - return obj;  
92 - }, []);  
93 - cooks.norms = result  
94 - cooks.norms.forEach(n => {  
95 - let obj = cooks.specArr.filter(i => {  
96 - return i.id == n.specid  
97 - })  
98 - n.price = (obj[0] && obj[0].price) ? obj[0].price : cooks.price;  
99 - n.member_price = (obj[0] && obj[0].member_price) ? obj[0].member_price : cooks.member_price;  
100 - n.id = cooks.id;  
101 - n.check2 = cooks.check2;  
102 - n.cookName = cooks.name;  
103 - n.check1 = cooks.check1;  
104 - let price = n.count * 1 * (n.price * 1);  
105 - let vipPrice = n.count * 1 * (n.member_price * 1);  
106 - probablyPrice += price;  
107 - vipProbablyPrice += vipPrice;  
108 - })  
109 - item.is_show = true  
110 - item.normsLen += cooks.norms.length  
111 - } else {  
112 - cooks.norms = []  
113 - }  
114 - })  
115 - })  
116 this.setData({ 47 this.setData({
117 - cookbooklist,  
118 - noData: true,  
119 - probablyPrice,  
120 - vipProbablyPrice 48 + cookbooklist
121 }) 49 })
122 }) 50 })
123 }, 51 },
@@ -167,9 +95,6 @@ Page({ @@ -167,9 +95,6 @@ Page({
167 let assortArr = []; 95 let assortArr = [];
168 let check1 = ''; 96 let check1 = '';
169 let check2 = ''; 97 let check2 = '';
170 - let that = this;  
171 - let complete = false  
172 - let complete1 = false  
173 if (sortArr.length > 0) { 98 if (sortArr.length > 0) {
174 has10CaiOpen = list[0].status == 1; 99 has10CaiOpen = list[0].status == 1;
175 sortArr.forEach(function (cate, i) { 100 sortArr.forEach(function (cate, i) {
@@ -215,9 +140,6 @@ Page({ @@ -215,9 +140,6 @@ Page({
215 } 140 }
216 cook.item_clear_num = item_clear_num; 141 cook.item_clear_num = item_clear_num;
217 cook.index = n; //分类下菜品的下标 142 cook.index = n; //分类下菜品的下标
218 - if (!cook.order_xx || cook.order_xx.length == 0) {  
219 - cook.norms = []; //做法规格  
220 - }  
221 cook.type = '1'; 143 cook.type = '1';
222 let cook_style = cook.cook_style ? util.determine(cook.cook_style) : { 144 let cook_style = cook.cook_style ? util.determine(cook.cook_style) : {
223 image_type: '1', 145 image_type: '1',
@@ -246,13 +168,92 @@ Page({ @@ -246,13 +168,92 @@ Page({
246 } 168 }
247 }) 169 })
248 } 170 }
  171 + let cookbooklist = JSON.parse(JSON.stringify(flist))
  172 + let newArr = JSON.parse(JSON.stringify(cookbooklist))
  173 + let num = 0
  174 + newArr.forEach((i, u) => {
  175 + if (i.cookbooklist.length != 0) {
  176 + i.cookbooklist[0].forEach(j => {
  177 + let cook_style = j.cook_style ? j.cook_style : j.image_type
  178 + if (cook_style && cook_style.image_type == 2) {
  179 + num++
  180 + } else {
  181 + if (num % 2 != 0) {
  182 + let k = cookbooklist[u].cookbooklist[0].findIndex((item) => {
  183 + return j.id == item.id
  184 + })
  185 + if (k != -1) {
  186 + let temp = {
  187 + boderNone: true,
  188 + image_type: '2',
  189 + }
  190 + cookbooklist[u].cookbooklist[0].splice(k, 0, temp)
  191 + }
  192 + }
  193 + num = 0
  194 + }
  195 + })
  196 + }
  197 + })
  198 + this.getCookNormsList(cookbooklist)
  199 + flist = cookbooklist;
249 this.setData({ 200 this.setData({
250 check1, 201 check1,
251 check2, 202 check2,
252 assortArr 203 assortArr
253 }) 204 })
254 return flist; 205 return flist;
255 - 206 + },
  207 + // 加减处理已点菜的数据
  208 + getCookNormsList(cookbooklist) {
  209 + let probablyPrice = 0;
  210 + let vipProbablyPrice = 0;
  211 + cookbooklist.forEach(i => {
  212 + i.normsLen = 0
  213 + i.cookbooklist[0].forEach(j=>{
  214 + if (j.order_xx && j.order_xx.length > 0) {
  215 + let arr = j.order_xx;
  216 + let result = arr.reduce((obj, item) => {
  217 + let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
  218 + let _d = {
  219 + ...item,
  220 + count: 1
  221 + };
  222 + find ? find.count++ : obj.push(_d);
  223 + return obj;
  224 + }, []);
  225 + result = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'practiceid'))
  226 + j.norms = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'specid'))
  227 + j.norms.forEach(n => {
  228 + n.id = j.id;
  229 + n.check2 = j.check2;
  230 + n.cookName = j.name;
  231 + n.check1 = j.check1;
  232 + let list = j.specArr.filter(i => {
  233 + return i.id == n.specid
  234 + })
  235 + n.price = (list[0] && list[0].price) ? list[0].price : j.price;
  236 + n.member_price = (list[0] && list[0].member_price) ? list[0].member_price : j.member_price;
  237 + let price = n.count * 1 * (n.price * 1);
  238 + let vipPrice = n.count * 1 * (n.member_price * 1);
  239 + probablyPrice += price;
  240 + vipProbablyPrice += vipPrice;
  241 + })
  242 + i.normsLen += j.norms.length
  243 + i.is_show = true
  244 + } else {
  245 + j.norms = []
  246 + }
  247 + })
  248 + })
  249 + console.log(cookbooklist);
  250 + this.setData({
  251 + cookbooklist,
  252 + noData: true,
  253 + probablyPrice,
  254 + vipProbablyPrice
  255 + })
  256 + return cookbooklist
256 }, 257 },
257 // 继续点菜 258 // 继续点菜
258 continueOrdering() { 259 continueOrdering() {
@@ -284,17 +285,17 @@ Page({ @@ -284,17 +285,17 @@ Page({
284 fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '', 285 fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
285 identity: this.data.options.identity 286 identity: this.data.options.identity
286 } 287 }
287 - if(type=='1'){ 288 + if (type == '1') {
288 App.Advance.AddCart(params).then(res => { 289 App.Advance.AddCart(params).then(res => {
289 this.getCheckCookList(this.data.options); 290 this.getCheckCookList(this.data.options);
290 }) 291 })
291 - return 292 + return
292 } 293 }
293 - if(type=='2'){ 294 + if (type == '2') {
294 App.Advance.ReduceOrder(params).then(res => { 295 App.Advance.ReduceOrder(params).then(res => {
295 this.getCheckCookList(this.data.options); 296 this.getCheckCookList(this.data.options);
296 }) 297 })
297 - return 298 + return
298 } 299 }
299 }, 300 },
300 /** 301 /**
@@ -67,7 +67,7 @@ Page({ @@ -67,7 +67,7 @@ Page({
67 let cookbookObj = { 67 let cookbookObj = {
68 ...this.data.options 68 ...this.data.options
69 } 69 }
70 - wx.setStorageSync('cookbookObj',JSON.stringify(cookbookObj)); 70 + wx.setStorageSync('cookbookObj', JSON.stringify(cookbookObj));
71 wx.navigateTo({ 71 wx.navigateTo({
72 url: `/pack-cookbook/pages/cart_new?cookbookObj=${JSON.stringify(cookbookObj)}`, 72 url: `/pack-cookbook/pages/cart_new?cookbookObj=${JSON.stringify(cookbookObj)}`,
73 }) 73 })
@@ -106,63 +106,6 @@ Page({ @@ -106,63 +106,6 @@ Page({
106 }; 106 };
107 App.Cookbook.GetCookbookByClass(param).then(json => { 107 App.Cookbook.GetCookbookByClass(param).then(json => {
108 let cookbooklist = this.formatCookList(json.data[0].list) 108 let cookbooklist = this.formatCookList(json.data[0].list)
109 - let newArr = JSON.parse(JSON.stringify(cookbooklist))  
110 - let num = 0  
111 - for (let i = 0; i < newArr.length; i++) {  
112 - if (newArr[i].cookbooklist.length == 0) {  
113 - continue;  
114 - }  
115 - for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {  
116 - let cook_style = newArr[i].cookbooklist[0][j].cook_style  
117 - if (cook_style.image_type == 2) {  
118 - num++  
119 - } else {  
120 - if (num % 2 != 0) {  
121 - let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {  
122 - return newArr[i].cookbooklist[0][j].id == item.id  
123 - })  
124 - if (k != -1) {  
125 - let temp = {  
126 - boderNone: true,  
127 - image_type: '2',  
128 - }  
129 - cookbooklist[i].cookbooklist[0].splice(k, 0, temp)  
130 - }  
131 - }  
132 - num = 0  
133 - }  
134 - }  
135 - }  
136 - cookbooklist.forEach(item => {  
137 - item.cookbooklist[0].forEach((cooks, idx) => {  
138 - if (cooks.order_xx && cooks.order_xx.length > 0) {  
139 - let arr = cooks.order_xx;  
140 - let result = arr.reduce((obj, item) => {  
141 - let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));  
142 - let _d = {  
143 - ...item,  
144 - count: 1  
145 - };  
146 - find ? find.count++ : obj.push(_d);  
147 - return obj;  
148 - }, []);  
149 - cooks.norms = result  
150 - cooks.norms.forEach(n => {  
151 - n.id = cooks.id;  
152 - n.check2 = cooks.check2;  
153 - n.cookName = cooks.name;  
154 - n.check1 = cooks.check1;  
155 - let obj = cooks.specArr.filter(i => {  
156 - return i.id == n.specid  
157 - })  
158 - n.price = (obj[0] && obj[0].price) ? obj[0].price : cooks.price;  
159 - n.member_price = (obj[0] && obj[0].member_price) ? obj[0].member_price : cooks.member_price;  
160 - })  
161 - } else {  
162 - cooks.norms = []  
163 - }  
164 - })  
165 - })  
166 this.setData({ 109 this.setData({
167 cookbooklist 110 cookbooklist
168 }) 111 })
@@ -287,10 +230,10 @@ Page({ @@ -287,10 +230,10 @@ Page({
287 res.data.cookbooklist.forEach(cb => { 230 res.data.cookbooklist.forEach(cb => {
288 if (this.data.options.identity == 1 && cb.status > 0) { 231 if (this.data.options.identity == 1 && cb.status > 0) {
289 let cookbookObj = { 232 let cookbookObj = {
290 - ...this.data.options 233 + ...this.data.options
291 } 234 }
292 wx.redirectTo({ 235 wx.redirectTo({
293 - url: `/pack-cookbook/pages/success_new?cookbookObj=${JSON.stringify(cookbookObj)}`, 236 + url: `/pack-cookbook/pages/success_new?cookbookObj=${JSON.stringify(cookbookObj)}`,
294 }) 237 })
295 return false; 238 return false;
296 } 239 }
@@ -352,9 +295,6 @@ Page({ @@ -352,9 +295,6 @@ Page({
352 let assortArr = []; 295 let assortArr = [];
353 let check1 = ''; 296 let check1 = '';
354 let check2 = ''; 297 let check2 = '';
355 - let that = this;  
356 - let complete = false  
357 - let complete1 = false  
358 if (sortArr.length > 0) { 298 if (sortArr.length > 0) {
359 has10CaiOpen = list[0].status == 1; 299 has10CaiOpen = list[0].status == 1;
360 sortArr.forEach(function (cate, i) { 300 sortArr.forEach(function (cate, i) {
@@ -400,9 +340,6 @@ Page({ @@ -400,9 +340,6 @@ Page({
400 } 340 }
401 cook.item_clear_num = item_clear_num; 341 cook.item_clear_num = item_clear_num;
402 cook.index = n; //分类下菜品的下标 342 cook.index = n; //分类下菜品的下标
403 - if (!cook.order_xx || cook.order_xx.length == 0) {  
404 - cook.norms = []; //做法规格  
405 - }  
406 cook.type = '1'; 343 cook.type = '1';
407 let cook_style = cook.cook_style ? util.determine(cook.cook_style) : { 344 let cook_style = cook.cook_style ? util.determine(cook.cook_style) : {
408 image_type: '1', 345 image_type: '1',
@@ -431,13 +368,77 @@ Page({ @@ -431,13 +368,77 @@ Page({
431 } 368 }
432 }) 369 })
433 } 370 }
  371 + let cookbooklist = JSON.parse(JSON.stringify(flist))
  372 + let newArr = JSON.parse(JSON.stringify(cookbooklist))
  373 + let num = 0
  374 + newArr.forEach((i, u) => {
  375 + if (i.cookbooklist.length != 0) {
  376 + i.cookbooklist[0].forEach(j => {
  377 + let cook_style = j.cook_style ? j.cook_style : j.image_type
  378 + if (cook_style && cook_style.image_type == 2) {
  379 + num++
  380 + } else {
  381 + if (num % 2 != 0) {
  382 + let k = cookbooklist[u].cookbooklist[0].findIndex((item) => {
  383 + return j.id == item.id
  384 + })
  385 + if (k != -1) {
  386 + let temp = {
  387 + boderNone: true,
  388 + image_type: '2',
  389 + }
  390 + cookbooklist[u].cookbooklist[0].splice(k, 0, temp)
  391 + }
  392 + }
  393 + num = 0
  394 + }
  395 + })
  396 + }
  397 + })
  398 + this.getCookNormsList(cookbooklist)
  399 + flist = cookbooklist;
434 this.setData({ 400 this.setData({
435 check1, 401 check1,
436 check2, 402 check2,
437 assortArr 403 assortArr
438 }) 404 })
439 return flist; 405 return flist;
440 - 406 + },
  407 + // 加减处理已点菜的数据
  408 + getCookNormsList(cookbooklist) {
  409 + cookbooklist.forEach(i => {
  410 + i.cookbooklist[0].forEach(j=>{
  411 + if (j.order_xx && j.order_xx.length > 0) {
  412 + let arr = j.order_xx;
  413 + let result = arr.reduce((obj, item) => {
  414 + let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
  415 + let _d = {
  416 + ...item,
  417 + count: 1
  418 + };
  419 + find ? find.count++ : obj.push(_d);
  420 + return obj;
  421 + }, []);
  422 + result = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'practiceid'))
  423 + j.norms = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'specid'))
  424 + j.norms.forEach(n => {
  425 + n.id = j.id;
  426 + n.check2 = j.check2;
  427 + n.cookName = j.name;
  428 + n.check1 = j.check1;
  429 + let list = j.specArr.filter(i => {
  430 + return i.id == n.specid
  431 + })
  432 + n.price = (list[0] && list[0].price) ? list[0].price : j.price;
  433 + n.member_price = (list[0] && list[0].member_price) ? list[0].member_price : j.member_price;
  434 + })
  435 + } else {
  436 + j.norms = []
  437 + }
  438 + })
  439 + });
  440 + console.log(cookbooklist);
  441 + return cookbooklist
441 }, 442 },
442 // 获取所有分类下所有菜品列表 443 // 获取所有分类下所有菜品列表
443 getCookList() { 444 getCookList() {
@@ -449,33 +450,6 @@ Page({ @@ -449,33 +450,6 @@ Page({
449 }; 450 };
450 App.Cookbook.GetCookbookByClass(param).then(json => { 451 App.Cookbook.GetCookbookByClass(param).then(json => {
451 let cookbooklist = this.formatCookList(json.data[0].list) 452 let cookbooklist = this.formatCookList(json.data[0].list)
452 - let newArr = JSON.parse(JSON.stringify(cookbooklist))  
453 - let num = 0  
454 - for (let i = 0; i < newArr.length; i++) {  
455 - if (newArr[i].cookbooklist.length == 0) {  
456 - continue;  
457 - }  
458 - for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {  
459 - let cook_style = newArr[i].cookbooklist[0][j].cook_style  
460 - if (cook_style.image_type == 2) {  
461 - num++  
462 - } else {  
463 - if (num % 2 != 0) {  
464 - let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {  
465 - return newArr[i].cookbooklist[0][j].id == item.id  
466 - })  
467 - if (k != -1) {  
468 - let temp = {  
469 - boderNone: true,  
470 - image_type: '2',  
471 - }  
472 - cookbooklist[i].cookbooklist[0].splice(k, 0, temp)  
473 - }  
474 - }  
475 - num = 0  
476 - }  
477 - }  
478 - }  
479 this.setData({ 453 this.setData({
480 cookbooklist, 454 cookbooklist,
481 isloading: false, 455 isloading: false,
@@ -74,10 +74,10 @@ @@ -74,10 +74,10 @@
74 </view> 74 </view>
75 <view class="practice" wx:if="{{item.specs}}" style="color:rgba({{textColor}})">{{item.specs}}</view> 75 <view class="practice" wx:if="{{item.specs}}" style="color:rgba({{textColor}})">{{item.specs}}</view>
76 </view> 76 </view>
77 - <image src="{{themeColor!='251,246,241,1'?'https://qn.colorcun.com/WechatIMG696.png':'https://qn.colorcun.com/Line1.png'}}" mode="aspectFill" class="imgs" data-type="0" bindtap="addition" data-item="{{item}}"/> 77 + <image src="{{themeColor!='251,246,241,1'?'https://qn.colorcun.com/WechatIMG696.png':'https://qn.colorcun.com/Line1.png'}}" mode="aspectFill" class="imgs" data-type="0" bindtap="addition" data-item="{{item}}" data-key="{{index}}" data-indexs="{{indexs}}"/>
78 </view> 78 </view>
79 <view wx:if="{{(item.specArr.length>1 || item.practice.length>1) || item.norms.length=='0'}}" class="algorithmImg flex-rr imgbox"> 79 <view wx:if="{{(item.specArr.length>1 || item.practice.length>1) || item.norms.length=='0'}}" class="algorithmImg flex-rr imgbox">
80 - <image src="{{themeColor!='251,246,241,1'?'https://qn.colorcun.com/WechatIMG696.png':'https://qn.colorcun.com/Line1.png'}}" class="imgs" mode="aspectFill" bindtap="addition" data-type="1" data-item="{{item}}"/> 80 + <image src="{{themeColor!='251,246,241,1'?'https://qn.colorcun.com/WechatIMG696.png':'https://qn.colorcun.com/Line1.png'}}" class="imgs" mode="aspectFill" bindtap="addition" data-type="1" data-item="{{item}}" data-key="{{index}}" data-indexs="{{indexs}}"/>
81 </view> 81 </view>
82 </view> 82 </view>
83 <view wx:else class="twoBox" data-idx="{{item.image_type}}" data-nameType="{{item.name_type}}"> 83 <view wx:else class="twoBox" data-idx="{{item.image_type}}" data-nameType="{{item.name_type}}">
@@ -147,14 +147,29 @@ function determine(str) { @@ -147,14 +147,29 @@ function determine(str) {
147 } catch (e) { 147 } catch (e) {
148 return str; 148 return str;
149 } 149 }
  150 + }else{
  151 + return str
150 } 152 }
151 } 153 }
  154 +// 比较大小函数key字段
  155 +function objCompare (obj1, obj2,key){
  156 + var val1 = obj1[key];
  157 + var val2 = obj2[key];
  158 + if (val1 < val2) {
  159 + return -1;
  160 + } else if (val1 > val2) {
  161 + return 1;
  162 + } else {
  163 + return 0;
  164 + }
  165 +}
152 module.exports = { 166 module.exports = {
153 formatTime: formatTime, 167 formatTime: formatTime,
154 unixtoTime: unixtoTime, 168 unixtoTime: unixtoTime,
155 timetouUnix: timetouUnix, 169 timetouUnix: timetouUnix,
156 parseDataValue, 170 parseDataValue,
157 determine, 171 determine,
  172 + objCompare,
158 cgi: function (act) { 173 cgi: function (act) {
159 return uri.HOST__LINE + act //正式 174 return uri.HOST__LINE + act //正式
160 //return uri.HOST__TEST+act //测试 175 //return uri.HOST__TEST+act //测试