detail.js 12 KB

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