// pages/index/index.js import Dialog from '../../../components/dialog/dialog' import { getFactoryPrice, getFactoryCity, hasActivity } from "../../../api/ztb" const app = getApp() Component({ options: { addGlobalClass: true, multipleSlots: true }, /** 页面的初始数据 */ data: { height: app.globalData.fragmentHeight - 90, loading: true, requesting: false, finished: false, tabList: [], tabIndex: 0, cateList: [], top: 0, orderList: [], form: { cityId: '', enableSalesAgent: 1, pageNum: 1, listType: 0 }, triggered: false, firstShow: false, hasActivity: false }, lifetimes: { attached: function () { if(app.userInfo){ hasActivity().then(result => { this.setData({ height: app.globalData.safeFragmentHeight - 90, hasActivity: result.data }) }).catch(err => { this.setData({ height: app.globalData.safeFragmentHeight - 90 }) }) } else { this.setData({ height: app.globalData.safeFragmentHeight - 90 }) } } }, methods: { onRestart: function(){ if (!this.data.firstShow) { this.fetchRegionList() this.fetchPapersList() } this.data.firstShow = true }, toAbility: function(){ wx.navigateTo({ url: '/pages/agent/ability-list/index' }) }, fetchRegionList: function () { getFactoryCity().then(result => { this.data.cateList = [{ cityId: '', cityName: '全部' }].concat(result.data) for (let index = 0; index < this.data.cateList.length; index++) { this.data.tabList.push(this.data.cateList[index].cityName) } this.setData({ tabList: this.data.tabList }) }) }, onTabChange: function ({ detail }) { if (this.data.tabIndex == Number(detail.index)) { return } this.data.tabIndex = Number(detail.index) this.data.form.cityId = this.data.cateList[this.data.tabIndex].cityId this.onRefreshList() }, // 下拉刷新... onRefreshList: function () { if (this.data.requesting) { return } this.setData({ orderList: [], tabIndex: this.data.tabIndex, ['form.pageNum']: 1, loading: true, finished: false }) this.fetchPapersList() }, // 获取特价列表 fetchPapersList: function () { if (this.data.requesting || this.data.finished) { return } this.data.requesting = true getFactoryPrice(this.data.form).then(result => { if (result.data.records.length) { var respList = result.data.records let nowList = `orderList[${this.data.orderList.length}]` var num = result.data.current var finished = result.data.current >= result.data.pages this.setData({[nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false }) } else { this.setData({ requesting: false, finished: true, loading: false, }) } }).catch(err => { this.setData({ requesting: false, finished: true, loading: false, }) }).then(() => { this.refresh = this.refresh || this.selectComponent('#refresh') this.refresh.setRefresh(false) }) } } })