|
|
|
// pack-cookbook/pages/index_new.js
|
|
|
|
var mta = require('mta-wechat-analysis')
|
|
|
|
import util from '../../utils/util';
|
|
|
|
import App from '../../utils/api';
|
|
|
|
Page({
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
type:'C',//样式A,B,C
|
|
|
|
scrollTop: 0,
|
|
|
|
isloading: true,
|
|
|
|
toView: "",
|
|
|
|
hasEnter: false,
|
|
|
|
totalWidth: getApp().system.windowWidth,
|
|
|
|
singleWidth: parseInt((getApp().system.windowWidth * 0.92 - 16) / 2),
|
|
|
|
totalHeight: getApp().system.windowHeight,
|
|
|
|
kindHeight: getApp().system.windowHeight - 68,
|
|
|
|
hasListModel: true,
|
|
|
|
cookbooklist: [{}, {}, {}, {}, {}, {}, {},],
|
|
|
|
showSkeleton: true,
|
|
|
|
order: {},
|
|
|
|
orderItemCount:0,
|
|
|
|
twoList:[
|
|
|
|
{
|
|
|
|
title:'烤鸽子',
|
|
|
|
info:'¥48/位 ',
|
|
|
|
vip:'会员 ¥38/位',
|
|
|
|
image:'https://img.zcool.cn/community/0143e15b0239e4a801218cf4503272.jpg@3000w_1l_0o_100sh.jpg',
|
|
|
|
quantum:0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title:'烤鸽子',
|
|
|
|
info:'¥48/位 ',
|
|
|
|
vip:'会员 ¥38/位',
|
|
|
|
image:'https://img.zcool.cn/community/0143e15b0239e4a801218cf4503272.jpg@3000w_1l_0o_100sh.jpg',
|
|
|
|
quantum:0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
title:'烤鸽子',
|
|
|
|
info:'¥48/位 ',
|
|
|
|
vip:'会员 ¥38/位',
|
|
|
|
image:'https://img.zcool.cn/community/0143e15b0239e4a801218cf4503272.jpg@3000w_1l_0o_100sh.jpg',
|
|
|
|
quantum:0,
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dishList:[
|
|
|
|
{
|
|
|
|
image:'https://img.zcool.cn/community/0143e15b0239e4a801218cf4503272.jpg@3000w_1l_0o_100sh.jpg',
|
|
|
|
title:'默认菜品样式A',
|
|
|
|
info:'¥168/份 会员 ¥160/份',
|
|
|
|
normsInfo:'味型:咸鲜 烹调:熬煮',
|
|
|
|
dw:'1个 (如果没有会员价,则不显示会员价)',
|
|
|
|
zs:'有图大',
|
|
|
|
quantum:1,
|
|
|
|
js:'有(菜品录入了就有,没录入就没有)',
|
|
|
|
xz:'否,只显示加号',
|
|
|
|
ggInfo:'江南传统名菜,口味咸鲜,汤白汁浓,肉质酥肥,笋清香脆嫩,鲜味浓厚。',
|
|
|
|
gg:'菜品名称(味型/烹调)和价格在顶部分开(默认),菜品味型/烹调 录入了才有,没录入没有。'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
image:'https://img.zcool.cn/community/0143e15b0239e4a801218cf4503272.jpg@3000w_1l_0o_100sh.jpg',
|
|
|
|
title:'默认菜品样式A',
|
|
|
|
info:'¥168/份 会员 ¥160/份',
|
|
|
|
normsInfo:'味型:咸鲜 烹调:熬煮',
|
|
|
|
dw:'1个 (如果没有会员价,则不显示会员价)',
|
|
|
|
zs:'有图大',
|
|
|
|
quantum:0,
|
|
|
|
js:'有(菜品录入了就有,没录入就没有)',
|
|
|
|
xz:'否,只显示加号',
|
|
|
|
ggInfo:'江南传统名菜,口味咸鲜,汤白汁浓,肉质酥肥,笋清香脆嫩,鲜味浓厚。',
|
|
|
|
gg:'菜品名称(味型/烹调)和价格在顶部分开(默认),菜品味型/烹调 录入了才有,没录入没有。'
|
|
|
|
},
|
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
*/
|
|
|
|
onLoad: function (options) {
|
|
|
|
this.setData({
|
|
|
|
options: options,
|
|
|
|
})
|
|
|
|
this.getCookList();
|
|
|
|
this.initOrder();
|
|
|
|
mta.Page.init({
|
|
|
|
"appID": "500667280",
|
|
|
|
"eventID": "500667287",
|
|
|
|
"statPullDownFresh": true,
|
|
|
|
"statShareApp": true,
|
|
|
|
"statReachBottom": true,
|
|
|
|
"lauchOpts": options, //渠道分析
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
onReady() {
|
|
|
|
|
|
|
|
},
|
|
|
|
// 点击加号
|
|
|
|
addition(e){
|
|
|
|
const item= e.currentTarget.dataset['item'];
|
|
|
|
const index= e.currentTarget.dataset['key'];
|
|
|
|
const type= e.currentTarget.dataset['type'];
|
|
|
|
let quantum = item.quantum * 1 + 1;
|
|
|
|
let obj;
|
|
|
|
if(type=='one') obj=`dishList[${index}].quantum`;
|
|
|
|
if(type=='two') obj=`twoList[${index}].quantum`;
|
|
|
|
this.setData({
|
|
|
|
[obj]:quantum
|
|
|
|
})
|
|
|
|
},
|
|
|
|
// 点击减号
|
|
|
|
subtraction(e){
|
|
|
|
const item= e.currentTarget.dataset['item'];
|
|
|
|
const index= e.currentTarget.dataset['key'];
|
|
|
|
const type= e.currentTarget.dataset['type'];
|
|
|
|
let quantum = item.quantum * 1 - 1;
|
|
|
|
let obj;
|
|
|
|
if(type=='one') obj=`dishList[${index}].quantum`;
|
|
|
|
if(type=='two') obj=`twoList[${index}].quantum`;
|
|
|
|
this.setData({
|
|
|
|
[obj]:quantum
|
|
|
|
})
|
|
|
|
},
|
|
|
|
initOrder() {
|
|
|
|
App.Advance.CreateOrder({
|
|
|
|
rid: this.data.options.rid,
|
|
|
|
identity: this.data.options.identity,
|
|
|
|
status: '0,1',
|
|
|
|
openid: getApp().openid,
|
|
|
|
}).then(res => {
|
|
|
|
let orderItemCount = 0;
|
|
|
|
res.data.cookbooklist.forEach(cb => {
|
|
|
|
if (this.data.options.identity == 1 && cb.status > 0) {
|
|
|
|
wx.redirectTo({
|
|
|
|
url: util.http_build_query({
|
|
|
|
rid: this.data.options.rid,
|
|
|
|
oid: res.data.id,
|
|
|
|
identity: 1
|
|
|
|
}, '/pack-cookbook/pages/success')
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
orderItemCount += parseInt(cb.num)
|
|
|
|
})
|
|
|
|
this.setData({
|
|
|
|
[`options.oid`]: res.data.id,
|
|
|
|
order: res.data,
|
|
|
|
orderItemCount: orderItemCount,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
formatCookList(list){
|
|
|
|
//原栏目下显示
|
|
|
|
let hasShowClass = false;
|
|
|
|
//菜单中展示沽清的菜品
|
|
|
|
let hasClearCookbook = false;
|
|
|
|
//十道必选菜
|
|
|
|
let has10CaiOpen = false;
|
|
|
|
let flist = [];
|
|
|
|
if (list.length > 0) {
|
|
|
|
has10CaiOpen = list[0].status == 1;
|
|
|
|
list.forEach(function (cate, i) {
|
|
|
|
if (cate.status == 1 && cate.cookbooklist[0].length > 0) {
|
|
|
|
let cooks = [];
|
|
|
|
//let cooks_order=[];
|
|
|
|
cate.cookbooklist[0].forEach(function (cook, n) {
|
|
|
|
if (cook.status == 1) {
|
|
|
|
let flag = true;
|
|
|
|
if (has10CaiOpen) {
|
|
|
|
if (cate.class_type == 2 && !hasShowClass && flist.length > 0 && flist[0].class_type == 1) {
|
|
|
|
for (let fi = 0; fi < flist[0].cookbooklist[0].length; fi++) {
|
|
|
|
if (flist[0].cookbooklist[0][fi].id == cook.id) {
|
|
|
|
flag = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cook.item_clear_num = cook.clear_num;
|
|
|
|
if (!hasClearCookbook) {//不显示卖光了
|
|
|
|
let item_clear_num = cook.clear_num;
|
|
|
|
if (cook.spec) {
|
|
|
|
let clear_num = null;
|
|
|
|
cook.spec.forEach(spec => {
|
|
|
|
if (spec.clear_num == 0) {
|
|
|
|
clear_num = 0;
|
|
|
|
} else {
|
|
|
|
clear_num = null;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (clear_num == 0) {
|
|
|
|
item_clear_num = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cook.item_clear_num = item_clear_num;
|
|
|
|
if (item_clear_num == 0) {
|
|
|
|
flag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag) {
|
|
|
|
cooks.push(cook);
|
|
|
|
//cooks_order.push(cook.order_o);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if (cooks.length > 0) {
|
|
|
|
//cooks 排序...
|
|
|
|
|
|
|
|
cate.cookbooklist[0] = cooks;
|
|
|
|
flist.push(cate)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return flist;
|
|
|
|
},
|
|
|
|
getCookList: function (orderid) {
|
|
|
|
let param = {
|
|
|
|
sellerid: this.data.options.sid,
|
|
|
|
identity: this.data.options.identity,
|
|
|
|
orderid : this.data.options.oid,
|
|
|
|
status:'0,1',
|
|
|
|
};
|
|
|
|
App.Advance.GetCookbookByClass(param).then(json => {
|
|
|
|
//菜单分类添加修饰
|
|
|
|
let cookbooklist = this.formatCookList(json.data[0].list);
|
|
|
|
setTimeout(() => {
|
|
|
|
this.setData({
|
|
|
|
cookbooklist: cookbooklist,
|
|
|
|
countPirce: json.data[0].countPirce ? json.data[0].countPirce : 0,
|
|
|
|
countTotal: json.data[0].countTotal ? json.data[0].countTotal : 0,
|
|
|
|
isloading: false,
|
|
|
|
showSkeleton: false,
|
|
|
|
})
|
|
|
|
}, 0)
|
|
|
|
|
|
|
|
}).catch(res => {
|
|
|
|
console.log('getCookList-catch', res);
|
|
|
|
this.selectComponent("#network").show('网络不给力,请检查网络后重试');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
*/
|
|
|
|
onShow() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
*/
|
|
|
|
onHide() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
*/
|
|
|
|
onUnload() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
onPullDownRefresh() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
*/
|
|
|
|
onReachBottom() {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户点击右上角分享
|
|
|
|
*/
|
|
|
|
onShareAppMessage() {
|
|
|
|
|
|
|
|
}
|
|
|
|
}) |
|
|
\ No newline at end of file |
...
|
...
|
|