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.
143 lines
4.6 KiB
143 lines
4.6 KiB
// pages/message/detail/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getFactoryPriceDetail, userPushFollowMill } from "../../../api/ztb"
|
|
import { getPreferList} from "../../../api/moment"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight - 90,
|
|
stickyTop: app.globalData.CustomBar,
|
|
scrollTop: 0,
|
|
toView: null,
|
|
id: null,
|
|
tabList: ['报价信息', '收货标准', '注意事项'],
|
|
tabIndex: 0,
|
|
factoryDetail: null,
|
|
cateIndex: 0,
|
|
cateId: '',
|
|
daytimes: '',
|
|
momentList: [],
|
|
requesting: false,
|
|
finished: false,
|
|
form: {
|
|
pageNum: 1
|
|
},
|
|
hasFollowed: false
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
if (options.id) {
|
|
this.data.id = options.id
|
|
this.data.form.millPaperId = options.id
|
|
getFactoryPriceDetail(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, hasFollowed: result.data.hasFollowed })
|
|
wx.hideLoading()
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
this.setData({
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragmentHeight: app.globalData.fragmentHeight - 90,
|
|
height: app.globalData.fragmentHeight,
|
|
stickyTop: app.globalData.CustomBar,
|
|
daytimes: util.formatDate(new Date(), 'Y-M-D')
|
|
// tabIndex: options.tabIndex ? parseInt(options.tabIndex) : 0
|
|
})
|
|
},
|
|
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) {
|
|
if (!app.userInfo) {
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
if(!this.data.factoryDetail.isOperations){
|
|
util.showToast('该纸厂已暂停接单,请联系相关负责人!')
|
|
return
|
|
}
|
|
var item = this.data.factoryDetail.paperCategoryList[this.data.cateIndex]
|
|
if (util.isEmpty(item.unitPrice)) {
|
|
util.showToast('该纸品暂无报价,无法卖货')
|
|
return
|
|
}
|
|
wx.navigateTo({url: `/pages/agent/appointment/index?id=${this.data.factoryDetail.paperMillId}&categoryId=${item.categoryId}`})
|
|
},
|
|
//*************************************************momentList************************************************//
|
|
fetchMomentList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
this.setData({ requesting: true })
|
|
getPreferList(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 })
|
|
})
|
|
},
|
|
onAttentionChange: function (e) {
|
|
var model = { follow: !this.data.hasFollowed, paperMillId: this.data.id }
|
|
wx.showLoading({ title: '处理中', mask: true })
|
|
userPushFollowMill(model).then(res => {
|
|
this.setData({ hasFollowed: model.follow })
|
|
wx.hideLoading()
|
|
event.emit('EventMessage', { what: 1101, desc: 'factoryDetails' })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
})
|