Commit 3b36561a3e28e9e9f156cfffaed74536d3d2c66d

Authored by yiren
1 parent 055f15a2

提前点餐

... ... @@ -32,92 +32,20 @@ Page({
this.setData({
options: obj,
})
this.setData({
options: obj,
})
this.getCheckCookList(obj);
this.getCheckCookList(obj)
},
// 获取点菜列表
getCheckCookList(obj) {
getCheckCookList(options) {
let param = {
sellerid: obj.sid,
identity: obj.identity,
orderid: obj.oid,
sellerid: options.sid,
identity: options.identity,
orderid: options.oid,
status: '0,1',
};
let probablyPrice = 0;
let vipProbablyPrice = 0;
App.Cookbook.GetCookbookByClass(param).then(json => {
let cookbooklist = this.formatCookList(json.data[0].list)
let newArr = JSON.parse(JSON.stringify(cookbooklist))
let num = 0
for (let i = 0; i < newArr.length; i++) {
if (newArr[i].cookbooklist.length == 0) {
continue;
}
for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {
let cook_style = newArr[i].cookbooklist[0][j].cook_style
if (cook_style.image_type == 2) {
num++
} else {
if (num % 2 != 0) {
let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {
return newArr[i].cookbooklist[0][j].id == item.id
})
if (k != -1) {
let temp = {
boderNone: true,
image_type: '2',
}
cookbooklist[i].cookbooklist[0].splice(k, 0, temp)
}
}
num = 0
}
}
}
cookbooklist.forEach(item => {
item.normsLen = 0
item.cookbooklist[0].forEach((cooks, idx) => {
if (cooks.order_xx && cooks.order_xx.length > 0) {
let arr = cooks.order_xx
let result = arr.reduce((obj, item) => {
let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
let _d = {
...item,
count: 1
};
find ? find.count++ : obj.push(_d);
return obj;
}, []);
cooks.norms = result
cooks.norms.forEach(n => {
let obj = cooks.specArr.filter(i => {
return i.id == n.specid
})
n.price = (obj[0] && obj[0].price) ? obj[0].price : cooks.price;
n.member_price = (obj[0] && obj[0].member_price) ? obj[0].member_price : cooks.member_price;
n.id = cooks.id;
n.check2 = cooks.check2;
n.cookName = cooks.name;
n.check1 = cooks.check1;
let price = n.count * 1 * (n.price * 1);
let vipPrice = n.count * 1 * (n.member_price * 1);
probablyPrice += price;
vipProbablyPrice += vipPrice;
})
item.is_show = true
item.normsLen += cooks.norms.length
} else {
cooks.norms = []
}
})
})
this.setData({
cookbooklist,
noData: true,
probablyPrice,
vipProbablyPrice
cookbooklist
})
})
},
... ... @@ -167,9 +95,6 @@ Page({
let assortArr = [];
let check1 = '';
let check2 = '';
let that = this;
let complete = false
let complete1 = false
if (sortArr.length > 0) {
has10CaiOpen = list[0].status == 1;
sortArr.forEach(function (cate, i) {
... ... @@ -215,9 +140,6 @@ Page({
}
cook.item_clear_num = item_clear_num;
cook.index = n; //分类下菜品的下标
if (!cook.order_xx || cook.order_xx.length == 0) {
cook.norms = []; //做法规格
}
cook.type = '1';
let cook_style = cook.cook_style ? util.determine(cook.cook_style) : {
image_type: '1',
... ... @@ -246,13 +168,92 @@ Page({
}
})
}
let cookbooklist = JSON.parse(JSON.stringify(flist))
let newArr = JSON.parse(JSON.stringify(cookbooklist))
let num = 0
newArr.forEach((i, u) => {
if (i.cookbooklist.length != 0) {
i.cookbooklist[0].forEach(j => {
let cook_style = j.cook_style ? j.cook_style : j.image_type
if (cook_style && cook_style.image_type == 2) {
num++
} else {
if (num % 2 != 0) {
let k = cookbooklist[u].cookbooklist[0].findIndex((item) => {
return j.id == item.id
})
if (k != -1) {
let temp = {
boderNone: true,
image_type: '2',
}
cookbooklist[u].cookbooklist[0].splice(k, 0, temp)
}
}
num = 0
}
})
}
})
this.getCookNormsList(cookbooklist)
flist = cookbooklist;
this.setData({
check1,
check2,
assortArr
})
return flist;
},
// 加减处理已点菜的数据
getCookNormsList(cookbooklist) {
let probablyPrice = 0;
let vipProbablyPrice = 0;
cookbooklist.forEach(i => {
i.normsLen = 0
i.cookbooklist[0].forEach(j=>{
if (j.order_xx && j.order_xx.length > 0) {
let arr = j.order_xx;
let result = arr.reduce((obj, item) => {
let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
let _d = {
...item,
count: 1
};
find ? find.count++ : obj.push(_d);
return obj;
}, []);
result = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'practiceid'))
j.norms = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'specid'))
j.norms.forEach(n => {
n.id = j.id;
n.check2 = j.check2;
n.cookName = j.name;
n.check1 = j.check1;
let list = j.specArr.filter(i => {
return i.id == n.specid
})
n.price = (list[0] && list[0].price) ? list[0].price : j.price;
n.member_price = (list[0] && list[0].member_price) ? list[0].member_price : j.member_price;
let price = n.count * 1 * (n.price * 1);
let vipPrice = n.count * 1 * (n.member_price * 1);
probablyPrice += price;
vipProbablyPrice += vipPrice;
})
i.normsLen += j.norms.length
i.is_show = true
} else {
j.norms = []
}
})
})
console.log(cookbooklist);
this.setData({
cookbooklist,
noData: true,
probablyPrice,
vipProbablyPrice
})
return cookbooklist
},
// 继续点菜
continueOrdering() {
... ... @@ -284,17 +285,17 @@ Page({
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
identity: this.data.options.identity
}
if(type=='1'){
if (type == '1') {
App.Advance.AddCart(params).then(res => {
this.getCheckCookList(this.data.options);
})
return
return
}
if(type=='2'){
if (type == '2') {
App.Advance.ReduceOrder(params).then(res => {
this.getCheckCookList(this.data.options);
})
return
return
}
},
/**
... ...
... ... @@ -67,7 +67,7 @@ Page({
let cookbookObj = {
...this.data.options
}
wx.setStorageSync('cookbookObj',JSON.stringify(cookbookObj));
wx.setStorageSync('cookbookObj', JSON.stringify(cookbookObj));
wx.navigateTo({
url: `/pack-cookbook/pages/cart_new?cookbookObj=${JSON.stringify(cookbookObj)}`,
})
... ... @@ -106,63 +106,6 @@ Page({
};
App.Cookbook.GetCookbookByClass(param).then(json => {
let cookbooklist = this.formatCookList(json.data[0].list)
let newArr = JSON.parse(JSON.stringify(cookbooklist))
let num = 0
for (let i = 0; i < newArr.length; i++) {
if (newArr[i].cookbooklist.length == 0) {
continue;
}
for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {
let cook_style = newArr[i].cookbooklist[0][j].cook_style
if (cook_style.image_type == 2) {
num++
} else {
if (num % 2 != 0) {
let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {
return newArr[i].cookbooklist[0][j].id == item.id
})
if (k != -1) {
let temp = {
boderNone: true,
image_type: '2',
}
cookbooklist[i].cookbooklist[0].splice(k, 0, temp)
}
}
num = 0
}
}
}
cookbooklist.forEach(item => {
item.cookbooklist[0].forEach((cooks, idx) => {
if (cooks.order_xx && cooks.order_xx.length > 0) {
let arr = cooks.order_xx;
let result = arr.reduce((obj, item) => {
let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
let _d = {
...item,
count: 1
};
find ? find.count++ : obj.push(_d);
return obj;
}, []);
cooks.norms = result
cooks.norms.forEach(n => {
n.id = cooks.id;
n.check2 = cooks.check2;
n.cookName = cooks.name;
n.check1 = cooks.check1;
let obj = cooks.specArr.filter(i => {
return i.id == n.specid
})
n.price = (obj[0] && obj[0].price) ? obj[0].price : cooks.price;
n.member_price = (obj[0] && obj[0].member_price) ? obj[0].member_price : cooks.member_price;
})
} else {
cooks.norms = []
}
})
})
this.setData({
cookbooklist
})
... ... @@ -287,10 +230,10 @@ Page({
res.data.cookbooklist.forEach(cb => {
if (this.data.options.identity == 1 && cb.status > 0) {
let cookbookObj = {
...this.data.options
...this.data.options
}
wx.redirectTo({
url: `/pack-cookbook/pages/success_new?cookbookObj=${JSON.stringify(cookbookObj)}`,
url: `/pack-cookbook/pages/success_new?cookbookObj=${JSON.stringify(cookbookObj)}`,
})
return false;
}
... ... @@ -352,9 +295,6 @@ Page({
let assortArr = [];
let check1 = '';
let check2 = '';
let that = this;
let complete = false
let complete1 = false
if (sortArr.length > 0) {
has10CaiOpen = list[0].status == 1;
sortArr.forEach(function (cate, i) {
... ... @@ -400,9 +340,6 @@ Page({
}
cook.item_clear_num = item_clear_num;
cook.index = n; //分类下菜品的下标
if (!cook.order_xx || cook.order_xx.length == 0) {
cook.norms = []; //做法规格
}
cook.type = '1';
let cook_style = cook.cook_style ? util.determine(cook.cook_style) : {
image_type: '1',
... ... @@ -431,13 +368,77 @@ Page({
}
})
}
let cookbooklist = JSON.parse(JSON.stringify(flist))
let newArr = JSON.parse(JSON.stringify(cookbooklist))
let num = 0
newArr.forEach((i, u) => {
if (i.cookbooklist.length != 0) {
i.cookbooklist[0].forEach(j => {
let cook_style = j.cook_style ? j.cook_style : j.image_type
if (cook_style && cook_style.image_type == 2) {
num++
} else {
if (num % 2 != 0) {
let k = cookbooklist[u].cookbooklist[0].findIndex((item) => {
return j.id == item.id
})
if (k != -1) {
let temp = {
boderNone: true,
image_type: '2',
}
cookbooklist[u].cookbooklist[0].splice(k, 0, temp)
}
}
num = 0
}
})
}
})
this.getCookNormsList(cookbooklist)
flist = cookbooklist;
this.setData({
check1,
check2,
assortArr
})
return flist;
},
// 加减处理已点菜的数据
getCookNormsList(cookbooklist) {
cookbooklist.forEach(i => {
i.cookbooklist[0].forEach(j=>{
if (j.order_xx && j.order_xx.length > 0) {
let arr = j.order_xx;
let result = arr.reduce((obj, item) => {
let find = obj.find(i => (i.practiceid === item.practiceid && i.specid === item.specid));
let _d = {
...item,
count: 1
};
find ? find.count++ : obj.push(_d);
return obj;
}, []);
result = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'practiceid'))
j.norms = result.sort((obj1, obj2) => util.objCompare(obj1, obj2, 'specid'))
j.norms.forEach(n => {
n.id = j.id;
n.check2 = j.check2;
n.cookName = j.name;
n.check1 = j.check1;
let list = j.specArr.filter(i => {
return i.id == n.specid
})
n.price = (list[0] && list[0].price) ? list[0].price : j.price;
n.member_price = (list[0] && list[0].member_price) ? list[0].member_price : j.member_price;
})
} else {
j.norms = []
}
})
});
console.log(cookbooklist);
return cookbooklist
},
// 获取所有分类下所有菜品列表
getCookList() {
... ... @@ -449,33 +450,6 @@ Page({
};
App.Cookbook.GetCookbookByClass(param).then(json => {
let cookbooklist = this.formatCookList(json.data[0].list)
let newArr = JSON.parse(JSON.stringify(cookbooklist))
let num = 0
for (let i = 0; i < newArr.length; i++) {
if (newArr[i].cookbooklist.length == 0) {
continue;
}
for (let j = 0; j < newArr[i].cookbooklist[0].length; j++) {
let cook_style = newArr[i].cookbooklist[0][j].cook_style
if (cook_style.image_type == 2) {
num++
} else {
if (num % 2 != 0) {
let k = cookbooklist[i].cookbooklist[0].findIndex((item) => {
return newArr[i].cookbooklist[0][j].id == item.id
})
if (k != -1) {
let temp = {
boderNone: true,
image_type: '2',
}
cookbooklist[i].cookbooklist[0].splice(k, 0, temp)
}
}
num = 0
}
}
}
this.setData({
cookbooklist,
isloading: false,
... ...
... ... @@ -74,10 +74,10 @@
</view>
<view class="practice" wx:if="{{item.specs}}" style="color:rgba({{textColor}})">{{item.specs}}</view>
</view>
<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}}"/>
<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}}"/>
</view>
<view wx:if="{{(item.specArr.length>1 || item.practice.length>1) || item.norms.length=='0'}}" class="algorithmImg flex-rr imgbox">
<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}}"/>
<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}}"/>
</view>
</view>
<view wx:else class="twoBox" data-idx="{{item.image_type}}" data-nameType="{{item.name_type}}">
... ...
... ... @@ -147,14 +147,29 @@ function determine(str) {
} catch (e) {
return str;
}
}else{
return str
}
}
// 比较大小函数key字段
function objCompare (obj1, obj2,key){
var val1 = obj1[key];
var val2 = obj2[key];
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
module.exports = {
formatTime: formatTime,
unixtoTime: unixtoTime,
timetouUnix: timetouUnix,
parseDataValue,
determine,
objCompare,
cgi: function (act) {
return uri.HOST__LINE + act //正式
//return uri.HOST__TEST+act //测试
... ...