// pages/indexPages/yyqhPages/selectTime/selectTime.js import { queryReserveDate, queryReserveTimePeriod, xcxjxyy } from "../../../../apis/index" Page({ /** * 页面的初始数据 */ data: { hall: "", business: "", dateBoxStyle: '', orgAreaNumber: "", dates: [], dateIndex: 0, times: [], timeIndex: 0, sfYy: false }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { let that = this that.init(options) }, init(e) { let that = this if (e) { if (e.business) { that.setData({ hall: wx.getStorageSync('MY_HALL').bsfwtmc, business: JSON.parse(e.business) }) } that.getData() } }, selectDate(e) { let that = this let index = e.currentTarget.dataset.index let item = e.currentTarget.dataset.item that.setData({ dateIndex: index }) that.getTime() }, selectTime(e) { let that = this let index = e.currentTarget.dataset.index let item = e.currentTarget.dataset.item that.setData({ timeIndex: index }) }, showHiden() { let that = this let dateBoxStyle = that.data.dateBoxStyle if (dateBoxStyle == '') { that.setData({ dateBoxStyle: "timesActive" }) } else { that.setData({ dateBoxStyle: "" }) } }, getWeek(e) { let weeks = [ "周日", "周一", "周二", "周三", "周四", "周五", "周六", ] return weeks[e] }, getData(e) { let that = this wx.showLoading({ title: '正在获取可预约日期', }) let form = { bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm } queryReserveDate(form).then(res => { wx.hideLoading() if (res.code == 200) { that.setData({ dates: res.billDateList.map((e) => { return { week: that.getWeek(new Date(e).getDay()), date: e.substring(5, 10), dates: e } }), orgAreaNumber: res.orgAreaNumber }) that.getTime() } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) }, getTime() { let that = this wx.showLoading({ title: '正在获取预约时间段', }) let form = { orgAreaNumber: that.data.orgAreaNumber, billDate: that.data.dates[that.data.dateIndex].dates, bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm, ywId: that.data.ywId } queryReserveTimePeriod(form).then(res => { wx.hideLoading() if (res.code == 200) { that.setData({ times: res.periodList }) } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) }, next() { let that = this let times = that.data.times[that.data.timeIndex] let dates = that.data.dates[that.data.dateIndex].dates let orgAreaNumber = that.data.orgAreaNumber let yyrs = Number(times.capacity) - Number(times.appointNum) let sfYy = that.data.sfYy if (!sfYy) { if (yyrs != 0) { that.setData({ sfYy: true }) wx.showLoading({ title: '正在预约中...', }) let form = { bsfwtDm: wx.getStorageSync('MY_HALL').bsfwtDm, ywId: that.data.business.ywId, ywxxId: that.data.business.ywxxId, unionid: wx.getStorageSync('PUBLIC_ID').unionid, yyrq: dates, yysjd: times.periodName, periodCode: times.periodCode, orgAreaNumber: orgAreaNumber, remainTicketNum: yyrs, } xcxjxyy(form).then(res => { that.setData({ sfYy: true }) wx.hideLoading() if (res.code == 200) { let datas = res.data wx.setStorageSync('YYDATA', datas) wx.reLaunch({ url: '../success/success?business=' + JSON.stringify(that.data.business), }) } else { wx.showToast({ title: res.msg || res.message, icon: "none", duration: 5000 }) } }) } else { wx.showToast({ title: '可预约人数为 0,请换个时间段预约', icon: "none", duration: 5000 }) } } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { } })