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.
149 lines
2.9 KiB
149 lines
2.9 KiB
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
|
|
const app = getApp()
|
|
Page({
|
|
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
boxArr: new Array(6),
|
|
tabActive: 0,
|
|
result: [],
|
|
sonCom: true,
|
|
popupShow: false,
|
|
mockData: [],
|
|
tempLate: ['一', '二', '三', '四', '五', '六', ]
|
|
},
|
|
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad(options) {
|
|
this.setData({
|
|
boxArr: wx.getStorageSync('brandData'),
|
|
result: wx.getStorageSync('brandData').map(ele => {
|
|
return JSON.stringify(ele)
|
|
})
|
|
})
|
|
wx.setStorageSync('brandRatioTime', {
|
|
sTimeType: '34'
|
|
})
|
|
this.brandReq()
|
|
},
|
|
onUnload() {
|
|
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
|
|
}
|
|
for (let i of detail) {
|
|
result.push(JSON.parse(i))
|
|
}
|
|
result.length = 6
|
|
this.setData({
|
|
result: detail,
|
|
boxArr: result
|
|
})
|
|
},
|
|
changeTab(val) {
|
|
let n = val.detail.index;
|
|
this.setData({
|
|
tabActive: n
|
|
})
|
|
},
|
|
addBrand() {
|
|
this.setData({
|
|
popupShow: true
|
|
})
|
|
},
|
|
popupClose() {
|
|
this.setData({
|
|
popupShow: false
|
|
})
|
|
wx.setStorageSync('brandData', this.data.boxArr)
|
|
this.reLoad()
|
|
},
|
|
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('brandData', boxArr)
|
|
this.reLoad()
|
|
},
|
|
changeTime(event) {
|
|
let {
|
|
detail
|
|
} = event
|
|
wx.setStorageSync('brandRatioTime', detail)
|
|
this.reLoad()
|
|
},
|
|
//获取品牌
|
|
brandReq() {
|
|
app.globalData.request({
|
|
action: 'getUserBrand',
|
|
token: wx.getStorageSync('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
|
|
})
|
|
})
|
|
},
|
|
reLoad() {
|
|
this.setData({
|
|
sonCom: false
|
|
})
|
|
this.setData({
|
|
sonCom: true
|
|
})
|
|
}
|
|
}) |