Commit a77f0c1d authored by wangxuelai's avatar wangxuelai

''

parent 02cbcf6a
......@@ -13,13 +13,67 @@ Page({
imageRoot: app.globalData.imageRoot,
imageVersion: app.globalData.imageVersion,
localImageRoot: '../../../images/',
sid: 0,
params: {
'1': { // 打卡
single: 1,
daily_limit: 1,
isUnlimit: 0 // 0 不是无限 1 无限
},
'2': { // 点赞别人
single: 2,
daily_limit: 2,
isUnlimit: 0 // 0 不是无限 1 无限
},
'3': { // 评论别人
single: 3,
daily_limit: 3,
isUnlimit: 0 // 0 不是无限 1 无限
},
'4': { // 转发打卡
single: 4,
daily_limit: 4,
isUnlimit: 0 // 0 不是无限 1 无限
},
'5': { // 被点赞
single: 5,
daily_limit: 5,
isUnlimit: 0 // 0 不是无限 1 无限
},
'6': { // 被围观
single: 6,
daily_limit: 6,
isUnlimit: 0 // 0 不是无限 1 无限
},
'7': { // 打卡被转发
single: 7,
daily_limit: 7,
isUnlimit: 0 // 0 不是无限 1 无限
},
'8': { // 被评论
single: 8,
daily_limit: 8,
isUnlimit: 0 // 0 不是无限 1 无限
},
'9': { // 被点评
single: 9,
daily_limit: 9,
isUnlimit: 0 // 0 不是无限 1 无限
}
},
addOrUpdate: 'add',
submitting: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
const {sid} = options;
this.setData({
sid
})
this.integralRulesShow();
},
/**
......@@ -63,11 +117,96 @@ Page({
onReachBottom: function () {
},
submit () {
this.data.submitting = true;
if (this.data.submitting) {
return
}
wx.showLoading({
title: '积分保存中...'
})
const params = JSON.parse(JSON.stringify(this.data.params));
for (let i in params) {
if (params[i].isUnlimit == 1) {
params[i].daily_limit = -1;
}
if (params[i].daily_limit == '') {
params[i].daily_limit = 0;
}
if (params[i].single == '') {
params[i].single = 0;
}
params[i].school_id = this.data.sid;
delete params[i].isUnlimit;
}
let ajax = null;
if (this.data.addOrUpdate == 'add') {
ajax = integralRulesAdd;
} else if (this.data.addOrUpdate == 'update') {
ajax = integralRulesUpdate;
}
ajax({
data: JSON.stringify(params)
}).then((res) => {
const {data, code} = res;
wx.hideLoading();
if (code == 200) {
wx.showToast({
title: '积分规则保存成功'
})
}
})
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
},
integralRulesShow () {
integralRulesShow({
school_id: this.data.sid
}).then((res) => {
const {code, data} = res;
if(code == 200) {
if (data.list.length > 0) {
this.data.addOrUpdate = 'update';
data.list.forEach((ele) => {
if (ele.daily_limit == -1) {
this.setData({
[`params.${ele.type}`]: {
daily_limit: 0,
single: ele.single,
isUnlimit: 1
}
})
} else {
this.setData({
[`params.${ele.type}`]: {
daily_limit: ele.daily_limit,
single: ele.single,
isUnlimit: 0
}
})
}
})
} else {
this.data.addOrUpdate = 'add';
}
}
})
},
selectUnLimit (e) {
const {dataset} = e.currentTarget;
let isUnlimit = `params.${dataset.type}.isUnlimit`
if (this.data.params[dataset.type].isUnlimit == 0) {
this.setData({
[isUnlimit]: 1
})
} else {
this.setData({
[isUnlimit]: 0
})
}
}
})
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment