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.
61 lines
1.9 KiB
61 lines
1.9 KiB
// pages/message/detail/index.js
|
|
import Scene from '../../index/scene'
|
|
import { getAllFactoryList, userPushFollowMill } from "../../../api/ztb"
|
|
const event = require('../../../utils/event')
|
|
const util = require('../../../utils/util')
|
|
const storage = require('../../../utils/storage')
|
|
const app = getApp()
|
|
|
|
Scene({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
height: app.globalData.fragmentHeight,
|
|
safeBottom: app.globalData.safeBottom,
|
|
factoryList: null,
|
|
form:{
|
|
follow: true,
|
|
paperMillIds: []
|
|
}
|
|
},
|
|
/**
|
|
* 生命周期函数--监听页面加载
|
|
*/
|
|
onLoad: function (options) {
|
|
var attString = storage.get('AttentionList' + app.userInfo.userId)
|
|
if(!util.isEmpty(attString)){
|
|
this.setData({ safeBottom: app.globalData.safeBottom, height: app.globalData.fragmentHeight, ['form.paperMillIds']: attString.split(',') })
|
|
} else {
|
|
this.setData({ safeBottom: app.globalData.safeBottom, height: app.globalData.fragmentHeight })
|
|
}
|
|
getAllFactoryList().then(result => {
|
|
this.setData({ factoryList: result.data })
|
|
}).catch(err => {
|
|
})
|
|
},
|
|
onChange: function(event) {
|
|
this.setData({ ['form.paperMillIds']: event.detail });
|
|
},
|
|
toggle: function(event) {
|
|
const { index } = event.currentTarget.dataset
|
|
const checkbox = this.selectComponent(`.checkboxes-${index}`)
|
|
checkbox.toggle()
|
|
},
|
|
noop: function() {},
|
|
submitForm: function(){
|
|
if(this.data.form.paperMillIds.length == 0){
|
|
util.showToast('请选择关注的纸厂')
|
|
return
|
|
}
|
|
wx.showLoading({ title: '正在获取', mask: true })
|
|
userPushFollowMill(this.data.form).then(result => {
|
|
wx.hideLoading()
|
|
storage.put('AttentionList' + app.userInfo.userId, this.data.form.paperMillIds.toString())
|
|
event.emit('EventMessage', { what: 110, desc: 'attentionPaperList' })
|
|
util.showBackToast('设置成功')
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
})
|
|
}
|
|
})
|