index.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. var _data;
  2. function _defineProperty(e, t, a) {
  3. return t in e ? Object.defineProperty(e, t, {
  4. value: a,
  5. enumerable: !0,
  6. configurable: !0,
  7. writable: !0
  8. }) : e[t] = a, e
  9. }
  10. var util = require("../../utils/helper.js"),
  11. utils = getApp().helper;
  12. Page(_defineProperty({
  13. data: (_data = {
  14. dare: !1,
  15. my: "0",
  16. todayStep: "0",
  17. authorize: !0,
  18. overStep: "0",
  19. banner_list: [],
  20. useStep: "0",
  21. nowAdd: "0.00",
  22. today: "",
  23. nextAdd: "0.00",
  24. people: "2153",
  25. friend: [],
  26. now: !1,
  27. convert_ratio: "",
  28. activity_data: [{
  29. id: 0
  30. }, {
  31. open_date: ""
  32. }, {
  33. name: ""
  34. }, {
  35. bail_currency: 0
  36. }, {
  37. step_num: 0
  38. }],
  39. convert_max: 0,
  40. title: "",
  41. goods: [],
  42. user_id: 0,
  43. time: "",
  44. encrypted_data: "",
  45. iv: "",
  46. code: "",
  47. page: 2,
  48. unit_id: ""
  49. }, _defineProperty(_data, "user_id", ""), _defineProperty(_data, "over", !1), _data),
  50. switch: function(e) {
  51. var t = 0;
  52. t = 1 == e.detail.value ? 1 : 0, getApp().request({
  53. url: getApp().api.step.remind,
  54. data: {
  55. remind: t
  56. }
  57. })
  58. },
  59. exchange: function() {
  60. var a = this,
  61. t = void 0,
  62. o = void 0,
  63. n = void 0,
  64. e = a.data.nowAdd,
  65. i = a.data.todayStep * (1 + e / 100),
  66. d = a.data.useStep,
  67. r = a.data.convert_ratio,
  68. s = a.data.convert_max,
  69. p = parseInt(i);
  70. 0 < s && +s < p && (p = +s), p -= d;
  71. var c = a.data.overStep,
  72. u = (p / r).toString().match(/^\d+(?:\.\d{0,2})?/);
  73. u < .01 || 0 == c ? getApp().core.showModal({
  74. content: "步数不足",
  75. showCancel: !1
  76. }) : getApp().core.showModal({
  77. content: "确认把" + c + "步兑换为" + u + (a.data.store.option.step.currency_name ? a.data.store.option.step.currency_name :
  78. "活力币"),
  79. success: function(e) {
  80. e.confirm && (getApp().core.showLoading({
  81. title: "兑换中...",
  82. mask: !0
  83. }), getApp().core.login({
  84. success: function(e) {
  85. o = e.code, getApp().core.getWeRunData({
  86. success: function(e) {
  87. t = e.iv, n = e.encryptedData, getApp().request({
  88. url: getApp().api.step.convert,
  89. method: "post",
  90. data: {
  91. iv: t,
  92. code: o,
  93. encrypted_data: n,
  94. num: a.data.todayStep
  95. },
  96. success: function(e) {
  97. if (getApp().core.hideLoading(), 0 == e.code) {
  98. 0 < s && +s < p && (p = +s), p -= e.list.num;
  99. var t = (+a.data.my + +e.list.convert).toFixed(2);
  100. a.setData({
  101. overStep: p,
  102. my: t,
  103. useStep: e.list.num
  104. })
  105. } else getApp().core.showModal({
  106. content: e.msg,
  107. showCancel: !1
  108. })
  109. }
  110. })
  111. }
  112. })
  113. }
  114. }))
  115. },
  116. fail: function(e) {
  117. getApp().core.hideLoading(), getApp().core.showModal({
  118. content: "为确保您的正常使用,请完善授权操作",
  119. showCancel: !1
  120. })
  121. }
  122. })
  123. },
  124. adError: function(e) {
  125. console.log(e.detail)
  126. },
  127. onShareAppMessage: function(e) {
  128. return getApp().page.onShareAppMessage(this), {
  129. path: "/step/dare/dare?user_id=" + getApp().getUser().id,
  130. title: this.data.title ? this.data.title : "步数挑战"
  131. }
  132. },
  133. onReachBottom: function() {
  134. var a = this,
  135. o = a.data.over;
  136. if (!o) {
  137. var e = this.data.encrypted_data,
  138. t = this.data.iv,
  139. n = this.data.code,
  140. i = this.data.user_id,
  141. d = this.data.goods,
  142. r = this.data.page;
  143. this.setData({
  144. loading: !0
  145. }), getApp().request({
  146. url: getApp().api.step.index,
  147. method: "POST",
  148. data: {
  149. encrypted_data: e,
  150. iv: t,
  151. code: n,
  152. user_id: i,
  153. page: r
  154. },
  155. success: function(e) {
  156. for (var t = 0; t < e.data.goods_data.length; t++) d.push(e.data.goods_data[t]);
  157. e.data.goods_data.length < 6 && (o = !0), a.setData({
  158. goods: d,
  159. page: r + 1,
  160. over: o,
  161. loading: !1
  162. })
  163. }
  164. })
  165. }
  166. },
  167. refresh: function() {
  168. getApp().core.showLoading({
  169. title: "步数加载中...",
  170. mask: !0
  171. });
  172. var e = this,
  173. t = e.data.convert_max;
  174. e.runData(e.data.user_id, t)
  175. },
  176. onShow: function() {
  177. if (0 != this.data.now) {
  178. var n = this,
  179. t = void 0,
  180. a = void 0,
  181. o = void 0,
  182. i = n.data.user_id;
  183. getApp().core.login({
  184. success: function(e) {
  185. t = e.code, getApp().core.getWeRunData({
  186. success: function(e) {
  187. a = e.iv, o = e.encryptedData, getApp().request({
  188. url: getApp().api.step.index,
  189. method: "POST",
  190. data: {
  191. encrypted_data: o,
  192. iv: a,
  193. code: t,
  194. user_id: i,
  195. page: 1
  196. },
  197. success: function(e) {
  198. getApp().core.hideLoading();
  199. var t = e.data.activity_data,
  200. a = e.data.user_data,
  201. o = e.data.user_data.step_currency;
  202. n.setData({
  203. activity_data: t,
  204. user_data: a,
  205. my: o
  206. })
  207. }
  208. })
  209. }
  210. })
  211. }
  212. })
  213. }
  214. },
  215. runData: function(y, S) {
  216. var D = this,
  217. M = void 0,
  218. x = void 0,
  219. L = void 0;
  220. getApp().core.login({
  221. success: function(e) {
  222. M = e.code, getApp().core.getWeRunData({
  223. success: function(e) {
  224. x = e.iv, L = e.encryptedData, getApp().request({
  225. url: getApp().api.step.index,
  226. method: "POST",
  227. data: {
  228. encrypted_data: L,
  229. iv: x,
  230. code: M,
  231. user_id: y,
  232. page: 1
  233. },
  234. success: function(e) {
  235. getApp().core.hideLoading();
  236. var t = void 0,
  237. a = void 0;
  238. null == e.data.activity_data.id ? (a = !1, t = []) : (a = !0, t = e.data.activity_data);
  239. var o = e.data.run_data.stepInfoList,
  240. n = e.data.user_data,
  241. i = void 0,
  242. d = [{
  243. pic_url: "../image/ad.png"
  244. }];
  245. 0 < e.data.banner_list.length && (d = e.data.banner_list);
  246. var r = !1;
  247. null !== e.data.ad_data && (r = e.data.ad_data.unit_id);
  248. var s = n.step_currency,
  249. p = e.data.ad_data,
  250. c = e.data.goods_data,
  251. u = o[o.length - 1].step,
  252. g = o[o.length - 1].timestamp,
  253. h = n.ratio / 10,
  254. l = n.invite_list,
  255. _ = 0,
  256. v = 0;
  257. n.now_ratio && (v = n.now_ratio / 10);
  258. var f = void 0;
  259. 0 == n.remind ? f = !1 : 1 == n.remind && (f = !0), 0 < n.convert_num && (_ = n.convert_num);
  260. var A = parseInt(u * (1 + v / 100));
  261. 0 < S && +S < A && (A = +S), 1e3 <= (A -= +_) && (A = String(A).replace(/(\d)(?=(\d{3})+$)/g,
  262. "$1,"));
  263. var m = "";
  264. null != t.open_date && (m = t.open_date.replace(".", "").replace(".", "")), i = !(t.step_num > u),
  265. A < 0 && (A = 0);
  266. var w = l.length;
  267. D.setData(_defineProperty({
  268. overStep: A,
  269. todayStep: u,
  270. nextAdd: h,
  271. friend: l,
  272. today: g,
  273. finish: i,
  274. nowAdd: v,
  275. my: s,
  276. now: !0,
  277. user: n,
  278. length: w,
  279. banner_list: d,
  280. useStep: _,
  281. goods: c,
  282. user_id: y,
  283. checked: f,
  284. encrypted_data: L,
  285. iv: x,
  286. page: 2,
  287. code: M,
  288. open_date: m,
  289. activity_data: t,
  290. dare: a,
  291. ad_data: p,
  292. unit_id: r
  293. }, "user_id", n.user_id))
  294. },
  295. fail: function(e) {
  296. getApp().core.showModal({
  297. content: e.errMsg,
  298. showCancel: !1
  299. })
  300. }
  301. })
  302. },
  303. fail: function(e) {
  304. "getWeRunData:fail cancel" == e.errMsg ? getApp().core.showModal({
  305. content: "读取失败,请稍后再试",
  306. showCancel: !1
  307. }) : "getWeRunData: fail device not support" == e.errMsg ? getApp().core.showModal({
  308. content: '请在微信中搜索"微信运动"公众号,并点击关注',
  309. showCancel: !1
  310. }) : getApp().core.showModal({
  311. content: e.errMsg,
  312. showCancel: !1
  313. })
  314. }
  315. })
  316. },
  317. fail: function(e) {
  318. getApp().core.showModal({
  319. content: e.errMsg,
  320. showCancel: !1
  321. })
  322. }
  323. })
  324. },
  325. openSetting: function() {
  326. var o = this;
  327. getApp().core.openSetting({
  328. success: function(e) {
  329. if (1 == e.authSetting["scope.werun"] && 1 == e.authSetting["scope.userInfo"]) {
  330. o.setData({
  331. authorize: !0
  332. }), getApp().core.showLoading({
  333. title: "步数加载中...",
  334. mask: !0
  335. });
  336. var t = o.data.user_id,
  337. a = o.data.convert_max;
  338. o.runData(t, a)
  339. }
  340. },
  341. fail: function(e) {
  342. o.setData({
  343. authorize: !1
  344. }), getApp().core.hideLoading()
  345. }
  346. })
  347. },
  348. onLoad: function(e) {
  349. getApp().page.onLoad(this, e);
  350. var o = 0;
  351. if (null !== e.scene) {
  352. var t = decodeURIComponent(e.scene),
  353. a = utils.scene_decode(t);
  354. 0 < a.uid && (o = a.uid)
  355. }
  356. 0 < e.user_id && (o = e.user_id), this.setData({
  357. user_id: o,
  358. now: !1
  359. });
  360. var n = util.formatTime(new Date),
  361. i = n[0] + n[1] + n[2] + n[3] + n[5] + n[6] + n[8] + n[9];
  362. this.setData({
  363. time: i
  364. }), getApp().core.showLoading({
  365. title: "步数加载中...",
  366. mask: !0
  367. }), getApp().page.onShow(this), getApp().core.showShareMenu({
  368. withShareTicket: !0
  369. });
  370. var d = this,
  371. r = void 0;
  372. getApp().request({
  373. url: getApp().api.step.setting,
  374. success: function(e) {
  375. if (0 == e.code) {
  376. var t = e.data.title,
  377. a = e.data.share_title;
  378. r = e.data.convert_max, t && (getApp().core.setNavigationBarTitle({
  379. title: t
  380. }), d.setData({
  381. title: t,
  382. share_title: a
  383. })), d.setData({
  384. convert_ratio: e.data.convert_ratio,
  385. convert_max: r
  386. }), getApp().core.getSetting({
  387. success: function(e) {
  388. 1 == e.authSetting["scope.werun"] && 1 == e.authSetting["scope.userInfo"] ? d.runData(o, r) : 1 == e.authSetting[
  389. "scope.userInfo"] && getApp().core.authorize({
  390. scope: "scope.werun",
  391. success: function(e) {
  392. "authorize:ok" == e.errMsg && d.runData(o, r)
  393. },
  394. fail: function(e) {
  395. d.setData({
  396. authorize: !1
  397. }), getApp().core.hideLoading()
  398. }
  399. })
  400. },
  401. fail: function(e) {
  402. d.setData({
  403. authorize: !1
  404. }), getApp().core.hideLoading()
  405. }
  406. })
  407. }
  408. },
  409. fail: function(e) {
  410. getApp().core.showModal({
  411. content: e.errMsg,
  412. showCancel: !1
  413. })
  414. }
  415. })
  416. }
  417. }, "onShareAppMessage", function(e) {
  418. return getApp().page.onShareAppMessage(this), {
  419. path: "/step/index/index?user_id=" + getApp().getUser().id,
  420. title: this.data.share_title ? this.data.share_title : this.data.title
  421. }
  422. }));