record.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. // pages/signIn/record/record.js
  2. import SignIn from '../../../api/signIn'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumberNew 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. const couponListT = []
  98. data.forEach(v => {
  99. v.coupon.isSn = true
  100. v.coupon.couponStartTime = v.coupon.couponBeginTimestamp
  101. v.coupon.couponEndTime = v.coupon.couponEndTimestamp
  102. couponListT.push(v.coupon)
  103. })
  104. this.data.couponList = this.data.couponList.concat(...couponListT)
  105. this.setData({
  106. mobileTop:getMobileCache(),
  107. couponList: this.data.couponList
  108. })
  109. },
  110. //未使用的券数量
  111. getUserAwardCouponNum: function() {
  112. SignIn.getUserAwardCouponNum(this.builtPublicParams()).then(res => {
  113. if (res.code == 200) {
  114. this.setData({
  115. notUseNum: res.data.notUseNum
  116. })
  117. }
  118. this.data.lock = false
  119. }).catch(_ => {
  120. console.log(_)
  121. this.data.lock = false
  122. })
  123. },
  124. // 签到明细
  125. getUserSignInList: function() {
  126. SignIn.getUserSignInList(this.builtPublicParams()).then(res => {
  127. if (res.code == 200) {
  128. this.userDetailListView(res.data)
  129. }
  130. this.data.lock = false
  131. }).catch(_ => {
  132. console.log(_)
  133. this.data.lock = false
  134. })
  135. },
  136. userDetailListView: function(data) {
  137. if (!Array.isArray(data) || data.length == 0) {
  138. console.log("获取明细数据为空");
  139. if (this.data.page == 1) {
  140. this.setData({
  141. mobileTop:getMobileCache(),
  142. noResult: true
  143. })
  144. } else {
  145. this.setData({
  146. mobileTop:getMobileCache(),
  147. noMore: true
  148. })
  149. }
  150. return
  151. }
  152. data.forEach(v => {
  153. let crateTime = v.crateTime
  154. v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}")
  155. })
  156. this.data.detailList = this.data.detailList.concat(...data)
  157. this.setData({
  158. mobileTop:getMobileCache(),
  159. detailList: this.data.detailList
  160. })
  161. },
  162. // 使用失效
  163. getCouponStateList: function() {
  164. SignIn.getUserAwardCouponUseStateList(this.builtPublicParams()).then(res => {
  165. if (res.code == 200) {
  166. this.userStateListView(res.data)
  167. }
  168. this.data.lock = false
  169. }).catch(_ => {
  170. console.log(_)
  171. this.data.lock = false
  172. })
  173. },
  174. userStateListView: function(data) {
  175. if (!Array.isArray(data) || data.length == 0) {
  176. console.log("使用失效数据为空");
  177. if (this.data.page == 1) {
  178. this.setData({
  179. mobileTop:getMobileCache(),
  180. noResult: true
  181. })
  182. } else {
  183. this.setData({
  184. mobileTop:getMobileCache(),
  185. noMore: true
  186. })
  187. }
  188. return
  189. }
  190. data.forEach(v => {
  191. let crateTime = v.crateTime
  192. v.crateTime = parseTime(crateTime, "{y}-{m}-{d} {h}:{i}")
  193. })
  194. this.data.stateList = this.data.stateList.concat(...data)
  195. this.setData({
  196. mobileTop:getMobileCache(),
  197. stateList: this.data.stateList
  198. })
  199. },
  200. // 授权手机号
  201. getPhoneNumber(e) {
  202. getPhoneNumberSync(e, _ => {
  203. this.setData({
  204. isLogin: true,
  205. mobileTop: getMobileCache(),
  206. noCoupon: true,
  207. hiddenCoupon: false,
  208. hiddenDetail: true,
  209. hiddenUtility: true,
  210. })
  211. this.getRequestData();
  212. // this.getUserAwardCouponNum();
  213. })
  214. },
  215. // 优惠券
  216. getCoupon(e) {
  217. this.setData({
  218. hiddenCoupon: false,
  219. hiddenDetail: true,
  220. hiddenUtility: true,
  221. page: 1,
  222. goodsType: 1,
  223. noMore: false,
  224. noResult: false,
  225. noCoupon: true,
  226. noDetail: false,
  227. noUtility: false,
  228. couponList: [],
  229. detailList: [],
  230. stateList: [],
  231. })
  232. this.getUserAwardCouponList()
  233. },
  234. //明细
  235. getDetail(e) {
  236. this.setData({
  237. hiddenCoupon: true,
  238. hiddenDetail: false,
  239. hiddenUtility: true,
  240. page: 1,
  241. goodsType: 2,
  242. noMore: false,
  243. noResult: false,
  244. noDetail: true,
  245. noCoupon: false,
  246. noUtility: false,
  247. couponList: [],
  248. detailList: [],
  249. stateList: [],
  250. })
  251. this.getUserSignInList()
  252. },
  253. //使用失效
  254. getUtility(e) {
  255. this.setData({
  256. hiddenCoupon: true,
  257. hiddenDetail: true,
  258. hiddenUtility: false,
  259. page: 1,
  260. goodsType: 2,
  261. noMore: false,
  262. noResult: false,
  263. noUtility: true,
  264. noCoupon: false,
  265. noDetail: false,
  266. couponList: [],
  267. detailList: [],
  268. stateList: [],
  269. })
  270. this.getCouponStateList()
  271. },
  272. /**
  273. * 生命周期函数--监听页面初次渲染完成
  274. */
  275. onReady: function () {
  276. },
  277. /**
  278. * 生命周期函数--监听页面显示
  279. */
  280. onShow: function () {
  281. },
  282. /**
  283. * 生命周期函数--监听页面隐藏
  284. */
  285. onHide: function () {
  286. },
  287. /**
  288. * 生命周期函数--监听页面卸载
  289. */
  290. onUnload: function () {
  291. },
  292. /**
  293. * 页面相关事件处理函数--监听用户下拉动作
  294. */
  295. onPullDownRefresh: function () {
  296. },
  297. /**
  298. * 页面上拉触底事件的处理函数
  299. */
  300. onReachBottom: function () {
  301. if (this.data.lock || this.data.noMore) {
  302. return
  303. }
  304. this.data.lock = true
  305. this.data.page++
  306. this.getRequestData();
  307. },
  308. scrollToBottom() {
  309. if (this.data.lock || this.data.noMore) {
  310. return
  311. }
  312. this.data.lock = true
  313. this.data.page++
  314. this.getRequestData();
  315. },
  316. /**
  317. * 用户点击右上角分享
  318. */
  319. onShareAppMessage: function () {
  320. }
  321. })