// pages/message/detail/index.js import Scene from '../../index/scene' import { getFactoryPriceDetail, userPushFollowMill } from "../../../api/ztb" 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(this.data.factoryDetail.manageNotifyMessage) 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}`}) }, 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: 110, desc: 'factoryDetails' }) }).catch(err => { wx.hideLoading() util.showToast(err) }) } })