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.

99 lines
2.7 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
},
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) {
const row = e.currentTarget.dataset.row;
wx.setStorageSync('sBrand', row.brandname);
},
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)
})
}
});