纸通宝小程序
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.
 

346 lines
10 KiB

// pages/order/order-info/index.js
import { $wuxCountDown } from '../../../components/index'
const request = require('../../../utils/request') //导入模块
const util = require('../../../utils/util')
const math = require('../../../utils/math')
const event = require('../../../utils/event.js')
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
backStr: '返回',
orderInfo: null,
current: 1,
imgList: [],
form: {
productId: null,
number: 1
},
amount: null,
offered: null,
safeBottom: app.globalData.safeBottom,
kg: app.globalData.kg,
imageHeight: 0,
visible: false,
videoUrl: null,
recordList: [],
expiredTime: null,
frist: true
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
if (getCurrentPages().length == 1) {
this.setData({ backStr: '首页' })
}
this.setData({ imageHeight: 750, kg: app.globalData.kg, safeBottom: app.globalData.safeBottom })
event.on('EventMessage', this, this.onEvent)
if (options.id) {
wx.showLoading({
title: '加载中',
mask: true
})
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
this.biddingDialog = this.biddingDialog || this.selectComponent('#bidding-good')
this.data.frist = true
this.fetchInfo(options.id)
}
},
fetchInfo: function (id) {
// /product/{id}产品详情
request.get('/recycle-service/get/user-product/' + id).then(result => {
//成功回调
wx.hideLoading()
if (Number(result.data.minBuyNum) > 1) {
this.data.form.number = parseInt(result.data.minBuyNum)
}
var vurl = null
var imgList = []
if (result.data.videoUrl) {
vurl = result.data.videoUrl
imgList = result.data.imgList
imgList.unshift(vurl)
this.videoContext = wx.createVideoContext('video')
} else {
imgList = result.data.imgList
}
this.setData({
['form.productId']: id,
orderInfo: result.data,
videoUrl: vurl,
imgList: imgList
})
if (result.data.bidType == 2 && (!result.data.biddingActivityId)) {
this.wuxDialog.open({
maskClosable: false,
title: '温馨提示',
content: '该商品已经下架,请选择其他商品进行报价',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateBack({ delta: 1 })
}
}]
})
} else if (result.data.bidType == 2 && (result.data.biddingActivityStatus != 0)) {
// this.wuxDialog.open({
// maskClosable: false,
// title: '温馨提示',
// content: '该商品的竞价已经结束,无法报价',
// buttons: [{
// text: '确定',
// type: 'primary'
// }]
// })
} else if (result.data.bidType == 2 && result.data.biddingActivityStatus == 0) {
this.fetchBiddingList(result.data.biddingActivityId)
if(this.data.frist){
this.expiredTime(result.data.biddingActivityExpiredTime, id)
}
}
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
},
expiredTime: function (etime, id) {
this.data.frist = false
const that = this
this.countDown = new $wuxCountDown({
date: new Date(etime.replace(/-/g, '/')),
render(date) {
const days = this.leadingZeros(date.days, 1) + ' 天 '
const hours = this.leadingZeros(date.hours, 2) + ' 时 '
const min = this.leadingZeros(date.min, 2) + ' 分 '
const sec = this.leadingZeros(date.sec, 2) + ' 秒 '
if (Number(this.leadingZeros(date.days, 1)) > 0) {
that.setData({ expiredTime: days + hours + min + sec })
} else {
that.setData({ expiredTime: hours + min + sec })
}
},
onEnd() {
that.fetchInfo(id)
}
})
},
onChange: function(e){
this.setData({ current: e.detail.current + 1 })
},
fetchBiddingList: function (biddingActivityId) {
request.get('/recycle-service/get/bidding-list/' + biddingActivityId).then(result => {
//成功回调
for (let index = 0; index < result.data.records.length; index++) {
const element = result.data.records[index]
if(element.isMine && app.globalData.userInfo){
this.data.offered = element.biddingUnitPrice
break
}
}
this.setData({ recordList: result.data.records, offered: this.data.offered })
})
},
isVideoUrl: function (url) {
if (url && url.indexOf('.mp4') >= 0) {
return true
}
return false
},
// 事件处理
onEvent: function (message) {
console.log('mall>>order>>onEvent', message)
if (message.what == 1) {
} else if (message.what == 10) {
wx.navigateBack()
}
},
videoTap: function () {
this.setData({
visible: true,
})
if (this.videoContext) {
this.videoContext.play()
}
},
onClose: function () {
this.setData({
visible: false,
})
if (this.videoContext) {
this.videoContext.pause()
}
},
bindended: function () {
this.videoContext.exitFullScreen()
this.setData({
visible: false
})
},
// 图片查看
viewImage: function (e) {
if (e.currentTarget.dataset.url.indexOf('.mp4') >= 0) {
return
}
var imgList = []
for (let index = 0; index < this.data.imgList.length; index++) {
if (this.data.imgList[index].indexOf('.mp4') >= 0) {
continue
}
imgList.push(this.data.imgList[index])
}
wx.previewImage({
urls: imgList,
current: e.currentTarget.dataset.url
});
},
// 进入支付流程
offerProject: function (e) {
if (!app.globalData.userInfo) {
wx.navigateTo({ url: '/pages/login/index' })
return
}
if (!app.globalData.userInfo.isVIP) {
this.wuxDialog.open({
resetOnClose: true,
title: '温馨提示',
content: '您还不是纸通宝的会员,无法购买,现在去开通会员?',
buttons: [{
text: '确定',
type: 'primary',
onTap(e) {
wx.navigateTo({ url: '/pages/ztbvip/index' })
}
}]
})
return
}
if (this.data.orderInfo) {
if (this.data.orderInfo.bidType == 2 && (this.data.orderInfo.biddingActivityStatus != 0)) {
this.wuxDialog.open({
maskClosable: false,
title: '温馨提示',
content: '该商品的竞价已经结束,无法报价',
buttons: [{
text: '确定',
type: 'primary'
}]
})
return
}
if (this.data.orderInfo.bidType == 1) {
wx.navigateTo({ url: '/pages/morder/create/index?productId=' + this.data.orderInfo.productId })
} else {
var that = this
// this.biddingDialog.showBidding(this.data.orderInfo)
var price = this.data.offered || that.data.orderInfo.unitPrice
this.wuxDialog.prompt({
offer: true,
title: '商品报价',
min: that.formatePrice(that.data.orderInfo.unitPrice, app.globalData.kg),
value: that.formatePrice(price, app.globalData.kg),
step: that.formatePrice(that.data.orderInfo.biddingRange, app.globalData.kg),
content: '请输入您的报价(元/' + (app.globalData.kg ? 'KG' : '吨') + ')',
fieldtype: app.globalData.kg ? 'digit' : 'numger',
defaultText: '',
placeholder: '请输入您的报价',
maxlength: 8,
onConfirm(e, response) {
that.biddingPrice(app.globalData.kg ? response : math.divide(response, 1000))
},
})
}
}
},
formatePrice: function (value, kg) {
if (value || value == 0) {
if(kg){
return (parseFloat(value)).toFixed(3)
} else {
return (parseFloat(value) * 1000).toFixed(1)
}
}
return 0
},
// 就行登录流程;然后进入下一步的支付操作
onGotPhoneNumber: function (e) {
request.loginWechat(e.detail).then(data => {
this.offerProject()
})
},
onShareAppMessage: function () {
var title = this.data.orderInfo.locProvinceName + this.data.orderInfo.locCityName
if(this.data.orderInfo.bidType == 2){
title += this.data.orderInfo.secondCategoryName + '竞价中'
} else {
title += '出售' + this.data.orderInfo.secondCategoryName
}
var imgUrl = this.data.orderInfo.imgList[0]
if(this.isVideoUrl(imgUrl) ){
if(this.data.orderInfo.imgList.length > 1){
imgUrl = this.data.orderInfo.imgList[1]
} else {
imgUrl = '/assets/image/icon_logo.png'
}
}
return {
title: title,
path: 'pages/index/index?url=/pages/mall/detail/index&key=id&value=' + this.data.orderInfo.productId,
imageUrl: imgUrl,
success: function (res) {}
}
},
// event的unregister
onUnload: function () {
event.remove('EventMessage', this)
if (this.countDown) {
this.countDown.stop()
this.countDown = null
}
},
toShopInfo: function () {
if (!this.data.orderInfo) {
return
}
if(!app.globalData.userInfo){
wx.navigateTo({ url: '/pages/login/index'})
return
}
util.navigateTo('/pages/shop/detail/index?storeId=' + this.data.orderInfo.storeId)
},
biddingPrice: function (price) {
if(util.isEmpty(price)){
util.showToast('请输入您的报价')
return
}
if(Number(price) <= 0){
util.showToast('请输入合理的报价')
return
}
// if(Number(price) < Number(this.data.orderInfo.unitPrice)){
// util.showToast('您输入单价低于最低报价,请重新输入')
// return
// }
wx.showLoading({
title: '加载中',
mask: true
})
// /recycle-service/bid/{biddingActivityId} 参与报价
request.post('/recycle-service/bid/' + this.data.orderInfo.biddingActivityId, { biddingUnitPrice: price }).then(result => {
//成功回调
wx.hideLoading()
this.fetchBiddingList(this.data.orderInfo.biddingActivityId)
util.showToast('报价成功')
}).catch(err => {
//异常回调
wx.hideLoading()
util.showToast(err)
})
}
})