dare.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. var util = require("../../utils/helper.js"),
  2. utils = getApp().helper;
  3. Page({
  4. data: {
  5. unit_id: "",
  6. ad: !1,
  7. space: !1,
  8. step: 0,
  9. page: 2,
  10. over: !1,
  11. success: !1
  12. },
  13. onReachBottom: function() {
  14. var i = this,
  15. s = i.data.over,
  16. o = i.data.activity_data,
  17. e = void 0,
  18. a = void 0,
  19. c = void 0;
  20. if (!s) {
  21. var n = this.data.page;
  22. this.setData({
  23. loading: !0
  24. }), getApp().core.login({
  25. success: function(t) {
  26. e = t.code, getApp().core.getWeRunData({
  27. success: function(t) {
  28. a = t.iv, c = t.encryptedData, getApp().request({
  29. url: getApp().api.step.activity,
  30. method: "POST",
  31. data: {
  32. encrypted_data: c,
  33. iv: a,
  34. code: e,
  35. user_id: void 0,
  36. page: n
  37. },
  38. success: function(t) {
  39. getApp().core.hideLoading();
  40. for (var e = 0; e < t.list.activity_data.length; e++) o.push(t.list.activity_data[e]);
  41. t.list.activity_data.length < 3 && (s = !0);
  42. for (var a = 0; a < o.length; a++) o[a].date = o[a].open_date.replace("-", "").replace("-", "");
  43. i.setData({
  44. page: n + 1,
  45. over: s,
  46. loading: !1,
  47. activity_data: o
  48. })
  49. }
  50. })
  51. }
  52. })
  53. }
  54. })
  55. }
  56. },
  57. openSetting: function() {
  58. var e = this,
  59. a = e.data.user_id;
  60. getApp().core.openSetting({
  61. success: function(t) {
  62. 1 == t.authSetting["scope.werun"] && 1 == t.authSetting["scope.userInfo"] && (e.setData({
  63. authorize: !0
  64. }), getApp().core.showLoading({
  65. title: "数据加载中...",
  66. mask: !0
  67. }), e.activity(a))
  68. },
  69. fail: function(t) {
  70. e.setData({
  71. authorize: !1
  72. }), getApp().core.hideLoading()
  73. }
  74. })
  75. },
  76. onLoad: function(t) {
  77. getApp().page.onLoad(this, t);
  78. var e = this,
  79. a = !1,
  80. i = !1,
  81. s = void 0;
  82. null !== t.user_id && (s = t.user_id), getApp().request({
  83. url: getApp().api.step.setting,
  84. success: function(t) {
  85. 0 == t.code && e.setData({
  86. title: t.data.title,
  87. share_title: t.data.share_title
  88. })
  89. }
  90. });
  91. var o = util.formatTime(new Date),
  92. c = o[0] + o[1] + o[2] + o[3] + o[5] + o[6] + o[8] + o[9];
  93. this.setData({
  94. page: 2,
  95. time: c
  96. }), null !== t.open_date && (a = t.open_date), null !== t.join && (i = t.join), e.setData({
  97. join: i,
  98. open_date: a
  99. }), getApp().core.showLoading({
  100. title: "数据加载中...",
  101. mask: !0
  102. }), getApp().core.getSetting({
  103. success: function(t) {
  104. 1 == t.authSetting["scope.werun"] && 1 == t.authSetting["scope.userInfo"] ? e.activity(s) : getApp().core.authorize({
  105. scope: "scope.userInfo",
  106. success: function(t) {
  107. getApp().core.authorize({
  108. scope: "scope.werun",
  109. success: function(t) {
  110. "authorize:ok" == t.errMsg && e.activity(s)
  111. },
  112. fail: function(t) {
  113. e.setData({
  114. authorize: !1
  115. }), getApp().core.hideLoading()
  116. }
  117. })
  118. }
  119. })
  120. },
  121. fail: function(t) {
  122. e.setData({
  123. authorize: !1
  124. }), getApp().core.hideLoading()
  125. }
  126. })
  127. },
  128. activity: function(e) {
  129. var p = this,
  130. a = void 0,
  131. i = void 0,
  132. s = void 0;
  133. getApp().core.login({
  134. success: function(t) {
  135. a = t.code, getApp().core.getWeRunData({
  136. success: function(t) {
  137. i = t.iv, s = t.encryptedData, getApp().request({
  138. url: getApp().api.step.activity,
  139. method: "POST",
  140. data: {
  141. encrypted_data: s,
  142. iv: i,
  143. code: a,
  144. user_id: e
  145. },
  146. success: function(t) {
  147. var e = t.list.run_data;
  148. getApp().core.hideLoading();
  149. var a = t.list.ad_data,
  150. i = t.list.activity_data,
  151. s = void 0;
  152. if (s = !1, i.length < 1) s = !0;
  153. else
  154. for (var o = 0; o < i.length; o++) i[o].date = i[o].open_date.replace("-", "").replace("-", "");
  155. var c = !1,
  156. n = !1;
  157. null !== a && (c = t.list.ad_data.unit_id, n = !0), p.setData({
  158. unit_id: c,
  159. step: e,
  160. space: s,
  161. activity_data: i,
  162. ad_data: a,
  163. ad: n
  164. })
  165. }
  166. })
  167. }
  168. })
  169. }
  170. })
  171. },
  172. adError: function(t) {
  173. console.log(t.detail)
  174. },
  175. close: function() {
  176. this.setData({
  177. join: !1
  178. })
  179. },
  180. onShareAppMessage: function(t) {
  181. return getApp().page.onShareAppMessage(this), this.setData({
  182. join: !1
  183. }), {
  184. path: "/step/index/index?user_id=" + getApp().getUser().id,
  185. title: this.data.share_title ? this.data.share_title : this.data.title
  186. }
  187. },
  188. submit: function(t) {
  189. var e = void 0,
  190. a = void 0,
  191. i = void 0;
  192. console.log(t);
  193. var s = t.currentTarget.dataset.id,
  194. o = (t.currentTarget.dataset.step, this),
  195. c = this.data.step;
  196. getApp().core.showLoading({
  197. title: "正在提交...",
  198. mask: !0
  199. }), getApp().core.login({
  200. success: function(t) {
  201. e = t.code, getApp().core.getWeRunData({
  202. success: function(t) {
  203. a = t.iv, i = t.encryptedData, getApp().request({
  204. url: getApp().api.step.activity_submit,
  205. method: "POST",
  206. data: {
  207. code: e,
  208. iv: a,
  209. encrypted_data: i,
  210. num: c,
  211. activity_id: s
  212. },
  213. success: function(t) {
  214. getApp().core.hideLoading(), 0 == t.code ? o.setData({
  215. success: !0
  216. }) : getApp().core.showModal({
  217. content: t.msg,
  218. showCancel: !1
  219. })
  220. }
  221. })
  222. }
  223. })
  224. }
  225. })
  226. },
  227. success: function() {
  228. this.setData({
  229. success: !1
  230. }), getApp().core.redirectTo({
  231. url: "../dare/dare"
  232. })
  233. }
  234. });