var sysT = require('../../../../tool/sys-tool.js') var businessT = require('../../../../tool/business-tool.js') var purchaseO = require('../../public/model/purchaseOrder.js') var p = require('../../public/model/public.js') var businessType = require('../../../../public/business-type.js') var app = getApp() Page({ /** * 页面的初始数据 */ data: { type: 'double', chooseAnimation: {}, tips: { s: false, t: ['开始时间仅支持近半年内的月份,最多可购买12个月'] }, calendar: [], status: 0,//0未选择,1选择开始月份,2选择结束月份 data: { firstYear: 2018, beginMonth: 1, }, result: { beginMonth: 0, endMonth: 0 }, lastChose: 0 }, chooseMonth: businessT.action(function (sender) { if (this.data.status == 2) { return } businessT.debugLog(sender.currentTarget) if (this.data.type == 'single') { this.data.status = 2 this.data.result.beginMonth = Number(sender.currentTarget.id) var chooseYear = (this.data.result.beginMonth / 100) | 0 var chooseMonth = this.data.result.beginMonth % 100 this.data.calendar[chooseYear - this.data.data.firstYear].m[chooseMonth - 1].s = true this.setData({ calendar: this.data.calendar }) console.log(this.data.calendar) var that = this setTimeout(function () { var pages = getCurrentPages() pages[pages.length - 2].finishChooseDate(that.data.result) wx.navigateBack({ }) }.bind(this), 1000) return } if (this.data.status == 0) { this.data.status = 1 this.data.lastChose = this.data.result.beginMonth this.data.result.beginMonth = Number(sender.currentTarget.id) this.reloadView() } else { if (Number(sender.currentTarget.id) < this.data.result.beginMonth) { this.data.lastChose = this.data.result.beginMonth this.data.result.beginMonth = Number(sender.currentTarget.id) this.reloadView() } else { if (this.data.type == 'single') { var order = app.purchase.order } else { var order = p.getOrder() } if (!order.isSupplementaryPay) { var purchase = app.purchase.purchaseData if (Number(sender.currentTarget.id) - this.data.result.beginMonth + 1 < purchase.nums) { wx.showToast({ title: '你选择的城市至少需要购买' + purchase.nums + '个月', icon: 'none' }) return } } this.data.status = 2 this.data.result.endMonth = Number(sender.currentTarget.id) var chooseYear = (this.data.result.endMonth / 100) | 0 var chooseMonth = this.data.result.endMonth % 100 this.data.calendar[chooseYear - this.data.data.firstYear].m[chooseMonth - 1].e = true this.setData({ result: this.data.result, status: this.data.status, calendar: this.data.calendar }) var that = this setTimeout(function () { var pages = getCurrentPages() pages[pages.length - 2].finishChooseDate(that.data.result) wx.navigateBack({ }) }.bind(this), 1000) } } }), reloadView: function () { var chooseYear = (this.data.result.beginMonth / 100) | 0 var chooseMonth = this.data.result.beginMonth % 100 if (this.data.type == 'single') { var order = app.purchase.order } else { var order = p.getOrder() } if (!order.isSupplementaryPay) { if (chooseYear == this.data.data.firstYear) { var secondR = { o: 0, l: chooseMonth - 1 } if (this.data.data.beginMonth < 7) { var firstR = { o: this.data.data.beginMonth - 1, l: 12 - this.data.data.beginMonth + 1 } this.data.calendar[0].m = this.createMonthsData(firstR, String(this.data.data.firstYear)) } var thirdR = { o: 0, l: 0 } this.data.calendar[2].m = this.createMonthsData(thirdR, String(this.data.data.firstYear + 2)) } else { var secondR = { o: 0, l: 12, } var thirdR = { o: 0, l: chooseMonth - 1 } this.data.calendar[2].m = this.createMonthsData(thirdR, String(this.data.data.firstYear + 2)) } this.data.calendar[1].m = this.createMonthsData(secondR, String(this.data.data.firstYear + 1)) } businessT.debugLog(this.data.calendar) if (this.data.lastChose != 0) { var lastChooseYear = ((this.data.lastChose / 100) | 0) - this.data.data.firstYear var lastChooseMonth = this.data.lastChose % 100 this.data.calendar[lastChooseYear].m[lastChooseMonth - 1].s = false } this.data.calendar[chooseYear - this.data.data.firstYear].m[chooseMonth - 1].s = true var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) var t = sysT.rpxToPx() * 390 animation.translateX(t).step() this.setData({ result: this.data.result, chooseAnimation: animation.export(), status: this.data.status, calendar: this.data.calendar }) }, createMonthsData: function (choose, year) { var months = [] for (var i = 0; i < 12; i++) { if (i < choose.o || i >= choose.o + choose.l) { months.push({ m: i + 1, h: '-u' }) } else { var id = (i + 1) < 10 ? year + '0' + String(i + 1) : year + String(i + 1) months.push({ m: i + 1, a: 'chooseMonth', i: id }) } } return months }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.type) { this.data.type = options.type } if (this.data.type == 'single') { var order = app.purchase.order } else { var order = p.getOrder() } if (order.isSupplementaryPay) { this.data.tips.s = false } else { this.data.tips.s = true } var purchase = app.purchase.purchaseData if (this.data.type == 'single') { var beginTime = options.beginTime } else { var beginTime = purchase.month } var year = Number(beginTime.slice(0, 4)) var month = Number(beginTime.slice(5, 7)) if (order.isSupplementaryPay) { if (month == 1) { this.data.data.firstYear = year - 2 this.data.data.beginMonth = 12 } else { this.data.data.firstYear = year - 1 this.data.data.beginMonth = month - 1 } businessT.debugLog(month) var canChoose = order.purchaseType == businessType.PurchaseType.socialInsurance ? purchase.addeds_num : purchase.addedf_num if (canChoose > 12) { canChoose = 12 } if (this.data.data.beginMonth - canChoose < 1) { var secondR = { o: 0, l: this.data.data.beginMonth } var begin = canChoose - this.data.data.beginMonth >= 12 ? 0 : 12 - (canChoose - this.data.data.beginMonth) var firstR = { o: begin, l: canChoose - this.data.data.beginMonth } } else { var secondR = { o: this.data.data.beginMonth - canChoose, l: canChoose } var firstR = { o: 0, l: 0 } } var chooseR = [firstR, secondR] } else { this.data.data.firstYear = year this.data.data.beginMonth = month if (12 - this.data.data.beginMonth + 1 < 6) { var firstR = { o: this.data.data.beginMonth -1, l: 12 - this.data.data.beginMonth + 1 } var secondR = { o: 0, l: 6 - (12 - this.data.data.beginMonth + 1) } var thirdR = { o: 0, l: 0 } } else { var firstR = { o: this.data.data.beginMonth - 1, l: 6 } var secondR = { o: 0, l: 0 } var thirdR = { o: 0, l: 0 } } var chooseR = [firstR, secondR, thirdR] } businessT.debugLog(chooseR) var calendar = [] for (var index in chooseR) { var choose = chooseR[index] var months = this.createMonthsData(choose, String(this.data.data.firstYear + Number(index))) calendar.push({ y: this.data.data.firstYear + Number(index), m: months }) } this.setData({ tips: this.data.tips, type: this.data.type, calendar: calendar }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ // onShareAppMessage: function () { // } })