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.
159 lines
5.0 KiB
159 lines
5.0 KiB
// pages/mall/factory/index.js
|
|
const request = require('../../../utils/request') //导入模块
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight - 90,
|
|
stickyTop: app.globalData.CustomBar,
|
|
kg: app.globalData.kg,
|
|
scrollTop: 0,
|
|
toView: null,
|
|
id: null,
|
|
tabList: [ '报价信息', '讨论', '收货标准', '注意事项' ],
|
|
tabIndex: 0,
|
|
factoryDetail: null,
|
|
cateIndex: 0,
|
|
cateId: '',
|
|
daytimes: '',
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
pageNum: 1
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight,
|
|
kg: app.globalData.kg,
|
|
stickyTop: app.globalData.CustomBar,
|
|
daytimes: util.formatDate(new Date(), 'Y-M-D')
|
|
// tabIndex: options.tabIndex ? parseInt(options.tabIndex) : 0
|
|
})
|
|
event.on('EventMessage', this, this.onEvent)
|
|
if(options.id){
|
|
this.data.id = options.id
|
|
this.data.form.millPaperId = options.id
|
|
wx.showLoading({ title: '加载中', mask: true })
|
|
request.get('/recycle-service/get/paper-mill-paper-category-price-details/' + options.id).then(result => {
|
|
//成功回调
|
|
if(result.data.paperCategoryList && result.data.paperCategoryList.length){
|
|
this.data.cateId = result.data.paperCategoryList[this.data.cateIndex].categoryId
|
|
}
|
|
this.setData({ factoryDetail: result.data })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
if (message.what == 570 || message.what == 571 || message.what == 572 || message.what == 573) {
|
|
// 帖子发布刷新
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
onFixedChange: function({detail}){
|
|
this.data.fixed = detail.fixed
|
|
},
|
|
onScroll: function({detail}) {
|
|
this.setData({ scrollTop: detail.scrollTop })
|
|
},
|
|
stopTouchMove: function(e){
|
|
return false
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.tabIndex == Number(detail.index)){
|
|
return
|
|
}
|
|
if(this.data.fixed){
|
|
this.setData({ tabIndex: parseInt(detail.index), toView: 'sticky' })
|
|
} else {
|
|
this.setData({ tabIndex: parseInt(detail.index) })
|
|
}
|
|
if(this.data.tabIndex == 1 && !this.data.momentList.length){
|
|
this.fetchMomentList()
|
|
}
|
|
},
|
|
checkTag: function(e){
|
|
if(!e.currentTarget.dataset){
|
|
return
|
|
}
|
|
if(!e.currentTarget.dataset.index && e.currentTarget.dataset.index != 0){
|
|
return
|
|
}
|
|
if(this.data.cateIndex == e.currentTarget.dataset.index){
|
|
return
|
|
}
|
|
this.setData({cateIndex : e.currentTarget.dataset.index})
|
|
},
|
|
saleGood: function(e){
|
|
var item = this.data.factoryDetail.paperCategoryList[this.data.cateIndex]
|
|
if(util.isEmpty(item.unitPrice)){
|
|
util.showToast('该纸品暂无报价,无法卖货')
|
|
return
|
|
}
|
|
wx.navigateTo({ url: '/pages/agent/edit/index?id=' + this.data.factoryDetail.paperMillId + '&categoryId=' + item.categoryId })
|
|
},
|
|
postMoment: function(){
|
|
wx.navigateTo({ url: '/pages/article/publish/index?factoryId=' + this.data.factoryDetail.paperMillId + '&name=' + this.data.factoryDetail.name })
|
|
},
|
|
//*************************************************momentList************************************************//
|
|
onRefreshList: function () {
|
|
this.setData({ momentList: [], ['form.pageNum']: 1, finished: false })
|
|
this.fetchMomentList()
|
|
},
|
|
fetchMomentList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.setData({ requesting: true })
|
|
request.get('/information-center/article/get/Article-list/', this.data.form).then(result => {
|
|
//成功回调
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `momentList[${this.data.momentList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form.pageNum']: (num + 1),
|
|
requesting: false,
|
|
finished
|
|
})
|
|
} else {
|
|
this.setData({ finished: true, requesting: false })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false })
|
|
})
|
|
},
|
|
onShareAppMessage: function () {
|
|
return {
|
|
title: this.data.factoryDetail.name + '废纸报价',
|
|
path: 'pages/index/index?url=/pages/agent/factory/index&key=id&value=' + this.data.factoryDetail.paperMillId
|
|
}
|
|
},
|
|
toService: function(){
|
|
wx.navigateTo({ url: '/pages/home/service/index'})
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
})
|