Files
gxtyzx-uniapp/dist/dev/mp-weixin/package/coupon/index.js
T

239 lines
6.6 KiB
JavaScript

"use strict";
const common_vendor = require("../../common/vendor.js");
const api_booking_coupon_index = require("../../api/booking/coupon/index.js");
require("../../utils/request.js");
const utils_common = require("../../utils/common.js");
const api_booking_userCoupon_index = require("../../api/booking/userCoupon/index.js");
const _sfc_main = {
components: {},
data() {
return {
isRefresh: false,
isLogin: false,
userId: 0,
where: {
page: 1,
status: 0
},
canReset: false,
loadMore: "more",
logo: "",
items: ["待使用(0)", "已使用(0)", "已失效(0)"],
list: [],
styles: [
{
value: "button",
text: "按钮",
checked: true
},
{
value: "text",
text: "文字"
}
],
colors: ["#333333", "#4cd964", "#dd524d"],
current: 0,
colorIndex: 0,
activeColor: "#108001",
styleType: "text",
getWeek: utils_common.getWeek,
disabled: false
};
},
onLoad(option) {
this.openLogin();
this.reload();
},
onShow(e) {
this.openLogin();
this.reload();
},
// 触底函数
onReachBottom() {
const app = this;
const {
where
} = this;
if (app.canReset) {
app.where.page = ++where.page;
app.reload();
}
},
methods: {
async reload() {
const app = this;
const {
where
} = this;
common_vendor.index.showLoading({
title: "数据读取中."
});
app.loadMore = "loading";
const userCouponIds = [];
await app.getUserCoupon({
userId: common_vendor.index.getStorageSync("user_id")
}).then((list) => {
list.map((d) => {
userCouponIds.push(d.couponId);
});
});
console.log("userCoupons: ", userCouponIds);
api_booking_coupon_index.pageCoupon(where).then((res) => {
const list = res.list.map((d) => {
if (userCouponIds.indexOf(d.id) == 0) {
d.disabled = true;
}
return d;
});
if (app.list.length < res.count) {
app.list = app.list.concat(list);
app.canReset = true;
app.loadMore = "no-more";
} else {
app.canReset = false;
app.loadMore = "no-more";
}
console.log("app.list: ", app.list);
common_vendor.index.hideLoading();
app.isRefresh = false;
}).catch(() => {
common_vendor.index.showToast({
title: "请检查您的网络.",
icon: "none"
});
common_vendor.index.hideLoading();
app.isRefresh = false;
});
},
getUserCoupon() {
return new Promise((resolve, reject) => {
api_booking_userCoupon_index.listUserCoupon({}).then((result) => {
resolve(result);
}).catch(reject);
});
},
onClickItem(e) {
const app = this;
const {
where,
userId
} = this;
const index = e.currentIndex;
if (this.current !== e.currentIndex) {
this.current = e.currentIndex;
}
if (userId == 0) {
app.openLogin();
return;
}
app.where.status = index;
this.where.page = 1;
this.list = [];
this.reload();
},
openUrl(url) {
common_vendor.index.navigateTo({
url
});
},
toPay(orderId) {
common_vendor.index.navigateTo({
url: "/package/booking/confirm?id=" + orderId
});
},
closeOrder(item) {
common_vendor.index.showModal({
title: "确定取消此订单?",
success(o) {
if (o.confirm) {
OrderApi.updateOrder({
orderStatus: 2,
orderId: item.orderId
}).then((msg) => {
common_vendor.index.showToast({
title: msg,
icon: "none"
});
item.orderStatus = 2;
}).catch(() => {
common_vendor.index.showToast({
title: "请检查您的网络.",
icon: "none"
});
common_vendor.index.hideLoading();
});
}
}
});
},
// 弹出登录提示框
async openLogin() {
this.userId = common_vendor.index.getStorageSync("user_id");
if (!this.userId) {
this.$refs.login.open("bottom");
return false;
}
},
save(item, index) {
const app = this;
item.couponId = item.id;
app.list[index].disabled = true;
api_booking_userCoupon_index.addUserCoupon(item).then((msg) => {
common_vendor.index.showToast({
title: "领取成功",
icon: "success"
});
setTimeout(() => {
app.reload();
}, 2e3);
});
}
}
};
if (!Array) {
const _easycom_uv_button2 = common_vendor.resolveComponent("uv-button");
const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
const _easycom_ws_login2 = common_vendor.resolveComponent("ws-login");
(_easycom_uv_button2 + _easycom_uni_load_more2 + _easycom_ws_login2)();
}
const _easycom_uv_button = () => "../../uni_modules/uv-button/components/uv-button/uv-button.js";
const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
const _easycom_ws_login = () => "../../uni_modules/ws-login/components/ws-login/ws-login.js";
if (!Math) {
(_easycom_uv_button + _easycom_uni_load_more + _easycom_ws_login)();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: common_vendor.f($data.list, (item, index, i0) => {
return {
a: common_vendor.o(($event) => $options.save(item, index), index),
b: "7c98fd37-0-" + i0,
c: common_vendor.p({
size: "mini",
customStyle: {
background: "linear-gradient(to right, #70b915, #008e04)",
color: "#ffffff",
border: "none"
},
text: item.disabled ? "已领取" : "领取",
disabled: item.disabled
}),
d: index
};
}),
b: $data.list.length > 0
}, $data.list.length > 0 ? {
c: common_vendor.p({
status: $data.loadMore
})
} : {}, {
d: common_vendor.sr("login", "7c98fd37-2"),
e: common_vendor.o($options.reload),
f: common_vendor.p({
logo: $data.logo
})
});
}
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/gxwebsoft/APP/gxtyzx-uniapp-cli/src/package/coupon/index.vue"]]);
wx.createPage(MiniProgramPage);