// pages/hobbyPicking/hobbyPicking.js const { getCategoryAPI,initRecommend } = require('../../API/appraise') var clientWidth = wx.getSystemInfoSync().windowWidth; Page({ /** * 页面的初始数据 */ data: { classifyList: [], left:clientWidth/2-40+'px' }, //获取点击分类的id detailClassifyTo({ currentTarget }) { const id = currentTarget.dataset.num; const title = currentTarget.dataset.title; wx.navigateTo({ url: '/pages/classify_detail/classify_detail?classify_id=' + id + '&title=' + title, }) }, /** * 生命周期函数--监听页面加载 */ onLoad(options) { this.getClassifyList(); }, getClassifyList() { getCategoryAPI(this.data) .then((res) => { const { code, data, mesage } = res.data; data.map((item)=>{ console.log(item); item['checked'] = false; }) this.setData({ classifyList: data }) }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, onHobbyChange:function(e) { let $id = e.currentTarget.dataset.id; let _this = this.data; _this.classifyList.map((item) => { if(item.Id === $id) { item.checked = e.detail; } }) this.setData({ classifyList:_this.classifyList }) }, initRecommendTap:function(e) { let _this = this.data; let cIds = [];//分类Id(用户选择) for(let i of _this.classifyList) { if(i.checked === true) { cIds.push(i.Id); } } let initRecommendOption = { cIds:cIds, uid:wx.getStorageSync('uid') } initRecommend(initRecommendOption).then((res) => { console.log(res); wx.switchTab({ url: '/pages/home/home', }) }).catch((err) => { console.log(err); }) } })