// pages/message/index.js const util = require('../../../utils/util') const event = require('../../../utils/event') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { item: { type: Object, value: null } }, data: { kg: app.globalData.kg, cateIndex: 0 }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { this.setData({ kg: app.globalData.kg }) event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { onEvent: function (message) { if(message.what == 1001){ this.setData({ kg: app.globalData.kg }) } }, lookItem: function (e) { util.navigateTo('/pages/agent/factory/index?id=' + this.data.item.paperMillId) }, unflodItem: function(){ this.setData({ ['item.fold']: !this.data.item.fold }) }, checkTag: function(e){ var cateIndex = -1 if(util.isEmpty(this.data.cateIndex)){ cateIndex = e.currentTarget.dataset.ck } else if(this.data.cateIndex != e.currentTarget.dataset.ck){ cateIndex = e.currentTarget.dataset.ck } if(cateIndex >= 0){ this.setData({ cateIndex }) } }, saleGood: function(e){ if (!app.globalData.userInfo) { wx.navigateTo({ url: '/pages/login/index' }) return } if(!this.data.item.isOperations){ util.showToast(this.data.item.manageNotifyMessage) return } if(util.isEmpty(this.data.cateIndex)){ util.showToast('请选择一个纸品') return } if(util.isEmpty(this.data.item.paperCategoryList[this.data.cateIndex].unitPrice)){ util.showToast('该纸品暂无报价,无法卖货') return } var categoryId = this.data.item.paperCategoryList[this.data.cateIndex].categoryId wx.navigateTo({ url: '/pages/agent/edit/index?id=' + this.data.item.paperMillId + '&categoryId=' + categoryId }) } } })