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 orderModel = require('../../public/model/order-model.js') var app = getApp() var businessType = require('../../../../public/business-type.js') var pay = require('../../../../public/pay.js') Page({ /** * 页面的初始数据 */ data: { scroll: true, isLoading: true, detailsView: { data: {}, scroll: false, left: 0, hidden: true, animation: {}, mt: '参保姓名\n身份证号\n购买月份\n购买城市\n订单号\n生成时间', m: '', t: '', at: '', a: '', discountU: true, discountT: ['', '', ''], discountC: 0, discountS: '未使用', sa: true, status: 1 }, discount: { canChoose: 0, fee: '0.00', chose: [], data: [], page: 0, finish: false, isLoading: true }, tab: { id: '1', animation: {} }, // bgScrollView: { // scroll: false, // left: 0 // }, data: [ [], [], [] ],//bs1是只有左边按钮,2是右边有一按钮,3都展示 bgAnimation:{} }, tabChoose: businessT.action(function (sender) { businessT.debugLog(sender.currentTarget.id) 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 var s = sender.currentTarget.id - 1 animation.translateX(s * w / 3).step() // this.data.bgScrollView.left = s * sysT.sysInfo().windowWidth 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, // bgScrollView: this.data.bgScrollView, bgAnimation: bgAnimation.export() }) }), payAction: businessT.action(function (sender) { businessT.debugLog(sender) var t = Number(this.data.tab.id) var data = this.data.data[t - 1][sender.currentTarget.id] this.showDetails(data) this.detailsScroll(1, false) }), cancelAction: businessT.action(function (sender) { businessT.debugLog(sender) if (this.data.tab.id == '1') { var item = this.data.data[0][sender.currentTarget.id] var that = this wx.showModal({ title: '取消后将无法恢复', content: item.cancelContent, confirmColor: '#3296FB', cancelColor: '#3296FB', confirmText: '确定', cancelText: '取消', success: function (res) { if (res.confirm) { that.cancelOrder(item.buy_no, () => { var index = that.data.data[1].indexOf(item) that.data.data[1].splice(index, 1) that.data.data[0].splice(Number(sender.currentTarget.id), 1) that.setData({ data: that.data.data }) }) } } }) } else if (this.data.tab.id == '2') { var item = this.data.data[1][sender.currentTarget.id] var that = this wx.showModal({ title: '取消后将无法恢复', content: item.cancelContent, confirmColor: '#3296FB', cancelColor: '#3296FB', confirmText: '确定', cancelText: '取消', success: function (res) { if (res.confirm) { that.cancelOrder(item.buy_no, () => { var index = that.data.data[1].indexOf(item) that.data.data[0].splice(index, 1) that.data.data[1].splice(Number(sender.currentTarget.id), 1) that.setData({ data: that.data.data }) }) } } }) } }), cancelOrder: function (no, success) { wx.showLoading({ title: '正在取消订单', mask: true }) net.connectNeedLogin({ url: url.app_host + url.cancelPurchaseOrder, data: { buy_no: no }, success: (err, res) => { if (res.code == businessType.NetworkErrorCode.success) { success() wx.hideLoading() wx.showToast({ title: '取消订单成功', icon: 'none' }) } else { wx.hideLoading() businessT.showFailTips(err, '取消订单失败') } }, fail: (err, res) => { wx.hideLoading() businessT.showFailTips(err, '取消订单失败') } }) }, detailsAction: businessT.action(function (sender) { businessT.debugLog(sender) var t = Number(this.data.tab.id) var data = this.data.data[t - 1][sender.currentTarget.id] if (data.status == 1) { if (!this.data.detailsView.hidden) { return } this.getTotal(data, true) } else { this.showDetails(data) } }), getTotal: function (data, s) { wx.showLoading({ title: '加载中', mask: true }) var obj = { sbuId: data.sbuId, cid: data.cid, shebao_card: data.new_card, hukou_type: data.hukou_type, month: data.start_month, fund: (data.fund / data.nums).toFixed(2), nums: data.nums, pay_for: data.pay_for } var path = data.added ? url.app_host + url.getTotalSupplementaryPayFee : url.app_host + url.getTotalFee var that = this net.connectNeedLogin({ url: path, data: obj, success: (err, res) => { data.total_fee = res.data.total_fee data.shebao = res.data.shebao data.shebao_charge = res.data.s_charge data.shebao_card = res.data.card_charge data.fund = res.data.fund data.fund_charge = res.data.f_charge wx.hideLoading() if (s) { that.showDetails(data) } else { that.pay() } }, fail: (err, res) => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }, true) }, detailsPay: businessT.action(function (sender) { businessT.debugLog(sender) this.detailsScroll(1, true) }), detailsScroll: function (i, a) { this.data.detailsView.scroll = true this.data.detailsView.sa = a this.setData({ detailsView: this.data.detailsView }) this.data.detailsView.left = i * sysT.sysInfo().windowWidth this.data.detailsView.scroll = false; this.setData({ detailsView: this.data.detailsView }) }, showDetails: function (data) { if (!this.data.detailsView.hidden) { return } this.data.detailsView.data = data this.data.detailsView.status = data.status if (this.data.detailsView.discountC == 0) { this.data.detailsView.discountS = '暂无优惠券' } else { this.data.detailsView.discountS = '未使用' } businessT.debugLog(data) var title var content if (data.pay_for == 1 || data.pay_for == 3) { title = '参保姓名' } else { title = '购买人姓名' } title = title + '\n身份证号\n购买月份\n购买城市' content = data.u_name + '\n' + data.id_card + '\n' + data.showTime + '\n' + data.city_name if (data.status == 2) { title = title + '\n支付方式' content = content + '\n' + data.pay_channel } if (data.pay_no.length != 0) { title = title + '\n流水号' content = content + '\n' + data.pay_no } if (data.status == 1) { title = title + '\n生成时间' } else { title = title + '\n成交时间' } content = content + '\n' + data.time this.data.detailsView.mt = title this.data.detailsView.m = content this.data.detailsView.t = data.a // this.data.detailsView.id = i var at = '' var a = '' if (data.shebao > 0) { at = at + '社保' a = a + '¥' + data.shebao.toFixed(2) } if (data.shebao_card > 0) { at = at + '\n社保卡' a = a + '\n¥' + data.shebao_card.toFixed(2) } if (data.fund > 0) { if (at != '') { at = at + '\n' a = a + '\n' } at = at + '公积金' a = a + '¥' + data.fund.toFixed(2) } at = at + '\n服务费' a = a + '\n¥' + (data.shebao_charge + data.fund_charge).toFixed(2) this.data.detailsView.at = at this.data.detailsView.a = a this.data.discount = { canChoose: data.nums, fee: '0.00', chose: [], data: [], page: 0, finish: false, isLoading: true } this.data.detailsView.discountT = this.getDiscountTips() this.data.detailsView.hidden = false //为了兼容iOS低版本系统,不能用bottom,所以计算margan-top的位置 sysT.adaptor() businessT.debugLog(sysT.sysInfo().windowHeight) var s = this.data.detailsView.suffix == '-X' ? -1068 : -1000 s = sysT.rpxToPx() * s this.data.detailsView.top = sysT.sysInfo().windowHeight - s this.setData({ detailsView: this.data.detailsView, scroll: false }) setTimeout(function () { var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) // animation.bottom('0rpx').step() animation.translateY(s).step() this.data.detailsView.animation = animation.export() this.setData({ detailsView: this.data.detailsView }) }.bind(this), 100) }, hiddenDetails: businessT.action(function (sender) { this.detailsScroll(0, false) var animation = wx.createAnimation({ duration: 300, timingFunction: 'ease', }) animation.translateY(0).step() this.data.detailsView.animation = animation.export() this.setData({ detailsView: this.data.detailsView }) setTimeout(function () { this.data.detailsView.hidden = true this.setData({ detailsView: this.data.detailsView, scroll: true }) }.bind(this), 300) }), getOrderData: function () { wx.showLoading({ title: '加载中', mask: true }) net.connectNeedLogin({ url: url.app_host + url.getMyOrder, data: {}, success: (err, res) => { this.data.data = orderModel.handleAllData(res.data) this.data.isLoading = false this.setData({ data: this.data.data, isLoading: this.data.isLoading }) wx.hideLoading() }, fail: (err, res) => { wx.hideLoading() businessT.showFailTips(err, '加载失败') setTimeout(function () { wx.navigateBack({ }) }.bind(this), 1000) } }, true) }, uploadDiscountView: businessT.action(function (sender) { businessT.debugLog('upload') if (this.data.discount.isLoading || this.data.discount.finish) { return } this.data.discount.isLoading = true this.getCashCouponList() businessT.debugLog('abc') }), getCashCouponList: function () { var page = this.data.discount.page + 1 net.connectNeedLogin({ url: url.app_host + url.getCashCoupon, data: { phone: app.globalData.userInfo.phone, page: page, expired: 0 }, success: (err, res) => { this.getCashCouponListSuccess(res) this.data.discount.isLoading = false wx.hideLoading() }, fail: (err, res) => { this.data.discount.isLoading = false x.hideLoading() businessT.showFailTips(err, '加载失败') } }, true) }, getCashCouponListSuccess: function (res) { this.data.discount.page = res.currentPage var data = res.data.list for (var index in data) { var item = data[index] if (item.status == 1 && item.expired == 0) { 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.discount.data = this.data.discount.data.concat(res.data.list) if (res.data.list.length < 10) { this.data.discount.finish = true } else { this.data.discount.finish = false } this.setData({ discount: this.data.discount }) }, getDiscountCount: function () { net.connectNeedLogin({ url: url.app_host + url.getCashCouponCount, data: { phone: app.globalData.userInfo.phone }, success: (err, res) => { this.data.detailsView.discountC = res.data.total if (this.data.detailsView.discountC == 0) { this.data.detailsView.discountS = '暂无优惠券' } else { this.data.detailsView.discountS = '未使用' } } }, true) }, getDiscountTips: function () { if (this.data.discount.chose.length > 0) { return ['您已选中优惠券 ' + this.data.discount.chose.length + ' 张,共可抵用', '¥' + this.data.discount.fee, ''] } return ['您当前下了 ' + this.data.discount.canChoose + ' 个月订单,可同时选 ', this.data.discount.canChoose, ' 张优惠券'] }, chooseDiscount: businessT.action(function (sender) { if (this.data.detailsView.discountC == 0) { wx.showToast({ title: '暂无优惠券', }) return } this.detailsScroll(2, true) if (this.data.discount.data.length == 0) { wx.showLoading({ title: '加载中', mask: true }) this.getCashCouponList() } }), //点击选择优惠券 chooseAction: businessT.action(function (sender) { businessT.debugLog(this.data.discount.chose) businessT.debugLog(sender.currentTarget.id) var c = Number(sender.currentTarget.id) var s = this.data.discount.chose.indexOf(c) businessT.debugLog(s) if (s >= 0) { this.data.discount.chose.splice(s, 1) } else { if (this.data.discount.canChoose <= this.data.discount.chose.length) { wx.showToast({ title: '本次购买只可选择' + this.data.discount.canChoose + '张抵用券', icon: 'none' }) return } this.data.discount.chose.push(c) } var fee = 0 for (var i in this.data.discount.chose) { var index = this.data.discount.chose[i] fee += this.data.discount.data[index].coupon_price } this.data.discount.fee = fee.toFixed(2) this.data.detailsView.discountT = this.getDiscountTips() this.setData({ discount: this.data.discount, detailsView: this.data.detailsView }) }, 100), confirmDiscount: businessT.action(function (sender) { if (this.data.discount.chose.length > 0) { this.data.detailsView.discountS = '-¥' + this.data.discount.fee } else { this.data.detailsView.discountS = '未使用' } this.setData({ detailsView: this.data.detailsView }) this.detailsScroll(1, true) }), pay: function () { wx.showLoading({ title: '正在提交订单', mask: true }) pay.prepay({ success: e => { var data = this.data.detailsView.data if (data.pay_for == businessType.PurchasePayFor.socialInsurance) { this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypeSB) } else if (data.pay_for == businessType.PurchasePayFor.socialInsurancePackage) { this.createSocialInsuranceOrder(businessType.ResultServeyType.resultServeyTypePack) } else if (data.pay_for == businessType.PurchasePayFor.accumulationFund) { this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypeAF) } else if (data.pay_for == businessType.PurchasePayFor.accumulationFundPackage) { this.createAccumulationFundOrder(businessType.ResultServeyType.resultServeyTypePack) } }, fail: e => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }) }, detailsConfirmPay: businessT.action(function (sender) { var data = this.data.detailsView.data this.getTotal(data, false) }), createSocialInsuranceOrder: function (type) { var data = this.data.detailsView.data var obj = this.getParameters({ fund: data.fund }) var path = data.added ? url.app_host + url.createShebaoSupplementaryPayOrder : url.app_host + url.createShebaoOrder var that = this net.connectNeedLogin({ url: path, data: obj, success: (err, res) => { pay.wxPay({ data: res.data, success: e => { if (obj.sb_wage > 0) { that.checkSurvey(true, type) } else { that.checkSurvey(false, type) } }, fail: e => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }) }, fail: (err, res) => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }, true) }, createAccumulationFundOrder: function (type) { businessT.debugLog(this.data.detailsView.data) var data = this.data.detailsView.data var obj = this.getParameters({ buyShebao: data.shebao == 0 ? 0 : 1, fund: data.fund / data.nums }) var path = data.added ? url.app_host + url.createFundSupplementaryPayOrder : url.app_host + url.createFundOrder var that = this net.connectNeedLogin({ url: path, data: obj, success: (err, res) => { pay.wxPay({ data: res.data, success: e => { if (obj.sb_wage > 0) { that.checkSurvey(true, type) } else { that.checkSurvey(false, type) } }, fail: e => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }) }, fail: (err, res) => { wx.hideLoading() businessT.showFailTips(err, '提交订单失败') } }, true) }, checkSurvey: function (isNeedSalary, type) { var pages = getCurrentPages() if (isNeedSalary) { pages[0].route('../../public/pages/pay-success/pay-success?type=salary') return } else { net.connectNeedLogin({ url: url.app_host + url.checkSurvey, data: {}, success: (err, res) => { wx.hideLoading() if (res.data) { pages[0].route('../../public/pages/pay-success/pay-success?type=survey&surveyType=' + type) } else { this.queryPayPriceDifference() } }, fail: (err, res) => { wx.hideLoading() pages[0].route('../../public/pages/pay-success/pay-success?type=share') } }, false) } }, queryPayPriceDifference: function () { var pages = getCurrentPages() net.connectNeedLogin({ url: url.app_host + url.queryPayPriceDifference, data: {}, success: (err, res) => { wx.hideLoading() if (res.data > 0) { pages[0].route('../../public/pages/pay-success/pay-success?type=pay') } else { pages[0].route('../../public/pages/pay-success/pay-success?type=share') } }, fail: (err, res) => { wx.hideLoading() pages[0].route('../../public/pages/pay-success/pay-success?type=share') } }, true) }, getParameters: function (par) { var data = this.data.detailsView.data var ids = '' for (var i in this.data.discount.chose) { var item = this.data.discount.data[this.data.discount.chose[i]] if (i == 0) { ids = ids + item.id } else { ids = ids + ',' + item.id } } var np = { sbuId: data.sbuId, cid: data.cid, shebao_card: data.new_card, hukou_type: data.hukou_type, month: data.start_month, nums: data.nums, first_sb: data.first_sb, first_fund: data.first_fund, working: data.working, sb_wage: data.sb_wage, pay_channel: 5, couponuser_id: ids } for (var key in par) { np[key] = par[key] } return np }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.data.detailsView.suffix = sysT.suffixOfClass() this.getOrderData() this.getDiscountCount() }, /** * 生命周期函数--监听页面初次渲染完成 */ 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多个城市,专业团队操作' } } })