const util = require('../../../utils/util') import { userPushFollowMill } from "../../../api/ztb" import { getMillPaperList } from "../../../api/moment" const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, properties: { item: { type: Object, value: null }, mclick: { type: Boolean, value: true } }, data: { unflod: false, loading: false, requesting: false, itemList: [] }, methods: { onFlodTap: function(){ 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.setData({ loading: false, ['item.hasFollowed']: !this.data.item.hasFollowed }) }).catch(err => { this.setData({ loading: false }) }) }, lookItem: function(e){ if(!this.data.item.isCooperate) { if(!app.globalData.userInfo){ util.navigateTo('/pages/login/index') return } } 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 categoryId = this.data.itemList[e.currentTarget.dataset.index] util.navigateTo(`/pages/agent/edit/index?id=${this.data.item.paperMillId}&categoryId=${categoryId}`) } } })