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.

142 lines
3.9 KiB

// index.js
const app = getApp();
Page({
data: {
value: "",
tabActive: 0,
active: 1,
height:app.globalData.navBarHeight + app.globalData.statusBarHeight,
statusBarHeight:app.globalData.statusBarHeight,
navBarHeight:app.globalData.navBarHeight,
navData: [],
sourceData: [],
mockData: [],
heightTop: 210,
lastTime: 0,
showPop: false,
series: []
},
onLaunch() {
wx.getSystemInfo({
success: (res) => {
const ratio = 750 / res.windowWidth
const menuInfo = wx.getMenuButtonBoundingClientRect();
this.setData({
top: menuInfo.top * ratio ,
left: menuInfo.left * ratio ,
height: menuInfo.height * ratio ,
})
}
})
},
onShow() {
this.getTabBar().init();
this.getData();
this.createSelectorQuery().select(".nav-top").boundingClientRect(res => {
if (res) {
const { height } = res;
this.setData({
heightTop: height
})
}
}).exec();
},
handlerSearch(e) {
let val = e.detail;
const arr = this.data.sourceData.filter(ele => {
return ele.brandname.toLowerCase().indexOf(val.toLowerCase()) != -1
})
this.setData({
navData: arr
})
},
handlerChoose(e) {
let thisTime = e.timeStamp;
let lastTime = this.data.lastTime;
const row = e.currentTarget.dataset.row;
wx.setStorageSync('sBrand', row.brandname);
if (lastTime != 0 && thisTime - lastTime < 500) {
this.setData({
showPop: false
})
wx.switchTab({
url: "/pages/brandCrisis/index"
})
} else {
this.setData({
lastTime: thisTime,
showPop: true
})
this.getSeries(row.brandname);
}
},
handlerCloseDialog() {
this.setData({
showPop: false
})
},
handlerChooseS(e) {
const row = e.currentTarget.dataset.row;
wx.setStorageSync('sSeriesName', row.name);
wx.switchTab({
url: "/pages/brandCrisis/index"
})
},
getSeries(brandname) {
let obj = {
action: 'getUserSeriesName',
token: wx.getStorageSync('token') || 't%2BrswgjvzGM=',
sBrandName: brandname
}
app.globalData.request(obj).then(res => {
this.setData({
series: res
})
})
},
getData() {
//页面数据
wx.showToast({
title: '加载中',
icon: 'loading',
duration: 30000
})
app.globalData.request({
action: 'getUserBrand',
token: 't%2BrswgjvzGM=',
}).then(res => {
let arr = [];
for (let i = 65; i <= 90; i++) {
arr.push({
name: String.fromCharCode(i),
data: []
});
}
for(let i of res){
for(let j of arr){
if(i.firstword == j.name){
j.data.push(i)
}
}
}
let newArr = [];
let obj = {};
for (var i = 0; i < res.length; i++) {
if (!obj[res[i].brandid]) {
newArr.push(res[i])
obj[res[i].brandid] = true
}
}
this.setData({
mockData:arr,
navData: newArr,
sourceData: newArr
})
setTimeout(() => {
wx.hideToast();
}, 1000)
})
}
});