7 changed files with 122 additions and 5 deletions
Split View
Diff Options
-
7pages/api/moment.js
-
1pages/api/ztb.js
-
7pages/mall/price-index/index.js
-
95pages/moment/paper/index.js
-
6pages/moment/paper/index.json
-
10pages/moment/paper/index.wxml
-
1pages/moment/paper/index.wxss
@ -0,0 +1,95 @@ |
|||
// pages/moment/paper/index.js
|
|||
import { getCategoryList } from "../../api/moment" |
|||
const util = require('../../../utils/util') |
|||
const storage = require('../../../utils/storage') |
|||
const event = require('../../../utils/event.js') |
|||
const app = getApp() |
|||
|
|||
Page({ |
|||
/** |
|||
* 页面的初始数据 |
|||
*/ |
|||
data: { |
|||
categoryList: [], |
|||
cateIds: null, |
|||
cateIdList: null |
|||
}, |
|||
/** |
|||
* 生命周期函数--监听页面加载 |
|||
*/ |
|||
onLoad: function (options) { |
|||
wx.showLoading({ |
|||
title: '加载中', |
|||
mask: true |
|||
}) |
|||
this.data.cateIds = storage.get('cateIdList' + app.globalData.userInfo.userId) |
|||
if(!util.isEmpty(this.data.cateIds)){ |
|||
this.data.cateIdList = this.data.cateIds.toString().split(',') |
|||
} |
|||
getCategoryList().then(result => { |
|||
//成功回调
|
|||
if(!util.isEmpty(this.data.cateIds)){ |
|||
for (let index = 0; index < result.data.records.length; index++) { |
|||
if(this.checkCategory(result.data.records[index].id)){ |
|||
result.data.records[index].checked = true |
|||
} |
|||
} |
|||
} |
|||
this.setData({categoryList: result.data.records}) |
|||
wx.hideLoading() |
|||
}).catch(err => { |
|||
//异常回调
|
|||
wx.hideLoading() |
|||
}) |
|||
}, |
|||
checkCategory: function(id){ |
|||
if(!this.data.cateIdList || !this.data.cateIdList.length){ |
|||
return false |
|||
} |
|||
for (let index = 0; index < this.data.cateIdList.length; index++) { |
|||
if(id == this.data.cateIdList[index]){ |
|||
return true |
|||
} |
|||
} |
|||
return false |
|||
}, |
|||
checkPaper: function(e) { |
|||
var index = e.target.dataset.index |
|||
var item = this.data.categoryList[index] |
|||
if(item.checked){ |
|||
this.setData({ ['categoryList[' + index + '].checked']: !item.checked}) |
|||
return |
|||
} |
|||
var sum = 0 |
|||
for (let i = 0; i < this.data.categoryList.length; i++) { |
|||
if(this.data.categoryList[i].checked){ |
|||
sum++ |
|||
} |
|||
} |
|||
if(sum >= 5){ |
|||
util.showToast('最多只能关注5个纸品') |
|||
return |
|||
} |
|||
this.setData({ ['categoryList[' + index + '].checked']: !item.checked}) |
|||
}, |
|||
onUnload: function(){ |
|||
var cateString = '' |
|||
for (let i = 0; i < this.data.categoryList.length; i++) { |
|||
if(this.data.categoryList[i].checked){ |
|||
if(util.isEmpty(cateString)){ |
|||
cateString = this.data.categoryList[i].id |
|||
} else { |
|||
cateString += ',' + this.data.categoryList[i].id |
|||
} |
|||
} |
|||
} |
|||
if(util.isEmpty(cateString) && util.isEmpty(this.data.cateIds)){ |
|||
return |
|||
} |
|||
if(cateString != this.data.cateIds){ |
|||
storage.put('cateIdList' + app.globalData.userInfo.userId, cateString) |
|||
event.emit('EventMessage', { what: 502, desc: 'CateChange' }) |
|||
} |
|||
} |
|||
|
|||
}) |
|||
@ -0,0 +1,6 @@ |
|||
{ |
|||
"usingComponents": { |
|||
"wux-cell-group": "/components/cell-group/index", |
|||
"wux-cell": "/components/cell/index" |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
<!--pages/moment/paper/index.wxml--> |
|||
<cu-custom bgColor="bg-white" isBack="{{true}}"> |
|||
<view slot="content">纸品列表</view> |
|||
</cu-custom> |
|||
<wux-cell-group> |
|||
<wux-cell wx:for="{{categoryList}}" wx:key="index" title="{{item.name}}" data-index="{{index}}" bind:click="checkPaper"> |
|||
<image slot="footer" style="width:48rpx;height:48rpx;" src="/assets/image/ico_checked.png" wx:if="{{item.checked}}"></image> |
|||
<image slot="footer" style="width:48rpx;height:48rpx;" src="/assets/image/ico_uncheck.png" wx:else></image> |
|||
</wux-cell> |
|||
</wux-cell-group> |
|||
@ -0,0 +1 @@ |
|||
/* pages/moment/paper/index.wxss */ |
|||
Write
Preview
Loading…
Cancel
Save