// pages/order/show/index.js let app = getApp(); import commonApi from "../../../utils/https/common" import util from "../../../utils/util" Page({ /** * 页面的初始数据 */ data: { dateArr: [ {date: '2024-11-19', price: 7000}, {date: '2024-11-20', price: 7000}, {date: '2024-11-21', price: 7000}, ], times:[ {sale_date: "2024-11-19", stock_number: 0, start_time: "07:30", end_time: "08:30"}, {sale_date: "2024-11-19", stock_number: 2, start_time: "07:30", end_time: "08:30"}, {sale_date: "2024-11-19", stock_number: 2, start_time: "07:30", end_time: "08:30"}, {sale_date: "2024-11-19", stock_number: 2, start_time: "07:30", end_time: "08:30"}, {sale_date: "2024-11-19", stock_number: 2, start_time: "07:30", end_time: "08:30"}, {sale_date: "2024-11-19", stock_number: 2, start_time: "07:30", end_time: "08:30"}, ], product:null, dateindex:-1, timeindex:-1, sku_id: null, producNum: 1, cartTop: 0, cartImgInfo: null, cartCount: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { let that = this let product = app.globalData.product,start_date = util.formatDate(new Date()); this.setData({ product:product }) let end_date = util.formatDate(new Date(new Date(start_date.replace(/-/g,'/')).getTime() + 30 * 24 * 60 * 60 * 1000)); commonApi.user_post("product/product_date_price",{ sku_id:1208, start_date:start_date, end_date:end_date }).then(res=>{ // this.setData({ // times:res.data, // dateindex:dateindex, // timeindex:timeindex // }) console.log(res) // 获取购物车按钮的位置 wx.createSelectorQuery().select('#cart').boundingClientRect(function (res) { console.log(res) that.setData({ cartTop: res.top }) }).exec() }) this.initDate() }, getDay: function (date) { let d = new Date(date.replace(/-/g, '/')).getDay(); let days = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"]; return days[d]; }, // 初始化日期 initDate () { let date = this.data.dateArr date.forEach(v=>{ v.short_date = v.date.split("-").splice(1, 2).join("-") }) this.setData({dateArr: date}) this.initTime() }, // 时间处理 initTime () { let times = this.data.times times.forEach(v=>{ v.week = this.getDay(v.sale_date) }) this.setData({times: times}) }, // 选择日期 changeDate:function(e){ let dateindex = e.currentTarget.dataset.date // todo获取时间 this.setData({ dateindex: dateindex }) }, selectTime:function(e){ let dateindex = e.currentTarget.dataset.dateindex,times = this.data.times,timeindex=e.currentTarget.dataset.timeindex; if(times[dateindex].screen[timeindex].is_ticket==1){ this.setData({ timeindex:timeindex, dateindex:dateindex }) } }, minus: function () { if (this.data.producNum == 1) return; this.setData({ producNum: this.data.producNum - 1 }) }, add: function () { this.setData({ producNum: this.data.producNum + 1 }) }, next:function(){ }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getCartNum() }, // 获取购物车数量 getCartNum () { commonApi.user_post('cart/get_list', {}).then(res => { this.setData({ cartCount: res.data.length }) }) }, // 加入购物车 showCart: function () { commonApi.user_post('wx/get_user_keep', { jumpurl: '/pages/info/postProductInfo/index?id=' + this.data.id, title: this.data.info.title, type: 'mini' }).then(res => { if (res.data.subscribe == 0) { this.setData({ wxqrcode: res.data.qrcode, showQrCode: true }) } else { if (this.data.info.sku.length == 0) { wx.showToast({ title: '该产品未设置规格,不能加购', icon: 'none' }) return; } this.setData({ skuFlag: "cart" }) let that = this wx.createSelectorQuery().select('#skuImg').boundingClientRect(function (res) { console.log(res) that.setData({ cartImgInfo: 'top:' + res.top + 'px;left:' + res.left + 'px;' }) }).exec() } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { } })