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.
310 lines
10 KiB
310 lines
10 KiB
// pages/message/index.js
|
|
import { getFactoryPrice, getProductList, getMiniProxyList, getBannerList, getSuccessNotices } from "../../api/ztb"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const app = getApp()
|
|
|
|
Component({
|
|
options: {
|
|
addGlobalClass: true,
|
|
multipleSlots: true
|
|
},
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.safeFragmentHeight - 100,
|
|
kg: app.globalData.kg,
|
|
stickyTop: app.globalData.CustomBar,
|
|
firstShow: false,
|
|
scrollTop: 0,
|
|
fixed: false,
|
|
toView: null,
|
|
banning: true,
|
|
bannerList: [],
|
|
noticeList: [],
|
|
iconList: [
|
|
{ icon: '/assets/image/ico_trade.png', badge: 0, name: '特价专区' },
|
|
{ icon: '/assets/image/ico_purchase.png', badge: 0, name: '采购商品' },
|
|
{ icon: '/assets/image/ico_agent.png', badge: 0, name: '我要代卖' },
|
|
{ icon: '/assets/image/ico_index.png', badge: 0, name: '价格指数' },
|
|
{ icon: '/assets/image/ico_price.png', badge: 0, name: '实时价格' },
|
|
{ icon: '/assets/image/ico_queue.png', badge: 0, name: '车辆排队' }
|
|
],
|
|
tabList: [ '卖废纸', '买废纸', '代卖' ],
|
|
tabIndex: 0,
|
|
loading: [true, true, true],
|
|
requesting: [false, false, false],
|
|
finished: [false, false, false],
|
|
form: [{ isOnlySupplyProduct: true, pageNum: 1 }, { pageNum: 1 }, { pageNum: 1, enableSalesAgent: 1 }],
|
|
orderList: [],
|
|
orderList1: [],
|
|
orderList2: []
|
|
},
|
|
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,
|
|
stickyTop: app.globalData.CustomBar,
|
|
firstShow: true
|
|
})
|
|
this.onRefreshList()
|
|
}
|
|
this.data.firstShow = true
|
|
if(!this.data.bannerList.length){
|
|
getBannerList(1).then(result => {
|
|
this.setData({ bannerList: result.data })
|
|
}).catch(err => {
|
|
})
|
|
}
|
|
if(!this.data.noticeList.length){
|
|
this.fetchNoticeList()
|
|
}
|
|
},
|
|
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()
|
|
}
|
|
if(message.what == 1001){
|
|
this.setData({ kg: app.globalData.kg })
|
|
}
|
|
},
|
|
stopTouchMove: function(e){
|
|
return false
|
|
},
|
|
onFixedChange: function({detail}){
|
|
this.data.fixed = detail.fixed
|
|
},
|
|
onScroll: function({detail}) {
|
|
this.setData({ scrollTop: detail.scrollTop })
|
|
},
|
|
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)
|
|
},
|
|
onGridTap: function(e){
|
|
var index = e.currentTarget.dataset.index
|
|
if (index === 0) {
|
|
util.navigateTo('/pages/goods/ablility/index')
|
|
} else if (index === 1) {
|
|
util.navigateTo('/pages/purchase/ability/index')
|
|
} else if (index === 2) {
|
|
util.navigateTo('/pages/agent/index/index')
|
|
} else if (index === 3) {
|
|
util.navigateTo('/pages/mall/price-index/index')
|
|
} else if (index === 4) {
|
|
util.navigateTo('/pages/article/price-detail/index')
|
|
} else if (index === 5) {
|
|
util.navigateTo('/pages/article/queue-detail/index')
|
|
}
|
|
},
|
|
onTabChange: function({detail}){
|
|
if(this.data.tabIndex == Number(detail.index)){
|
|
return
|
|
}
|
|
if(this.data.fixed){
|
|
this.setData({ tabIndex: parseInt(detail.index), toView: 'sticky' })
|
|
} else {
|
|
this.setData({ tabIndex: parseInt(detail.index) })
|
|
}
|
|
if(this.data.tabIndex == 0 && !this.data.orderList.length){
|
|
this.fetchGoodsList()
|
|
} else if(this.data.tabIndex == 1 && !this.data.orderList1.length){
|
|
this.fetchPurchaseList()
|
|
} else if(this.data.tabIndex == 2 && !this.data.orderList2.length){
|
|
this.fetchAgentList()
|
|
}
|
|
},
|
|
fetchNoticeList: function(){
|
|
if (this.data.loopRequesting) {
|
|
return
|
|
}
|
|
this.data.loopRequesting = true
|
|
getSuccessNotices().then(result => {
|
|
this.data.loopRequesting = false
|
|
this.data.noticeList = []
|
|
if(result.data && result.data.length){
|
|
for (let index = 0; index < result.data.length; index++) {
|
|
this.data.noticeList.push(result.data[index].msg)
|
|
}
|
|
this.setData({noticeList: this.data.noticeList})
|
|
}
|
|
}).catch(err => {
|
|
this.data.loopRequesting = false
|
|
})
|
|
},
|
|
onRefreshList: function () {
|
|
if(this.data.tabIndex == 0){
|
|
this.setData({
|
|
orderList: [],
|
|
['form[' + this.data.tabIndex + '].pageNum']: 1,
|
|
['loading[' + this.data.tabIndex + ']']: true,
|
|
['finished[' + this.data.tabIndex + ']']: false
|
|
})
|
|
this.fetchGoodsList()
|
|
} else if(this.data.tabIndex == 1){
|
|
this.setData({
|
|
orderList1: [],
|
|
['form[' + this.data.tabIndex + '].pageNum']: 1,
|
|
['loading[' + this.data.tabIndex + ']']: true,
|
|
['finished[' + this.data.tabIndex + ']']: false
|
|
})
|
|
this.fetchPurchaseList()
|
|
} else if(this.data.tabIndex == 2){
|
|
this.setData({
|
|
orderList2: [],
|
|
['form[' + this.data.tabIndex + '].pageNum']: 1,
|
|
['loading[' + this.data.tabIndex + ']']: true,
|
|
['finished[' + this.data.tabIndex + ']']: false
|
|
})
|
|
this.fetchAgentList()
|
|
}
|
|
|
|
},
|
|
fetchMoreList: function(){
|
|
if(this.data.tabIndex == 0){
|
|
this.fetchGoodsList()
|
|
} else if(this.data.tabIndex == 1){
|
|
this.fetchPurchaseList()
|
|
} else if(this.data.tabIndex == 2){
|
|
this.fetchAgentList()
|
|
}
|
|
},
|
|
//*************************************************fetchGoodsList************************************************//
|
|
fetchGoodsList: function () {
|
|
if (this.data.requesting[this.data.tabIndex] || this.data.finished[this.data.tabIndex]) {
|
|
return
|
|
}
|
|
if (this.data.loading[this.data.tabIndex]) {
|
|
this.data.requesting[this.data.tabIndex] = true
|
|
} else {
|
|
this.setData({ ['requesting[' + this.data.tabIndex + ']']: true })
|
|
}
|
|
getMiniProxyList(this.data.form[0]).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[0].pageNum']: (num + 1),
|
|
['finished[0]']: finished,
|
|
['requesting[0]']: false,
|
|
['loading[0]']: false
|
|
})
|
|
} else {
|
|
this.setData({
|
|
['finished[0]']: true,
|
|
['requesting[0]']: false,
|
|
['loading[0]']: false
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
this.setData({
|
|
['requesting[0]']: false,
|
|
['finished[0]']: true,
|
|
['loading[0]']: false
|
|
})
|
|
})
|
|
},
|
|
//*************************************************fetchPurchaseList************************************************//
|
|
fetchPurchaseList: function () {
|
|
if (this.data.requesting[1] || this.data.finished[1]) {
|
|
return
|
|
}
|
|
if (this.data.loading[1]) {
|
|
this.data.requesting[1] = true
|
|
} else {
|
|
this.setData({ ['requesting[1]']: true })
|
|
}
|
|
getProductList(this.data.form[1]).then(result => {
|
|
//成功回调
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList1[${this.data.orderList1.length}]`
|
|
var num = result.data.current
|
|
var finished = result.data.current >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form[1].pageNum']: (num + 1),
|
|
['finished[1]']: finished,
|
|
['requesting[1]']: false,
|
|
['loading[1]']: false
|
|
})
|
|
} else {
|
|
this.setData({
|
|
['requesting[1]']: false,
|
|
['finished[1]']: true,
|
|
['loading[1]']: false
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({
|
|
['requesting[1]']: false,
|
|
['finished[1]']: true,
|
|
['loading[1]']: false
|
|
})
|
|
})
|
|
},
|
|
//*************************************************fetchAgentList************************************************//
|
|
// 获取特价列表
|
|
fetchAgentList: function () {
|
|
if (this.data.requesting[2] || this.data.finished[2]) {
|
|
return
|
|
}
|
|
if (this.data.loading[2]) {
|
|
this.data.requesting[2] = true
|
|
} else {
|
|
this.setData({ ['requesting[2]']: true })
|
|
}
|
|
getFactoryPrice(this.data.form[2]).then(result => {
|
|
if (result.data.records.length) {
|
|
var respList = result.data.records
|
|
let nowList = `orderList2[${this.data.orderList2.length}]`
|
|
var num = result.data.current
|
|
var finished = result.data.current >= result.data.pages
|
|
this.setData({
|
|
[nowList]: respList,
|
|
['form[2].pageNum']: (num + 1),
|
|
['finished[2]']: finished,
|
|
['requesting[2]']: false,
|
|
['loading[2]']: false
|
|
})
|
|
} else {
|
|
this.setData({
|
|
['requesting[2]']: false,
|
|
['finished[2]']: true,
|
|
['loading[2]']: false
|
|
})
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
this.setData({
|
|
['requesting[2]']: false,
|
|
['finished[2]']: true,
|
|
['loading[2]']: false
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
})
|