Explorar el Código

优惠券页面数据调用

kk.shi hace 3 años
padre
commit
fc1af3af72
Se han modificado 1 ficheros con 63 adiciones y 0 borrados
  1. 63 0
      pages/signIn/record/record.js

+ 63 - 0
pages/signIn/record/record.js

@@ -1,10 +1,25 @@
 // pages/signIn/record/record.js
+import SignIn from '../../../api/signIn'
+import { parseTime } from '../../../utils/util'
 Page({
 
     /**
      * 页面的初始数据
      */
     data: {
+        page: 1,
+        pageSize: 10,
+        lock: false,
+        noResult: false,
+        noMore: false,
+        isLogin: false,
+        hidden1: false,
+        hidden2: false,
+        mobileTop: 'TONY WU',
+        couponNum: 0,
+        productNum: 0,
+        activityId: 1,
+        couponList: []
 
     },
 
@@ -12,7 +27,55 @@ Page({
      * 生命周期函数--监听页面加载
      */
     onLoad: function (options) {
+        this.getUserAwardCouponList();
+    },
+
+    getUserAwardCouponList: function() {
+        SignIn.getUserAwardCouponList({
+            page: this.data.page,
+            pageSize: this.data.pageSize,
+            mobile: "16602120168",
+            activityId: this.data.activityId
+        }).then(res => {
+            if (res.code == 200) {
+                this.userCouponListView(res.data)
+                console.log(res)
+            }
+            this.data.lock = false
+        }).catch(_ => {
+            console.log(_)
+            this.data.lock = false
+        })
+    },
 
+    userCouponListView: function(data) {
+        if (!Array.isArray(data) || data.length == 0) {
+            console.log("优惠券数据为空");
+            if (this.data.page == 1) {
+                this.setData({
+                    // mobileTop:getMobileCache(),
+                    noResult: true
+                })
+            } else {
+                this.setData({
+                    // mobileTop:getMobileCache(),
+                    noMore: true
+                })
+            }
+            return
+        }
+        data.forEach(v => {
+            let beginTime = v.coupon.couponBeginTimestamp
+            let endTime = v.coupon.couponEndTimestamp
+            v.coupon.couponBeginTimestamp = parseTime(beginTime, "{y}.{m}.{d}")
+            v.coupon.couponEndTimestamp = parseTime(endTime, "{y}.{m}.{d}")
+        })
+
+        this.data = this.data.concat(...data)
+        this.setData({
+            // mobileTop:getMobileCache(),
+            couponList: this.data
+        })
     },
 
     /**