record.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. // pages/signIn/record/record.js
  2. import SignIn from '../../../api/signIn'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. page: 1,
  11. pageSize: 10,
  12. lock: false,
  13. noResult: false,
  14. noMore: false,
  15. noCoupon: false,
  16. noDetail: false,
  17. noUtility: false,
  18. isLogin: false,
  19. hiddenCoupon: true,
  20. hiddenDetail: true,
  21. hiddenUtility: true,
  22. mobileTop: 'TONY WU',
  23. couponNum: 0,
  24. productNum: 0,
  25. couponList: [],
  26. detailList: [],
  27. stateList: [],
  28. notUseNum: 0
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function (options) {
  34. this.setData({
  35. isLogin: getMobileCache() != ''
  36. })
  37. if(this.data.isLogin){
  38. this.setData({
  39. hiddenCoupon: false,
  40. hiddenDetail: true,
  41. hiddenUtility: true,
  42. noCoupon: true,
  43. noDetail: false,
  44. noUtility: false,
  45. })
  46. // this.getUserAwardCouponNum();
  47. this.getRequestData();
  48. }
  49. },
  50. // 类型区分
  51. getRequestData() {
  52. if (this.data.noCoupon) {
  53. this.getUserAwardCouponList();
  54. }
  55. if (this.data.noDetail) {
  56. this.getUserSignInList();
  57. }
  58. if (this.data.noUtility) {
  59. this.getCouponStateList();
  60. }
  61. },
  62. builtPublicParams() {
  63. return {
  64. page: this.data.page,
  65. pageSize: this.data.pageSize,
  66. mobile: getMobileCache(),
  67. }
  68. },
  69. // 优惠券数据
  70. getUserAwardCouponList: function() {
  71. SignIn.getUserAwardCouponList(this.builtPublicParams()).then(res => {
  72. if (res.code == 200) {
  73. this.userCouponListView(res.data)
  74. }
  75. this.data.lock = false
  76. }).catch(_ => {
  77. console.log(_)
  78. this.data.lock = false
  79. })
  80. },
  81. userCouponListView: function(data) {
  82. if (!Array.isArray(data) || data.length == 0) {
  83. console.log("优惠券数据为空");
  84. if (this.data.page == 1) {
  85. this.setData({
  86. mobileTop:getMobileCache(),
  87. noResult: true
  88. })
  89. } else {
  90. this.setData({
  91. mobileTop:getMobileCache(),
  92. noMore: true
  93. })
  94. }
  95. return
  96. }
  97. data.forEach(v => {
  98. let beginTime = v.coupon.couponBeginTimestamp
  99. let endTime = v.coupon.couponEndTimestamp
  100. v.coupon.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
  101. v.coupon.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
  102. })
  103. this.data.couponList = this.data.couponList.concat(...data)
  104. this.setData({
  105. mobileTop:getMobileCache(),
  106. couponList: this.data.couponList
  107. })
  108. },
  109. //未使用的券数量
  110. getUserAwardCouponNum: function() {
  111. SignIn.getUserAwardCouponNum(this.builtPublicParams()).then(res => {
  112. if (res.code == 200) {
  113. this.setData({
  114. notUseNum: res.data.notUseNum
  115. })
  116. }
  117. this.data.lock = false
  118. }).catch(_ => {
  119. console.log(_)
  120. this.data.lock = false
  121. })
  122. },
  123. // 签到明细
  124. getUserSignInList: function() {
  125. SignIn.getUserSignInList(this.builtPublicParams()).then(res => {
  126. if (res.code == 200) {
  127. this.userDetailListView(res.data)
  128. }
  129. this.data.lock = false
  130. }).catch(_ => {
  131. console.log(_)
  132. this.data.lock = false
  133. })
  134. },
  135. userDetailListView: function(data) {
  136. if (!Array.isArray(data) || data.length == 0) {
  137. console.log("获取明细数据为空");
  138. if (this.data.page == 1) {
  139. this.setData({
  140. mobileTop:getMobileCache(),
  141. noResult: true
  142. })
  143. } else {
  144. this.setData({
  145. mobileTop:getMobileCache(),
  146. noMore: true
  147. })
  148. }
  149. return
  150. }
  151. data.forEach(v => {
  152. let crateTime = v.crateTime
  153. v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}")
  154. })
  155. this.data.detailList = this.data.detailList.concat(...data)
  156. this.setData({
  157. mobileTop:getMobileCache(),
  158. detailList: this.data.detailList
  159. })
  160. },
  161. // 使用失效
  162. getCouponStateList: function() {
  163. SignIn.getUserAwardCouponUseStateList(this.builtPublicParams()).then(res => {
  164. if (res.code == 200) {
  165. this.userStateListView(res.data)
  166. }
  167. this.data.lock = false
  168. }).catch(_ => {
  169. console.log(_)
  170. this.data.lock = false
  171. })
  172. },
  173. userStateListView: function(data) {
  174. if (!Array.isArray(data) || data.length == 0) {
  175. console.log("使用失效数据为空");
  176. if (this.data.page == 1) {
  177. this.setData({
  178. mobileTop:getMobileCache(),
  179. noResult: true
  180. })
  181. } else {
  182. this.setData({
  183. mobileTop:getMobileCache(),
  184. noMore: true
  185. })
  186. }
  187. return
  188. }
  189. data.forEach(v => {
  190. let crateTime = v.crateTime
  191. v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}")
  192. })
  193. this.data.stateList = this.data.stateList.concat(...data)
  194. this.setData({
  195. mobileTop:getMobileCache(),
  196. stateList: this.data.stateList
  197. })
  198. },
  199. // 授权手机号
  200. getPhoneNumber(e) {
  201. getPhoneNumberSync(e, _ => {
  202. this.setData({
  203. isLogin: true,
  204. mobileTop: getMobileCache(),
  205. noCoupon: true,
  206. hiddenCoupon: false,
  207. hiddenDetail: true,
  208. hiddenUtility: true,
  209. })
  210. this.getRequestData();
  211. // this.getUserAwardCouponNum();
  212. })
  213. },
  214. // 优惠券
  215. getCoupon(e) {
  216. this.setData({
  217. hiddenCoupon: false,
  218. hiddenDetail: true,
  219. hiddenUtility: true,
  220. page: 1,
  221. goodsType: 1,
  222. noMore: false,
  223. noResult: false,
  224. noCoupon: true,
  225. noDetail: false,
  226. noUtility: false,
  227. couponList: [],
  228. detailList: [],
  229. stateList: [],
  230. })
  231. this.getUserAwardCouponList()
  232. },
  233. //明细
  234. getDetail(e) {
  235. this.setData({
  236. hiddenCoupon: true,
  237. hiddenDetail: false,
  238. hiddenUtility: true,
  239. page: 1,
  240. goodsType: 2,
  241. noMore: false,
  242. noResult: false,
  243. noDetail: true,
  244. noCoupon: false,
  245. noUtility: false,
  246. couponList: [],
  247. detailList: [],
  248. stateList: [],
  249. })
  250. this.getUserSignInList()
  251. },
  252. //使用失效
  253. getUtility(e) {
  254. this.setData({
  255. hiddenCoupon: true,
  256. hiddenDetail: true,
  257. hiddenUtility: false,
  258. page: 1,
  259. goodsType: 2,
  260. noMore: false,
  261. noResult: false,
  262. noUtility: true,
  263. noCoupon: false,
  264. noDetail: false,
  265. couponList: [],
  266. detailList: [],
  267. stateList: [],
  268. })
  269. this.getCouponStateList()
  270. },
  271. /**
  272. * 生命周期函数--监听页面初次渲染完成
  273. */
  274. onReady: function () {
  275. },
  276. /**
  277. * 生命周期函数--监听页面显示
  278. */
  279. onShow: function () {
  280. },
  281. /**
  282. * 生命周期函数--监听页面隐藏
  283. */
  284. onHide: function () {
  285. },
  286. /**
  287. * 生命周期函数--监听页面卸载
  288. */
  289. onUnload: function () {
  290. },
  291. /**
  292. * 页面相关事件处理函数--监听用户下拉动作
  293. */
  294. onPullDownRefresh: function () {
  295. },
  296. /**
  297. * 页面上拉触底事件的处理函数
  298. */
  299. onReachBottom: function () {
  300. if (this.data.lock || this.data.noMore) {
  301. return
  302. }
  303. this.data.lock = true
  304. this.data.page++
  305. this.getRequestData();
  306. },
  307. scrollToBottom() {
  308. if (this.data.lock || this.data.noMore) {
  309. return
  310. }
  311. this.data.lock = true
  312. this.data.page++
  313. this.getRequestData();
  314. },
  315. /**
  316. * 用户点击右上角分享
  317. */
  318. onShareAppMessage: function () {
  319. }
  320. })