record.js 8.9 KB

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