list.js 8.4 KB

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