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.
144 lines
4.6 KiB
144 lines
4.6 KiB
// pages/message/index.js
|
|
import { getFactoryPrice, getBannerList } from "../../../api/ztb"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
properties:{
|
|
cityName: { //这个是可以自定义最外层的view的样式
|
|
type: String,
|
|
value: ''
|
|
}
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.safeFragmentHeight - 100,
|
|
kg: app.globalData.kg,
|
|
firstShow: false,
|
|
banning: true,
|
|
bannerList: [],
|
|
tabList: [ '黄纸', '白纸', '灰纸', '杂纸' ],
|
|
tabIndex: 0,
|
|
loading: true,
|
|
requesting: false,
|
|
finished: false,
|
|
form: { pageNum: 1 },
|
|
orderList: [1, 2, 3, 5],
|
|
show: false
|
|
},
|
|
lifetimes: {
|
|
// 生命周期函数,可以为函数,或一个在methods段中定义的方法名
|
|
attached: function () {
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
detached: function () {
|
|
event.remove('EventMessage', this)
|
|
}
|
|
},
|
|
methods: {
|
|
onRestart: function () {
|
|
if(!this.data.firstShow){
|
|
this.setData({
|
|
height: app.globalData.safeFragmentHeight - 100,
|
|
kg: app.globalData.kg,
|
|
StatusBar: app.globalData.StatusBar || 40,
|
|
customHeight: app.globalData.customHeight,
|
|
CustomBar: app.globalData.CustomBar || (app.globalData.isIos ? 64 : 80),
|
|
firstShow: true
|
|
})
|
|
this.fetchAgentList()
|
|
}
|
|
this.data.firstShow = true
|
|
if(!this.data.bannerList.length){
|
|
getBannerList(1).then(result => {
|
|
this.setData({ bannerList: result.data })
|
|
}).catch(err => {
|
|
})
|
|
}
|
|
},
|
|
onEvent: function (message) {
|
|
console.log('mall>>index>>onEvent', message)
|
|
if (message.what == 10 && app.globalData.isVIP == 1) {
|
|
// this.setData({ token: app.globalData.token })
|
|
// this.onRefreshList()
|
|
} else if(message.what == 1001){
|
|
this.setData({ kg: app.globalData.kg })
|
|
} else if(message.what == 888){
|
|
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false })
|
|
this.fetchAgentList()
|
|
} else if(message.what == 444){
|
|
this.setData({ orderList: [], ['form.pageNum']: 1, loading: true, finished: false, cityName: app.nowCity.cityName })
|
|
this.fetchAgentList()
|
|
}
|
|
},
|
|
chooseCity: function(){
|
|
wx.navigateTo({url: `/pages/home/city-select/index?type=1` })
|
|
},
|
|
searchList: function(){
|
|
wx.navigateTo({url: `/pages/mall/search-list/index` })
|
|
},
|
|
postList: function(){
|
|
|
|
},
|
|
gridTap: function(e){
|
|
if(e.currentTarget.id == 'agent'){
|
|
this.triggerEvent("click", { what: 1 })
|
|
} else if(e.currentTarget.id == 'trans'){
|
|
util.navigateTo('/pages/agent/index/index')
|
|
} else if(e.currentTarget.id == 'action'){
|
|
util.navigateTo(`/pages/agent/ability/index`)
|
|
}
|
|
},
|
|
tapBanner: function(e){
|
|
var item = this.data.bannerList[e.currentTarget.dataset.index]
|
|
if(item.redirectInfo.targetView == 'showH5'){
|
|
util.navigateTo('/pages/html/html/index?link=' + item.redirectInfo.params.id + '?title=' + item.title)
|
|
return
|
|
}
|
|
util.navigateTarget(item.redirectInfo)
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.tabIndex == Number(detail.index)){
|
|
return
|
|
}
|
|
this.fetchAgentList()
|
|
},
|
|
topBubble: function(){
|
|
this.setData({ show: !this.data.show })
|
|
},
|
|
//*************************************************fetchAgentList************************************************//
|
|
// 获取特价列表
|
|
fetchAgentList: 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
|
|
this.setData({ [nowList]: respList, ['form.pageNum']: (num + 1), finished, requesting: false, loading: false })
|
|
} else {
|
|
this.setData({ requesting: false, finished: true, loading: false })
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({ requesting: false, finished: true, loading: false })
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|