detail.js 13 KB

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