// pages/task/task-detail/index.js const request = require('../../../utils/request'); //导入模块 const util = require('../../../utils/util'); const float = require('../../../utils/floatObj'); const app = getApp() Page({ /** * 页面的初始数据 */ data: { form: {}, addressInfo: null, isIPhoneX: false }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { if (options.json) { var form = JSON.parse(options.json) form.payType = form.sellMode == 1 ? 1 : 3 // form.totalPrice = float.accAdd(float.accMul(form.unitPrice, form.number), form.dividePrice) form.totalPrice = float.accMul(form.unitPrice, form.number).toFixed(2) form.preAmount = float.accMul(float.accMul(form.unitPrice, form.number), 0.1).toFixed(2) form.monthAmount = float.accMul(form.monthPrice, form.number).toFixed(2) this.setData({ form: form, isIPhoneX: app.globalData.isIPhoneX }) } }, chooseAddress() { wx.chooseAddress({ success: (res) => { this.setData({ addressInfo: res }) } }) }, checkMode: function (e) { this.setData({ ['form.payType']: Number(e.currentTarget.dataset.index) }) }, showDialog: function (e) { var that = this $wuxDialog().open({ resetOnClose: true, title: '温馨提示', content: '跳过确认事宜之后,没有确认的事项将不在记录,同时意味着您已经装货入仓了,确定跳过?', buttons: [{ text: '取消', }, { text: '确定', type: 'primary', onTap(e) { that.setData({ step: steps.length + 1 }) } }] }) }, // 创建订单 offerProject: function (e) { if (!this.data.addressInfo) { util.showToast('请选择收货地址') return } var data = {} data.productId = Number(this.data.form.productId) data.skuId = this.data.form.skuId data.number = this.data.form.number data.sellMode = Number(this.data.form.sellMode) data.payType = Number(this.data.form.payType) if (data.payType == 1) { data.realPrice = this.data.form.preAmount data.unitPrice = this.data.form.unitPrice data.totalPrice = this.data.form.totalPrice } else if (data.payType == 2 || data.payType == 4) { data.realPrice = this.data.form.totalPrice data.totalPrice = this.data.form.totalPrice data.unitPrice = this.data.form.unitPrice } else if (data.payType == 3) { data.realPrice = 0 data.unitPrice = this.data.form.monthPrice data.totalPrice = this.data.form.monthAmount } data.mobile = this.data.addressInfo.telNumber data.realName = this.data.addressInfo.userName data.address = this.data.addressInfo.provinceName + this.data.addressInfo.cityName + this.data.addressInfo.countyName + this.data.addressInfo.detailInfo // /product/{id}产品详情 wx.showLoading({ title: '加载中', mask: true }) request.post('/bxe-mall/order', data).then(result => { //成功回调 wx.hideLoading() if (data.payType == 3) { wx.requestSubscribeMessage({ tmplIds: app.tmplIds, complete(res) { wx.redirectTo({ url: '/pages/mall/order-result/index?type=1' }) } }) } else { this.requestPayment(result.data.wxpay) } }).catch(err => { //异常回调 wx.hideLoading() util.showToast(err) }) }, // 微信支付流程 requestPayment: function (data) { data.success = function (res) { util.showToast('订单支付成功') wx.requestSubscribeMessage({ tmplIds: app.tmplIds, complete(res) { wx.redirectTo({ url: '/pages/mall/order-result/index?type=2' }) } }) } data.fail = function (res) { util.showToast('订单支付失败') } wx.requestPayment(data) } })