|
|
@ -15,6 +15,7 @@ Page({ |
|
|
orderInfo: null, |
|
|
orderInfo: null, |
|
|
matchTag: null, |
|
|
matchTag: null, |
|
|
sukList: [], |
|
|
sukList: [], |
|
|
|
|
|
imgList: [], |
|
|
form: { |
|
|
form: { |
|
|
productId: null, |
|
|
productId: null, |
|
|
skuId: null, |
|
|
skuId: null, |
|
|
@ -22,18 +23,23 @@ Page({ |
|
|
unitPrice: 0 |
|
|
unitPrice: 0 |
|
|
}, |
|
|
}, |
|
|
amount: null, |
|
|
amount: null, |
|
|
isIPhoneX: false |
|
|
|
|
|
|
|
|
isIPhoneX: false, |
|
|
|
|
|
status: 0, |
|
|
|
|
|
controls: true |
|
|
}, |
|
|
}, |
|
|
/** |
|
|
/** |
|
|
* 生命周期函数--监听页面加载 |
|
|
* 生命周期函数--监听页面加载 |
|
|
*/ |
|
|
*/ |
|
|
onLoad: function (options) { |
|
|
onLoad: function (options) { |
|
|
if(getCurrentPages().length == 1){ |
|
|
|
|
|
|
|
|
if (getCurrentPages().length == 1) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
backStr: '首页' |
|
|
backStr: '首页' |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
this.setData({ token: app.globalData.token, isIPhoneX: app.globalData.isIPhoneX }) |
|
|
|
|
|
|
|
|
this.setData({ |
|
|
|
|
|
token: app.globalData.token, |
|
|
|
|
|
isIPhoneX: app.globalData.isIPhoneX |
|
|
|
|
|
}) |
|
|
event.on('EventMessage', this, this.onEvent) |
|
|
event.on('EventMessage', this, this.onEvent) |
|
|
if (options.id) { |
|
|
if (options.id) { |
|
|
wx.showLoading({ |
|
|
wx.showLoading({ |
|
|
@ -44,9 +50,29 @@ Page({ |
|
|
request.get('/bxe-mall/product/' + options.id).then(result => { |
|
|
request.get('/bxe-mall/product/' + options.id).then(result => { |
|
|
//成功回调
|
|
|
//成功回调
|
|
|
wx.hideLoading() |
|
|
wx.hideLoading() |
|
|
|
|
|
var vindex = -1 |
|
|
|
|
|
var vurl = null |
|
|
|
|
|
var imgList = [] |
|
|
|
|
|
for (let index = 0; index < result.data.imgList.length; index++) { |
|
|
|
|
|
const element = result.data.imgList[index] |
|
|
|
|
|
if(this.isVideoUrl(element)){ |
|
|
|
|
|
vindex = index |
|
|
|
|
|
vurl = element |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if(vindex >= 1){ |
|
|
|
|
|
result.data.imgList.splice(vindex, 1) |
|
|
|
|
|
imgList = result.data.imgList |
|
|
|
|
|
imgList.unshift(vurl) |
|
|
|
|
|
this.videoContext = wx.createVideoContext('video') |
|
|
|
|
|
} else { |
|
|
|
|
|
imgList = result.data.imgList |
|
|
|
|
|
} |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
['form.productId']: options.id, |
|
|
['form.productId']: options.id, |
|
|
orderInfo: result.data |
|
|
|
|
|
|
|
|
orderInfo: result.data, |
|
|
|
|
|
imgList: imgList |
|
|
}) |
|
|
}) |
|
|
}).catch(err => { |
|
|
}).catch(err => { |
|
|
//异常回调
|
|
|
//异常回调
|
|
|
@ -55,15 +81,85 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
swapArray: function (arr, index1, index2) { |
|
|
|
|
|
arr[index1] = arr.splice(index2, 1, arr[index1])[0] |
|
|
|
|
|
return arr |
|
|
|
|
|
}, |
|
|
|
|
|
isVideoUrl: function (url) { |
|
|
|
|
|
if (url && url.indexOf('.mp4') >= 0) { |
|
|
|
|
|
return true |
|
|
|
|
|
} |
|
|
|
|
|
return false |
|
|
|
|
|
}, |
|
|
// 事件处理
|
|
|
// 事件处理
|
|
|
onEvent: function (message) { |
|
|
onEvent: function (message) { |
|
|
console.log('mall>>order>>onEvent', 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){ |
|
|
|
|
|
|
|
|
if (message.what == 1 && util.isEmpty(this.data.token)) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
token: app.globalData.token |
|
|
|
|
|
}) |
|
|
|
|
|
} else if (message.what == 10) { |
|
|
wx.navigateBack() |
|
|
wx.navigateBack() |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
bindchange: function (event) { |
|
|
|
|
|
if (this.videoContext && this.data.status == 1) { |
|
|
|
|
|
this.videoContext.pause() |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
videoTouch: function () { |
|
|
|
|
|
console.log('videoTouch>>>') |
|
|
|
|
|
if (this.timeout) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if (!this.data.controls && this.data.status == 1) { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
controls: true |
|
|
|
|
|
}) |
|
|
|
|
|
this.timeout = setTimeout(() => { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
controls: false |
|
|
|
|
|
}) |
|
|
|
|
|
this.timeout = null |
|
|
|
|
|
}, 1000) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
videoTap: function () { |
|
|
|
|
|
console.log('videoTap>>>') |
|
|
|
|
|
if (this.videoContext) { |
|
|
|
|
|
if (this.data.status == 0) { |
|
|
|
|
|
this.videoContext.play() |
|
|
|
|
|
} else if (this.data.status == 1) { |
|
|
|
|
|
this.videoContext.pause() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
bindplay: function () { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
status: 1 |
|
|
|
|
|
}) |
|
|
|
|
|
this.timeout = setTimeout(() => { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
controls: false |
|
|
|
|
|
}) |
|
|
|
|
|
this.timeout = null |
|
|
|
|
|
}, 1500) |
|
|
|
|
|
}, |
|
|
|
|
|
bindpause: function () { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
status: 0, |
|
|
|
|
|
controls: true |
|
|
|
|
|
}) |
|
|
|
|
|
if (this.timeout) { |
|
|
|
|
|
clearTimeout(this.timeout) |
|
|
|
|
|
this.timeout = null |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
bindended: function () { |
|
|
|
|
|
this.setData({ |
|
|
|
|
|
status: 0 |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
// phone: function (e) {
|
|
|
// phone: function (e) {
|
|
|
// var mobile = e.currentTarget.dataset.index
|
|
|
// var mobile = e.currentTarget.dataset.index
|
|
|
// if (util.checkPhone(mobile)) {
|
|
|
// if (util.checkPhone(mobile)) {
|
|
|
@ -74,17 +170,27 @@ Page({ |
|
|
// },
|
|
|
// },
|
|
|
// 图片查看
|
|
|
// 图片查看
|
|
|
viewImage: function (e) { |
|
|
viewImage: function (e) { |
|
|
|
|
|
if (e.currentTarget.dataset.url.indexOf('.mp4') >= 0) { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
var imgList = [] |
|
|
|
|
|
for (let index = 0; index < this.data.orderInfo.imgList.length; index++) { |
|
|
|
|
|
if (this.data.orderInfo.imgList[index].indexOf('.mp4') >= 0) { |
|
|
|
|
|
continue |
|
|
|
|
|
} |
|
|
|
|
|
imgList.push(this.data.orderInfo.imgList[index]) |
|
|
|
|
|
} |
|
|
wx.previewImage({ |
|
|
wx.previewImage({ |
|
|
urls: this.data.orderInfo.imgList, |
|
|
|
|
|
|
|
|
urls: imgList, |
|
|
current: e.currentTarget.dataset.url |
|
|
current: e.currentTarget.dataset.url |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
// 根据
|
|
|
// 根据
|
|
|
checkDisableTag: function(sukId, match, element){ |
|
|
|
|
|
|
|
|
checkDisableTag: function (sukId, match, element) { |
|
|
match[sukId] = element.id |
|
|
match[sukId] = element.id |
|
|
for (let index = 0; index < this.data.orderInfo.skuList.length; index++) { |
|
|
for (let index = 0; index < this.data.orderInfo.skuList.length; index++) { |
|
|
const item = this.data.orderInfo.skuList[index]; |
|
|
const item = this.data.orderInfo.skuList[index]; |
|
|
if(this.checkSkuPrice(match, item)){ |
|
|
|
|
|
|
|
|
if (this.checkSkuPrice(match, item)) { |
|
|
delete match[sukId] |
|
|
delete match[sukId] |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
@ -95,8 +201,8 @@ Page({ |
|
|
// tag 点击事件
|
|
|
// tag 点击事件
|
|
|
tagClick: function (e) { |
|
|
tagClick: function (e) { |
|
|
this.data.matchTag = null |
|
|
this.data.matchTag = null |
|
|
var sukId = e.currentTarget.dataset.suk// 对应的是一级列表的Id
|
|
|
|
|
|
var id = e.currentTarget.dataset.index// 对应的是二级列表的Id,相应是有价格计算的
|
|
|
|
|
|
|
|
|
var sukId = e.currentTarget.dataset.suk // 对应的是一级列表的Id
|
|
|
|
|
|
var id = e.currentTarget.dataset.index // 对应的是二级列表的Id,相应是有价格计算的
|
|
|
//------------------------------sukList-------------------------------------------
|
|
|
//------------------------------sukList-------------------------------------------
|
|
|
// 检查是否需要跟新,或者修改,跟新sukList;
|
|
|
// 检查是否需要跟新,或者修改,跟新sukList;
|
|
|
var push_flag = true |
|
|
var push_flag = true |
|
|
@ -108,7 +214,7 @@ Page({ |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(push_flag){ |
|
|
|
|
|
|
|
|
if (push_flag) { |
|
|
this.data.sukList.push({ |
|
|
this.data.sukList.push({ |
|
|
skuId: sukId, |
|
|
skuId: sukId, |
|
|
id: id |
|
|
id: id |
|
|
@ -124,7 +230,7 @@ Page({ |
|
|
for (let i = 0; i < attributeList.length; i++) { |
|
|
for (let i = 0; i < attributeList.length; i++) { |
|
|
for (let k = 0; k < attributeList[i].values.length; k++) { |
|
|
for (let k = 0; k < attributeList[i].values.length; k++) { |
|
|
const element = attributeList[i].values[k]; |
|
|
const element = attributeList[i].values[k]; |
|
|
// 点击的列判断 对应的是一级列表,肯定是可以点击的
|
|
|
|
|
|
|
|
|
// 点击的列判断 对应的是一级列表,肯定是可以点击的
|
|
|
if (attributeList[i].id == sukId) { |
|
|
if (attributeList[i].id == sukId) { |
|
|
element.select = false |
|
|
element.select = false |
|
|
if (element.id == id) { |
|
|
if (element.id == id) { |
|
|
@ -151,25 +257,25 @@ Page({ |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// 根据所有选择的规格校验获取价格
|
|
|
// 根据所有选择的规格校验获取价格
|
|
|
checkSkuPrice: function(tag, element){ |
|
|
|
|
|
if(!tag){ |
|
|
|
|
|
|
|
|
checkSkuPrice: function (tag, element) { |
|
|
|
|
|
if (!tag) { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
for (var key in tag) { |
|
|
for (var key in tag) { |
|
|
if(element.price <=0 || tag[key] != element[key]){ |
|
|
|
|
|
|
|
|
if (element.price <= 0 || tag[key] != element[key]) { |
|
|
return false |
|
|
return false |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return true |
|
|
return true |
|
|
}, |
|
|
}, |
|
|
// 数量变化的函数监听
|
|
|
|
|
|
|
|
|
// 数量变化的函数监听
|
|
|
onNumChange: function (e) { |
|
|
onNumChange: function (e) { |
|
|
if (e) { |
|
|
if (e) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
['form.number']: e.detail.value |
|
|
['form.number']: e.detail.value |
|
|
}) |
|
|
}) |
|
|
// 如果查询到了价格,进行价格计算
|
|
|
// 如果查询到了价格,进行价格计算
|
|
|
if(this.data.form.unitPrice){ |
|
|
|
|
|
|
|
|
if (this.data.form.unitPrice) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
amount: float.accMul(this.data.form.unitPrice, this.data.form.number) |
|
|
amount: float.accMul(this.data.form.unitPrice, this.data.form.number) |
|
|
}) |
|
|
}) |
|
|
@ -178,12 +284,12 @@ Page({ |
|
|
// 根据规格,克重,以及其他筛选价格
|
|
|
// 根据规格,克重,以及其他筛选价格
|
|
|
for (let index = 0; index < this.data.orderInfo.skuList.length; index++) { |
|
|
for (let index = 0; index < this.data.orderInfo.skuList.length; index++) { |
|
|
const element = this.data.orderInfo.skuList[index]; |
|
|
const element = this.data.orderInfo.skuList[index]; |
|
|
if(this.checkSkuPrice(this.data.matchTag, element)){ |
|
|
|
|
|
|
|
|
if (this.checkSkuPrice(this.data.matchTag, element)) { |
|
|
this.data.form.unitPrice = Number(element.price) |
|
|
this.data.form.unitPrice = Number(element.price) |
|
|
this.data.form.monthPrice = Number(element.groupMonthPrice) |
|
|
this.data.form.monthPrice = Number(element.groupMonthPrice) |
|
|
this.data.form.stockNumber = Number(element.stockNumber) |
|
|
this.data.form.stockNumber = Number(element.stockNumber) |
|
|
// 如果当前的数量大于所选规格的库存数量,那么就设置成库存数量;
|
|
|
// 如果当前的数量大于所选规格的库存数量,那么就设置成库存数量;
|
|
|
if(this.data.form.number > this.data.form.stockNumber){ |
|
|
|
|
|
|
|
|
if (this.data.form.number > this.data.form.stockNumber) { |
|
|
this.data.form.number = Number(element.stockNumber) |
|
|
this.data.form.number = Number(element.stockNumber) |
|
|
} |
|
|
} |
|
|
this.data.form.dividePrice = Number(element.dividePrice) |
|
|
this.data.form.dividePrice = Number(element.dividePrice) |
|
|
@ -193,7 +299,7 @@ Page({ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 如果查询到了价格,进行价格计算
|
|
|
// 如果查询到了价格,进行价格计算
|
|
|
if(this.data.form.unitPrice){ |
|
|
|
|
|
|
|
|
if (this.data.form.unitPrice) { |
|
|
this.setData({ |
|
|
this.setData({ |
|
|
['form.number']: this.data.form.number, |
|
|
['form.number']: this.data.form.number, |
|
|
['form.unitPrice']: this.data.form.unitPrice, |
|
|
['form.unitPrice']: this.data.form.unitPrice, |
|
|
@ -220,11 +326,11 @@ Page({ |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(this.data.form.number <= 0){ |
|
|
|
|
|
|
|
|
if (this.data.form.number <= 0) { |
|
|
util.showToast('请输入购买数量,必选大于0') |
|
|
util.showToast('请输入购买数量,必选大于0') |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
if(this.data.form.stockNumber <= 0){ |
|
|
|
|
|
|
|
|
if (this.data.form.stockNumber <= 0) { |
|
|
util.showToast('暂无库存,请选择其他规格类型') |
|
|
util.showToast('暂无库存,请选择其他规格类型') |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
@ -239,29 +345,28 @@ Page({ |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
// 就行登录流程;然后进入下一步的支付操作
|
|
|
// 就行登录流程;然后进入下一步的支付操作
|
|
|
onGotPhoneNumber: function(e){ |
|
|
|
|
|
|
|
|
onGotPhoneNumber: function (e) { |
|
|
request.loginWechat(e.detail).then(data => { |
|
|
request.loginWechat(e.detail).then(data => { |
|
|
this.offerProject() |
|
|
this.offerProject() |
|
|
}) |
|
|
}) |
|
|
}, |
|
|
}, |
|
|
onShareAppMessage: function() { |
|
|
|
|
|
|
|
|
onShareAppMessage: function () { |
|
|
return { |
|
|
return { |
|
|
title: this.data.orderInfo.name, |
|
|
title: this.data.orderInfo.name, |
|
|
path: '/pages/mall/order-info/index?id=' + this.data.orderInfo.id, |
|
|
path: '/pages/mall/order-info/index?id=' + this.data.orderInfo.id, |
|
|
imageUrl: this.data.orderInfo.litimgUrl, |
|
|
imageUrl: this.data.orderInfo.litimgUrl, |
|
|
success: function(res) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
success: function (res) {} |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// event的unregister
|
|
|
// event的unregister
|
|
|
onUnload: function(){ |
|
|
|
|
|
|
|
|
onUnload: function () { |
|
|
event.remove('EventMessage', this) |
|
|
event.remove('EventMessage', this) |
|
|
if(getCurrentPages().length == 1){ |
|
|
|
|
|
|
|
|
if (getCurrentPages().length == 1) { |
|
|
this.toHome() |
|
|
this.toHome() |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
// 返回到主页
|
|
|
// 返回到主页
|
|
|
toHome(){ |
|
|
|
|
|
|
|
|
toHome() { |
|
|
wx.reLaunch({ |
|
|
wx.reLaunch({ |
|
|
url: '/pages/mall/shops/index', |
|
|
url: '/pages/mall/shops/index', |
|
|
}) |
|
|
}) |
|
|
|