// pages/agent/index/index.js import { getFactoryPrice, getFactoryCity } from "../../api/ztb" const app = getApp() Page({ /** * 页面的初始数据 */ data: { height: app.globalData.fragmentHeight - 90, CustomBar: app.globalData.CustomBar, kg: app.globalData.kg, loading: true, requesting: false, finished: false, tabList: [], tabIndex: 0, cateList: [], scrolled: false, top: 0, orderList: [], form: { cityId: '', enableSalesAgent: 1, pageNum: 1 }, form2: { pageNum: 1 }, bidType: 1, }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ height: app.globalData.fragmentHeight - 90, kg: app.globalData.kg, CustomBar: app.globalData.CustomBar }) this.fetchRegionList() this.fetchPapersList() }, 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, scrolled: this.data.cateList.length >= 5 }) }) }, //获取纸厂列表 fetchRegionList2: function () { }, onTabChangeTop: function (e) { if (this.data.bidType == Number(e.currentTarget.dataset.index)) { return } var tabIndex = Number(e.currentTarget.dataset.index) this.data.firstCategoryId = '' this.setData({ pageIndex: 0, ['bidType']: tabIndex }) console.log(this.bidType) if (this.data.bidType == 1) { this.onRefreshList() } }, 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 () { this.setData({ orderList: [], tabIndex: this.data.tabIndex, ['form.pageNum']: 1, loading: true, finished: false }) this.fetchPapersList() }, // 下拉刷新关注... onRefreshList2: function () { this.setData({ ['form2.pageNum']: 1, }) this.fetchPapersList() }, // 获取特价列表 fetchPapersList: function () { if (this.data.requesting || this.data.finished) { return } if (this.data.loading) { this.data.requesting = true } else { this.setData({ 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 if (this.data.form.pageNum == 1) { this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), top: 0, finished, requesting: false, loading: false }) } else { this.setData({ [nowList]: respList, total: result.data.total, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false }) } } else { this.setData({ finished: true, requesting: false, loading: false }) } }).catch(err => { //异常回调 this.setData({ requesting: false, finished: true, loading: false }) }) } })