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.
89 lines
2.6 KiB
89 lines
2.6 KiB
import { getPreferType, getPreferList } from "../../../api/moment"
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties: {
|
|
height: { type: Number, value: 0 }
|
|
},
|
|
data: {
|
|
mHeight: app.globalData.safeFragmentHeight - 190,
|
|
tabList: [],
|
|
tabIndex: 0,
|
|
typeList: [],
|
|
scrolled: false,
|
|
form: {
|
|
pageNum: 1,
|
|
pageSize: 10
|
|
},
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
orderList: []
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
this.fetchTypeList()
|
|
if(!this.firstShow){
|
|
this.setData({mHeight: app.globalData.safeFragmentHeight - 360 })
|
|
this.fetchList()
|
|
}
|
|
this.firstShow = true
|
|
},
|
|
fetchTypeList: function(){
|
|
if(this.data.tabList.length > 0){
|
|
return
|
|
}
|
|
getPreferType().then(result => {
|
|
this.data.typeList = [{ id: '', name: '全部' }].concat(result.data)
|
|
for (let index = 0; index < this.data.typeList.length; index++) {
|
|
this.data.tabList.push(this.data.typeList[index].name)
|
|
}
|
|
this.setData({ tabList: this.data.tabList, scrolled: this.data.typeList.length >= 5 })
|
|
})
|
|
},
|
|
onTabChange: function ({ detail }) {
|
|
if (this.data.tabIndex == Number(detail.index)) {
|
|
return
|
|
}
|
|
this.data.tabIndex = Number(detail.index)
|
|
this.data.form.categoryId = this.data.typeList[this.data.tabIndex].id
|
|
this.onRefreshList()
|
|
},
|
|
// 下拉刷新...
|
|
onRefreshList: function () {
|
|
if (this.data.requesting) {
|
|
return
|
|
}
|
|
this.setData({ orderList: [], tabIndex: this.data.tabIndex, ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchList()
|
|
},
|
|
fetchList: function(){
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if(this.data.orderList.length > 0){
|
|
this.setData({ requesting: true })
|
|
}
|
|
getPreferList(this.data.form).then(result => {
|
|
if (result.data && result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList[${this.data.orderList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
|
|
} else {
|
|
this.setData({ finished: true, requesting: false, loading: false })
|
|
}
|
|
}).catch(err => {
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|