|
|
@@ -1,247 +1,284 @@
|
|
|
-const app = getApp()
|
|
|
+const app = getApp();
|
|
|
const api = require("../../../../request/api.js");
|
|
|
-const http = require('../../../../request/http.js');
|
|
|
-const utils = require('../../../../utils/util.js');
|
|
|
-const storeKeys = require('../../../../utils/storageKeys.js');
|
|
|
+const http = require("../../../../request/http.js");
|
|
|
+const utils = require("../../../../utils/util.js");
|
|
|
+const storeKeys = require("../../../../utils/storageKeys.js");
|
|
|
Page({
|
|
|
- data: {
|
|
|
- isLoading: true, //是否处于加载
|
|
|
- list: [], //政策优惠券
|
|
|
- Limitcouponlist:[], //限时抢购优惠券
|
|
|
- couponState: 0, //0:可领取 1:已领取 2:领完啦
|
|
|
- showConfirmModal: false, //是否显示确定激活弹窗
|
|
|
- couponInputValue: '',
|
|
|
- page: 1, //分页
|
|
|
- list: [], //页面数据
|
|
|
- dataObj: {}, //页面对象
|
|
|
- is_bottom: false, //到底了
|
|
|
- price: 100,
|
|
|
- inputFocusValue: false,
|
|
|
- isOnLoad: true
|
|
|
- },
|
|
|
- onLoad: function (options) {
|
|
|
- this.getData()
|
|
|
- },
|
|
|
- onShow: function (options) {
|
|
|
- if (!this.data.isOnLoad) {
|
|
|
- this.getData()
|
|
|
- }
|
|
|
- this.data.isOnLoad = false;
|
|
|
- },
|
|
|
- //获取页面内容
|
|
|
- getData(noLoading) {
|
|
|
- if(!noLoading){
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中",
|
|
|
- mask: true
|
|
|
- });
|
|
|
- }
|
|
|
- let promise1 = new Promise((resolve) => {
|
|
|
- this.getPageData(() => {
|
|
|
- resolve();
|
|
|
- });
|
|
|
- })
|
|
|
- let promise2 = new Promise((resolve) => {
|
|
|
- this.getLimitcouponlist(() => {
|
|
|
- resolve();
|
|
|
- });
|
|
|
- })
|
|
|
- Promise.all([promise1, promise2]).then((values) => {
|
|
|
- !noLoading && wx.hideLoading();
|
|
|
- this.setData({
|
|
|
- isLoading: false
|
|
|
- })
|
|
|
- }).catch((error) => {})
|
|
|
- },
|
|
|
- //获取限时抢购优惠卷
|
|
|
- getLimitcouponlist(resolve) {
|
|
|
- http.request({
|
|
|
- url: api.URL + "/api/coupon/limitcouponlist",
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- method: 'GET',
|
|
|
- success: (res) => {
|
|
|
- resolve && resolve();
|
|
|
- console.log(res)
|
|
|
- let Limitcouponlist = res.data.data.list;
|
|
|
- Limitcouponlist.forEach(item => {
|
|
|
- if (item.coupon_type == 10) {
|
|
|
- item.coupon_title_ = "立减券"
|
|
|
- } else if (item.coupon_type == 20) {
|
|
|
- item.coupon_title_ = "满减券"
|
|
|
- } else if (item.coupon_type == 30) {
|
|
|
- item.coupon_title_ = "首单券"
|
|
|
- } else if (item.coupon_type == 40) {
|
|
|
- item.coupon_title_ = "新人券"
|
|
|
- } else if (item.coupon_type == 50) {
|
|
|
- item.coupon_title_ = "折扣券"
|
|
|
- }else {
|
|
|
- item.coupon_title_ = ""
|
|
|
- }
|
|
|
- });
|
|
|
- this.setData({
|
|
|
- Limitcouponlist
|
|
|
- });
|
|
|
- },
|
|
|
- error: (res) => {
|
|
|
- resolve && resolve();
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- //获取正常优惠卷
|
|
|
- getPageData(resolve) {
|
|
|
- http.request({
|
|
|
- url: api.URL + "/api/coupon/couponlist",
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- method: 'GET',
|
|
|
- success: (res) => {
|
|
|
- resolve && resolve();
|
|
|
- let list = res.data.data.list;
|
|
|
- list.forEach(item => {
|
|
|
- if (item.coupon_type == 10) {
|
|
|
- item.coupon_title_ = "立减券"
|
|
|
- } else if (item.coupon_type == 20) {
|
|
|
- item.coupon_title_ = "满减券"
|
|
|
- } else if (item.coupon_type == 30) {
|
|
|
- item.coupon_title_ = "首单券"
|
|
|
- } else if (item.coupon_type == 40) {
|
|
|
- item.coupon_title_ = "新人券"
|
|
|
- } else if (item.coupon_type == 50) {
|
|
|
- item.coupon_title_ = "折扣券"
|
|
|
- } else {
|
|
|
- item.coupon_title_ = ""
|
|
|
- }
|
|
|
- });
|
|
|
- this.setData({
|
|
|
- list,
|
|
|
- dataObj: res.data.data
|
|
|
- });
|
|
|
- // if (!noLoading) {
|
|
|
- // wx.hideLoading();
|
|
|
- // }
|
|
|
- },
|
|
|
- error: (res) => {
|
|
|
- resolve && resolve();
|
|
|
- // if (!noLoading) {
|
|
|
- // wx.hideLoading();
|
|
|
- // }
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
-
|
|
|
- onCardCouponSecInput: function (e) {
|
|
|
- let couponInputValue = e.detail.value.replace(/\s+/g, '');
|
|
|
+ data: {
|
|
|
+ isLoading: true, //是否处于加载
|
|
|
+ goodsList: [], //积分商品
|
|
|
+ Limitcouponlist: [], //限时抢购优惠券
|
|
|
+ couponState: 0, //0:可领取 1:已领取 2:领完啦
|
|
|
+ showConfirmModal: false, //是否显示确定激活弹窗
|
|
|
+ couponInputValue: "",
|
|
|
+ page: 1, //分页
|
|
|
+ list: [], //页面数据
|
|
|
+ dataObj: {}, //页面对象
|
|
|
+ is_bottom: false, //到底了
|
|
|
+ price: 100,
|
|
|
+ inputFocusValue: false,
|
|
|
+ isOnLoad: true,
|
|
|
+ tabSelected: 0,
|
|
|
+ info: {},
|
|
|
+ },
|
|
|
+ onLoad: function (options) {
|
|
|
+ this.getData();
|
|
|
+ },
|
|
|
+ onShow: function (options) {
|
|
|
+ if (!this.data.isOnLoad) {
|
|
|
+ this.getData();
|
|
|
+ }
|
|
|
+ this.data.isOnLoad = false;
|
|
|
+ },
|
|
|
+ //获取页面内容
|
|
|
+ getData(noLoading) {
|
|
|
+ if (!noLoading) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ let promise1 = new Promise(resolve => {
|
|
|
+ this.getPageData(() => {
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ let promise2 = new Promise(resolve => {
|
|
|
+ this.getUserInfo(() => {
|
|
|
+ resolve();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ Promise.all([promise1, promise2])
|
|
|
+ .then(values => {
|
|
|
+ !noLoading && wx.hideLoading();
|
|
|
this.setData({
|
|
|
- couponInputValue
|
|
|
- })
|
|
|
- // this.data.couponInputValue = e.detail.value;
|
|
|
- },
|
|
|
- onItemButtonClicked: utils.throttle(function (e) {
|
|
|
- if (!utils.getStorageSync(storeKeys.TOKEN)) {
|
|
|
- wx.navigateTo({
|
|
|
- url: "/pages/tabBar/login/login"
|
|
|
- })
|
|
|
- return;
|
|
|
- }
|
|
|
- let item = e.currentTarget.dataset.item;
|
|
|
- let index = e.currentTarget.dataset.index;
|
|
|
- let state = e.currentTarget.dataset.type;
|
|
|
- let id = item.coupon_id;
|
|
|
- let num = item.avaiable_num;
|
|
|
- if (state == 1) {
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中"
|
|
|
- });
|
|
|
- http.request({
|
|
|
- url: api.URL + '/api/MyCoupon/receive?coupon_id=' + id,
|
|
|
- method: 'GET',
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- success: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
- if (res.data.status == 200) {
|
|
|
- wx.showToast({
|
|
|
- title: '领取成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 3000
|
|
|
- });
|
|
|
- this.getData(true)
|
|
|
- }
|
|
|
- },
|
|
|
- error: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
-
|
|
|
- wx.showToast({
|
|
|
- title: '领取失败',
|
|
|
- icon: 'error',
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- },
|
|
|
- })
|
|
|
- } else if (state == 0) {
|
|
|
- wx.switchTab({
|
|
|
- url: '/pages/tabBar/allGoods/allGoods'
|
|
|
- })
|
|
|
+ isLoading: false,
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .catch(error => {});
|
|
|
+ },
|
|
|
+ changeNavTab(e) {
|
|
|
+ let { index } = e.currentTarget.dataset;
|
|
|
+ let tabSelected = this.data.tabSelected
|
|
|
+ this.setData({
|
|
|
+ tabSelected: parseInt(index),
|
|
|
+ });
|
|
|
+ if (index < 2 && tabSelected !== index) {
|
|
|
+ this.getPageData()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //获取积分产品
|
|
|
+ getPageData(noLoading) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ mask: true,
|
|
|
+ });
|
|
|
+ http.request({
|
|
|
+ url:
|
|
|
+ api.URL +
|
|
|
+ "/api/goods/list?goods_type=40&sortStyle=" +
|
|
|
+ this.data.sortStyle +
|
|
|
+ "&sortSort=" +
|
|
|
+ this.data.sortSort +
|
|
|
+ "&page=" +
|
|
|
+ this.data.page,
|
|
|
+ token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
+ method: "GET",
|
|
|
+ success: res => {
|
|
|
+ let list = [];
|
|
|
+ let tmpList = res.data.data.list.data;
|
|
|
+ if (this.data.page == 1) {
|
|
|
+ list = tmpList;
|
|
|
+ } else {
|
|
|
+ list = this.data.list.concat(tmpList);
|
|
|
}
|
|
|
- }),
|
|
|
- activateCode: utils.throttle(function (e) {
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中"
|
|
|
+ this.setData({
|
|
|
+ list: list.filter(i => this.data.tabSelected === 1 ? i.points_to_exchange <= this.data.info.accumulate_points : true),
|
|
|
+ dataObj: res.data.data.list,
|
|
|
+ });
|
|
|
+ setTimeout(() => {
|
|
|
+ this.setData({
|
|
|
+ isLoading: false,
|
|
|
+ });
|
|
|
+ }, 300);
|
|
|
+ wx.hideLoading();
|
|
|
+ },
|
|
|
+ error: res => {
|
|
|
+ this.setData({
|
|
|
+ isLoading: false,
|
|
|
});
|
|
|
- http.request({
|
|
|
- url: api.URL + '/api/MyCoupon/exchange?redeemCode=' + this.data.couponInputValue,
|
|
|
- method: 'GET',
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- success: (res) => {
|
|
|
- // wx.hideLoading();
|
|
|
+ wx.hideLoading();
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
- if (res.data.status == 200) {
|
|
|
- // this.getPageData()
|
|
|
- this.setData({
|
|
|
- couponInputValue: ""
|
|
|
- })
|
|
|
- wx.showToast({
|
|
|
- title: '兑换成功',
|
|
|
- icon: 'success',
|
|
|
- duration: 3000
|
|
|
- })
|
|
|
- }
|
|
|
- },
|
|
|
- error: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
- this.setData({
|
|
|
- inputFocusValue: true,
|
|
|
- couponInputValue: ""
|
|
|
- });
|
|
|
- // wx.showToast({
|
|
|
- // title: res.data.message,
|
|
|
- // icon: 'error',
|
|
|
- // duration: 3000
|
|
|
- // })
|
|
|
+ //获取用户信息
|
|
|
+ getUserInfo() {
|
|
|
+ http.request({
|
|
|
+ url: api.URL + "/api/user/info",
|
|
|
+ method: "GET",
|
|
|
+ token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
+ success: res => {
|
|
|
+ let info = res.data.data.userInfo;
|
|
|
+ // 开发专用
|
|
|
|
|
|
- utils.toast(res.data.message)
|
|
|
- },
|
|
|
- })
|
|
|
- }),
|
|
|
- //显示确定激活弹窗
|
|
|
- showConfirmModal(e) {
|
|
|
- if (this.data.couponInputValue.length == 0) {
|
|
|
- return;
|
|
|
+ if (info.mobile == "17573207179") {
|
|
|
+ // info.show_cash_box = true;
|
|
|
+ // info.role = 1;
|
|
|
+ // info.seller_grade = 3;
|
|
|
+ info.grade_id = 10001;
|
|
|
+ info.is_pickup = 1;
|
|
|
}
|
|
|
+ //是否为特殊身份
|
|
|
+ let chara = false;
|
|
|
+ if ((info.role && info.role != 1) || info.show_cash_box) {
|
|
|
+ chara = true;
|
|
|
+ }
|
|
|
+ info.chara = chara;
|
|
|
+ utils.setStorageSync(storeKeys.USERINFO, info);
|
|
|
this.setData({
|
|
|
- showConfirmModal: true,
|
|
|
- })
|
|
|
- },
|
|
|
- //关闭确定激活弹窗
|
|
|
- hideConfirmModal() {
|
|
|
- this.setData({
|
|
|
- showConfirmModal: false
|
|
|
+ info,
|
|
|
});
|
|
|
+ setTimeout(() => {
|
|
|
+ this.setData({
|
|
|
+ isLoading: false,
|
|
|
+ });
|
|
|
+ }, 300);
|
|
|
+ },
|
|
|
+ error: res => {
|
|
|
+ utils.toast(res.data.message);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onCardCouponSecInput: function (e) {
|
|
|
+ let couponInputValue = e.detail.value.replace(/\s+/g, "");
|
|
|
+ this.setData({
|
|
|
+ couponInputValue,
|
|
|
+ });
|
|
|
+ // this.data.couponInputValue = e.detail.value;
|
|
|
+ },
|
|
|
+ onItemButtonClicked: utils.throttle(function (e) {
|
|
|
+ if (!utils.getStorageSync(storeKeys.TOKEN)) {
|
|
|
+ wx.navigateTo({
|
|
|
+ url: "/pages/tabBar/login/login",
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ let item = e.currentTarget.dataset.item;
|
|
|
+ let index = e.currentTarget.dataset.index;
|
|
|
+ let state = e.currentTarget.dataset.type;
|
|
|
+ let id = item.coupon_id;
|
|
|
+ let num = item.avaiable_num;
|
|
|
+ if (state == 1) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ });
|
|
|
+ http.request({
|
|
|
+ url: api.URL + "/api/MyCoupon/receive?coupon_id=" + id,
|
|
|
+ method: "GET",
|
|
|
+ token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
+ success: res => {
|
|
|
+ wx.hideLoading();
|
|
|
+ if (res.data.status == 200) {
|
|
|
+ wx.showToast({
|
|
|
+ title: "领取成功",
|
|
|
+ icon: "success",
|
|
|
+ duration: 3000,
|
|
|
+ });
|
|
|
+ this.getData(true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: res => {
|
|
|
+ wx.hideLoading();
|
|
|
|
|
|
+ wx.showToast({
|
|
|
+ title: "领取失败",
|
|
|
+ icon: "error",
|
|
|
+ duration: 3000,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ });
|
|
|
+ } else if (state == 0) {
|
|
|
+ wx.switchTab({
|
|
|
+ url: "/pages/tabBar/allGoods/allGoods",
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }),
|
|
|
+ activateCode: utils.throttle(function (e) {
|
|
|
+ wx.showLoading({
|
|
|
+ title: "加载中",
|
|
|
+ });
|
|
|
+ http.request({
|
|
|
+ url:
|
|
|
+ api.URL +
|
|
|
+ "/api/MyCoupon/exchange?redeemCode=" +
|
|
|
+ this.data.couponInputValue,
|
|
|
+ method: "GET",
|
|
|
+ token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
+ success: res => {
|
|
|
+ // wx.hideLoading();
|
|
|
|
|
|
- },
|
|
|
- onButtonActiveCode() {
|
|
|
+ if (res.data.status == 200) {
|
|
|
+ // this.getPageData()
|
|
|
+ this.setData({
|
|
|
+ couponInputValue: "",
|
|
|
+ });
|
|
|
+ wx.showToast({
|
|
|
+ title: "兑换成功",
|
|
|
+ icon: "success",
|
|
|
+ duration: 3000,
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: res => {
|
|
|
+ wx.hideLoading();
|
|
|
this.setData({
|
|
|
- showConfirmModal: false
|
|
|
+ inputFocusValue: true,
|
|
|
+ couponInputValue: "",
|
|
|
});
|
|
|
- this.activateCode();
|
|
|
+ // wx.showToast({
|
|
|
+ // title: res.data.message,
|
|
|
+ // icon: 'error',
|
|
|
+ // duration: 3000
|
|
|
+ // })
|
|
|
+
|
|
|
+ utils.toast(res.data.message);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ }),
|
|
|
+ //显示确定激活弹窗
|
|
|
+ showConfirmModal(e) {
|
|
|
+ if (this.data.couponInputValue.length == 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
-})
|
|
|
+ this.setData({
|
|
|
+ showConfirmModal: true,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ //关闭确定激活弹窗
|
|
|
+ hideConfirmModal() {
|
|
|
+ this.setData({
|
|
|
+ showConfirmModal: false,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ onButtonActiveCode() {
|
|
|
+ this.setData({
|
|
|
+ showConfirmModal: false,
|
|
|
+ });
|
|
|
+ this.activateCode();
|
|
|
+ },
|
|
|
+ //前往兑换
|
|
|
+ goExchange(e) {
|
|
|
+ let { item } = e.currentTarget.dataset;
|
|
|
+ console.log(item)
|
|
|
+ let data = {
|
|
|
+ mode: "pointsExchange",
|
|
|
+ goodsId: item.goods_id, //商品ID
|
|
|
+ goodsSkuId: item.goods_sku_id || 0, //商品规格ID
|
|
|
+ goodsNum: 1, //商品数量
|
|
|
+ };
|
|
|
+ // return
|
|
|
+ let url = "/pages/cart/pages/confirmOrder/confirmOrder?data=" + JSON.stringify(data);
|
|
|
+ app.navigateToUrl(url);
|
|
|
+ },
|
|
|
+});
|