|
|
|
// component/menu/addDelete.js
|
|
|
|
import util from '../../../utils/util';
|
|
|
|
import App from '../../../utils/api';
|
|
|
|
const {regeneratorRuntime} = global
|
|
|
|
Component({
|
|
|
|
/**
|
|
|
|
* 组件的属性列表
|
|
|
|
*/
|
|
|
|
properties: {
|
|
|
|
item:{
|
|
|
|
type:Object // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
|
|
|
|
},
|
|
|
|
type:{
|
|
|
|
type:String,
|
|
|
|
default:'+'
|
|
|
|
},
|
|
|
|
sellerid:{
|
|
|
|
type:Number
|
|
|
|
},
|
|
|
|
orderid:{
|
|
|
|
type:Number
|
|
|
|
},
|
|
|
|
fromSoucre:{
|
|
|
|
type:Number,
|
|
|
|
value:0
|
|
|
|
},
|
|
|
|
request_uri:{
|
|
|
|
type:Boolean,
|
|
|
|
value:false,
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 组件的初始数据
|
|
|
|
*/
|
|
|
|
data: {
|
|
|
|
hiddenFoodSpec:true,//加菜规格
|
|
|
|
hiddenFoodSpecReduce:true,//减菜规格
|
|
|
|
selectKind:[{title:'xxxxx'},{title:'yyyyy'}],
|
|
|
|
},
|
|
|
|
ready () {
|
|
|
|
|
|
|
|
},
|
|
|
|
detached(){
|
|
|
|
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 组件的方法列表
|
|
|
|
*/
|
|
|
|
methods: {
|
|
|
|
init(){
|
|
|
|
console.log('food-spec init');
|
|
|
|
this.setData({
|
|
|
|
hiddenFoodSpec:false
|
|
|
|
})
|
|
|
|
},
|
|
|
|
//关闭规格框
|
|
|
|
close:function(){
|
|
|
|
this.setData({
|
|
|
|
hiddenFoodSpec:true,
|
|
|
|
hiddenFoodSpecReduce:true,
|
|
|
|
})
|
|
|
|
//关闭了规格窗口
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
type:'specWin',
|
|
|
|
value:'hide'
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//构造KindMenu
|
|
|
|
initKindMenu(){
|
|
|
|
return new Promise((success,fail)=>{
|
|
|
|
let price=this.data.item.price;
|
|
|
|
let hasSpec = this.data.item.spec.length>0;
|
|
|
|
let hasPractice = this.data.item.practice.length>0;
|
|
|
|
if(hasSpec || hasPractice){
|
|
|
|
var specs = this.data.item.spec//规格
|
|
|
|
var practice = this.data.item.practice//做法
|
|
|
|
var kind = []
|
|
|
|
var foodMenu=[]
|
|
|
|
if(this.data.type=='-'){
|
|
|
|
if(specs){
|
|
|
|
specs.map(function(r,n){
|
|
|
|
if(r.id){//某规格卖光了 就不显示 && r.clear_num>1
|
|
|
|
kind.push({id:r.id,price:r.price,title:r.specs,iskind:false})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
if(practice) {
|
|
|
|
practice.map(function (r, n) {
|
|
|
|
if (r.id) {
|
|
|
|
foodMenu.push({id: r.id, price: r.price, title: r.name, iskind: false})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
util.rpc(uri.CGI__USER_GETCOOKBOOKSELBYSPECSID,{
|
|
|
|
sellerid:this.data.sellerid,
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
cookbookid: this.data.item.id,
|
|
|
|
status:this.data.fromSoucre!=''?2:'',//只查没有下单的
|
|
|
|
}).then(res=>{
|
|
|
|
this.setData({
|
|
|
|
selectKind:res.data[0],
|
|
|
|
hiddenFoodSpecReduce:false,
|
|
|
|
kind:kind?kind:'',
|
|
|
|
foodMenu:foodMenu,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}else{
|
|
|
|
specs.map(function(r,n){
|
|
|
|
if ((r.id && r.clear_num > 0) || r.clear_num==null){//某规格卖光了 就不显示 && r.clear_num>1
|
|
|
|
kind.push({id:r.id,price:r.price,title:r.specs,iskind:false})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if(kind.length>0){
|
|
|
|
kind[0].iskind=true;
|
|
|
|
var kindPrice=kind[0].price;
|
|
|
|
var specs_id=kind[0].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
practice.map(function(r,n){
|
|
|
|
if(r.id){
|
|
|
|
foodMenu.push({id:r.id,price:price,title:r.name,iskind:false})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if(foodMenu.length>0){
|
|
|
|
foodMenu[0].iskind=true;
|
|
|
|
var foodMenuPrice=foodMenu[0].price;
|
|
|
|
var practice_id=foodMenu[0].id;
|
|
|
|
}
|
|
|
|
util.rpc(uri.CGI__USER_GETCOOKBOOKSELBYSPECSID,{
|
|
|
|
sellerid:this.data.sellerid,
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
cookbookid: this.data.item.id,
|
|
|
|
status:this.data.fromSoucre!=''?2:'',//只查没有下单的
|
|
|
|
}).then(res=>{
|
|
|
|
this.setData({
|
|
|
|
selectKind:res.data[0],
|
|
|
|
hiddenFoodSpec:false,
|
|
|
|
kind:kind,
|
|
|
|
foodMenu:foodMenu,
|
|
|
|
showSpecsPrice:false,
|
|
|
|
cookbook_name:this.data.item.name,
|
|
|
|
cookbook_id:this.data.item.id,
|
|
|
|
specs_id:specs_id ? specs_id :'',
|
|
|
|
practice_id:practice_id ? practice_id : '',
|
|
|
|
selectPrice:kindPrice>0 ? kindPrice : foodMenuPrice,
|
|
|
|
add_target:''
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
success();
|
|
|
|
}else{
|
|
|
|
fail();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//选择规格
|
|
|
|
kindSelect: function (e) {
|
|
|
|
var index = e.currentTarget.dataset.key
|
|
|
|
var specsid = e.currentTarget.id
|
|
|
|
var price = e.currentTarget.dataset.price
|
|
|
|
for (var i = 0; i < this.data.kind.length; i++) {
|
|
|
|
if (i == index) {
|
|
|
|
this.data.kind[i].iskind = true;
|
|
|
|
} else {
|
|
|
|
this.data.kind[i].iskind = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var is_show = ''
|
|
|
|
if(this.data.foodMenu==''){
|
|
|
|
is_show=1
|
|
|
|
}else if(specsid && this.data.practice_id){
|
|
|
|
is_show=1
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
kind: this.data.kind,
|
|
|
|
selectPrice:price,
|
|
|
|
specs_id:specsid,
|
|
|
|
foodMenu:this.data.foodMenu?this.data.foodMenu:'',
|
|
|
|
showSpecsPrice:price?false:true,
|
|
|
|
showAdd:is_show?false:true//showAdd:specsid?false:true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//选择做法
|
|
|
|
menuSelect: function (e) {
|
|
|
|
var index = e.currentTarget.dataset.key
|
|
|
|
var practiceid = e.currentTarget.id
|
|
|
|
var price = e.currentTarget.dataset.price
|
|
|
|
for (var i = 0; i < this.data.foodMenu.length; i++) {
|
|
|
|
if (i == index) {
|
|
|
|
this.data.foodMenu[i].iskind = true;
|
|
|
|
} else {
|
|
|
|
this.data.foodMenu[i].iskind = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var is_show = ''
|
|
|
|
if(this.data.kind==''){
|
|
|
|
is_show=1
|
|
|
|
}else if(this.data.specs_id && practiceid){
|
|
|
|
is_show=1
|
|
|
|
}
|
|
|
|
this.setData({
|
|
|
|
foodMenu: this.data.foodMenu,
|
|
|
|
foodMenuPrice:price,
|
|
|
|
practice_id:practiceid,
|
|
|
|
showAdd:is_show?false:true
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//加菜面板
|
|
|
|
addCook:function(e){
|
|
|
|
console.log('addCook',this.data.item,e);
|
|
|
|
var cookbookid = this.data.item.id
|
|
|
|
var price=this.data.item.price;
|
|
|
|
|
|
|
|
this.initKindMenu().then(res=>{
|
|
|
|
//打开了规格窗口
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
type:'specWin',
|
|
|
|
value:'show'
|
|
|
|
});
|
|
|
|
}).catch(res=>{
|
|
|
|
console.log('initKindMenu',res);
|
|
|
|
if( this.data.item.clear_num && this.data.item.clear_num>0
|
|
|
|
&& this.data.item.num+1 > this.data.item.clear_num){
|
|
|
|
wx.showToast({
|
|
|
|
title:'该菜品最多能点'+this.data.item.clear_num+'份',
|
|
|
|
duration:2000,
|
|
|
|
mask:true,
|
|
|
|
icon:'none'
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
//通知
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
type:1,
|
|
|
|
});
|
|
|
|
//this.matchArray(cookbookid,1,countTotal,countPirce)
|
|
|
|
util.post(uri.CGI__USER_ADDCRAT,{
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
openid:util.cache('openid'),
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
price: price,
|
|
|
|
source: 1,
|
|
|
|
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
|
|
|
|
fromSoucre:this.data.fromSoucre?this.data.fromSoucre:'',
|
|
|
|
identity:util.cache('identity')
|
|
|
|
},uri.CGI__USER_ADDCRAT__CODE,'0','0');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//减菜面板
|
|
|
|
subtractCook(){
|
|
|
|
console.log('addFunction',this.data.item);
|
|
|
|
var cookbookid = this.data.item.id
|
|
|
|
var price=this.data.item.price;
|
|
|
|
this.initKindMenu().then(res=>{
|
|
|
|
//打开了规格窗口
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
type:'specWin',
|
|
|
|
value:'show'
|
|
|
|
});
|
|
|
|
}).catch(res=>{
|
|
|
|
//通知
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
type:-1,
|
|
|
|
});
|
|
|
|
|
|
|
|
util.post(uri.CGI__USER_REDUCEORDER, {
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
openid: getApp().openid,
|
|
|
|
cookbookid: cookbookid,
|
|
|
|
//specid: specid ? specid : '',
|
|
|
|
//practiceid: specid ? specid : '',
|
|
|
|
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
|
|
|
|
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
|
|
|
|
status:this.data.fromSoucre!=''?2:'',//只查没有下单的
|
|
|
|
source: 2,
|
|
|
|
}, uri.CGI__USER_REDUCEORDER__CODE, '0', '0');
|
|
|
|
});
|
|
|
|
},
|
|
|
|
//减菜面板加菜按钮
|
|
|
|
add:function(e){
|
|
|
|
console.log('add',util.attr(e,'cookbookid'),e);
|
|
|
|
let index=util.attr(e,'index');
|
|
|
|
let selectKind=this.data.selectKind;
|
|
|
|
|
|
|
|
console.log('selectKind',selectKind,index);
|
|
|
|
let specs=this.data.item.spec;
|
|
|
|
let clear_num=null;
|
|
|
|
specs.forEach(spec=>{
|
|
|
|
if(spec.id==selectKind[index].specid){
|
|
|
|
clear_num=spec.clear_num;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if( clear_num && clear_num>0
|
|
|
|
&& selectKind[index].foodNum+1 > clear_num){
|
|
|
|
wx.showToast({
|
|
|
|
title:'该菜品最多能点'+clear_num+'份',
|
|
|
|
duration:2000,
|
|
|
|
mask:true,
|
|
|
|
icon:'none'
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selectKind[index].foodNum=parseInt(selectKind[index].foodNum)+1;
|
|
|
|
this.setData({selectKind:selectKind});
|
|
|
|
this.formSubmit(e,true);
|
|
|
|
},
|
|
|
|
//减菜面板减菜按钮
|
|
|
|
reduce(e){
|
|
|
|
console.log('reduce',util.attr(e,'cookbookid'),e);
|
|
|
|
var cookbookid = util.attr(e,'cookbookid')
|
|
|
|
var specid = util.attr(e,'specid')
|
|
|
|
var practice_id = util.attr(e,'practiceid')
|
|
|
|
var price = util.attr(e,'price')
|
|
|
|
|
|
|
|
let index=util.attr(e,'index');
|
|
|
|
let selectKind=this.data.selectKind;
|
|
|
|
selectKind[index].foodNum-=1;
|
|
|
|
if(selectKind[index].foodNum<=0){
|
|
|
|
selectKind.splice(index,1);
|
|
|
|
}
|
|
|
|
this.setData({selectKind:selectKind});
|
|
|
|
if(selectKind.length<1){
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
type:-1
|
|
|
|
});
|
|
|
|
|
|
|
|
//执行删除操作
|
|
|
|
let params={
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
openid: getApp().openid,
|
|
|
|
cookbookid: cookbookid,
|
|
|
|
fromSoucre: this.data.fromSoucre ? this.data.fromSoucre : '',
|
|
|
|
status:this.data.fromSoucre?2:'',//只查没有下单的
|
|
|
|
request_uri: this.data.request_uri == true ? 1 : '',//服务员通过消息通知进来 又加菜的标识
|
|
|
|
source: 2,
|
|
|
|
};
|
|
|
|
if(specid>0){
|
|
|
|
params.specid=specid;
|
|
|
|
}
|
|
|
|
if(practice_id>0){
|
|
|
|
params.practiceid=practice_id;
|
|
|
|
}
|
|
|
|
util.post(uri.CGI__USER_REDUCEORDER, params, uri.CGI__USER_REDUCEORDER__CODE, '0', '0');
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param e
|
|
|
|
* @param subtractCook 减菜面板
|
|
|
|
*/
|
|
|
|
formSubmit(e,subtractCook=false){
|
|
|
|
if(subtractCook){//减菜面板
|
|
|
|
var cookbookid = util.attr(e,'cookbookid')
|
|
|
|
var specid = util.attr(e,'specid')
|
|
|
|
var practice_id = util.attr(e,'practiceid')
|
|
|
|
var price = util.attr(e,'price')
|
|
|
|
}else{
|
|
|
|
var cookbookid = util.val(e,'cookbookid')
|
|
|
|
var specid = util.val(e,'specs_id')
|
|
|
|
var practice_id = util.val(e,'practice_id')
|
|
|
|
var price = util.val(e,'price')
|
|
|
|
if(this.data.selectPrice){
|
|
|
|
console.log(666666,this.data.selectPrice)
|
|
|
|
price=this.data.selectPrice
|
|
|
|
}else{
|
|
|
|
console.log('yyyyyy',this.data.foodMenuPrice)
|
|
|
|
price=this.data.foodMenuPrice
|
|
|
|
}
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
console.log('formSubmit',specid,practice_id,price)
|
|
|
|
|
|
|
|
|
|
|
|
let selectKindNum=0;
|
|
|
|
if(this.data.selectKind){
|
|
|
|
this.data.selectKind.forEach((kind)=>{
|
|
|
|
if(kind.specid==specid){
|
|
|
|
selectKindNum=kind.foodNum
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
console.log('selectKindNum',this.data.selectKind,selectKindNum);
|
|
|
|
if(selectKindNum>0){
|
|
|
|
let clear_num=null;
|
|
|
|
let specs=this.data.item.spec;
|
|
|
|
specs.forEach(spec=>{
|
|
|
|
if(spec.id==specid){
|
|
|
|
clear_num=spec.clear_num;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if( clear_num && clear_num>0
|
|
|
|
&& selectKindNum+1 > clear_num){
|
|
|
|
wx.showToast({
|
|
|
|
title:'该菜品最多能点'+clear_num+'份',
|
|
|
|
duration:2000,
|
|
|
|
mask:true,
|
|
|
|
icon:'none'
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
type:1
|
|
|
|
});
|
|
|
|
let param={
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
openid:util.cache('openid'),
|
|
|
|
cookbookid:this.data.item.id,
|
|
|
|
price: price,
|
|
|
|
source: 1,
|
|
|
|
request_uri: this.data.request_uri==true?1:'',//服务员通过消息通知进来 又加菜的标识
|
|
|
|
fromSoucre:this.data.fromSoucre?this.data.fromSoucre:'',
|
|
|
|
identity:util.cache('identity')
|
|
|
|
}
|
|
|
|
if(specid>0){
|
|
|
|
param.specid=specid;
|
|
|
|
}
|
|
|
|
if(practice_id>0){
|
|
|
|
param.practiceid=practice_id;
|
|
|
|
}
|
|
|
|
util.post(uri.CGI__USER_ADDCRAT,param,uri.CGI__USER_ADDCRAT__CODE,'0','0');
|
|
|
|
},
|
|
|
|
//清除订单下某菜品所有数量
|
|
|
|
clean(){
|
|
|
|
let cookbookid=this.data.item.id
|
|
|
|
this.triggerEvent('foodSpecCallback',{
|
|
|
|
cookbookid:cookbookid,
|
|
|
|
type:this.data.item.num*-1
|
|
|
|
});
|
|
|
|
util.post(uri.CGI__USER_CLEARCOOKBYID,{
|
|
|
|
orderid: this.data.orderid,
|
|
|
|
sellerid: this.data.sellerid,
|
|
|
|
cookbookid:cookbookid
|
|
|
|
},uri.CGI__USER_CLEARCOOKBYID__CODE,'0','0');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}) |
...
|
...
|
|