123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352 |
- 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 () {
-
- // }
- })
|