supermama.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // pages/supermama/supermama.js
  2. const app = getApp()
  3. const util = require("../../utils/util.js");
  4. Page({
  5. data: {
  6. isFullSucreen: app.globalData.isFullSucreen ? true : false, //判断机型
  7. stepIcon: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/box.png', // 进度条礼物盒-关闭
  8. stepIconO: 'https://yuesuo.yueguanjia.com/MiniProgram/images/phaseI/boxOpen.png', // 进度条礼物盒-打开
  9. process: 0,
  10. info: {}, // 超人信息
  11. showGift: false, // 显示礼品弹窗
  12. giftData: {}, // 礼物弹窗信息
  13. taskNum: 0, // 待完成任务
  14. isFirst: '',
  15. loaddisplay: true,
  16. isSet: false,
  17. currentmama: 0
  18. },
  19. onLoad: function(options) {
  20. this.setData({
  21. navH: app.globalData.navHeight
  22. })
  23. let xu_content_type = wx.getStorageSync('xu_content_type');
  24. if (xu_content_type == 'B01') {
  25. this.setData({
  26. isSet: true
  27. })
  28. }
  29. },
  30. // 生命周期函数--监听页面显示
  31. onShow: function() {
  32. if (wx.getStorageSync('branche_name') == '北京') {
  33. wx.reLaunch({
  34. url: '/pages/yuesuo/yuesuo'
  35. })
  36. return
  37. }
  38. var isFirst = wx.getStorageSync('isFirst');
  39. const _this = this;
  40. wx.checkSession({
  41. success(res) { //已经登陆
  42. app.setUserInfo().then(() => {
  43. _this.getInfo();
  44. });
  45. }
  46. })
  47. },
  48. //微信登陆及手机号授权
  49. toLoginAuthorization: function() {
  50. return new Promise((resolve, reject) => {
  51. app.checkSession().then(res => {
  52. app.ifAuthorization();
  53. resolve();
  54. });
  55. })
  56. },
  57. //点击加入
  58. setNotFirst: function() {
  59. const _this = this
  60. _this.setData({
  61. isFirst: 1
  62. });
  63. wx.setStorageSync('isFirst', 1)
  64. app.checkSession({
  65. fromwhere: 'mama'
  66. }).then(res => {
  67. util.postData('/college/enableCollege?openid=' + app.globalData.openid, {});
  68. _this.getInfo({
  69. shouldphone: true
  70. });
  71. }); //第一次进来就是没登陆所以不进入then
  72. },
  73. // 获取列表数据
  74. getInfo: function(shouldphone) {
  75. let _this = this;
  76. util.postData('/college/queryUserPoints', {
  77. openid: app.globalData.openid,
  78. city: wx.getStorageSync('branche_code')
  79. }).then(res => {
  80. if (res.errStatus * 1 != 9) {
  81. //开启过,收到设置页面展示
  82. _this.setData({
  83. isFirst: 1
  84. });
  85. wx.setStorageSync('isFirst', 1)
  86. }
  87. if (res.stage) {
  88. _this.compontsNum(res)
  89. _this.setData({
  90. info: res,
  91. loaddisplay: 'none',
  92. nickName: app.globalData.userInfo ? app.globalData.userInfo.nickName : ''
  93. })
  94. _this.setProcess(res.credit, res.present_received)
  95. if (res.surprise) {
  96. if (res.surprise_type == 1) {
  97. _this.openGift(res.credit, 'fn')
  98. } else {
  99. // 实物
  100. }
  101. }
  102. _this.setData({
  103. currentmama: 0
  104. })
  105. for (var i = 0; i < res.present_received.length; i++) {
  106. if (res.present_received[i].received == 1) {
  107. _this.setData({
  108. currentmama: _this.data.currentmama + 1
  109. })
  110. }
  111. }
  112. } else if (res.errStatus * 1 == 6) {
  113. // if (shouldphone && shouldphone.shouldphone) {
  114. app.ifAuthorization();
  115. // }
  116. } else if (res.errStatus * 1 == 5) {
  117. //开启过,收到设置页面展示
  118. _this.toLoginAuthorization().then(res => {
  119. wx.navigateTo({
  120. url: '/pages/select/select'
  121. })
  122. });
  123. }
  124. })
  125. },
  126. babyBorn() {
  127. wx.navigateTo({
  128. url: '/pages/select/select?page=babyBorn'
  129. })
  130. },
  131. // 计算已完成、待完成任务的数量
  132. compontsNum: function(res) {
  133. let ing = {
  134. all: 0
  135. },
  136. end = {
  137. all: 0
  138. };
  139. ['college_core', 'college_practice', 'college_experience'].forEach(o => {
  140. ing[o] = 0;
  141. end[o] = 0;
  142. if (res[o] && res[o].length > 0) {
  143. res[o].map(item => {
  144. if (item.status != '已完成' && item.learningStatus != '已过期') {
  145. ing.all += 1;
  146. ing[o] += 1;
  147. } else {
  148. end.all += 1;
  149. end[o] += 1;
  150. }
  151. })
  152. }
  153. })
  154. this.setData({
  155. taskNum: ing,
  156. taskEnd: end
  157. })
  158. },
  159. goRule() {
  160. wx.navigateTo({
  161. url: '/pages/supermama/rules/rules'
  162. });
  163. },
  164. // 计算分数进度条的百分比
  165. setProcess: function(credit, arr) {
  166. let i = this.getPresentInd(credit, arr)
  167. let preCredit = arr[i].value
  168. let nextCredit = arr[i + 1].value
  169. let a = i / (arr.length - 1)
  170. let b = (credit - preCredit) / (nextCredit - preCredit) * (1 / (arr.length - 1))
  171. this.setData({
  172. process: (a + b) * 0.8 * 100 > 80 ? 80 : (a + b) * 0.8 * 100
  173. })
  174. },
  175. // 获取分数在礼物进度中的位置下标
  176. getPresentInd: function(credit, arr) {
  177. let ind = null;
  178. if (arr && arr.length > 0) {
  179. for (let i = 0; i < arr.length - 1; i++) {
  180. if (credit >= arr[i].value && credit < arr[i + 1].value) {
  181. ind = i;
  182. break;
  183. }
  184. }
  185. }
  186. if (ind != null) {
  187. return ind
  188. } else {
  189. return 0
  190. }
  191. },
  192. // 设置礼物弹窗参数并展示
  193. openGift: function(event, type = 'tap') {
  194. let arr = this.data.info.present_received,
  195. o;
  196. if (type == 'tap') {
  197. o = arr[event.currentTarget.dataset['ind']]
  198. } else if (type == 'fn') {
  199. let ind = this.getPresentInd(event, arr)
  200. o = arr[ind]
  201. }
  202. if (type == 'fn' || o.received == 1) {
  203. this.setData({
  204. giftData: {
  205. isReady: true,
  206. one: '恭喜您',
  207. two: '升级为' + o.name,
  208. surprise_name: type == 'fn' ? this.data.info.surprise_name : o.present_name
  209. },
  210. showGift: true
  211. })
  212. } else {
  213. this.setData({
  214. giftData: {
  215. isReady: false,
  216. one: '学分达' + o.value + '分',
  217. two: '将成为' + o.name,
  218. surprise_name: o.present_name
  219. },
  220. showGift: true
  221. })
  222. }
  223. },
  224. // 关闭弹窗
  225. closeGift: function() {
  226. this.setData({
  227. showGift: false
  228. })
  229. this.getInfo()
  230. }
  231. })