You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
141 lines
3.8 KiB
141 lines
3.8 KiB
// pages/agent/index/index.js
|
|
import { getFactoryPrice, getBaseInfo, updateUserInfo } from "../../api/ztb"
|
|
const event = require('../../../utils/event')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
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,
|
|
listType: 1
|
|
}
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
this.setData({ height: app.globalData.fragmentHeight, kg: app.globalData.kg })
|
|
this.fetchPapersList()
|
|
event.on('factoryDetails', this, this.onEvent)
|
|
event.on('attentionPaperList', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('factoryDetails', this)
|
|
event.remove('attentionPaperList', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onEvent: function (message) {
|
|
if (message.what == 1100 || message.what == 1101) {
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
onRestart: function () {
|
|
getBaseInfo().then(result => {
|
|
if (result.data.isSetProxyTag == false) {
|
|
updateUserInfo({ isSetProxyTag: true }).then(result => {})
|
|
this.wuxDialog = this.wuxDialog || this.selectComponent('#wux-dialog')
|
|
this.wuxDialog.open({
|
|
resetOnClose: true,
|
|
title: '温馨提示',
|
|
content: '是否选择关注您常卖的纸厂?',
|
|
buttons: [{
|
|
text: '取消'
|
|
}, {
|
|
text: '确定',
|
|
type: 'primary',
|
|
onTap(e) {
|
|
wx.navigateTo({
|
|
url: '/pages/home/attentionPaperList/index'
|
|
})
|
|
}
|
|
}]
|
|
})
|
|
}
|
|
})
|
|
},
|
|
// 下拉刷新...
|
|
onRefreshList: function () {
|
|
this.setData({
|
|
orderList: [],
|
|
['form.pageNum']: 1,
|
|
loading: true,
|
|
finished: false
|
|
})
|
|
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,
|
|
pageNum: 1
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false, finished: true, loading: false })
|
|
})
|
|
},
|
|
goattentionIndex: function () {
|
|
wx.navigateTo({ url: '/pages/home/attentionPaperList/index' })
|
|
}
|
|
}
|
|
|
|
})
|