// pages/stock/index.js const request = require('../../../utils/request') //导入模块 const util = require('../../../utils/util') const storage = require('../../../utils/storage') const event = require('../../../utils/event.js') const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, /** * 页面的初始数据 */ data: { height: app.globalData.safeFragmentHeight - 190, chartList: null, momentList: [], requesting: false, finished: false, idList: '', form: { categoryId: 1, pageNum: 1 }, factoryList: [], priceId: null, priceName: '', priceList: [] }, lifetimes: { // 生命周期函数,可以为函数,或一个在methods段中定义的方法名 attached: function () { this.setData({ height: app.globalData.safeFragmentHeight - 190, kg: app.globalData.kg }) this.data.priceId = storage.get('priceId' + app.globalData.userInfo.userId) event.on('EventMessage', this, this.onEvent) }, detached: function () { event.remove('EventMessage', this) } }, methods: { onRestart: function () { if (!this.data.firstShow) { // this.fetchPriceList(this.data.priceId) this.onRefreshList() } this.data.firstShow = true }, onEvent: function (message) { if (message.what == 555) { // 纸厂价格的纸厂选择 this.data.priceId = message.obj.paperMillId storage.put('priceId' + app.globalData.userInfo.userId, this.data.priceId) // this.fetchPriceList(this.data.priceId) } else if (message.what == 571) { // 帖子发布刷新 this.onRefreshList() } }, //***********************************参与纸厂讨论*****************************************// // 纸品价格>>>>选择纸厂 // selectFactory: function(event){ // wx.navigateTo({ url: '/pages/article/factory/index?type=' + event.currentTarget.id}) // }, // toPriceList: function(){ // console.log(this.data.priceId) // wx.navigateTo({ url: '/pages/article/price-detail/index?id=' + this.data.priceId }) // }, // fetchPriceList: function(millId){ // if(millId){ // request.get('/recycle-service/get/paper-mill-paper-category-price-details/' + millId).then(result => { // //成功回调 // this.setData({ priceList: result.data.paperCategoryList.slice(0, 8), priceName: result.data.name }) // }) // } else { // request.get('/recycle-service/get/paper-mill-list').then(result => { // this.data.priceId = result.data.records[0].paperMillId // this.fetchPriceList(this.data.priceId) // }) // } // }, //*************************************************momentList************************************************// onRefreshList: function () { this.setData({ momentList: [], ['form.pageNum']: 1, finished: false }) this.fetchMomentList() }, fetchMomentList: function(){ if (this.data.requesting || this.data.finished) { return } this.data.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), finished, requesting: false }) } else { this.setData({ finished: true, requesting: false }) } }).catch(err => { //异常回调 this.setData({ requesting: false }) }) }, lookItem: function(e){ var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index] wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.id }) }, likeItem: function(e){ var item = this.data.momentList[e.currentTarget.dataset.page][e.currentTarget.dataset.index] if(item.isLiked){ util.showToast('请勿重复点赞') return } request.post('/information-center/like-or-cancel/post', {postId: item.id}).then(result => { this.setData({ ['momentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].likeQuantity']: result.data.likeQuantity, ['momentList[' + e.currentTarget.dataset.page + '][' + e.currentTarget.dataset.index + '].isLiked']: 1 }) }).catch(error => { util.showToast(error) }) }, //*************************************************noticeList************************************************// fetchNoticeList: function(){ if (this.data.loopRequesting) { return } this.data.loopRequesting = true request.get('/recycle-service/get/index-info-id').then(result => { //成功回调 this.data.loopRequesting = false this.data.noticeList = result.data if(result.data && result.data.length){ this.data.noticeIndex = 0 this.data.loopIndex = 0 this.setData({ content: result.data[0].title}) } }).catch(err => { //异常回调 this.data.loopRequesting = false }) }, onLoop: function(){ if(!this.data.noticeList.length){ this.data.loopIndex++ if(this.data.loopIndex >= 600){ this.fetchNoticeList() } return } this.data.noticeIndex++ if(this.data.noticeIndex >= this.data.noticeList.length){ this.data.loopIndex++ this.data.noticeIndex = 0 } if(this.data.loopIndex >= 60){ this.fetchNoticeList() } this.setData({ content: this.data.noticeList[this.data.noticeIndex].title }) this.notice = this.notice || this.selectComponent('#wux-notice-bar') this.notice.resetAnimation() }, onClick: function(){ wx.navigateTo({ url: '/pages/html/notice/index?id=' + this.data.noticeList[this.data.noticeIndex].id }) } } })