123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- // pages/cardBag/cardBag.js
- import {
- get,
- post
- } from '../../../utils/http.js'
- const app = getApp()
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- current: 1,
- list: [],
- page: 1,
- limit: 50,
- total: 0,
- storeId: wx.getStorageSync('store_id'),
- couponType: ['抵扣券', '满减券', '全额减免', '卡券'], //卡券类型 优惠券类型,1直接抵扣券,2满减券,3全额减免券,4卡券
- couponList: [], //优惠券列表
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- this.setData({
- current:options.current
- })
- // 获取卡包列表
- this.getList()
- // 获取优惠券列表
- this.getCoupon()
- },
- /**
- * 切换状态
- */
- selectTab(e) {
- let current = e.currentTarget.dataset.current
- this.setData({
- current,
- page: 1,
- total: 0,
- couponList: [],
- list: [],
- })
- if (current == 1) {
- this.getList(1)
- } else {
- this.getCoupon(1)
- }
- },
- // 获取卡包列表
- getList(_page) {
- let {
- page,
- limit,
- current,
- list
- } = this.data
- get('v2/api/user/card/list', {
- page: _page || page,
- limit,
- type: 0
- }, (res) => {
- if (_page == 1 || page == 1) {
- list = []
- this.data.page = 1
- }
- list.push(...res.data.list)
- this.setData({
- list,
- total: res.data.total
- })
- })
- },
- /**
- * 获取优惠券列表
- * /api/user/coupon
- */
- getCoupon(_page) {
- let {
- couponList,
- page
- } = this.data
- get(
- 'v2/api/user/coupon/list', {
- type: 'project',
- page: _page || page,
- limit: 10
- },
- (res) => {
- if (_page == 1 || page == 1) {
- couponList = []
- this.data.page = 1
- }
- couponList.push(...res.data.list)
- this.setData({
- couponList,
- total: res.data.total
- })
- }
- )
- },
- /**
- * 使用优惠券
- */
- goToOrderBy(e) {
- let coupon_range = e.currentTarget.dataset.item.coupon_range
- let project_id = e.currentTarget.dataset.item.project_id
- if (coupon_range == 3) {
- wx.switchTab({
- url: "/pages/shoppingMall/shoppingMall"
- })
- }else if(coupon_range == 1){
- if(project_id==0){
- wx.switchTab({
- url: '/pages/orderBy/orderBy',
- })
- }else{
- wx.navigateTo({
- url: `/pages/projectDetail/projectDetail?source=project&id=${project_id}`,
- })
- }
- }else{
- wx.switchTab({
- url: '/pages/orderBy/orderBy',
- })
- }
- wx.setStorageSync('curre', 1)
- },
- // 下拉触底触发
- toLower() {
- if (this.data.list.length < this.data.total) {
- // 获取卡包列表
- this.getList(++this.data.page)
- }
- },
- // 跳转到次卡详情
- jumpCard(e) {
- let id = e.currentTarget.dataset.id
- let status = e.currentTarget.dataset.status
- if(status==-1){
- wx.showToast({
- title: '次卡已过期',
- icon:'none'
- })
- return
- }
- if(status==0){
- wx.showToast({
- title: '次卡已使用',
- icon:'none'
- })
- return
- }
- if(status==-2){
- wx.showToast({
- title: '次卡已注销',
- icon:'none'
- })
- return
- }
- wx.navigateTo({
- url: `/subPackages/pages/subCardDetails/subCardDetails?source=project&id=${id}&store_id=${this.data.storeId}`,
- })
- },
- // 跳转到项目详情
- jumpProject(e) {
- let project_id = e.currentTarget.dataset.project_id
- let id = e.currentTarget.dataset.id
- if (project_id == 0) {
- wx.navigateTo({
- url: `/subPackages/pages/subCardDetails/subCardDetails?source=project&id=${id}&store_id=${this.data.storeId}`,
- })
- return
- }
- wx.navigateTo({
- url: `/pages/projectDetail/projectDetail?source=project&id=${project_id}&store_id=${this.data.storeId}`,
- })
- },
- // 跳转到历史记录页面
- jumpHis() {
- if (this.data.current == 1) {
- wx.navigateTo({
- url: `/subPackages/pages/couponHistory/couponHistory`,
- })
- } else {
- wx.navigateTo({
- url: `/pages/couponHistory/couponHistory`,
- })
- }
- },
- // 跳转到更多
- goMoreCard() {
- app.globalData.isCardBag = true
- wx.redirectTo({
- url: '/pages/shoppingMall/shoppingMall',
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
- if (this.data.page * 10 < this.data.total) {
- this.getCoupon(++this.data.page)
- }
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
- }
- })
|