// pages/user/order/sceneOrderInfo/index.js import commonApi from "../../../../utils/https/common" import QRCode from '../../../../utils/weapp-qrcode.js' import util from "../../../../utils/util" let app = getApp(),timer; Page({ /** * 页面的初始数据 */ data: { info:null, isPickup: false, // 是否自提 orderState:app.globalData.orderState, productState:app.globalData.productState, product_model:null, isRefund:false, feeInfoFlag:false, codeIndex:0, codeImgs:[], imgLen: [], minute:"", second:"", id:null, pay_methods:app.globalData.pay_methods, tjList:[], showLoading:true, ids:[], // 权益卡 isCard: false, cardPostList: [], deliveryNum: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ id:options.id }) commonApi._post("product/get_product_by_type", { offset: 0, limit: 6, rand: true, type:"venue,post,line,ticket" }).then(res => { this.setData({ showLoading:false }) try { this.setData({ tjList: res.data.list }) } catch (error) { console.log(error); } }) }, close:function(){ let _this = this,info = _this.data.info; wx.showModal({ title:'提示', content:"确定取消吗", success:function(res){ if(res.confirm){ commonApi.user_post("order/close",{ order_id:info.order_id }).then(res=>{ if(res.code==1){ wx.showToast({ title: '取消成功', icon:'success' }) info.state = "CLOSED"; info.state_text = "已关闭"; info.order_product_list.map(item=>{ item.state='CLOSED' item.state_text='已关闭' }) _this.setData({ info:info }) } }) } } }) }, copy:function(e){ wx.setClipboardData({ data: e.currentTarget.dataset.num, success: function (res) { wx.showToast({ title: '复制成功', icon:'success' }) } }) }, getCodeImg:function(){ let that = this,sys =wx.getSystemInfoSync(),radio = sys.screenWidth / 750, qrcode=this.data.info.order_product_list[0].qrcode,codeImgs=[],codeId=0,arr = []; this.data.info.order_product_list.forEach(qrcode=>{ qrcode.qrcode.map((item,index)=>{ console.log(qrcode.is_force_display_code); item.is_force_display_code = qrcode.is_force_display_code console.log(item.is_force_display_code); arr.push(index) this.setData({imgLen:arr}) if(item.use_url&&item.use_code){ codeImgs.push({img:item.use_url,code:item.use_code,text:item.use_code_display_text,state:item.stateText,is_force_display_code:item.is_force_display_code,flag:item.state}); that.setData({ codeImgs:codeImgs }) } else { new QRCode('damocode'+codeId,{ text: item.use_code, width: 300 * radio, height: 300 * radio, padding:10, // 生成二维码四周自动留边宽度,不传入默认为0 correctLevel: QRCode.CorrectLevel.H, // 二维码可辨识度 callback: (res) => { codeImgs.push({img:res.path,code:item.use_code,text:item.use_code_display_text,state:item.stateText,is_force_display_code:item.is_force_display_code,flag:item.state}); that.setData({ codeImgs:codeImgs }) } }) codeId = codeId + 1 } }) }) }, prevCodeImg:function(){ let qrcode=this.data.info.order_product_list[0].qrcode,codeIndex = this.data.codeIndex; if(codeIndex==0){ this.setData({ codeIndex:qrcode.length-1 }) } else { this.setData({ codeIndex:codeIndex-1 }) } }, nextCodeImg:function(){ let qrcode=this.data.info.order_product_list[0].qrcode,codeIndex = this.data.codeIndex; codeIndex = codeIndex + 1; if(codeIndex==qrcode.length){ codeIndex = 0; } this.setData({ codeIndex:codeIndex }) }, showFeeInfo:function(){ this.setData({ feeInfoFlag:!this.data.feeInfoFlag }) }, refund:function(){ let _this = this,info = _this.data.info; wx.showModal({ title:'提示', content:"确定退款吗", success:function(res){ if(res.confirm){ commonApi.user_post("order/refund",{ order_id:info.order_id }).then(res=>{ if(res.code==1){ wx.showToast({ title: '取消成功', icon:'success' }) info.state = "WAIT_REFUND"; info.order_product_list.map(item=>{ item.state='WAIT_REFUND' }) _this.setData({ info:info }) } }) } } }) }, // 查看苏康码 gotoSku:function(){ commonApi.user_post("pbservice/Ztfw/sukangCode").then(res=>{ console.log(res) app.globalData.weburl = res.data.url; wx.navigateTo({ url: '/pages/pbService/web/index' }) return; }) }, gotoComment:function(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/order/comment/index?id='+id, }) }, goDetail(e){ console.log(e.currentTarget.dataset); let item = e.currentTarget.dataset.set if (item.compose_product_id) { wx.navigateTo({ url: '/pages/info/roadInfo/index?id='+item.compose_product_id }) return } if (item.is_package == 1) { wx.navigateTo({ url:"/pages/info/postProductInfo/index?id="+item.product_id }) return } else if (item.is_package==2) { wx.navigateTo({ url: '/subPackages/goods/oneCardTour/info/index?id='+item.scene_id }); return } else if (item.is_package==3) { wx.navigateTo({ url: '/subPackages/goods/memberCard/index?id='+item.product_id }); return } if (item.product_model=='ticket') { wx.navigateTo({ url:"/pages/info/sceneProductInfo/index?id="+item.scene_id }) }else if (item.product_model=='post') { wx.navigateTo({ url:"/pages/info/postProductInfo/index?id="+item.product_id }) } }, expandPost:function (e) { let index = e.currentTarget.dataset.index let productList = this.data.info.order_product_list let item = productList[index] item.showMore = !item.showMore this.setData({ info: this.data.info }) }, expandMsg: function(e) { let index = e.currentTarget.dataset.index let productList = this.data.info.order_product_list let item = productList[index] item.showMsg = !item.showMsg this.setData({ info: this.data.info }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, daojishi:function(time){ let now = new Date().getTime(); if(now>time){ clearTimeout(timer); timer = null; util.back(); return; } let times = time - now,minute = Math.floor(times / (60 * 1000)),second = Math.round((times - minute * 60 * 1000) / 1000); this.setData({ minute:util.formatNumber(minute), second:util.formatNumber(second) }) timer = setTimeout(()=>{ this.daojishi(time); },1000) }, // 确认收货 toConfirmPost() { let _this =this; wx.showModal({ title:'提示', content:"确定收货吗", success:function(res){ if(res.confirm){ commonApi.user_post("order/confirm_post",{ order_id:_this.data.info.order_id }).then(res=>{ wx.showToast({ title: '操作成功', icon:'success' }) _this.getInfo() }) } } }) }, getInfo () { commonApi.user_post("order/query",{ order_id:this.data.id }).then(res=>{ if(res.data.create_time && res.data.auto_close_time && res.data.state=='UNPAID'){ let time = (new Date(res.data.create_time.replace(/-/g,'/')).getTime() + Number(res.data.auto_close_time) * 1000); this.daojishi(time); } let proId = [] res.data.order_product_list.forEach(item => { proId.push(item.product_id) }) let state = ""; res.data.stateNums = {} res.data.order_product_list.map(order=>{ if(res.data.stateNums[order.state]){ res.data.stateNums[order.state]++; } else { res.data.stateNums[order.state] = 1; } order.consignee_info = order.consignee_info?JSON.parse(order.consignee_info):null; state = state + order.state; order.contacts_info = order.contacts_info?JSON.parse(order.contacts_info):[] if (order.pickup_shop_id>0) { try { order.pickupShop = JSON.parse(order.pickup_shop_info) } catch(e) { order.pickupShop = null } } }) // 2025-7-21能否确认收货 res.data.is_all_confirm = true; if (res.data.state=='PAID' && res.data.stateNums.WAIT_DELIVERY==res.data.order_product_list.length) { res.data.order_product_list.forEach(v=>{ if (v.shipped_batch_count < v.batch_count ) { res.data.is_all_confirm = false } }) } else { res.data.is_all_confirm = false; } // 权益卡 let cardPostList = []; let isCard= false; let deliveryNum = 0; if (res.data.order_product_list.some(v=>v.order_card_product)) { cardPostList = res.data.order_product_list.slice(1) res.data.order_product_list = [res.data.order_product_list[0]] isCard = true; cardPostList.forEach(v=>{ console.log(v) if (v.order_card_product) { v.order_card_product.month = new Date(v.order_card_product.delivery_start_date).getMonth()+1 v.order_card_product.delivery_start_date = v.order_card_product.delivery_start_date.slice(0,10) v.order_card_product.delivery_end_date = v.order_card_product.delivery_end_date.slice(0,10) } if (['WAIT_DELIVERY', 'WAIT_COMMENT', 'COMPLETED'].includes(v.state)) { deliveryNum += 1 } }) } console.log(res.data, 'aaa') this.setData({ isRefund:state.indexOf("REFUND")!=-1, isPickup: res.data.order_product_list.some(v=>v.pickup_shop_id>0), info:res.data, product_model:res.data.order_product_list[0].product_model, ids: proId.join(","), cardPostList: cardPostList, isCard: isCard, deliveryNum: deliveryNum }) this.getCodeImg() }) }, gotoDetail: function (e) { let item = e.currentTarget.dataset.item; util.pagePoint({ event: 'recommend_click', param: { id: item.id, type: item.type } }, 1) if (item.type == 'travels') { // 游记做特殊处理 其他都按照原来的来 wx.navigateTo({ url: '/pages/info/strategyInfo/index?id=' + item.s_id, }) } else { util.gotoDetail(item); } }, callPhone: function (e) { let item = e.currentTarget.dataset.item let phone = item.pickupShop.tel wx.makePhoneCall({ phoneNumber: phone }) }, gotolocation: function(e) { let item = e.currentTarget.dataset.item let info = item.pickupShop wx.openLocation({ latitude: Number(info.lat), longitude: Number(info.lon), name:info.title, address:info.address }) }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getInfo() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { clearTimeout(timer) timer = null; }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { } })