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.
128 lines
3.3 KiB
128 lines
3.3 KiB
// pages/mall/shops/index.js
|
|
const request = require('../../../utils/request'); //导入模块
|
|
const util = require('../../../utils/util');
|
|
const event = require('../../../utils/event.js')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight - 100,
|
|
CustomBar: app.globalData.CustomBar,
|
|
tabs: ['待出车', '进行中', '已完成', '进行中', '已完成', '进行中', '已完成', '进行中', '已完成'],
|
|
loading: true,
|
|
finished: false,
|
|
requesting: false,
|
|
cheapList: [],
|
|
taskList: [],
|
|
form: {
|
|
pageSize: 10,
|
|
pageNum: 1
|
|
},
|
|
token: null
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
this.setData({
|
|
height: app.globalData.fragmentHeight,
|
|
CustomBar: app.globalData.CustomBar
|
|
})
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
|
|
onEvent: function (message) {
|
|
console.log('mall>>index>>onEvent', message)
|
|
if(message.what == 1 && util.isEmpty(this.data.token)){
|
|
// this.setData({ token: app.globalData.token })
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
*/
|
|
onReady: function () {
|
|
if (!this.data.firstShow) {
|
|
this.setData({
|
|
token: app.globalData.token
|
|
})
|
|
this.fetchCheapList()
|
|
this.fetchTaskList()
|
|
}
|
|
},
|
|
|
|
fetchCheapList: function () {
|
|
request.get('/bxe-mall/product/cheapList').then(result => {
|
|
//成功回调
|
|
this.setData({ loading: false, cheapList: result.data })
|
|
console.log(this.data.cheapList.length > 0)
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ loading: false })
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
|
|
fetchTaskList: function () {
|
|
if (this.data.requesting || this.data.finished) {
|
|
return
|
|
}
|
|
if (this.data.form.pageNum == 1 && this.data.taskList.length == 0) {
|
|
this.setData({ loading: true })
|
|
}
|
|
this.data.requesting = true
|
|
// /product/cheapList特价产品列表
|
|
request.get('/bxe-mall/product/groupList', this.data.form).then(result => {
|
|
//成功回调
|
|
this.setData({ requesting: false, loading: false })
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `taskList[${this.data.taskList.length}]`
|
|
var num = this.data.form.pageNum
|
|
var finished = this.data.form.pageNum >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
total: result.data.total,
|
|
['form.pageNum']: (num + 1),
|
|
finished
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false, loading: false })
|
|
util.showToast(err)
|
|
})
|
|
},
|
|
|
|
searchList: function (e) {
|
|
wx.navigateTo({
|
|
url: '/pages/mall/search-list/index'
|
|
})
|
|
},
|
|
|
|
lookGroupItem: function (e) {
|
|
var item = this.data.taskList[e.currentTarget.dataset.page][e.currentTarget.dataset.index]
|
|
wx.navigateTo({
|
|
url: '/pages/mall/order-info/index?id=' + item.id
|
|
})
|
|
},
|
|
|
|
lookCheapItem: function (e) {
|
|
var item = this.data.cheapList[e.currentTarget.dataset.index]
|
|
wx.navigateTo({
|
|
url: '/pages/mall/order-info/index?id=' + item.id
|
|
})
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面卸载
|
|
*/
|
|
onUnload: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
|
|
})
|