// pages/order/comment/index.js let app = getApp() import commonApi from "../../../utils/https/common" Page({ /** * 页面的初始数据 */ data: { goodsList: [], ticketList: [], // 仅展示用,区分邮寄自提 postList: [], pickUpList: [], productPrice: 0, ticketPrice: 0, product:"", sku_id: '', kjId: null, gp_id: null, showPrice: 0, postFee: 0, coupon:app.globalData.couponInfo, select_allowance: false, allowance_data: null, allowance_price: 0, flag:null, linkmanList:[], finalPrice: 0, showCoupon: true, explainDataList: [], showContent: null, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ goodsList: app.globalData.postProduct || [], ticketList: app.globalData.list || [], kjId: app.globalData.kjId, gp_id: app.globalData.gp_id || app.globalData.team_id, flag:options.flag, // showCoupon: (app.globalData.list || []).length<=0, // linkmanList: app.globalData.linkmanList }) console.log('-------------',this.data.ticketList, this.data.goodsList); // debugger let price = 0, sku_id = [] ,postFee= 0; this.data.goodsList.map(item => { try { item.postFee = parseFloat(item.postFee) } catch(e){ item.postFee = 0 } if (!app.globalData.kjId && !this.data.gp_id) { price = price + item.sku.price * item.productNum ; postFee += item.sku.batch_shipment?item.postFee*(item.sku.batch_count || 0):item.postFee; } else if (this.data.gp_id) { price = price + item.sku.event_price * item.productNum; } sku_id.push(item.sku.id) }) this.data.ticketList.map(item => { // price = price + item.sku.price * item.linkmanList.length; price = price + item.sku.price * item.num; sku_id.push(item.sku.id) }) this.setData({ showPrice: app.globalData.kjId ? 0 : price, postFee:postFee, sku_id: sku_id.join(",") }) this.handlePostData() if (!this.data.kjId && !this.data.gp_id) { this.couponCom = this.selectAllComponents("#coupon")[0]; } this.getExplain() }, handlePostData () { let postList = this.data.goodsList.filter(x=>x.user_select_type === 0) let pickUpList = this.data.goodsList.filter(x=>x.user_select_type === 1) this.setData({ postList: postList, pickUpList: pickUpList, }) }, order: function (){ console.log(app.globalData.createDate); let explainData = (this.data.explainDataList || []).filter(x=>x.selectExplain).map(x=>{ return { product_id: x.product.id, product_num: 1, sku_id: x.sku.id, type: x.product.type, } }) app.globalData.createDate.product_list = app.globalData.createDate.product_list.concat(explainData) app.globalData.createDate.coupon_id= this.data.coupon ? this.data.coupon.id : null; let service = "order/create", postData = {data: JSON.stringify(app.globalData.createDate)} commonApi.user_post(service, postData).then(res => { }) }, changePrice: function () { let product = this.data.product, price = 0; product.map(item => { price = price + item.sku.price * item.productNum; if (this.data.allowance_data && this.data.select_allowance && this.data.allowance_price) { let spread_price = Number(this.data.allowance_data.discount_limit_price - this.data.allowance_data.user_used_price); price -= this.data.allowance_price * item.productNum < spread_price ? this.data.allowance_price * item.productNum : spread_price } }) if (this.data.coupon && this.data.showPrice != price) { wx.showToast({ title: '订单价格发生变化,请重新选择优惠券', icon: 'none' }) app.globalData.couponInfo = null; if (!this.data.kjId && !this.data.gp_id) { this.couponCom.setNullCoupon() } this.setData({ coupon: null }) } this.setData({ showPrice: app.globalData.kjId ? 0 : price }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, inputRemark: function (e) { app.globalData.createDate.product_list.map((item)=>{ if (item.type.includes('post')) { item.remark = e.detail.value; } }) }, //获取最高优惠券 getNewCoupon(e){ this.setData({ coupon:e.detail }) }, // 讲解 getExplain () { if (this.data.ticketList.length>0) { let explainArr = [] let productId = this.data.ticketList.map(x=>x.product.id) Promise.all( productId.map(x=>commonApi._post("product/get_product_compose_list", { product_id: x })) ).then(res=>{ if (res) { res.forEach(x=>{ if (x.data && x.data[0] && !explainArr.find(v=>v.sku.id == x.data[0].sku.id)) { explainArr.push(x.data[0]) } }) this.setData({ explainDataList: explainArr }) } console.log(res) }) } }, changeSeletExplain (e) { let val = e.currentTarget.dataset.val; let index = e.currentTarget.dataset.index; let explainDataList = this.data.explainDataList let explainData = this.data.explainDataList[index] explainData.selectExplain = val this.setData({ explainDataList: explainDataList }) }, changeContent (e) { let val = e.currentTarget.dataset.val; this.setData({ showContent: val }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { try { if (Object.keys(app.globalData.couponInfo).length!=0) { this.setData({ coupon: app.globalData.couponInfo }) }else{ this.setData({ coupon:null }) } } catch (error) { this.setData({ coupon:null }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { // 清空购物车 console.log("清除购物车") try { app.globalData.list = null app.globalData.createDate = null app.globalData.index = 0 app.globalData.productPrice = 0 app.globalData.ticketPrice = 0 } catch(e) { console.log("清空购物车失败", e) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })