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() var wxyj = require('../../../../public/wxyj.js') Page({ data: { list: [], current: 0, orderStatus: false, discountStatus: false, discountData: '', cheapData: [] }, initData() { swan.showLoading({ title: '请稍后...', mask: true, }); net.connectNeedLogin({ url: url.app_host + url.getMyOrder, data: {}, success: (err, res) => { swan.hideLoading(); this.countTime(res.data) }, failed: (err, res) => { swan.hideLoading(); businessT.showFailTips(err) } }) net.connectNeedLogin({ url: url.app_host + url.getCashCoupon, data: { phone: app.globalData.userInfo.phone, page: 1, expired: 0 }, success: (err, res) => { this.getCashCouponListSuccess(res, 0) }, failed: (err, res) => { businessT.showFailTips(err) } }) }, getSystemData() { swan.getSystemInfo({ success: res => { var width = res.windowWidth this.setData({ width: res.windowWidth }) }, }); // setTimeout(() => { var tabWidth, tabItemWidth swan.createSelectorQuery().select('#tabWrap').boundingClientRect((rect) => { tabWidth = rect.width }).exec() swan.createSelectorQuery().select('#tabItem').boundingClientRect((rect) => { tabItemWidth = rect.width var moveX = (tabWidth - tabItemWidth * 3) / 2 + tabItemWidth this.setData({ moveX }) }).exec() // }, 300) }, getCashCouponListSuccess(res, expired) { var data = res.data.list if (data.length == 0) { this.setData({ haveCashCoupon: false }) return } else { this.setData({ haveCashCoupon: true }) } 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.setData({ discountData: data }) }, choose(e) { let current = this.data.discountData[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 }) this.setData({ discountData: this.data.discountData, cheapDataLength: this.data.cheapData.length, cheapMoney: cheapMoney.toFixed(2) }) }, showPayModalLater() { this.closeModal('showPay') }, showPayModal(e) { if (e) { var currentData = this.data.list[this.data.current][e.currentTarget.dataset.index] } else { var currentData = this.data.currentData } this.setData({ currentData }) this.getParams(currentData) if (this.data.discountData.length) { const animation = swan.createAnimation() animation.translateY(-500).step(); this.setData({ discountStatus: true, nums: currentData.nums }, () => { this.setData({ animationData: animation.export() }) }) } else { this.pay() } }, changeData(res) { var list = [], notpay = [], ispay = [] res.forEach((item) => { if (item.status == 1) { notpay.push(item) } else if (item.status == 2) { ispay.push(item) } }) list[0] = res.slice(0, 10) list[1] = notpay.slice(0, 10) list[2] = ispay.slice(0, 10) console.log(ispay) this.setData({ list, notpay, ispay, allData: res, }) }, countTime(res) { res.forEach((item) => { item.syear = String(item.start_month).substring(0, 4) item.smonth = String(item.start_month).slice(-2) if (Number(item.smonth) + item.nums == 13) { item.eyear = item.syear item.emonth = 12 } else if (Number(item.smonth) + item.nums > 13) { item.eyear = Number(item.syear) + 1 item.emonth = Number(item.smonth) + item.nums - 13 } else { item.eyear = Number(item.syear) item.emonth = Number(item.smonth) + item.nums - 1 } }) this.setData({ res }) this.changeData(res) }, move(e) { const animationLine = swan.createAnimation() const animationContent = swan.createAnimation() if (e.currentTarget.dataset.index == 1) { animationLine.translateX(this.data.moveX).step() animationContent.translateX(-this.data.width).step(); } else if (e.currentTarget.dataset.index == 2) { animationLine.translateX(this.data.moveX * 2).step() animationContent.translateX(-this.data.width * 2).step(); } else { animationLine.translateX(0).step() animationContent.translateX(0).step(); } this.setData({ current: e.currentTarget.dataset.index, animationLine: animationLine.export(), animationContent: animationContent.export() }) }, showModal(e) { var current = this.data.current var index = e.currentTarget.dataset.index var buyNo = this.data.list[current][index].buy_no var syear = this.data.list[current][index].syear var smonth = this.data.list[current][index].smonth var eyear = this.data.list[current][index].eyear var emonth = this.data.list[current][index].emonth if (e.currentTarget.dataset.type == 'delete') { var type var content if (this.data.list[current][index].pay_for == 1 || this.data.list[current][index].pay_for == 2) { type = this.data.list[current][index].title + '缴纳' } else { type = this.data.list[current][index].title } if (this.data.list[current][index].nums == 1) { content = '是否要取消' + syear + '年' + smonth + '月的' + type + '订单' } else { content = '是否要取消' + syear + '年' + smonth + '月-' + eyear + '年' + emonth + '月的' + type + '订单' } swan.showModal({ title: '取消后将无法恢复', content: content, showCancel: true, cancelText: '取消', cancelColor: '#3296FB', confirmText: '确定', confirmColor: '#3296FB', success: res => { if (res.confirm) { this.deleteOrder(buyNo) } } }) } else if (e.currentTarget.dataset.type == 'detail') { const animation = swan.createAnimation() animation.translateY(-500).step(); this.setData({ orderStatus: true }, () => { this.setData({ animationData: animation.export() }) }) var detail = {} detail.data = this.data.list[current][index] if (this.data.list[current][index].nums == 1) { detail.date = this.data.list[current][index].syear + '年' + this.data.list[current][index].smonth + '月' } else { detail.date = this.data.list[current][index].syear + '年' + this.data.list[current][index].smonth + '月-' + this.data.list[current][index].eyear + '年' + this.data.list[current][index].emonth + '月' } this.setData({ orderStatus: true, detail, currentData: this.data.list[current][index] }) this.getParams(this.data.currentData) } }, closeModal(status) { const animation = swan.createAnimation() animation.translateY(0).step(); this.setData({ animationData: animation.export(), cheapData: [] }, () => { var timer = setTimeout(() => { this.setData({ orderStatus: false, discountStatus: false }) if (status == 'showPay') { this.showPayModal() } clearTimeout(timer) }, 400) this.data.discountData.forEach((item) => { item.isSelected = false }) this.setData({ discountData: this.data.discountData, cheapDataLength: 0 }) }) }, deleteOrder(buy_no) { swan.showLoading({ title: '请稍后...', mask: true, }); net.connectNeedLogin({ url: url.app_host + url.cancelPurchaseOrder, data: { buy_no }, success: (err, res) => { this.data.res.forEach((item, index) => { if (item.buy_no == buy_no) { this.data.res.splice(index, 1) } }) this.changeData(this.data.res) swan.showToast({ title: '取消订单成功', icon: 'none', mask: true }); }, fail: (err, res) => { swan.hideLoading(); businessT.showFailTips(err) } }) }, loadMore(e) { if (e.currentTarget.dataset.sc == 0) { this.data.list[0] = this.data.allData.slice(0, this.data.list[0].length + 10) } else if (e.currentTarget.dataset.sc == 1) { this.data.list[1] = this.data.notpay.slice(0, this.data.list[1].length + 10) } else if (e.currentTarget.dataset.sc == 2) { this.data.list[2] = this.data.ispay.slice(0, this.data.list[2].length + 10) } this.setData({ list: this.data.list }) }, getParams(currentData) { var obj = { sbuId: currentData.sbuId, id_card: '', cid: currentData.cid, month: currentData.start_month, newCard: currentData.newCard, shebao_card: currentData.shebao_card, hukou_type: currentData.hukou_type, fund: currentData.fund / currentData.nums, couponuser_id: '', pay_channel: 13, nums: currentData.nums, first_sb: currentData.first_sb, first_fund: currentData.first_fund, sb_wage: currentData.sb_wage, working: currentData.working } if (currentData.pay_for == 2) { obj.buyShebao = false } else { obj.buyShebao = true } this.setData({ payData: obj }) }, pay() { var currentData = this.data.currentData, path if (this.data.cheapData.length) { var id = '' this.data.cheapData.forEach((item) => { if (item) { id += item.id + ',' } }) if (id) { id = id.slice(0, -1) } this.data.payData.couponuser_id = id } if (currentData.pay_for == 1 || currentData.pay_for == 3) { if (currentData.added) { path = url.createShebaoSupplementaryPayOrder } else { path = url.createShebaoOrder } } else if (currentData.pay_for == 2 || currentData.pay_for == 4) { if (currentData.added) { path = url.createFundSupplementaryPayOrder } else { path = url.createFundOrder } } net.connectNeedLogin({ url: url.app_host + path, data: this.data.payData, success: (err, res) => { swan.requestPolymerPayment({ orderInfo: res.data, success: res => { this.needSurvey() }, fail: err => { swan.showToast({ title: '支付失败', icon: 'none' }); } }); }, fail: (err, res) => { swan.hideLoading() businessT.showFailTips(err, '提交订单失败') } }, true) if (this.data.orderStatus || this.data.discountStatus) { this.closeModal() } }, needSurvey() { if (wxyj.wxyjData.order.sb_wage) { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=salary' }); return } net.connectNeedLogin({ url: url.app_host + url.checkSurvey, data: {}, success: (err, res) => { if (res.data) { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=survey&payfor=' + order.pay_for, }); } else { this.needRepair() } }, fail: (err, res) => { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=share' }); } }, false) }, needRepair() { net.connectNeedLogin({ url: url.app_host + url.queryPayPriceDifference, data: {}, success: (err, res) => { if (res.data) { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=repair' }); } else { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=share' }); } }, fail: (err, res) => { swan.navigateTo({ url: '../../../../public/pages/pay-success/pay-success?type=share' }); } }, false) }, onLoad: function () { this.initData() this.setData({ suffix: sysT.suffixOfClass() }) 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('设置失败'); }, }) // 监听页面加载的生命周期函数 }, onReady: function () { // this.initData()监听页面初次渲染完成的生命周期函数 this.getSystemData() }, 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 () { // 用户点击右上角转发 } });