|
- const util = require("../../../utils/util.js");
- const config = require("../../../config/config.js");
- const Http = require("../../../utils/HttpBasics");
- let app = getApp();
- const imgurl = require("../../../utils/imgurl");
- Page({
- data: {
- couponUrl: imgurl.coupon.url,
- linessUrl: imgurl.liness.url,
- loadingUrl: imgurl.loading.url,
- tabs: [{
- key: 4,
- name: "使用中"
- },
- {
- key: "5,6,7",
- name: "已失效"
- }
- ],
- list: [],
- current: "4",
- current_scroll: "4",
- page: 1,
- allow_load: true,
- loading: true, //"上拉加载"的变量,默认false,隐藏
- content: "",
- mystatus: '',
- showPage: false
- },
- onLoad() {
- this.getList(4, 1);
- },
- onShow: function() {
- let that = this;
- wx.setStorage({
- key: 'couponNum',
- data: "couponNum1",
- })
- wx.hideTabBarRedDot({
- index: 2
- })
- },
- // 扫一扫去支付
- gotoPay: function(e) {
- let that = this;
- wx.scanCode({
- success: (res) => {
- wx.navigateTo({
- url: `/pages/scanPay/scanPay?merChant=${res.result}&cardid=${e.currentTarget.dataset.cardid}&remainingAmount=${e.currentTarget.dataset.remainingamount}`,
- })
- },
- fail: (res) => {
- console.log(res);
- }
- })
- },
- // 跳转到详情
- gotoConsumeDetail: function(e) {
- console.log(e.currentTarget.dataset.id)
- wx.navigateTo({
- url: `/pages/ConsumeDetail/ConsumeDetail?cardId=${e.currentTarget.dataset.id}`,
- })
- },
- //点击跳转到券详情页面
- gotouse: function(e) {
- if (this.data.mystatus == '' || this.data.mystatus == 'undefined') {
- var mystatus = e.currentTarget.dataset.couponorderstatus;
- } else {
- var mystatus = this.data.mystatus;
- }
- wx.navigateTo({
- url: `/pages/couponorder/detail/index?quancode=${
- e.currentTarget.dataset.quancode}&couponorderstatus=${mystatus}`
- });
- },
- gotoBuy:function(){
- wx.navigateTo({
- url: '/pages/discountCardList/discountCardList',
- })
- },
- getList(key, pageNum) {
- var that = this;
- console.log(key)
- if (that.data.allow_load) {
- that.setData({
- loading: true,
- content: "小主,我在玩命加载中...",
- });
- if (key == 4) {
- var data = {
- pageNum: pageNum,
- pageSize: 6,
- couponType: "7",
- couponOrderStatus: 4
- }
- } else if (key == '5,6,7') {
- var data = {
- pageNum: pageNum,
- pageSize: 6,
- couponType: "7",
- statusStr: "5,6,7"
- }
- }
- Http.get({
- url: config.api.cardorderList,
- data: data
- })
- .then(res => {
- if (res.code == 200) {
- that.setData({
- showPage: true
- })
- }
- res.data.list.map(file => {
- file.expiredTime = util.fmtDate(file.expiredTime);
- if (file.couponOrderStatus == 5 || file.couponOrderStatus == 6 || file.couponOrderStatus == 7) {
- file.background = 'rgba(179,180,181,1)';
- file.showImg = true;
- } else if (file.couponOrderStatus == 4) {
- if (file.remainingAmount > 0 && 500 >= file.remainingAmount) {
- file.background = '#7184E2'
- } else if (file.remainingAmount > 500 && 5000 >= file.remainingAmount) {
- file.background = '#63AAE6'
- } else if (file.remainingAmount > 5000) {
- file.background = '#E2A471'
- }
- }
-
- });
- setTimeout(function() {
- that.setData({
- loading: false
- });
- }, 1400);
- if (pageNum >= res.data.pages) {
- that.setData({
- allow_load: false
- });
- }
- if (pageNum == 1) {
- that.setData({
- list: []
- })
- }
- var tmpArr = that.data.list;
- tmpArr.push.apply(tmpArr, res.data.list);
- that.setData({
- list: tmpArr
- })
- })
- .catch(err => {
- wx.showModal({
- title: '提示',
- content: err.errMsg,
- showCancel: false
- })
- })
- } else {
- that.setData({
- loading: true,
- content: "——— 再拉裤子就掉了啦 ———"
- });
- setTimeout(function() {
- that.setData({
- loading: false
- });
- }, 1400);
- }
- },
- handleChangeScroll({
- detail
- }) {
- this.setData({
- list: [],
- allow_load: true,
- current_scroll: detail.key,
- page: 1,
- });
- this.getList(detail.key, 1);
- },
- onReachBottom: function() {
- var that = this;
- that.data.page++;
- that.setData({
- page: that.data.page
- });
- that.getList(that.data.current_scroll, that.data.page);
- }
- });
|