record.js 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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. 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. hiddenCoupon: false,
  210. hiddenDetail: true,
  211. hiddenUtility: true,
  212. })
  213. this.getRequestData();
  214. this.getUserAwardCouponNum();
  215. })
  216. },
  217. // 优惠券
  218. getCoupon(e) {
  219. this.setData({
  220. hiddenCoupon: false,
  221. hiddenDetail: true,
  222. hiddenUtility: true,
  223. page: 1,
  224. goodsType: 1,
  225. noMore: false,
  226. noResult: false,
  227. noCoupon: true,
  228. noDetail: false,
  229. noUtility: false,
  230. couponList: [],
  231. detailList: [],
  232. stateList: [],
  233. })
  234. this.getUserAwardCouponList()
  235. wx.setNavigationBarTitle({
  236. title: '签到优惠券',
  237. })
  238. },
  239. //明细
  240. getDetail(e) {
  241. this.setData({
  242. hiddenCoupon: true,
  243. hiddenDetail: false,
  244. hiddenUtility: true,
  245. page: 1,
  246. goodsType: 2,
  247. noMore: false,
  248. noResult: false,
  249. noDetail: true,
  250. noCoupon: false,
  251. noUtility: false,
  252. couponList: [],
  253. detailList: [],
  254. stateList: [],
  255. })
  256. this.getUserSignInList()
  257. wx.setNavigationBarTitle({
  258. title: '获取明细',
  259. })
  260. },
  261. //使用失效
  262. getUtility(e) {
  263. this.setData({
  264. hiddenCoupon: true,
  265. hiddenDetail: true,
  266. hiddenUtility: false,
  267. page: 1,
  268. goodsType: 2,
  269. noMore: false,
  270. noResult: false,
  271. noUtility: true,
  272. noCoupon: false,
  273. noDetail: false,
  274. couponList: [],
  275. detailList: [],
  276. stateList: [],
  277. })
  278. this.getCouponStateList()
  279. wx.setNavigationBarTitle({
  280. title: '使用/失效',
  281. })
  282. },
  283. /**
  284. * 生命周期函数--监听页面初次渲染完成
  285. */
  286. onReady: function () {
  287. },
  288. /**
  289. * 生命周期函数--监听页面显示
  290. */
  291. onShow: function () {
  292. },
  293. /**
  294. * 生命周期函数--监听页面隐藏
  295. */
  296. onHide: function () {
  297. },
  298. /**
  299. * 生命周期函数--监听页面卸载
  300. */
  301. onUnload: function () {
  302. },
  303. /**
  304. * 页面相关事件处理函数--监听用户下拉动作
  305. */
  306. onPullDownRefresh: function () {
  307. },
  308. /**
  309. * 页面上拉触底事件的处理函数
  310. */
  311. onReachBottom: function () {
  312. if (this.data.lock || this.data.noMore) {
  313. return
  314. }
  315. this.data.lock = true
  316. this.data.page++
  317. this.getRequestData();
  318. },
  319. scrollToBottom() {
  320. if (this.data.lock || this.data.noMore) {
  321. return
  322. }
  323. this.data.lock = true
  324. this.data.page++
  325. this.getRequestData();
  326. },
  327. /**
  328. * 用户点击右上角分享
  329. */
  330. onShareAppMessage: function () {
  331. }
  332. })