list.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_util_index = require("../../sheep/util/index.js");
  5. const sheep_api_promotion_coupon = require("../../sheep/api/promotion/coupon.js");
  6. require("../../sheep/url/index.js");
  7. require("../../sheep/store/index.js");
  8. require("../../sheep/store/app.js");
  9. require("../../sheep/api/promotion/diy.js");
  10. require("../../sheep/request/index.js");
  11. require("../../sheep/config/index.js");
  12. require("../../sheep/platform/index.js");
  13. require("../../sheep/platform/provider/wechat/index.js");
  14. require("../../sheep/platform/provider/wechat/miniProgram.js");
  15. require("../../sheep/api/member/auth.js");
  16. require("../../sheep/api/member/social.js");
  17. require("../../sheep/api/member/user.js");
  18. require("../../sheep/platform/provider/apple/index.js");
  19. require("../../sheep/platform/share.js");
  20. require("../../sheep/router/index.js");
  21. require("../../sheep/hooks/useModal.js");
  22. require("../../sheep/helper/index.js");
  23. require("../../sheep/helper/test.js");
  24. require("../../sheep/helper/digit.js");
  25. require("../../sheep/api/member/signin.js");
  26. require("../../sheep/helper/throttle.js");
  27. require("../../sheep/platform/pay.js");
  28. require("../../sheep/api/pay/order.js");
  29. require("../../sheep/store/user.js");
  30. require("../../sheep/store/cart.js");
  31. require("../../sheep/api/trade/cart.js");
  32. require("../../sheep/api/pay/wallet.js");
  33. require("../../sheep/api/trade/order.js");
  34. require("../../sheep/store/sys.js");
  35. require("../../sheep/store/modal.js");
  36. require("../../sheep/config/zIndex.js");
  37. if (!Array) {
  38. const _easycom_su_tabs2 = common_vendor.resolveComponent("su-tabs");
  39. const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
  40. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  41. const _easycom_s_coupon_list2 = common_vendor.resolveComponent("s-coupon-list");
  42. const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  43. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  44. (_easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_s_empty2 + _easycom_s_coupon_list2 + _easycom_uni_load_more2 + _easycom_s_layout2)();
  45. }
  46. const _easycom_su_tabs = () => "../../sheep/ui/su-tabs/su-tabs.js";
  47. const _easycom_su_sticky = () => "../../sheep/ui/su-sticky/su-sticky.js";
  48. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  49. const _easycom_s_coupon_list = () => "../../sheep/components/s-coupon-list/s-coupon-list.js";
  50. const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
  51. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  52. if (!Math) {
  53. (_easycom_su_tabs + _easycom_su_sticky + _easycom_s_empty + _easycom_s_coupon_list + _easycom_uni_load_more + _easycom_s_layout)();
  54. }
  55. const _sfc_main = {
  56. __name: "list",
  57. setup(__props) {
  58. const state = common_vendor.reactive({
  59. currentTab: 0,
  60. // 当前 tab
  61. type: "1",
  62. pagination: {
  63. list: [],
  64. total: 0,
  65. pageNo: 1,
  66. pageSize: 5
  67. },
  68. loadStatus: ""
  69. });
  70. const tabMaps = [
  71. {
  72. name: "领券中心",
  73. value: "all"
  74. },
  75. {
  76. name: "已领取",
  77. value: "1"
  78. },
  79. {
  80. name: "已使用",
  81. value: "2"
  82. },
  83. {
  84. name: "已失效",
  85. value: "3"
  86. }
  87. ];
  88. function onTabsChange(e) {
  89. state.currentTab = e.index;
  90. state.type = e.value;
  91. sheep_util_index.resetPagination(state.pagination);
  92. if (state.currentTab === 0) {
  93. getData();
  94. } else {
  95. getCoupon();
  96. }
  97. }
  98. async function getData() {
  99. state.loadStatus = "loading";
  100. const { data, code } = await sheep_api_promotion_coupon.CouponApi.getCouponTemplatePage({
  101. pageNo: state.pagination.pageNo,
  102. pageSize: state.pagination.pageSize
  103. });
  104. if (code !== 0) {
  105. return;
  106. }
  107. state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
  108. state.pagination.total = data.total;
  109. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  110. }
  111. async function getCoupon() {
  112. state.loadStatus = "loading";
  113. const { data, code } = await sheep_api_promotion_coupon.CouponApi.getCouponPage({
  114. pageNo: state.pagination.pageNo,
  115. pageSize: state.pagination.pageSize,
  116. status: state.type
  117. });
  118. if (code !== 0) {
  119. return;
  120. }
  121. state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
  122. state.pagination.total = data.total;
  123. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  124. }
  125. async function getBuy(id) {
  126. const { code } = await sheep_api_promotion_coupon.CouponApi.takeCoupon(id);
  127. if (code !== 0) {
  128. return;
  129. }
  130. common_vendor.index.showToast({
  131. title: "领取成功"
  132. });
  133. setTimeout(() => {
  134. sheep_util_index.resetPagination(state.pagination);
  135. getData();
  136. }, 1e3);
  137. }
  138. function loadMore() {
  139. if (state.loadStatus === "noMore") {
  140. return;
  141. }
  142. state.pagination.pageNo++;
  143. if (state.currentTab === 0) {
  144. getData();
  145. } else {
  146. getCoupon();
  147. }
  148. }
  149. common_vendor.onLoad((Option) => {
  150. if (Option.type === "all" || !Option.type) {
  151. getData();
  152. } else {
  153. Option.type === "geted" ? state.currentTab = 1 : Option.type === "used" ? state.currentTab = 2 : state.currentTab = 3;
  154. state.type = state.currentTab;
  155. getCoupon();
  156. }
  157. });
  158. common_vendor.onReachBottom(() => {
  159. loadMore();
  160. });
  161. return (_ctx, _cache) => {
  162. return common_vendor.e({
  163. a: common_vendor.o(onTabsChange),
  164. b: common_vendor.p({
  165. list: tabMaps,
  166. scrollable: false,
  167. current: state.currentTab
  168. }),
  169. c: common_vendor.p({
  170. bgColor: "#fff"
  171. }),
  172. d: state.pagination.total === 0
  173. }, state.pagination.total === 0 ? {
  174. e: common_vendor.p({
  175. icon: "/static/coupon-empty.png",
  176. text: "暂无优惠券"
  177. })
  178. } : {}, {
  179. f: state.currentTab === 0
  180. }, state.currentTab === 0 ? {
  181. g: common_vendor.f(state.pagination.list, (item, k0, i0) => {
  182. return {
  183. a: common_vendor.t(item.canTake ? "立即领取" : "已领取"),
  184. b: common_vendor.n(!item.canTake ? "border-btn" : ""),
  185. c: common_vendor.o(($event) => getBuy(item.id), item.id),
  186. d: !item.canTake,
  187. e: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
  188. id: item.id
  189. }), item.id),
  190. f: "019d569f-4-" + i0 + ",019d569f-0",
  191. g: common_vendor.p({
  192. data: item
  193. }),
  194. h: item.id
  195. };
  196. })
  197. } : {
  198. h: common_vendor.f(state.pagination.list, (item, k0, i0) => {
  199. return {
  200. a: common_vendor.t(item.status === 1 ? "立即使用" : item.status === 2 ? "已使用" : "已过期"),
  201. b: common_vendor.n(item.status !== 1 ? "disabled-btn" : ""),
  202. c: item.status !== 1,
  203. d: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
  204. couponId: item.id
  205. }), item.id),
  206. e: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/coupon/detail", {
  207. couponId: item.id
  208. }), item.id),
  209. f: "019d569f-5-" + i0 + ",019d569f-0",
  210. g: common_vendor.p({
  211. data: item,
  212. type: "user"
  213. }),
  214. h: item.id
  215. };
  216. })
  217. }, {
  218. i: state.pagination.total > 0
  219. }, state.pagination.total > 0 ? {
  220. j: common_vendor.o(loadMore),
  221. k: common_vendor.p({
  222. status: state.loadStatus,
  223. ["content-text"]: {
  224. contentdown: "上拉加载更多"
  225. }
  226. })
  227. } : {}, {
  228. l: common_vendor.p({
  229. title: "优惠券",
  230. bgStyle: {
  231. color: "#f2f2f2"
  232. }
  233. })
  234. });
  235. };
  236. }
  237. };
  238. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-019d569f"], ["__file", "D:/zx/mall-front-app/pages/coupon/list.vue"]]);
  239. wx.createPage(MiniProgramPage);