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.
112 lines
2.8 KiB
112 lines
2.8 KiB
// pages/moment/price/index.js
|
|
import { getFactoryPrice } from "../../api/ztb"
|
|
const event = require('../../../utils/event')
|
|
const storage = require('../../../utils/storage')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight,
|
|
kg: app.globalData.kg,
|
|
loading: false,
|
|
requesting: false,
|
|
finished: false,
|
|
top: 0,
|
|
orderList: [],
|
|
form: { pageNum: 1 }
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
var ids = storage.get('ztb-paper-price')
|
|
if(ids){
|
|
this.data.form.paperMillIdList = ids
|
|
this.onRefreshList()
|
|
}
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
onEvent: function (message) {
|
|
if(message.what == 508){
|
|
this.data.form.paperMillIdList = message.obj
|
|
storage.put('ztb-paper-price', message.obj)
|
|
this.onRefreshList()
|
|
}
|
|
},
|
|
// 下拉刷新...
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({
|
|
orderList: [],
|
|
['form.pageNum']: 1,
|
|
loading: true,
|
|
kg: app.globalData.kg,
|
|
height: app.globalData.fragmentHeight,
|
|
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
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
this.setData({
|
|
requesting: false,
|
|
finished: true,
|
|
loading: false
|
|
})
|
|
})
|
|
},
|
|
selectMill: function(){
|
|
wx.navigateTo({ url: '/pages/article/factory/index?type=4&ids=' + this.data.form.paperMillIdList})
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
|
|
})
|