var businessT = require('../../../../tool/business-tool.js') var sysT = require('../../../../tool/sys-tool.js') var url = require('../../../../constant/url.js') import Net from '../../../../tool/net.js' var net = new Net() var app = getApp() Page({ data: { ui: ['未使用', '已失效'], left: 0, className: 0, lineLeft: 120, list: [[], []], current: 0, choose: false, cheapData: [], status: false }, getSysInfo() { var tabWidth swan.getSystemInfo({ success: res => { this.setData({ width: res.screenWidth }) }, }); swan.createSelectorQuery().select('#tabWrap').boundingClientRect((rect) => { tabWidth = rect.width }).exec() swan.createSelectorQuery().select('#tabItem').boundingClientRect((rect) => { this.setData({ moveX: tabWidth - rect.width }) }).exec() }, //点击tab ontab(e) { var n = e.currentTarget.dataset.class; const animation = swan.createAnimation() const animationLine = swan.createAnimation() if (n == 1) { animation.translateX(-this.data.width).step() animationLine.translateX(this.data.moveX).step() if (this.data.list[1].length == 0) { if (!this.data.status) { this.initData(n) this.data.status = true } } } else { animation.translateX(0).step() animationLine.translateX(0).step() } this.setData({ animationData: animation.export(), animationLine: animationLine.export(), current: n }) }, initData(expired) { swan.showLoading({ title: '请稍后...', mask: true, }); net.connectNeedLogin({ url: url.app_host + url.getCashCoupon, data: { phone: app.globalData.userInfo.phone, page: 1, expired }, success: (err, res) => { console.log(res) swan.hideLoading(); this.getCashCouponListSuccess(res, expired) }, failed: (err, res) => { swan.hideLoading(); businessT.showFailTips(err) } }) }, getCashCouponListSuccess(res, expired) { var data = res.data.list if (data.length == 0) { this.data.list[expired] = [] this.setData({ list: this.data.list }) return } 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) } this.data.list[expired] = data this.setData({ list: this.data.list }) }, //选择优惠券 choose(e) { let current = this.data.list[0][e.currentTarget.id] var i, cheapMoney = 0 if (current.isSelected) { current.isSelected = false this.data.cheapData.forEach((item, index) => { if (current.id == item.id) { i = index } }) this.data.cheapData.splice(i, 1) } else { if (this.data.cheapData.length < this.data.nums) { current.isSelected = true this.data.cheapData.push(current) } else { swan.showToast({ title: '本次购买仅可选择' + this.data.nums + '张抵用券', icon: 'none', mask: false }); } } this.data.cheapData.forEach((item, index) => { cheapMoney += item.coupon_price }) if (this.data.cheapData.length) { this.setData({ chooesdCashCoupon: true }) } else { this.setData({ chooesdCashCoupon: false }) } this.setData({ list: this.data.list, cheapDataLength: this.data.cheapData.length, cheapMoney:cheapMoney.toFixed(2) }) }, goBack() { var page = getCurrentPages() var prePage = page[page.length - 2] prePage.setData({ cheapData: this.data.cheapData }) swan.navigateBack() }, onLoad: function (e) { // 监听页面加载的生命周期函数 this.initData(this.data.current) if (e.status) { this.setData({ choose: true, nums: e.nums, suffix: sysT.suffixOfClass() }) } console.log(this.data.choose) }, onReady: function () { // 监听页面初次渲染完成的生命周期函数 this.getSysInfo() }, onShow: function () { // 监听页面显示的生命周期函数 swan.setPageInfo && swan.setPageInfo({ title: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页', keywords: '我的社保,我的社保网,我的社保APP,社会保障,社保,社保代缴,公积金代缴,社会保险,五险一金,医保,医疗保险,公积金,养老,生育,工伤,失业,住房公积金,社保代理,代缴社保,公积金代理,查悦社保,大社保,亲亲小保,社保掌上通,招聘求职,创业,买房,贷款,计算器,人社局,摇号', description: '我的社保APP是为个人、企业提供社保代缴代扣、公积金代扣代缴、社保查询、公积金查询服务的名牌产品。解决个体工商户、自由职业者、待业人员、全职妈妈、创业者等的个人社保公积金断缴难题,同时解决贷款, 买房, 买车, 养老, 医疗, 生育, 医疗报销等难题。同时为企业提供全国专业社保代理和公积金代理。', articleTitle: '【我的社保】官方APP-社保挂靠公积金代理全国自助缴纳查询社保公积金_主页', release_date: '2019-02-23 20:00:00', success: function () { console.log('页面基础信息设置完成'); }, fail: function (res) { console.log('设置失败'); }, }) }, onHide: function () { // 监听页面隐藏的生命周期函数 }, onUnload: function () { // 监听页面卸载的生命周期函数 }, onPullDownRefresh: function () { // 监听用户下拉动作 }, onReachBottom: function () { // 页面上拉触底事件的处理函数 }, onShareAppMessage: function () { // 用户点击右上角转发 } });