detail.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const sheep_index = require("../../sheep/index.js");
  4. const sheep_api_promotion_coupon = require("../../sheep/api/promotion/coupon.js");
  5. const sheep_hooks_useGoods = require("../../sheep/hooks/useGoods.js");
  6. const sheep_api_product_spu = require("../../sheep/api/product/spu.js");
  7. const sheep_api_product_category = require("../../sheep/api/product/category.js");
  8. const sheep_util_index = require("../../sheep/util/index.js");
  9. require("../../sheep/url/index.js");
  10. require("../../sheep/store/index.js");
  11. require("../../sheep/store/app.js");
  12. require("../../sheep/api/promotion/diy.js");
  13. require("../../sheep/request/index.js");
  14. require("../../sheep/config/index.js");
  15. require("../../sheep/platform/index.js");
  16. require("../../sheep/platform/provider/wechat/index.js");
  17. require("../../sheep/platform/provider/wechat/miniProgram.js");
  18. require("../../sheep/api/member/auth.js");
  19. require("../../sheep/api/member/social.js");
  20. require("../../sheep/api/member/user.js");
  21. require("../../sheep/platform/provider/apple/index.js");
  22. require("../../sheep/platform/share.js");
  23. require("../../sheep/router/index.js");
  24. require("../../sheep/hooks/useModal.js");
  25. require("../../sheep/helper/index.js");
  26. require("../../sheep/helper/test.js");
  27. require("../../sheep/helper/digit.js");
  28. require("../../sheep/api/member/signin.js");
  29. require("../../sheep/helper/throttle.js");
  30. require("../../sheep/platform/pay.js");
  31. require("../../sheep/api/pay/order.js");
  32. require("../../sheep/store/user.js");
  33. require("../../sheep/store/cart.js");
  34. require("../../sheep/api/trade/cart.js");
  35. require("../../sheep/api/pay/wallet.js");
  36. require("../../sheep/api/trade/order.js");
  37. require("../../sheep/store/sys.js");
  38. require("../../sheep/store/modal.js");
  39. require("../../sheep/config/zIndex.js");
  40. if (!Array) {
  41. const _easycom_uni_collapse_item2 = common_vendor.resolveComponent("uni-collapse-item");
  42. const _easycom_uni_collapse2 = common_vendor.resolveComponent("uni-collapse");
  43. const _easycom_su_tabs2 = common_vendor.resolveComponent("su-tabs");
  44. const _easycom_su_sticky2 = common_vendor.resolveComponent("su-sticky");
  45. const _easycom_s_goods_column2 = common_vendor.resolveComponent("s-goods-column");
  46. const _easycom_uni_load_more2 = common_vendor.resolveComponent("uni-load-more");
  47. const _easycom_s_empty2 = common_vendor.resolveComponent("s-empty");
  48. const _easycom_s_layout2 = common_vendor.resolveComponent("s-layout");
  49. (_easycom_uni_collapse_item2 + _easycom_uni_collapse2 + _easycom_su_tabs2 + _easycom_su_sticky2 + _easycom_s_goods_column2 + _easycom_uni_load_more2 + _easycom_s_empty2 + _easycom_s_layout2)();
  50. }
  51. const _easycom_uni_collapse_item = () => "../../uni_modules/uni-collapse/components/uni-collapse-item/uni-collapse-item.js";
  52. const _easycom_uni_collapse = () => "../../uni_modules/uni-collapse/components/uni-collapse/uni-collapse.js";
  53. const _easycom_su_tabs = () => "../../sheep/ui/su-tabs/su-tabs.js";
  54. const _easycom_su_sticky = () => "../../sheep/ui/su-sticky/su-sticky.js";
  55. const _easycom_s_goods_column = () => "../../sheep/components/s-goods-column/s-goods-column.js";
  56. const _easycom_uni_load_more = () => "../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.js";
  57. const _easycom_s_empty = () => "../../sheep/components/s-empty/s-empty.js";
  58. const _easycom_s_layout = () => "../../sheep/components/s-layout/s-layout.js";
  59. if (!Math) {
  60. (_easycom_uni_collapse_item + _easycom_uni_collapse + _easycom_su_tabs + _easycom_su_sticky + _easycom_s_goods_column + _easycom_uni_load_more + _easycom_s_empty + _easycom_s_layout)();
  61. }
  62. const _sfc_main = {
  63. __name: "detail",
  64. setup(__props) {
  65. const state = common_vendor.reactive({
  66. id: 0,
  67. // 优惠劵模版编号 templateId
  68. couponId: 0,
  69. // 用户优惠劵编号 couponId
  70. coupon: {},
  71. // 优惠劵信息
  72. pagination: {
  73. list: [],
  74. total: 0,
  75. pageNo: 1,
  76. pageSize: 1
  77. },
  78. categoryId: 0,
  79. // 选中的商品分类编号
  80. tabMaps: [],
  81. // 指定分类时,每个分类构成一个 tab
  82. currentTab: 0,
  83. // 选中的 tabMaps 下标
  84. loadStatus: ""
  85. });
  86. function onTabsChange(e) {
  87. sheep_util_index.resetPagination(state.pagination);
  88. state.currentTab = e.index;
  89. state.categoryId = e.value;
  90. getGoodsListByCategory();
  91. }
  92. async function getGoodsListByCategory() {
  93. state.loadStatus = "loading";
  94. const { code, data } = await sheep_api_product_spu.SpuApi.getSpuPage({
  95. categoryId: state.categoryId,
  96. pageNo: state.pagination.pageNo,
  97. pageSize: state.pagination.pageSize
  98. });
  99. if (code !== 0) {
  100. return;
  101. }
  102. state.pagination.list = common_vendor._.concat(state.pagination.list, data.list);
  103. state.pagination.total = data.total;
  104. state.loadStatus = state.pagination.list.length < state.pagination.total ? "more" : "noMore";
  105. }
  106. async function getGoodsListById() {
  107. const { data, code } = await sheep_api_product_spu.SpuApi.getSpuListByIds(state.coupon.productScopeValues.join(","));
  108. if (code !== 0) {
  109. return;
  110. }
  111. state.pagination.list = data;
  112. }
  113. async function getCategoryList() {
  114. const { data, code } = await sheep_api_product_category.CategoryApi.getCategoryListByIds(state.coupon.productScopeValues.join(","));
  115. if (code !== 0) {
  116. return;
  117. }
  118. state.tabMaps = data.map((category) => ({ name: category.name, value: category.id }));
  119. if (state.tabMaps.length > 0) {
  120. state.categoryId = state.tabMaps[0].value;
  121. await getGoodsListByCategory();
  122. }
  123. }
  124. async function getCoupon() {
  125. const { code } = await sheep_api_promotion_coupon.CouponApi.takeCoupon(state.id);
  126. if (code !== 0) {
  127. return;
  128. }
  129. common_vendor.index.showToast({
  130. title: "领取成功"
  131. });
  132. setTimeout(() => {
  133. getCouponContent();
  134. }, 1e3);
  135. }
  136. async function getCouponContent() {
  137. const { code, data } = state.id > 0 ? await sheep_api_promotion_coupon.CouponApi.getCouponTemplate(state.id) : await sheep_api_promotion_coupon.CouponApi.getCoupon(state.couponId);
  138. if (code !== 0) {
  139. return;
  140. }
  141. state.coupon = data;
  142. if (state.coupon.productScope === 2) {
  143. await getGoodsListById();
  144. } else if (state.coupon.productScope === 3) {
  145. await getCategoryList();
  146. }
  147. }
  148. function loadMore() {
  149. if (state.loadStatus === "noMore") {
  150. return;
  151. }
  152. state.pagination.pageNo++;
  153. getGoodsListByCategory();
  154. }
  155. common_vendor.onLoad((options) => {
  156. state.id = options.id;
  157. state.couponId = options.couponId;
  158. getCouponContent(state.id, state.couponId);
  159. });
  160. common_vendor.onReachBottom(() => {
  161. loadMore();
  162. });
  163. return (_ctx, _cache) => {
  164. return common_vendor.e({
  165. a: common_vendor.unref(sheep_index.sheep).$url.static("/static/images/coupon_icon.png"),
  166. b: common_vendor.t(state.coupon.name),
  167. c: common_vendor.t(common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.coupon.usePrice)),
  168. d: common_vendor.t(state.coupon.discountType === 1 ? "减 " + common_vendor.unref(sheep_hooks_useGoods.fen2yuan)(state.coupon.discountPrice) + " 元" : "打 " + state.coupon.discountPercent / 10 + " 折"),
  169. e: state.id > 0
  170. }, state.id > 0 ? {
  171. f: common_vendor.t(state.coupon.canTake ? "立即领取" : "已领取")
  172. } : {
  173. g: common_vendor.t(state.coupon.status === 1 ? "立即使用" : state.coupon.status === 2 ? "已使用" : "已过期")
  174. }, {
  175. h: common_vendor.n(state.coupon.canTake || state.coupon.status === 1 ? "use-btn" : "disable-btn"),
  176. i: !state.coupon.canTake,
  177. j: common_vendor.o(getCoupon),
  178. k: state.coupon.validityType === 2
  179. }, state.coupon.validityType === 2 ? {
  180. l: common_vendor.t(state.coupon.fixedEndTerm)
  181. } : {
  182. m: common_vendor.t(common_vendor.unref(sheep_index.sheep).$helper.timeFormat(state.coupon.validStartTime, "yyyy-mm-dd")),
  183. n: common_vendor.t(common_vendor.unref(sheep_index.sheep).$helper.timeFormat(state.coupon.validEndTime, "yyyy-mm-dd"))
  184. }, {
  185. o: common_vendor.t(state.coupon.discountType === 1 ? "满减券" : "折扣券"),
  186. p: state.coupon.description
  187. }, state.coupon.description ? {
  188. q: common_vendor.t(state.coupon.description),
  189. r: common_vendor.p({
  190. title: "优惠券说明"
  191. })
  192. } : {}, {
  193. s: state.coupon.productScope === 1
  194. }, state.coupon.productScope === 1 ? {} : common_vendor.e({
  195. t: common_vendor.t(state.coupon.productScope === 2 ? "指定商品可用" : "指定分类可用"),
  196. v: state.coupon.productScope === 3
  197. }, state.coupon.productScope === 3 ? {
  198. w: common_vendor.o(onTabsChange),
  199. x: common_vendor.p({
  200. scrollable: true,
  201. list: state.tabMaps,
  202. current: state.currentTab
  203. })
  204. } : {}, {
  205. y: common_vendor.p({
  206. bgColor: "#fff"
  207. })
  208. }), {
  209. z: state.coupon.productScope === 2
  210. }, state.coupon.productScope === 2 ? {
  211. A: common_vendor.f(state.pagination.list, (item, index, i0) => {
  212. return {
  213. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  214. id: item.id
  215. }), index),
  216. b: "2d1fcfdf-5-" + i0 + ",2d1fcfdf-0",
  217. c: common_vendor.p({
  218. size: "lg",
  219. data: item,
  220. goodsFields: {
  221. title: {
  222. show: true
  223. },
  224. subtitle: {
  225. show: true
  226. },
  227. price: {
  228. show: true
  229. },
  230. original_price: {
  231. show: true
  232. },
  233. sales: {
  234. show: true
  235. },
  236. stock: {
  237. show: false
  238. }
  239. }
  240. }),
  241. d: index
  242. };
  243. })
  244. } : {}, {
  245. B: state.coupon.productScope === 3
  246. }, state.coupon.productScope === 3 ? {
  247. C: common_vendor.f(state.pagination.list, (item, index, i0) => {
  248. return {
  249. a: common_vendor.o(($event) => common_vendor.unref(sheep_index.sheep).$router.go("/pages/goods/index", {
  250. id: item.id
  251. }), index),
  252. b: "2d1fcfdf-6-" + i0 + ",2d1fcfdf-0",
  253. c: common_vendor.p({
  254. size: "lg",
  255. data: item,
  256. goodsFields: {
  257. title: {
  258. show: true
  259. },
  260. subtitle: {
  261. show: true
  262. },
  263. price: {
  264. show: true
  265. },
  266. original_price: {
  267. show: true
  268. },
  269. sales: {
  270. show: true
  271. },
  272. stock: {
  273. show: false
  274. }
  275. }
  276. }),
  277. d: index
  278. };
  279. })
  280. } : {}, {
  281. D: state.pagination.total > 0 && state.coupon.productScope === 3
  282. }, state.pagination.total > 0 && state.coupon.productScope === 3 ? {
  283. E: common_vendor.o(loadMore),
  284. F: common_vendor.p({
  285. status: state.loadStatus,
  286. ["content-text"]: {
  287. contentdown: "上拉加载更多"
  288. }
  289. })
  290. } : {}, {
  291. G: state.coupon.productScope === 3 && state.pagination.total === 0
  292. }, state.coupon.productScope === 3 && state.pagination.total === 0 ? {
  293. H: common_vendor.p({
  294. paddingTop: "0",
  295. icon: "/static/soldout-empty.png",
  296. text: "暂无商品"
  297. })
  298. } : {}, {
  299. I: common_vendor.p({
  300. title: "优惠券详情"
  301. })
  302. });
  303. };
  304. }
  305. };
  306. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-2d1fcfdf"], ["__file", "D:/zx/mall-front-app/pages/coupon/detail.vue"]]);
  307. wx.createPage(MiniProgramPage);