const app = getApp(); Component({ data: { brandList: [], modalList: [], popShow: false, currentBrand: '', history: [], queryname: '', alphalist: [], }, methods: { modalChoose(e) { let id = e.currentTarget.dataset.id; //获取点击的id app.globalData.request({ action: 'getUserSeriesName', token: wx.getStorageSync('token'), sBrandName: id }).then(res => { this.setData({ modalList: res, popShow: true, currentBrand: id, }) }); }, handlerSearch() { app.globalData.request({ action: 'getQueryrSeriesName', token: wx.getStorageSync('token'), queryname: this.data.queryname }).then(res => { //图片少了.png后缀 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){ let obj = { brandname: i.name, img: i.img+'.png', data: i.data, firstword: i.firstword } j.data.push(obj) } } }; this.setData({ brandList: arr }); }); }, toModalInsight(value) { let id = value.target.dataset.id; if(wx.getStorageSync('historyModal').length == 0) { let arr = [id]; wx.setStorageSync('historyModal', arr); this.setData({history: arr}) } else { if(wx.getStorageSync('historyModal').indexOf(id) == -1) { let newArr = [id, ...wx.getStorageSync('historyModal')]; wx.setStorageSync('historyModal', newArr); this.setData({history: newArr}) } else { let newArr = wx.getStorageSync('historyModal'); let index = wx.getStorageSync('historyModal').indexOf(id); newArr.splice(index, 1); let result = [id, ...newArr]; wx.setStorageSync('historyModal', result); this.setData({history: result}) } } app.globalData.request({ action: 'getBrandName', token: wx.getStorageSync('token'), sSeriesName: id }).then(res => { wx.setStorageSync('sBrand', res); }); wx.setStorageSync('sSeriesName', id); wx.navigateTo({ url: "/pages/insight/pages/modalInsight/index" }) }, onClose() { this.setData({ popShow: false }) }, onChange(e) { this.setData({queryname: e.detail}); } }, lifetimes: { attached() { if(wx.getStorageSync('historyModal')) { this.setData({history: wx.getStorageSync('historyModal')}) } //页面数据 app.globalData.request({ action: 'getUserBrand', token: wx.getStorageSync('token'), }).then(res => { let arr = []; let alphalist = []; res.forEach(ele => { if(ele.firstword != '热门' && alphalist.indexOf(ele.firstword) == -1) { alphalist.push(ele.firstword) } }); alphalist.forEach(ele => { arr.push({ name: ele, data: [] }); }); for(let i of res){ for(let j of arr){ if(i.firstword == j.name){ j.data.push(i) } } } this.setData({ alphalist: alphalist, brandList: arr }); }); }, }, })