123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- var sysT = require('../../../tool/sys-tool.js')
- var businessT = require('../../../tool/business-tool.js')
- var url = require('../../../constant/url.js')
- import Net from '../../../tool/net.js'
- var net = new Net()
- var app = getApp()
- var p = require('../../../page/home/public/model/public.js')
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: 'choose',
- fee: '0.00',
- status: 0,//0有效的,1无效的
- usedPage:0,
- unusedPage: 0,
- isLoading: true,
- usedNoData: false,
- unusedNoData: false,
- adapter: {
- suffix: ''
- },
- chose: [],
- usedData:[],
- unusedData:[],
- tips: ['', '', ''],
- tab: {
- id: '1',
- animation: {}
- },
- hadLeft: false,//判断左边是否有数据
- hadRight: false,//判断右边边是否有数据
- },
- tabChoose: businessT.action(function (sender) {
- if (sender.currentTarget.id == this.data.tab.id) {
- return
- }
- // this.data.bgScrollView.scroll = true;
- // this.setData({
- // bgScrollView: this.data.bgScrollView
- // })
- var animation = wx.createAnimation({
- duration: 300,
- timingFunction: 'ease',
- })
- var bgAnimation = wx.createAnimation({
- duration: 300,
- timingFunction: 'ease',
- })
- var w = sysT.sysInfo().windowWidth
- businessT.debugLog(w)
- var s = sender.currentTarget.id - 1
- // if (sender.currentTarget.id == "1") {
- // animation.translateX(0).step()
- // this.data.bgScrollView.left = 0
- // } else {
- // animation.translateX(w / 2).step()
- // this.data.bgScrollView.left = sysT.sysInfo().windowWidth
- // }
- animation.translateX(s * w / 2).step()
- bgAnimation.translateX(-w * s).step()
- this.data.tab.id = sender.currentTarget.id
- this.data.tab.animation = animation.export()
- // this.data.bgScrollView.scroll = false;
- this.setData({
- tab: this.data.tab,
- bgAnimation: bgAnimation.export()
- // bgScrollView: this.data.bgScrollView
- })
- businessT.debugLog(sender.currentTarget.id)
- if (this.data.tab.id == "1") {
- this.data.status = 0
- if (!this.data.hadLeft) {
- this.getCashCouponList()
- }
- } else {
- this.data.status = 1
- if (!this.data.hadRight) {
- this.getCashCouponList()
- }
- }
- }),
- chooseAction: businessT.action(function (sender) {
- if (this.data.type != 'choose') {
- if (this.data.status == 0) {
- wx.switchTab({
- url: '../../../page/home/index',
- })
- }
- return
- }
- businessT.debugLog(this.data.chose)
- businessT.debugLog(sender.currentTarget.id)
- var c = Number(sender.currentTarget.id)
- var s = this.data.chose.indexOf(c)
- businessT.debugLog(s)
- if (s >= 0) {
- this.data.chose.splice(s, 1)
- } else {
- var order = app.purchase.order
- businessT.debugLog(order.timeInterval)
- if (order.timeInterval <= this.data.chose.length) {
- wx.showToast({
- title: '本次购买只可选择' + order.timeInterval + '张抵用券',
- icon: 'none'
- })
- return
- }
- this.data.chose.push(c)
- }
- var fee = 0
- for (var i in this.data.chose) {
- var index = this.data.chose[i]
- fee += this.data.unusedData[index].coupon_price
- }
- this.data.fee = fee.toFixed(2)
- this.setData({
- fee: this.data.fee,
- chose: this.data.chose,
- tips: this.getTips()
- })
- }, 100),
- checkUnuseAction: businessT.action(function (sender) {
- this.getCashCouponList()
- }),
- confirmAction: businessT.action(function (sender) {
- var page = getCurrentPages()
- if (page[page.length - 2].route == 'page/home/pages/pay-order/pay-order') {
- var fee = 0
- var ids = ''
- for (var i in this.data.chose) {
- var item = this.data.unusedData[this.data.chose[i]]
- fee += item.coupon_price
- if (i == 0) {
- ids = ids + item.id
- } else {
- ids = ids + ',' + item.id
- }
- }
- var dis = {
- fee: fee,
- ids: ids
- }
- page[page.length-2].refreshDiscount(dis)
- }
-
- wx.navigateBack({
-
- })
- }),
- getCashCouponList: function (flag) {
- if (flag) {
- wx.showLoading({
- title: '加载中',
- mask: true
- })
- }
- this.setData({
- isLoading: true
- })
- var page = this.data.status == 0 ? this.data.unusedPage + 1 : this.data.usedPage + 1
- net.connectNeedLogin({
- url: url.app_host + url.getCashCoupon,
- data: {
- phone: app.globalData.userInfo.phone,
- page: page,
- expired: this.data.status == 0 ? 0 : 1
- },
- success: (err, res) => {
- this.getCashCouponListSuccess(res)
- this.data.isLoading = false
- if (this.data.status == 0) {
- this.setData({
- isLoading: this.data.isLoading,
- unusedData: this.data.unusedData
- })
- } else {
- this.setData({
- isLoading: this.data.isLoading,
- usedData: this.data.usedData
- })
- }
- wx.hideLoading()
- },
- fail: (err, res) => {
- this.data.isLoading = false
- this.setData({
- isLoading: this.data.isLoading
- })
- wx.hideLoading()
- businessT.showFailTips(err, '加载失败')
- }
- }, true)
- },
- getCashCouponListSuccess: function (res) {
- var data = res.data.list
- if (data.length == 0) {
- return
- }
- if (this.data.status == 0) {
- this.data.unusedPage = res.currentPage
- } else {
- this.data.usedPage = res.currentPage
- }
- for (var index in data) {
- var item = data[index]
- if (item.status == 1 && item.expired == 0) {
- // item.end_time = '2019-03-17 00:00:01'
- var now = new Date().format('yyyy-MM-dd h:m:s')
- var nowDate = now.slice(0, 10)
- var endDate = item.end_time.slice(0, 10)
- if (nowDate == endDate) {
- item.p = '今天过期'
- } else {
- var tempNowDate = nowDate + ' 00:00:00'
- var tempEndDate = endDate + ' 00:00:00'
- var d = businessT.dateDiff('d', tempNowDate, tempEndDate)
- if (tempEndDate == item.end_time) {
- d -= 1
- }
- if (d == 0) {
- item.p = '今天过期'
- } else {
- item.p = '还有' + d + '天过期'
- }
- }
- } else {
- if (item.status == 1) {
- item.p = '已过期'
- } else {
- item.p = '已使用'
- }
- }
- item.end = item.end_time.slice(0, 10)
-
- }
- var noData = false
- if (res.data.list.length < 10) {
- noData = true
- }
- if (this.data.status == 0) {
- this.data.unusedData = this.data.unusedData.concat(res.data.list)
- this.data.unusedNoData = noData
- } else {
- this.data.usedData = this.data.usedData.concat(res.data.list)
- this.data.usedNoData = noData
- }
-
- },
- uploadView: businessT.action(function (sender) {
- if (this.data.isLoading) {
- return
- }
- if (this.data.status == 0 && this.data.unusedNoData) {
- return
- }
- if (this.data.status == 1 && this.data.usedNoData) {
- return
- }
- this.getCashCouponList()
- businessT.debugLog('abc')
- }),
- getTips: function () {
- if (this.data.type != 'choose') {
- return []
- }
- if (this.data.chose.length > 0) {
- return ['您已选中优惠券 ' + this.data.chose.length + ' 张,共可抵用', '¥' + this.data.fee, '']
- }
- var order = app.purchase.order
- return ['您当前下了 ' + order.timeInterval + ' 个月订单,可同时选 ', order.timeInterval, ' 张优惠券']
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.type) {
- this.data.type = options.type
- }
- this.data.adapter = {
- suffix: sysT.suffixOfClass(),
- }
- this.setData({
- adapter: this.data.adapter,
- type: this.data.type,
- tips: this.getTips()
- })
- this.getCashCouponList(true)
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
-
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
-
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
-
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
-
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
-
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
-
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- return {
- path: '/page/home/index',
- imageUrl: '../../../icon/public/share_img.png',
- title: '自助缴社保公积金,覆盖200多个城市,专业团队操作'
- }
- }
- })
|