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.

129 lines
3.1 KiB

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