store.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. "use strict";
  2. const common_vendor = require("../common/vendor.js");
  3. const api_live = require("../api/live.js");
  4. const common_assets = require("../common/assets.js");
  5. const _sfc_main = {
  6. data() {
  7. return {
  8. page: 1,
  9. // 当前页码,初始为1
  10. pageSize: 6,
  11. // 每页条数(和之前保持一致)
  12. isLoading: false,
  13. // 是否正在加载数据,防止重复请求
  14. hasMore: true,
  15. // 是否还有更多数据
  16. inputInfo: "",
  17. searchTimer: null,
  18. tabList: [{
  19. name: "推荐"
  20. }, {
  21. name: "分类"
  22. }],
  23. products: [],
  24. liveId: null,
  25. storeId: null,
  26. statusBarHeight: common_vendor.index.getWindowInfo().statusBarHeight,
  27. // 右侧的胶囊距离右侧屏幕距离-px
  28. menuRight: common_vendor.index.getStorageSync("menuInfo").menuRight,
  29. // 右侧的胶囊宽度-px
  30. menuWidth: common_vendor.index.getStorageSync("menuInfo").menuWidth,
  31. opacity: 0,
  32. opacityTxt: 0,
  33. tabbar: [{
  34. name: "商品"
  35. }, {
  36. name: "商家"
  37. }],
  38. current: 0,
  39. storeInfo: {},
  40. // logoUrl: "/static/images/adfd21c004854c9b8997d371d7a0ce8c.jpg",
  41. // 商家资质图片
  42. // licenseImagesList: ["/static/images/sjzz.jpg"],
  43. divHeight: "0px",
  44. allCates: [],
  45. cates: [],
  46. subCates: [],
  47. // 选中药品分类
  48. cateSelect: 0,
  49. // 轮播图
  50. advs: [],
  51. // 'company'表示销售管理的进来的
  52. from: ""
  53. };
  54. },
  55. onLoad(options) {
  56. console.log("接收到的options:", options);
  57. if (options.liveId) {
  58. this.liveId = options.liveId;
  59. console.log("接收到的liveId:", this.liveId);
  60. }
  61. if (options.storeId) {
  62. this.storeId = options.storeId || "";
  63. } else {
  64. common_vendor.index.showToast({
  65. title: "storeId不存在~",
  66. icon: "none"
  67. });
  68. }
  69. },
  70. mounted() {
  71. this.queryStore();
  72. this.queryCollect();
  73. },
  74. onShow() {
  75. this.divHeight = `calc(100vh - 44px - 88rpx - ${this.statusBarHeight}px)`;
  76. },
  77. onPageScroll(e) {
  78. if (e.scrollTop <= 44) {
  79. this.opacityTxt = 0;
  80. this.opacity = e.scrollTop > this.statusBarHeight ? 0.6 : 0;
  81. } else if (e.scrollTop > 50) {
  82. this.opacity = 1;
  83. this.opacityTxt = 1;
  84. }
  85. if (this.isLoading || !this.hasMore)
  86. return;
  87. const {
  88. scrollHeight,
  89. scrollTop,
  90. windowHeight
  91. } = common_vendor.index.getSystemInfoSync();
  92. const distanceToBottom = scrollHeight - scrollTop - windowHeight;
  93. if (distanceToBottom < 300) {
  94. this.page++;
  95. this.queryStore();
  96. }
  97. },
  98. methods: {
  99. handleSearchInput() {
  100. clearTimeout(this.searchTimer);
  101. this.searchTimer = setTimeout(() => {
  102. this.page = 1;
  103. this.hasMore = true;
  104. this.queryStore();
  105. }, 500);
  106. },
  107. getPureDecimal(num, precision = 6) {
  108. const decimalPart = Math.abs(num).toFixed(precision).split(".")[1];
  109. return (decimalPart == null ? void 0 : decimalPart.replace(/0+$/, "")) || "";
  110. },
  111. // // 店铺商品展示(支持分页)
  112. // getliveStore() {
  113. // // 如果正在加载或没有更多数据,直接返回
  114. // if (this.isLoading || !this.hasMore) return;
  115. // this.isLoading = true; // 标记为加载中
  116. // const data = {
  117. // pageSize: this.pageSize,
  118. // page: this.page // 使用当前页码
  119. // };
  120. // liveStore(this.liveId, this.inputInfo, data)
  121. // .then(res => {
  122. // this.isLoading = false; // 结束加载状态
  123. // if (res.code === 200) {
  124. // const newProducts = res.data || [];
  125. // // 如果是第一页,直接替换数据;否则合并数据
  126. // if (this.page === 1) {
  127. // this.products = newProducts;
  128. // } else {
  129. // this.products = [...this.products, ...newProducts];
  130. // }
  131. // // 判断是否还有更多数据(如果返回的数量小于每页条数,说明没有更多了)
  132. // this.hasMore = newProducts.length >= this.pageSize;
  133. // } else {
  134. // uni.showToast({
  135. // title: res.msg,
  136. // icon: 'none'
  137. // });
  138. // }
  139. // })
  140. // .catch(rej => {
  141. // this.isLoading = false; // 异常时也要结束加载状态
  142. // uni.showToast({
  143. // title: '加载失败',
  144. // icon: 'none'
  145. // });
  146. // });
  147. // },
  148. //查询店铺
  149. queryStore() {
  150. if (!this.storeId)
  151. return;
  152. if (this.isLoading || !this.hasMore)
  153. return;
  154. this.isLoading = true;
  155. api_live.queryStore(this.storeId, this.pageSize, this.page, this.inputInfo).then(
  156. (res) => {
  157. this.isLoading = false;
  158. if (res.code == 200) {
  159. const newProducts = res.rows || [];
  160. if (this.page === 1) {
  161. this.products = newProducts;
  162. } else {
  163. this.products = [...this.products, ...newProducts];
  164. }
  165. this.hasMore = newProducts.length >= this.pageSize;
  166. } else {
  167. common_vendor.index.showToast({
  168. title: res.msg,
  169. icon: "none"
  170. });
  171. }
  172. },
  173. (rej) => {
  174. }
  175. );
  176. },
  177. // 小黄车查询店铺
  178. queryCollect() {
  179. if (!this.storeId)
  180. return;
  181. api_live.store(this.storeId, "").then(
  182. (res) => {
  183. if (res.code == 200) {
  184. console.log("查询店铺>>", res);
  185. this.storeInfo = res.data;
  186. } else {
  187. common_vendor.index.showToast({
  188. title: res.msg,
  189. icon: "none"
  190. });
  191. }
  192. },
  193. (rej) => {
  194. }
  195. );
  196. },
  197. rightClick() {
  198. const pages = getCurrentPages();
  199. if (pages.length > 1) {
  200. common_vendor.index.navigateBack();
  201. } else {
  202. common_vendor.index.redirectTo({
  203. url: "/pages/home/living"
  204. // 替换为你的首页路径
  205. });
  206. }
  207. },
  208. clickTab(item) {
  209. this.current = item.index;
  210. },
  211. // 预览图片
  212. previewImage(index) {
  213. common_vendor.index.previewImage({
  214. current: index,
  215. urls: this.licenseImagesList
  216. });
  217. },
  218. // getStoreInfo() {
  219. // getStoreById({
  220. // storeId: this.storeId
  221. // }).then(
  222. // res => {
  223. // if (res.code == 200) {
  224. // this.storeInfo = res.data || {}
  225. // // this.licenseImagesList = this.storeInfo.licenseImages ? this.storeInfo.licenseImages.split(',') : []
  226. // } else {
  227. // uni.showToast({
  228. // icon: 'none',
  229. // title: res.msg,
  230. // });
  231. // }
  232. // },
  233. // rej => {}
  234. // );
  235. // },
  236. handleAdvClick(item) {
  237. if (item.showType == 1) {
  238. common_vendor.index.setStorageSync("url", item.advUrl);
  239. common_vendor.index.navigateTo({
  240. url: "/pages/home/h5?storeId=" + this.storeId || ""
  241. });
  242. } else if (item.showType == 2) {
  243. common_vendor.index.navigateTo({
  244. url: item.advUrl
  245. });
  246. } else if (item.showType == 3) {
  247. common_vendor.index.setStorageSync("content", item.content);
  248. common_vendor.index.navigateTo({
  249. url: "/pages/home/content?storeId=" + this.storeId || ""
  250. });
  251. }
  252. },
  253. // getAdv() {
  254. // let data = {
  255. // advType: 2
  256. // };
  257. // getAdv(data).then(
  258. // res => {
  259. // if (res.code == 200) {
  260. // this.advs = res.data;
  261. // }
  262. // },
  263. // rej => {}
  264. // );
  265. // },
  266. // getProductCate() {
  267. // let data = {};
  268. // getProductCate(data).then(
  269. // res => {
  270. // if (res.code == 200) {
  271. // this.allCates = res.data;
  272. // this.cates = this.allCates.filter(function(item) {
  273. // return item.pid == 0
  274. // });
  275. // if (this.cates != null && this.cates.length > 0) {
  276. // this.cateSelect = this.cates[0].cateId;
  277. // this.getSubCate()
  278. // }
  279. // } else {
  280. // uni.showToast({
  281. // icon: 'none',
  282. // title: "请求失败",
  283. // });
  284. // }
  285. // },
  286. // rej => {}
  287. // );
  288. // },
  289. // 药品分类选择
  290. choseCate(item) {
  291. this.cateSelect = item.cateId;
  292. this.getSubCate();
  293. },
  294. getSubCate() {
  295. var that = this;
  296. this.subCates = this.allCates.filter(function(item) {
  297. return item.pid == that.cateSelect;
  298. });
  299. },
  300. // 查看药品详情
  301. showProductList(item) {
  302. common_vendor.index.navigateTo({
  303. url: "/pages_shop/goods?productId=" + item.productId + "&liveId=" + this.liveId + "&goodsId=" + item.goodsId + "&storeId=" + this.storeId
  304. });
  305. }
  306. }
  307. };
  308. if (!Array) {
  309. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  310. const _easycom_u_image2 = common_vendor.resolveComponent("u-image");
  311. (_easycom_u_icon2 + _easycom_u_image2)();
  312. }
  313. const _easycom_u_icon = () => "../uni_modules/uview-plus/components/u-icon/u-icon.js";
  314. const _easycom_u_image = () => "../uni_modules/uview-plus/components/u-image/u-image.js";
  315. if (!Math) {
  316. (_easycom_u_icon + _easycom_u_image)();
  317. }
  318. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  319. var _a;
  320. return common_vendor.e({
  321. a: $data.statusBarHeight + "px",
  322. b: common_vendor.o($options.rightClick),
  323. c: common_vendor.p({
  324. name: "arrow-left",
  325. color: "#ffffff",
  326. size: "20"
  327. }),
  328. d: common_assets._imports_0$9,
  329. e: common_vendor.o([($event) => $data.inputInfo = $event.detail.value, (...args) => $options.handleSearchInput && $options.handleSearchInput(...args)]),
  330. f: $data.inputInfo,
  331. g: common_vendor.o((...args) => _ctx.toSearch && _ctx.toSearch(...args)),
  332. h: common_vendor.p({
  333. shape: "square",
  334. src: (_a = $data.storeInfo) == null ? void 0 : _a.logoUrl,
  335. width: "100rpx",
  336. height: "100rpx",
  337. radius: "6"
  338. }),
  339. i: common_vendor.t($data.storeInfo.storeName || ""),
  340. j: common_vendor.t($data.storeInfo.salesCount),
  341. k: $data.storeInfo.storeName,
  342. l: common_vendor.f($data.products, (subItem, index, i0) => {
  343. return {
  344. a: subItem.imgUrl,
  345. b: common_vendor.t(subItem.productName),
  346. c: common_vendor.t(Math.trunc(subItem.price)),
  347. d: common_vendor.t($options.getPureDecimal(subItem.price) ? $options.getPureDecimal(subItem.price) : "00"),
  348. e: index,
  349. f: common_vendor.o(($event) => $options.showProductList(subItem), index)
  350. };
  351. }),
  352. m: $data.page > 1
  353. }, $data.page > 1 ? common_vendor.e({
  354. n: $data.isLoading
  355. }, $data.isLoading ? {} : !$data.hasMore ? {} : {}, {
  356. o: !$data.hasMore
  357. }) : {});
  358. }
  359. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-dd5fc6f3"]]);
  360. _sfc_main.__runtimeHooks = 1;
  361. wx.createPage(MiniProgramPage);