// pages/varComm/pages/brandRatio/index.js import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog'; const app = getApp() Page({ /** * 页面的初始数据 */ data: { boxArr: new Array(6), tabActive: 0, sonCom: true, popupShow: false, popupShow2: false, result: [], mockData: [], sBrand: [], tempLate: ['一', '二', '三', '四', '五', '六', ] }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { app.globalData.request({ action: 'getUserBrand', token: app.globalData.getStorage('token'), }).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) } } } this.setData({ mockData: arr }) }) this.setData({ boxArr: wx.getStorageSync('modelsData'), sBrand: wx.getStorageSync('sBrand'), result: wx.getStorageSync('modelsData').map(ele => { return JSON.stringify(ele) }) }) wx.setStorageSync('brandRatioTime', { sTimeType: '34' }) }, onChange(event) { this.triggerEvent('hide') const { detail } = event const result = [] for (let i = 0; i <= detail.length; i++) { if (detail[i] == 'null') detail.splice(i, 1), i-- } if (detail.length > 6) { Dialog.alert({ message: '至多六个', context: this }) return } let sBrand = [] for (let i of detail) { let item = JSON.parse(i) result.push(item) sBrand.push(item.brand) } result.length = 6 this.setData({ result: detail, boxArr: result, sBrand }) }, changeTab(val) { let n = val.detail.index; this.setData({ tabActive: n }) }, addcarModels() { this.setData({ popupShow: true }) }, popupClose() { this.setData({ popupShow: false }) wx.setStorageSync('modelsData', this.data.boxArr) wx.setStorageSync('sBrand', this.data.sBrand) this.reLoad() }, onClose2() { this.setData({ popupShow2: false }) }, del(e) { this.triggerEvent('hide') let filter = this.data.result.filter(ele => { return ele != "null" }) if (filter.length == 2) { Dialog.alert({ message: '至少需要两个车型才可以对比哦!', context: this }) return } let index = e.currentTarget.dataset.index let result = [...this.data.result] let boxArr = [] result.splice(index, 1) for (let i of result) { boxArr.push(JSON.parse(i)) } boxArr.length = 6 this.setData({ result: result, boxArr: boxArr }) wx.setStorageSync('modelsData', this.data.boxArr) this.reLoad() }, modalChoose(e) { let id = e.currentTarget.dataset.id; //获取点击的id app.globalData.request({ action: 'getUserSeriesName', token: app.globalData.getStorage('token'), sBrandName: id }).then(res => { for (let i of res) { i.brand = id } this.setData({ modalList: res, popupShow2: true, currentBrand: id, }) }); }, changeTime(event) { let { detail } = event wx.setStorageSync('brandRatioTime', detail) this.reLoad() }, reLoad() { this.setData({ sonCom: false }) this.setData({ sonCom: true }) } })