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