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.

145 lines
3.7 KiB

// pages/task/task-detail/index.js
import { $wuxDialog } from '../../../components/index'
const request = require('../../../utils/request'); //导入模块
const util = require('../../../utils/util');
const float = require('../../../utils/floatObj');
const event = require('../../../utils/event.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
form: {
payType: 1,
},
addressInfo: null
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
event.on('EventMessage', this, this.onEvent)
if (options.json) {
var form = JSON.parse(options.json)
form.payType = 1
// form.totalPrice = float.accAdd(float.accMul(form.unitPrice, form.number), form.dividePrice)
form.totalPrice = float.accMul(form.unitPrice, form.number)
this.setData({
form: form
})
}
},
// 事件处理
onEvent: function (message) {
console.log('mall>>offer>>onEvent', message)
if (message.what == 10 && message.arg == 1) {
wx.navigateBack()
}
},
chooseAddress() {
wx.chooseAddress({
success: (res) => {
this.setData({
addressInfo: res
})
}
})
},
checkMode: function (e) {
this.setData({
['form.payType']: 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
}
if (Number(this.data.form.payType) == 1) {
// 微信支付
wx.requestPayment({
'timeStamp': '',
'nonceStr': '',
'package': '',
'signType': 'MD5',
'paySign': '',
'success': function (res) {
},
'fail': function (res) {
},
'complete': function (res) {
}
})
} else {
this.postOrder(0)
}
},
// 创建订单
postOrder: function(realPrice){
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)
data.realPrice = realPrice
data.unitPrice = this.data.form.unitPrice
data.totalPrice = this.data.form.totalPrice
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()
wx.requestSubscribeMessage({
tmplIds: ['cEHKFWCuzOz-QsPsMbyo7Q_Xjnf2EShCEKJzPnLPFYA'],
complete (res) {
wx.navigateTo({url: '/pages/mall/order-result/index?type=1'})
}
})
}).catch(err => {
//异常回调
wx.hideLoading()
wx.navigateTo({
url: '/pages/mall/order-result/index?type=0&message=' + err
})
})
},
// event的unregister
onUnload: function () {
event.remove('EventMessage', this)
}
})