box.js 1.2 KB
import App from '../../utils/api.js'
import util from '../../utils/util.js'
Component({
	properties:{
		seller:Object
	},
	data:{
		boxhidden:true,
	},
	attached(){
		console.log(this.data.seller)
	},
	methods:{
		getcartlist(){
			App.Orders.GetCartByOpenid({sellerid:this.data.seller.id,openid:util.cache('openid')}).then((json)=>{
				console.log(json,'yyyyyyy')
				if(json.ret==200){
					json.data.forEach((v,i)=>{
						v.price=Number(v.price);
						v.member_price=Number(v.member_price);
						v.count=Number(v.count);
					})
					this.setData({
						cartlist:json.data
					})
					
				}
			})
		},
		showbox(){
			this.setData({
				boxhidden:false
			})
			this.getcartlist();
		},
		hidebox(){
			this.setData({
				boxhidden:true
			})
		},
		tellfood(e){
			this.triggerEvent('tellfood',e.detail);
			if(e.detail.count==0){
				this.getcartlist();
			}
		},
		clearfood(){
			App.Orders.ClearCar({sellerid:this.data.seller.id,openid:util.cache('openid')}).then((json)=>{
				if(json.ret==200){
					wx.showToast({
						title:'购物车已清空',
						icon:'none',
						duration:1500,
						mask:true
					})
					this.getcartlist();
					this.hidebox();
					this.triggerEvent('refresh')
				}
			})
		}
	}
})