// pages/varComm/pages/addEvent/index.js const app = getApp() Page({ /** * 页面的初始数据 */ data: { active: 0, result: [], themeList: [], themeData: [], issList: [], titleList: [{ title: '我的主题', index: 0, active: true }, { title: '往期主题', index: 1, active: false }] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.getData() if (options.switchTheme) { let switchTheme = JSON.parse(options.switchTheme) this.setData({ switchTheme }) } }, onUnload() { if (this.data.switchTheme) { this.back('switch') } }, changeTitle(e) { let index = e.currentTarget.dataset.index let arr = this.data.titleList for (let [index1, i] of arr.entries()) { if (index1 == index) { i.active = true } else { i.active = false } } this.setData({ titleList: arr, active: index }) }, onChange(event) { const { detail } = event let themeData = [] for (let i of detail) { themeData.push(JSON.parse(i)) } themeData.len = 6 this.setData({ result: detail, themeData, }) wx.setStorageSync('themeData', themeData) this.setData({ hasAdd:true }) this.back('add') }, back(type) { if (type == 'add') { wx.navigateBack({ delta: 1, }) } else if (type == "switch" && !this.data.hasAdd) { console.log("执行切换"); let { themeData } = this.data themeData.push(this.data.switchTheme) wx.setStorageSync('themeData', themeData) } }, getData() { let themeData = wx.getStorageSync('themeData') let result = [] themeData.forEach(ele => { if (ele) result.push(JSON.stringify(ele)), this.data.themeData.push(ele) }) this.setData({ result }) app.globalData.request({ action: 'getSchemeDataToTheme', token: wx.getStorageSync('token'), sType: 'contrast' }).then(res => { for (let i of themeData) { if (i) { for (let j = 0; j < res.length; j++) { if (i.Id == res[j].Id) { res.splice(j, 1) } } } } this.setData({ themeList: res }) }) app.globalData.request({ action: 'getSchemeDataToTheme', token: wx.getStorageSync('token'), sType: 'former' }).then(res => { this.setData({ issList: res }) }) } })