const util = require('../../../utils/util') const event = require('../../../utils/event') import { userPushFollowMill } from "../../../api/ztb" import { getMillPaperList } from "../../../api/moment" const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { keyword: { type: String, value: null }, item: { type: Object, value: null }, mclick: { type: Boolean, value: true } }, data: { unflod: false, loading: false, requesting: false, itemList: [] }, methods: { onFlodTap: function(){ if(this.data.item.isCooperate === 1) { if(!app.globalData.userInfo || !app.globalData.userInfo.isVIP){ event.emit('EventMessage', {what: 223, desc: 'Logout'}) return } } this.setData({ unflod: !this.data.unflod }) if(!this.data.itemList.length && this.data.unflod){ this.fetchItemList() } }, attention: function(){ if (this.data.loading) { return } if(!app.globalData.userInfo){ util.navigateTo('/pages/login/index') return } this.setData({ loading: true }) userPushFollowMill({ paperMillId: this.data.item.paperMillId, follow: !this.data.item.hasFollowed }).then(result => { this.data.item.hasFollowed = !this.data.item.hasFollowed this.setData({ loading: false, ['item.hasFollowed']: this.data.item.hasFollowed }) this.triggerEvent("attention", this.data.item) }).catch(err => { this.setData({ loading: false }) }) }, lookItem: function(e){ util.navigateTo('/pages/agent/factory/index?id=' + this.data.item.paperMillId) }, fetchItemList: function(){ if (this.data.requesting) { return } this.setData({ requesting: true }) var date = this.data.item.latestQuoteTime.length > 10 ? this.data.item.latestQuoteTime.substring(0, 10) : this.data.item.latestQuoteTime getMillPaperList({ paperMillId: this.data.item.paperMillId, date }).then(result => { if (result.data.length) { this.setData({ requesting: false, itemList: result.data }) } else { this.setData({ requesting: false }) } }).catch(err => { this.setData({ requesting: false }) }) }, agentOrder: function(e){ var element = this.data.itemList[e.currentTarget.dataset.index] util.navigateTo(`/pages/agent/edit/index?id=${this.data.item.paperMillId}&categoryId=${element.categoryId}`) } } })