You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
120 lines
3.5 KiB
120 lines
3.5 KiB
// 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 == 2 ? 3 : 1
|
|
// 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)
|
|
})
|
|
},
|
|
// 创建订单
|
|
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)
|
|
}
|
|
})
|