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.
220 lines
6.3 KiB
220 lines
6.3 KiB
// pages/order/order-info/index.js
|
|
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: {
|
|
token: app.globalData.token,
|
|
backStr: '返回',
|
|
orderInfo: null,
|
|
sukList: [],
|
|
form: {
|
|
productId: null,
|
|
skuId: null,
|
|
number: 1,
|
|
unitPrice: 0
|
|
},
|
|
skuJson: '',
|
|
amount: null
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if(getCurrentPages().length == 1){
|
|
this.setData({
|
|
backStr: '首页'
|
|
})
|
|
}
|
|
this.setData({ token: app.globalData.token })
|
|
event.on('EventMessage', this, this.onEvent)
|
|
if (options.id) {
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
mask: true
|
|
})
|
|
// /product/{id}产品详情
|
|
request.get('/bxe-mall/product/' + options.id).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
this.setData({
|
|
['form.productId']: options.id,
|
|
orderInfo: result.data
|
|
})
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
// 事件处理
|
|
onEvent: function (message) {
|
|
console.log('mall>>order>>onEvent', message)
|
|
if(message.what == 1 && util.isEmpty(this.data.token)){
|
|
this.setData({ token: app.globalData.token })
|
|
} else if(message.what == 10 && message.arg == 1){
|
|
wx.navigateBack()
|
|
}
|
|
},
|
|
// phone: function (e) {
|
|
// var mobile = e.currentTarget.dataset.index
|
|
// if (util.checkPhone(mobile)) {
|
|
// wx.makePhoneCall({
|
|
// phoneNumber: mobile
|
|
// })
|
|
// }
|
|
// },
|
|
// 图片查看
|
|
viewImage: function (e) {
|
|
wx.previewImage({
|
|
urls: this.data.orderInfo.imgList,
|
|
current: e.currentTarget.dataset.url
|
|
});
|
|
},
|
|
tagClick: function (e) {
|
|
var sukId = e.currentTarget.dataset.suk
|
|
var id = e.currentTarget.dataset.index
|
|
var attributeList = this.data.orderInfo.attributeList
|
|
for (let i = 0; i < attributeList.length; i++) {
|
|
if (attributeList[i].id == sukId) {
|
|
for (let k = 0; k < attributeList[i].values.length; k++) {
|
|
const element = attributeList[i].values[k];
|
|
element.select = false
|
|
if (element.id == id) {
|
|
element.select = true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (this.data.sukList.length == 0) {
|
|
this.data.sukList.push({
|
|
skuId: sukId,
|
|
id: id
|
|
})
|
|
this.setData({
|
|
['orderInfo.attributeList']: attributeList
|
|
})
|
|
} else {
|
|
for (let index = 0; index < this.data.sukList.length; index++) {
|
|
const element = this.data.sukList[index];
|
|
if (element.skuId == sukId) {
|
|
this.data.sukList[index].id = id
|
|
this.setData({
|
|
['orderInfo.attributeList']: attributeList
|
|
})
|
|
return
|
|
}
|
|
}
|
|
this.data.sukList.push({
|
|
skuId: sukId,
|
|
id: id
|
|
})
|
|
this.setData({
|
|
['orderInfo.attributeList']: attributeList
|
|
})
|
|
if (this.data.sukList.length == this.data.orderInfo.attributeList.length) {
|
|
var match = {}
|
|
for (let index = 0; index < this.data.sukList.length; index++) {
|
|
const element = this.data.sukList[index];
|
|
match[element.skuId] = element.id
|
|
|
|
}
|
|
this.data.skuJson = JSON.stringify(match)
|
|
this.data.skuJson = this.data.skuJson.substring(1, this.data.skuJson.length - 1)
|
|
this.onNumChange(null)
|
|
}
|
|
}
|
|
},
|
|
// 数量变化的函数监听
|
|
onNumChange: function (e) {
|
|
if (e) {
|
|
this.setData({
|
|
['form.number']: e.detail.value
|
|
})
|
|
// 如果查询到了价格,进行价格计算
|
|
if(this.data.form.unitPrice){
|
|
this.setData({
|
|
amount: float.accMul(this.data.form.unitPrice, this.data.form.number)
|
|
})
|
|
}
|
|
} else if (this.data.sukList.length == this.data.orderInfo.attributeList.length) {
|
|
// 根据规格,克重,以及其他筛选价格
|
|
for (let index = 0; index < this.data.orderInfo.skuList.length; index++) {
|
|
const element = this.data.orderInfo.skuList[index];
|
|
if(JSON.stringify(element).indexOf(this.data.skuJson) >= 0){
|
|
this.data.form.unitPrice = Number(element.price)
|
|
this.data.form.dividePrice = Number(element.dividePrice)
|
|
this.data.form.skuId = element.id
|
|
}
|
|
}
|
|
// 如果查询到了价格,进行价格计算
|
|
if(this.data.form.unitPrice){
|
|
this.setData({
|
|
amount: float.accMul(this.data.form.unitPrice, this.data.form.number)
|
|
})
|
|
}
|
|
}
|
|
},
|
|
// 进入支付流程
|
|
offerProject: function (e) {
|
|
var attributeList = this.data.orderInfo.attributeList
|
|
for (let i = 0; i < attributeList.length; i++) {
|
|
var toast = '请选择' + attributeList[i].name
|
|
for (let k = 0; k < attributeList[i].values.length; k++) {
|
|
const element = attributeList[i].values[k];
|
|
if (element.select) {
|
|
toast = ''
|
|
break
|
|
}
|
|
}
|
|
if (!util.isEmpty(toast)) {
|
|
util.showToast(toast)
|
|
return
|
|
}
|
|
}
|
|
this.data.form.summary = this.data.orderInfo.summary
|
|
this.data.form.sellMode = this.data.orderInfo.sellMode
|
|
this.data.form.name = this.data.orderInfo.name
|
|
this.data.form.litimgUrl = this.data.orderInfo.litimgUrl
|
|
this.data.form.unit = this.data.orderInfo.unit
|
|
wx.navigateTo({
|
|
url: '/pages/mall/order-offer/index?json=' + JSON.stringify(this.data.form)
|
|
})
|
|
},
|
|
// 就行登录流程;然后进入下一步的支付操作
|
|
onGotPhoneNumber: function(e){
|
|
request.loginWechat(e.detail).then(data => {
|
|
this.offerProject()
|
|
})
|
|
},
|
|
onShareAppMessage: function() {
|
|
return {
|
|
title: this.data.orderInfo.name,
|
|
path: '/pages/mall/order-info/index?id=' + this.data.orderInfo.id,
|
|
imageUrl: this.data.orderInfo.litimgUrl,
|
|
success: function(res) {
|
|
console.log(res)
|
|
}
|
|
}
|
|
},
|
|
// event的unregister
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
if(getCurrentPages().length == 1){
|
|
this.toHome()
|
|
}
|
|
},
|
|
// 返回到主页
|
|
toHome(){
|
|
wx.reLaunch({
|
|
url: '/pages/mall/shops/index',
|
|
})
|
|
}
|
|
})
|