index.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import util from '../../utils/util.js';
  2. import { postSignUser, getSignConfig, getSignList, setSignIntegral} from '../../api/user.js';
  3. import { setFormId } from '../../api/api.js';
  4. const app=getApp();
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. parameter: {
  11. 'navbar': '1',
  12. 'return': '1',
  13. 'title': '签到',
  14. 'color': true,
  15. 'class':'0'
  16. },
  17. active:false,
  18. userInfo:{},
  19. signCount:[],
  20. signSystemList:[],
  21. signList:[],
  22. integral:0,
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad: function (options) {
  28. },
  29. /**
  30. * 授权回调
  31. */
  32. onLoadFun:function(){
  33. this.getUserInfo();
  34. this.getSignSysteam();
  35. this.getSignList();
  36. },
  37. /**
  38. * 获取签到配置
  39. */
  40. getSignSysteam:function(){
  41. var that=this;
  42. getSignConfig().then(res=>{
  43. that.setData({ signSystemList: res.data, day: that.Rp(res.data.length) });
  44. })
  45. },
  46. /**
  47. * 去签到记录页面
  48. *
  49. */
  50. goSignList:function(){
  51. return app.Tips('/pages/user_sgin_list/index');
  52. },
  53. /**
  54. * 获取用户信息
  55. */
  56. getUserInfo:function(){
  57. var that=this;
  58. postSignUser({ sign: 1 }).then(res=>{
  59. res.data.integral = parseInt(res.data.integral);
  60. var sum_sgin_day = res.data.sum_sgin_day;
  61. that.setData({ userInfo: res.data, signCount: that.PrefixInteger(sum_sgin_day, 4), sign_index: res.data.sign_num });
  62. });
  63. },
  64. /**
  65. * 获取签到列表
  66. *
  67. */
  68. getSignList:function(){
  69. var that=this;
  70. getSignList({page:1,limit:3}).then(res=>{
  71. that.setData({ signList: res.data });
  72. })
  73. },
  74. /**
  75. * 数字转中文
  76. *
  77. */
  78. Rp: function (n) {
  79. var cnum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  80. var s = '';
  81. n = '' + n; // 数字转为字符串
  82. for (var i = 0; i < n.length; i++) {
  83. s += cnum[parseInt(n.charAt(i))];
  84. }
  85. return s;
  86. },
  87. /**
  88. * 数字分割为数组
  89. * @param int num 需要分割的数字
  90. * @param int length 需要分割为n位数组
  91. */
  92. PrefixInteger: function (num, length) {
  93. return (Array(length).join('0') + num).slice(-length).split('');
  94. },
  95. /**
  96. * 用户签到
  97. */
  98. goSign:function(e){
  99. let that = this, sum_sgin_day = that.data.userInfo.sum_sgin_day;
  100. if (that.data.userInfo.is_day_sgin) return app.Tips({title:'您今日已签到!'});
  101. setSignIntegral().then(res=>{
  102. that.setData({
  103. active: true,
  104. integral: res.data.integral,
  105. sign_index: (that.data.sign_index + 1) > that.data.signSystemList.length ? 1 : that.data.sign_index + 1,
  106. signCount: that.PrefixInteger(sum_sgin_day + 1, 4),
  107. 'userInfo.is_day_sgin': true,
  108. 'userInfo.integral': util.$h.Add(that.data.userInfo.integral, res.data.integral)
  109. });
  110. that.getSignList();
  111. }).catch(err=>{
  112. return app.Tips({title:err})
  113. });
  114. },
  115. /**
  116. * 关闭签到提示
  117. */
  118. close:function(){
  119. this.setData({active: false});
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom: function () {
  125. }
  126. })