index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. "use strict";
  2. const common_vendor = require("../../common/vendor.js");
  3. const hooks_useToast = require("../../hooks/useToast.js");
  4. const api_index = require("../../api/index.js");
  5. if (!Array) {
  6. const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
  7. const _component_up_line = common_vendor.resolveComponent("up-line");
  8. (_easycom_uni_icons2 + _component_up_line)();
  9. }
  10. const _easycom_uni_icons = () => "../../uni_modules/uni-icons/components/uni-icons/uni-icons.js";
  11. if (!Math) {
  12. (common_vendor.unref(productConSwiper) + _easycom_uni_icons + common_vendor.unref(productWindow) + common_vendor.unref(couponListWindow))();
  13. }
  14. const productConSwiper = () => "../../components/productConSwiper/index.js";
  15. const couponListWindow = () => "../../components/couponListWindow/index.js";
  16. const productWindow = () => "../../components/productWindow/index.js";
  17. const _sfc_main = {
  18. __name: "index",
  19. setup(__props) {
  20. const {
  21. Toast
  22. } = hooks_useToast.useToast();
  23. const coupon = common_vendor.ref({
  24. coupon: false,
  25. type: 1,
  26. list: [],
  27. count: []
  28. });
  29. const attrTxt = common_vendor.ref("请选择");
  30. const attrValue = common_vendor.ref("");
  31. common_vendor.ref(false);
  32. const id = common_vendor.ref(0);
  33. const productInfo = common_vendor.ref({});
  34. const productValue = common_vendor.ref([]);
  35. common_vendor.ref([]);
  36. common_vendor.ref(1);
  37. common_vendor.ref(false);
  38. const storeImage = common_vendor.ref("");
  39. common_vendor.ref("");
  40. common_vendor.ref("/static/images/posterbackgd.png");
  41. const sharePacket = common_vendor.ref({
  42. isState: true
  43. });
  44. common_vendor.ref("");
  45. common_vendor.ref([]);
  46. common_vendor.ref(0);
  47. common_vendor.ref(false);
  48. const attr = common_vendor.ref({
  49. cartAttr: false,
  50. productAttr: [],
  51. productSelect: {}
  52. });
  53. const description = common_vendor.ref("");
  54. common_vendor.ref(0);
  55. const activityH5 = common_vendor.ref([]);
  56. const retunTop = common_vendor.ref(true);
  57. common_vendor.ref("");
  58. const opacity = common_vendor.ref(0);
  59. const scrollY = common_vendor.ref(0);
  60. common_vendor.ref([]);
  61. const height = common_vendor.ref(0);
  62. common_vendor.ref([]);
  63. const lock = common_vendor.ref(false);
  64. const scrollTop = common_vendor.ref(0);
  65. const sliderImage = common_vendor.ref([]);
  66. common_vendor.ref(false);
  67. common_vendor.ref("");
  68. const imgTop = common_vendor.ref("");
  69. common_vendor.ref("");
  70. const homeTop = common_vendor.ref(20);
  71. const userCollect = common_vendor.ref(false);
  72. const returnShow = common_vendor.ref(true);
  73. const type = common_vendor.ref("");
  74. const showProductPopup = common_vendor.ref(false);
  75. const showCouponPopup = common_vendor.ref(false);
  76. const handleBtnTpe = common_vendor.ref("");
  77. common_vendor.onLoad((options) => {
  78. const pages = getCurrentPages();
  79. returnShow.value = pages.length > 1;
  80. retunTop.value = pages.length > 1;
  81. setTimeout(() => {
  82. if (options.spread) {
  83. spread(options.spread).catch(() => {
  84. });
  85. }
  86. }, 2e3);
  87. common_vendor.index.getSystemInfo({
  88. success(res) {
  89. height.value = res.windowHeight;
  90. }
  91. });
  92. if (options.id || options.scene) {
  93. if (options.scene) {
  94. const qrCodeValue = $util.getUrlParams(decodeURIComponent(options.scene));
  95. const mapeMpQrCodeValue = $util.formatMpQrCodeData(qrCodeValue);
  96. id.value = mapeMpQrCodeValue.id;
  97. setTimeout(() => {
  98. spread(mapeMpQrCodeValue.spread).catch(() => {
  99. });
  100. }, 2e3);
  101. } else {
  102. id.value = options.id;
  103. }
  104. type.value = options.type ?? "normal";
  105. }
  106. getGoodsDetails();
  107. });
  108. common_vendor.onShow(() => {
  109. getCartCount();
  110. });
  111. common_vendor.onReady(() => {
  112. const menuButton = common_vendor.index.getMenuButtonBoundingClientRect();
  113. const query = common_vendor.index.createSelectorQuery().in(this);
  114. query.select("#home").boundingClientRect((data) => {
  115. homeTop.value = menuButton.top * 2 + menuButton.height - data.height;
  116. }).exec();
  117. });
  118. const handleScroll = (e) => {
  119. const scrollYVal = e.detail.scrollTop;
  120. const opacityVal = scrollYVal / 350 > 1 ? 1 : scrollYVal / 350;
  121. opacity.value = opacityVal;
  122. scrollY.value = scrollYVal;
  123. if (lock.value) {
  124. lock.value = false;
  125. return;
  126. }
  127. };
  128. const getGoodsDetails = async () => {
  129. try {
  130. const res = await api_index.getArticleDetailId("34");
  131. const product = res.data.productInfo;
  132. sliderImage.value = [product.image];
  133. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:453", "sliderImage.value", sliderImage.value);
  134. productInfo.value = product;
  135. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:455", "productInfo.value", productInfo.value);
  136. description.value = product.content;
  137. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:457", "description.value", description.value);
  138. userCollect.value = res.data.userCollect;
  139. attr.value.productAttr = res.data.productAttr;
  140. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:460", "res.data.productValue", res.data);
  141. productValue.value = res.data.productValue;
  142. sharePacket.value.priceName = res.data.priceName;
  143. sharePacket.value.isState = Math.floor(res.data.priceName) !== 0;
  144. activityH5.value = res.data.activityAllH5 || [];
  145. common_vendor.index.setNavigationBarTitle({
  146. title: product.storeName.substring(0, 7) + "..."
  147. });
  148. attr.value.productAttr = attr.value.productAttr.map((item) => ({
  149. attrName: item.attrName,
  150. attrValues: item.attrValues.split(","),
  151. id: item.id,
  152. isDel: item.isDel,
  153. productId: item.productId,
  154. type: item.type
  155. }));
  156. imgTop.value = productInfo.value.image;
  157. downloadFilestoreImage();
  158. DefaultSelect();
  159. } catch (err) {
  160. Toast({
  161. title: err.toString(),
  162. icon: "none"
  163. });
  164. }
  165. };
  166. const DefaultSelect = () => {
  167. let value = [];
  168. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:523", "productValue.value", common_vendor.toRaw(productValue.value));
  169. const keys = Object.keys(productValue.value);
  170. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:525", "keys", keys);
  171. for (let i = 0; i < keys.length; i++) {
  172. const key = keys[i];
  173. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:528", "key", key);
  174. value = attr.value.productAttr.length ? key.split(",") : [];
  175. }
  176. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:534", "value", value);
  177. attr.value.productAttr.forEach((item, i) => {
  178. item.index = value[i];
  179. });
  180. const productSelect = productValue.value[value.join(",")];
  181. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:539", {
  182. productSelect
  183. });
  184. common_vendor.index.__f__("log", "at pages/goods_details/index.vue:542", {
  185. attr
  186. });
  187. if (productSelect && attr.value.productAttr.length) {
  188. attr.value.productSelect = {
  189. ...attr.value.productSelect,
  190. storeName: productInfo.value.storeName,
  191. image: productSelect.image,
  192. sales: productSelect.sales,
  193. weight: productSelect.weight,
  194. price: productSelect.price,
  195. storePrice: productSelect.storePrice,
  196. stock: productSelect.stock,
  197. unique: productSelect.id,
  198. cart_num: 1
  199. };
  200. attrValue.value = value.join(",");
  201. attrTxt.value = "已选择";
  202. } else if (!productSelect && attr.value.productAttr.length) {
  203. attr.value.productSelect = {
  204. ...attr.value.productSelect,
  205. storeName: productInfo.value.storeName,
  206. image: productInfo.value.image,
  207. sales: productSelect.sales,
  208. weight: productSelect.weight,
  209. price: productInfo.value.price,
  210. storePrice: productSelect.storePrice,
  211. stock: 0,
  212. unique: productInfo.value.id,
  213. cart_num: 1
  214. };
  215. attrValue.value = "";
  216. attrTxt.value = "请选择";
  217. } else if (!productSelect && !attr.value.productAttr.length) {
  218. attr.value.productSelect = {
  219. ...attr.value.productSelect,
  220. storeName: productInfo.value.storeName,
  221. image: productInfo.value.image,
  222. sales: productSelect.sales,
  223. weight: productSelect.weight,
  224. price: productInfo.value.price,
  225. storePrice: productSelect.storePrice,
  226. stock: productInfo.value.stock,
  227. unique: productInfo.value.id || "",
  228. cart_num: 1
  229. };
  230. attrValue.value = "";
  231. attrTxt.value = "请选择";
  232. }
  233. };
  234. const selecAttr = () => {
  235. showProductPopup.value = true;
  236. handleBtnTpe.value = "buy";
  237. };
  238. const handleCoupon = () => {
  239. };
  240. const toShopCart = () => {
  241. };
  242. const getCartCount = async (isAnima = false) => {
  243. };
  244. const setDomain = (url) => {
  245. url = url ? url.toString() : "";
  246. return url.includes("https://") ? url : url.replace("http://", "https://");
  247. };
  248. const downloadFilestoreImage = async () => {
  249. try {
  250. const res = await common_vendor.index.downloadFile({
  251. url: setDomain(productInfo.value.image)
  252. });
  253. storeImage.value = res.tempFilePath;
  254. } catch {
  255. storeImage.value = "";
  256. }
  257. };
  258. function toMessagePage() {
  259. common_vendor.index.navigateTo({
  260. url: "/pages/message_create/message_create"
  261. });
  262. }
  263. return (_ctx, _cache) => {
  264. var _a;
  265. return common_vendor.e({
  266. a: common_vendor.p({
  267. ["indicator-dots"]: false,
  268. imgUrls: sliderImage.value
  269. }),
  270. b: common_vendor.t(productInfo.value.storeName),
  271. c: common_vendor.t(attr.value.productSelect.price || 0),
  272. d: common_vendor.t(attr.value.productSelect.weight),
  273. e: common_vendor.t(Number(((_a = attr.value.productSelect) == null ? void 0 : _a.sales) || 0)),
  274. f: common_vendor.t(productInfo.value.unitName || ""),
  275. g: common_vendor.t(attr.value.productSelect.storePrice),
  276. h: coupon.value.list.length > 0
  277. }, coupon.value.list.length > 0 ? {
  278. i: common_vendor.t(coupon.value.list[0].minPrice),
  279. j: common_vendor.t(coupon.value.list[0].money),
  280. k: common_vendor.o(handleCoupon)
  281. } : {}, {
  282. l: common_vendor.t(attrTxt.value),
  283. m: common_vendor.t(attrValue.value),
  284. n: common_vendor.o(selecAttr),
  285. o: common_vendor.p({
  286. type: "cart",
  287. size: "24"
  288. }),
  289. p: common_vendor.p({
  290. color: "#ccc",
  291. length: "100%",
  292. margin: "10px 0"
  293. }),
  294. q: common_vendor.p({
  295. size: "24",
  296. type: "hand-up"
  297. }),
  298. r: scrollTop.value,
  299. s: common_vendor.s("height:" + height.value + "px;"),
  300. t: common_vendor.o(handleScroll),
  301. v: common_vendor.p({
  302. size: "22",
  303. color: "#666",
  304. customPrefix: "iconfont",
  305. type: "icon-shouye"
  306. }),
  307. w: common_vendor.p({
  308. size: "22",
  309. color: "#666",
  310. customPrefix: "iconfont",
  311. type: "icon-kefu1"
  312. }),
  313. x: common_vendor.o(toMessagePage),
  314. y: common_vendor.p({
  315. size: "22",
  316. color: "#666",
  317. customPrefix: "iconfont",
  318. type: "icon-gouwuche"
  319. }),
  320. z: common_vendor.o(toShopCart),
  321. A: common_vendor.p({
  322. attr: attr.value,
  323. isShow: 1,
  324. iSplus: 1,
  325. showPopup: showProductPopup.value,
  326. id: "product-window"
  327. }),
  328. B: common_vendor.p({
  329. coupon: coupon.value,
  330. showPopup: showCouponPopup.value
  331. })
  332. });
  333. };
  334. }
  335. };
  336. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-c5c6bbf1"]]);
  337. wx.createPage(MiniProgramPage);
  338. //# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/goods_details/index.js.map