纸通宝小程序
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.
 

169 lines
5.5 KiB

// pages/message/index.js
import { getFactoryPrice, getBannerList } from "../../../api/ztb"
import { getCategoryType, getPreferList, getMomentList } from "../../../api/moment"
const event = require('../../../utils/event')
const storage = require('../../../utils/storage')
const util = require('../../../utils/util')
const app = getApp()
var form = {sortBy: 1, pageNum: 10, pageSize: 1, categoryId: ''}
var typeList = []
Component({
options: {
addGlobalClass: true,
multipleSlots: true
},
properties:{
cityName: { //这个是可以自定义最外层的view的样式
type: String,
value: ''
}
},
/**
* 页面的初始数据
*/
data: {
height: app.globalData.safeFragmentHeight - 100,
firstShow: false,
bannerList: [],
momentList: [],
tabList: [],
tabIndex: 0,
requesting: false,
orderList: [],
popover: false,
sortList: [
{sort: 1, text: '更新时间'},
{sort: 2, text: '价格升序'},
{sort: 3, text: '价格降序'},
{sort: 4, text: '排队升序'},
{sort: 5, text: '排队降序'}
],
sortIndex: 0,
},
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,
StatusBar: app.globalData.StatusBar || 40,
customHeight: app.globalData.customHeight,
CustomBar: app.globalData.CustomBar || (app.globalData.isIos ? 64 : 80),
firstShow: true
})
getPreferList().then(result => {
this.setData({ momentList: result.data.records.slice(0, 3) })
})
getCategoryType().then(result => {
typeList = result.data
var tabList = []
for (let index = 0; index < typeList.length; index++) {
tabList.push(typeList[index].categoryName)
}
form.categoryId = typeList[0].categoryId
console.log(form)
this.setData({ tabList })
this.fetchAgentList()
})
}
this.data.firstShow = true
var bannerstring = storage.get('ztb-banner-list')
if(!util.isEmpty(bannerstring)){
this.setData({ bannerList: JSON.parse(bannerstring) })
}
if(!this.data.bannerList.length){
getBannerList(1).then(result => {
this.setData({ bannerList: result.data })
storage.put('ztb-banner-list', JSON.stringify(result.data))
})
}
},
onEvent: function (message) {
console.log('mall>>fragment>>onEvent', message)
if(message.what == 888){
this.fetchAgentList()
} else if(message.what == 444){
this.setData({ cityName: app.nowCity.cityName })
this.fetchAgentList()
}
},
searchList: function(){
wx.navigateTo({url: `/pages/mall/search-list/index` })
},
postInfo: function(e){
var item = this.data.momentList[e.currentTarget.dataset.index]
wx.navigateTo({ url: '/pages/article/detail/index?id=' + item.id })
},
gridTap: function(e){
if(e.currentTarget.id == 'agent'){
this.triggerEvent("click", { what: 2 })
} else if(e.currentTarget.id == 'trans'){
util.navigateTo('/pages/mall/index/index')
} else if(e.currentTarget.id == 'action'){
util.navigateTo(`/pages/agent/ability/index`)
} else if(e.currentTarget.id == 'moment'){
this.triggerEvent("click", { what: 1 })
} else if(e.currentTarget.id == 'info'){
util.navigateTo('/pages/article/index/index')
} else if(e.currentTarget.id == 'city'){
wx.navigateTo({url: `/pages/home/city-select/index?type=1` })
}
},
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
}
form.categoryId = typeList[Number(detail.index)].categoryId
this.fetchAgentList()
},
topBubble: function(e){
if(this.data.sortIndex == Number(e.currentTarget.dataset.index)){
this.setData({ popover: !this.data.popover })
return
}
if(!util.isEmpty(e.currentTarget.dataset.index)){
this.data.sortIndex = Number(e.currentTarget.dataset.index)
if(this.data.popover){
form.sortBy = this.data.sortIndex
this.fetchAgentList()
}
}
this.setData({ popover: !this.data.popover, sortIndex: this.data.sortIndex })
},
//*************************************************fetchAgentList************************************************//
fetchAgentList: function () {
if (this.data.requesting) {
return
}
this.setData({ requesting: true, orderList: [] })
getMomentList(form).then(result => {
console.log(result)
if (result.data.records.length) {
this.setData({ orderList: result.data.records, requesting: false })
} else {
this.setData({ requesting: false })
}
}).catch(err => {
this.setData({ requesting: false })
})
}
}
})