123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import util from '../../utils/util.js';
- import { postSignUser, getSignConfig, getSignList, setSignIntegral} from '../../api/user.js';
- import { setFormId } from '../../api/api.js';
- const app=getApp();
- Page({
-
- data: {
- parameter: {
- 'navbar': '1',
- 'return': '1',
- 'title': '签到',
- 'color': true,
- 'class':'0'
- },
- active:false,
- userInfo:{},
- signCount:[],
- signSystemList:[],
- signList:[],
- integral:0,
- },
-
- onLoad: function (options) {
-
- },
-
- onLoadFun:function(){
- this.getUserInfo();
- this.getSignSysteam();
- this.getSignList();
- },
-
- getSignSysteam:function(){
- var that=this;
- getSignConfig().then(res=>{
- that.setData({ signSystemList: res.data, day: that.Rp(res.data.length) });
- })
- },
-
- goSignList:function(){
- return app.Tips('/pages/user_sgin_list/index');
- },
-
- getUserInfo:function(){
- var that=this;
- postSignUser({ sign: 1 }).then(res=>{
- res.data.integral = parseInt(res.data.integral);
- var sum_sgin_day = res.data.sum_sgin_day;
- that.setData({ userInfo: res.data, signCount: that.PrefixInteger(sum_sgin_day, 4), sign_index: res.data.sign_num });
- });
- },
-
- getSignList:function(){
- var that=this;
- getSignList({page:1,limit:3}).then(res=>{
- that.setData({ signList: res.data });
- })
- },
-
- Rp: function (n) {
- var cnum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
- var s = '';
- n = '' + n;
- for (var i = 0; i < n.length; i++) {
- s += cnum[parseInt(n.charAt(i))];
- }
- return s;
- },
-
- PrefixInteger: function (num, length) {
- return (Array(length).join('0') + num).slice(-length).split('');
- },
-
- goSign:function(e){
- let that = this, sum_sgin_day = that.data.userInfo.sum_sgin_day;
- if (that.data.userInfo.is_day_sgin) return app.Tips({title:'您今日已签到!'});
- setSignIntegral().then(res=>{
- that.setData({
- active: true,
- integral: res.data.integral,
- sign_index: (that.data.sign_index + 1) > that.data.signSystemList.length ? 1 : that.data.sign_index + 1,
- signCount: that.PrefixInteger(sum_sgin_day + 1, 4),
- 'userInfo.is_day_sgin': true,
- 'userInfo.integral': util.$h.Add(that.data.userInfo.integral, res.data.integral)
- });
- that.getSignList();
- }).catch(err=>{
- return app.Tips({title:err})
- });
- },
-
- close:function(){
- this.setData({active: false});
- },
-
- onReachBottom: function () {
- }
- })
|