|
|
@@ -1,330 +1,66 @@
|
|
|
-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");
|
|
|
+// pages/index/pages/bonusShop/bonusShop.js
|
|
|
Page({
|
|
|
- data: {
|
|
|
- isLoading: true, //是否处于加载
|
|
|
- goodsList: [], //积分商品
|
|
|
- exchangeList: [],
|
|
|
- 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({
|
|
|
- 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()
|
|
|
- } else if (index == 2) {
|
|
|
- this.getExchangeList()
|
|
|
- }
|
|
|
- },
|
|
|
- //获取积分产品
|
|
|
- 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);
|
|
|
- }
|
|
|
- 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,
|
|
|
- });
|
|
|
- wx.hideLoading();
|
|
|
- },
|
|
|
- });
|
|
|
- },
|
|
|
|
|
|
- //获取用户信息
|
|
|
- getUserInfo() {
|
|
|
- http.request({
|
|
|
- url: api.URL + "/api/user/info",
|
|
|
- method: "GET",
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- success: res => {
|
|
|
- let info = res.data.data.userInfo;
|
|
|
- // 开发专用
|
|
|
+ /**
|
|
|
+ * Page initial data
|
|
|
+ */
|
|
|
+ data: {
|
|
|
|
|
|
- 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({
|
|
|
- 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();
|
|
|
+ /**
|
|
|
+ * Lifecycle function--Called when page load
|
|
|
+ */
|
|
|
+ onLoad(options) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Lifecycle function--Called when page is initially rendered
|
|
|
+ */
|
|
|
+ onReady() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Lifecycle function--Called when page show
|
|
|
+ */
|
|
|
+ onShow() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Lifecycle function--Called when page hide
|
|
|
+ */
|
|
|
+ onHide() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Lifecycle function--Called when page unload
|
|
|
+ */
|
|
|
+ onUnload() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Page event handler function--Called when user drop down
|
|
|
+ */
|
|
|
+ onPullDownRefresh() {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Called when page reach bottom
|
|
|
+ */
|
|
|
+ onReachBottom() {
|
|
|
+
|
|
|
+ },
|
|
|
|
|
|
- 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
|
|
|
- // })
|
|
|
+ /**
|
|
|
+ * Called when user click on the top right corner to share
|
|
|
+ */
|
|
|
+ onShareAppMessage() {
|
|
|
|
|
|
- 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);
|
|
|
- },
|
|
|
- //列表
|
|
|
- getExchangeList(){
|
|
|
- // dataType //订单类型 (all全部 payment待付款 received待发货 received待收货 comment待评价)
|
|
|
- let that = this, request_url = '';
|
|
|
- wx.showLoading({
|
|
|
- title: "加载中"
|
|
|
- });
|
|
|
- http.request({
|
|
|
- method: 'GET',
|
|
|
- url: api.URL + '/api/order/list?isExchange=1&dataType=all',
|
|
|
- token: utils.getStorageSync(storeKeys.TOKEN),
|
|
|
- success: (res) => {
|
|
|
- wx.hideLoading();
|
|
|
- let data_obj = res.data.data.list
|
|
|
- data_obj.data.forEach((item)=>{
|
|
|
- item.isShowMoreBtn = false
|
|
|
- if(item.state_value==30 && item.za){//已完成
|
|
|
- item.isShowMoreBtn = true
|
|
|
- item.leftBox = false
|
|
|
- }
|
|
|
- })
|
|
|
- console.log(data_obj.data)
|
|
|
- let list = [];
|
|
|
- if (that.data.page == 1) {
|
|
|
- list = data_obj.data;
|
|
|
- } else {
|
|
|
- list = that.data.list.concat(data_obj.data);
|
|
|
- }
|
|
|
- that.setData({
|
|
|
- exchangeList: list,
|
|
|
- isLoading: false
|
|
|
- });
|
|
|
- // console.log(that.data.list)
|
|
|
- if (data_obj.total == 0) {
|
|
|
- that.setData({ is_bottom: false });
|
|
|
- }
|
|
|
- if (data_obj.current_page >= data_obj.last_page && data_obj.total > 0) {
|
|
|
- that.setData({ is_bottom: true });
|
|
|
- }
|
|
|
- },
|
|
|
- error: (res) => {},
|
|
|
- })
|
|
|
- },
|
|
|
-});
|
|
|
+})
|