record.js 9.0 KB

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