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.
299 lines
8.7 KiB
299 lines
8.7 KiB
// pages/bidding/detail/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const util = require('../../../utils/util')
|
|
const math = require('../../../utils/math')
|
|
const event = require('../../../utils/event.js')
|
|
import { $wuxCountDown } from '../../../components/index'
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
type: 0, // 0 默认是买家
|
|
biddingInfo: null,
|
|
expiredTime: null,
|
|
recordList: [],
|
|
recordIndex: -1,
|
|
safeBottom: app.globalData.safeBottom,
|
|
kg: app.globalData.kg,
|
|
recordInfo: null,
|
|
frist: true
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if (options.id) {
|
|
this.data.type = options.type ? Number(options.type) : 0
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
this.fetchInfo(options.id)
|
|
}
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
|
|
// 事件处理
|
|
onEvent: function (message) {
|
|
if (message.what == 112 && this.data.biddingInfo && this.data.biddingInfo.id) {
|
|
this.fetchInfo(this.data.biddingInfo.id)
|
|
}
|
|
},
|
|
|
|
fetchInfo: function(id){
|
|
if (this.data.type == 1) {
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
// recycle-service/get/bidding-activity-detail/{biddingActivityId}
|
|
request.get('/recycle-service/get/bidding-activity-detail/' + id).then(result => {
|
|
//成功回调
|
|
this.setData({
|
|
type: this.data.type,
|
|
biddingInfo: result.data,
|
|
kg: app.globalData.kg,
|
|
safeBottom: app.globalData.safeBottom
|
|
})
|
|
if(result.data.status == 0 && this.data.frist){
|
|
this.expiredTime(result.data.expiredTime, id)
|
|
}
|
|
this.fetchBiddingList(id)
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
})
|
|
} else {
|
|
this.biddingDialog = this.biddingDialog || this.selectComponent('#bidding-good')
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
// recycle-service/get/bidding-detail/{biddingId}
|
|
request.get('/recycle-service/get/bidding-detail/' + id).then(result => {
|
|
//成功回调
|
|
if(result.data.status == 0 && this.data.frist){
|
|
this.expiredTime(result.data.biddingActivity.expiredTime, id)
|
|
} else if(result.data.status == 1 && this.data.frist){
|
|
this.expiredTime(result.data.expiredTime, id)
|
|
}
|
|
this.setData({ type: this.data.type, biddingInfo: result.data })
|
|
if(result.data.status == 0){
|
|
this.fetchBiddingList(result.data.biddingActivity.id)
|
|
}
|
|
this.fetchBiddingInfo(result.data.biddingActivity.id)
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
})
|
|
}
|
|
},
|
|
expiredTime: function(etime, id){
|
|
this.data.frist = false
|
|
var that = this
|
|
this.countDown = new $wuxCountDown({
|
|
date: etime,
|
|
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)
|
|
}
|
|
})
|
|
},
|
|
|
|
fetchBiddingInfo: function (biddingActivityId) {
|
|
request.get('/recycle-service/get/my-bidding/' + biddingActivityId).then(result => {
|
|
//成功回调
|
|
this.setData({
|
|
recordInfo: result.data
|
|
})
|
|
})
|
|
},
|
|
|
|
fetchBiddingList: function (biddingActivityId) {
|
|
request.get('/recycle-service/get/bidding-list/' + biddingActivityId).then(result => {
|
|
//成功回调
|
|
var record = null
|
|
if(this.data.biddingInfo.winBiddingId){
|
|
for (let index = 0; index < result.data.records.length; index++) {
|
|
const element = result.data.records[index]
|
|
if(Number(element.id) == Number(this.data.biddingInfo.winBiddingId)){
|
|
record = element
|
|
break
|
|
}
|
|
}
|
|
}
|
|
this.setData({
|
|
recordList: result.data.records,
|
|
recordInfo: record
|
|
})
|
|
})
|
|
},
|
|
toShopInfo: function () {
|
|
if (!this.data.biddingInfo) {
|
|
return
|
|
}
|
|
wx.navigateTo({
|
|
url: '/pages/shop/detail/index?storeId=' + this.data.biddingInfo.biddingActivity.storeId
|
|
})
|
|
},
|
|
formatePrice: function (value, kg) {
|
|
if (value || value == 0) {
|
|
if(kg){
|
|
return (parseFloat(value)).toFixed(3)
|
|
} else {
|
|
return (parseFloat(value) * 1000).toFixed(1)
|
|
}
|
|
}
|
|
return 0
|
|
},
|
|
biddingActicity: function () {
|
|
var that = this
|
|
this.wuxDialog.prompt({
|
|
offer: true,
|
|
title: '商品报价',
|
|
value: that.formatePrice(that.data.biddingInfo.unitPrice, app.globalData.kg),
|
|
step: that.formatePrice(that.data.biddingInfo.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))
|
|
},
|
|
})
|
|
},
|
|
biddingPrice: function (price) {
|
|
if(util.isEmpty(price)){
|
|
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.biddingInfo.biddingActivity.id, { biddingUnitPrice: price }).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
util.showToast('报价成功')
|
|
this.setData({
|
|
['biddingInfo.unitPrice']: price
|
|
})
|
|
this.fetchBiddingList(this.data.biddingInfo.biddingActivity.id)
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
|
|
showDialog: function(){
|
|
var that = this
|
|
this.wuxDialog.open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content: '确定取消该商品的竞价活动?',
|
|
buttons: [{
|
|
text: '取消'
|
|
}, {
|
|
text: '确定',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
that.cancelActivity()
|
|
}
|
|
}]
|
|
})
|
|
},
|
|
|
|
cancelActivity: function(){
|
|
wx.showLoading({
|
|
title: '处理中',
|
|
mask: true
|
|
})
|
|
// /recycle-service/bid/{biddingActivityId} 参与报价
|
|
request.post('/recycle-service/cancel/bidding-activity/' + this.data.biddingInfo.id).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
util.showToast('竞价取消成功')
|
|
event.emit('EventMessage', { what: 301, desc: 'bidding-cancel' })
|
|
wx.navigateBack({ delta: 1 })
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
|
|
checkRecord: function(e){
|
|
if(this.data.biddingInfo.status == 0){
|
|
this.setData({recordIndex: e.currentTarget.dataset.index})
|
|
}
|
|
},
|
|
|
|
biddingConfrim: function(){
|
|
if(this.data.recordIndex < 0){
|
|
util.showToast('请选择一个报价')
|
|
return
|
|
}
|
|
wx.showLoading({
|
|
title: '处理中',
|
|
mask: true
|
|
})
|
|
// /recycle-service/bid/{biddingActivityId} 参与报价
|
|
var biddingId = this.data.recordList[this.data.recordIndex].id
|
|
request.post('/recycle-service/confirm/bidding', { biddingId }).then(result => {
|
|
//成功回调
|
|
wx.hideLoading()
|
|
util.showToast('确认报价成功')
|
|
if (this.countDown) {
|
|
this.countDown.stop()
|
|
this.countDown = null
|
|
}
|
|
event.emit('EventMessage', { what: 301, desc: 'bidding-confrim' })
|
|
this.setData({
|
|
['biddingInfo.status']: 1,
|
|
expiredTime: null,
|
|
recordInfo: this.data.recordList[this.data.recordIndex]
|
|
})
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
|
|
offerOrder: function(){
|
|
var productId = this.data.biddingInfo.biddingActivity.productId
|
|
wx.navigateTo({
|
|
url: '/pages/morder/create/index?productId=' + productId + '&price=' + this.data.biddingInfo.unitPrice
|
|
})
|
|
},
|
|
|
|
restartActivity: function(){
|
|
wx.redirectTo({
|
|
url: '/pages/goods/create/index?id=' + this.data.biddingInfo.productId
|
|
})
|
|
},
|
|
|
|
onUnload: function () {
|
|
if (this.countDown) {
|
|
this.countDown.stop()
|
|
this.countDown = null
|
|
}
|
|
event.remove('EventMessage', this)
|
|
}
|
|
|
|
})
|