store.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. <template>
  2. <!-- v-show="liveId" -->
  3. <view class="content">
  4. <view class="uni-nav-bar" style="background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);">
  5. <view :style="{height: statusBarHeight + 'px',width: '100%'}"></view>
  6. <view class="uni-nav-barbox">
  7. <view class="uni-nav-back">
  8. <u-icon name="arrow-left" color="#ffffff" size="20" @click="rightClick"></u-icon>
  9. </view>
  10. <view class="uni-nav-title">
  11. <view class="inputbox" style="background: rgba(255, 255, 255, 0.4);width:70%;" @click="toSearch">
  12. <image class="icon-search" src="/static/images/search_white.png"></image>
  13. <input placeholder="搜索本店" placeholder-style="color: #ffffff;" v-model="inputInfo"
  14. @input="handleSearchInput" />
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. <!-- <view class="bg"></view> -->
  20. <!-- <image class="bg" src="/static/images/chu_query.png" mode="widthFix"></image> -->
  21. <view class="content-body">
  22. <view class="store-head" v-show="storeInfo.storeName">
  23. <view class="store-head-top">
  24. <view class="store-head-logo">
  25. <u-image shape="square" :src="storeInfo?.logoUrl" width="100rpx" height="100rpx"
  26. radius="6"></u-image>
  27. </view>
  28. <view class="store-head-name">{{storeInfo.storeName || ''}}</view>
  29. </view>
  30. <view class="store-head-desc">
  31. <view>销售{{storeInfo.salesCount }}</view>
  32. <view>24小时营业</view>
  33. <view>支持预订</view>
  34. </view>
  35. </view>
  36. <view class="storebox">
  37. <!-- 商品 -->
  38. <view class="medic-box">
  39. <!-- <view class="cate-list">
  40. <view v-for="(item,index) in cates" :key="index" :class="cateSelect == item.cateId?'item active':'item'" @click="choseCate(item)">
  41. {{item.cateName }}</view>
  42. </view> -->
  43. <view class="medic">
  44. <!-- <u-tabs :list="tabList" lineColor="linear-gradient( 90deg, #FE8227 0%, #FE4E12 100%)"
  45. :activeStyle="{
  46. color: '#222222',
  47. fontWeight: '600',
  48. fontSize: '28rpx'
  49. }" :inactiveStyle="{
  50. color: '#757575',
  51. fontSize: '28rpx',
  52. fontWeight: '400'
  53. }" @click="selectTabList"></u-tabs> -->
  54. <!-- 轮播图 -->
  55. <!-- <view class="banner-box">
  56. <swiper class="swiper" :indicator-dots="true" :circular="true" :autoplay="true"
  57. :interval="3000" :duration="1000" indicator-color="rgba(255, 255, 255, 0.6)"
  58. indicator-active-color="#ffffff">
  59. <swiper-item class="swiper-item" v-for="(item,index) in advs" :key="index" @click="handleAdvClick(item)">
  60. <image :src="item.imageUrl" mode=""></image>
  61. </swiper-item>
  62. </swiper>
  63. </view> -->
  64. <!-- 商品列表 -->
  65. <view class="medic-list">
  66. <view class="inner-list">
  67. <view class="definite" v-for="(subItem,index) in products" :key="index"
  68. @click="showProductList(subItem)">
  69. <view class="img-box">
  70. <image :src="subItem.imgUrl" mode="widthFix"></image>
  71. </view>
  72. <view class="name ellipsis2">{{subItem.productName}}</view>
  73. <view class="price">
  74. <text class="red"><text style="font-size: 20rpx;">¥</text><text
  75. style="font-size: 36rpx;">{{Math.trunc(subItem.price)}}</text>.{{getPureDecimal(subItem.price)?getPureDecimal(subItem.price):'00'}}</text>
  76. <text class="del">¥19.80</text>
  77. </view>
  78. </view>
  79. <!-- 加载状态提示 -->
  80. <view class="load-more" v-if="page > 1">
  81. <text v-if="isLoading">加载中...</text>
  82. <text v-else-if="!hasMore">没有更多数据了</text>
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 商家信息 -->
  89. <!-- <view class="storebox-info" :style="{height: divHeight}" v-show="current == 1">
  90. <view class="storebox-map">
  91. <u-icon name="map" color="#ccc" size="18"></u-icon>
  92. <view style="margin-left: 10rpx;">{{storeInfo.address || "--"}}</view>
  93. </view>
  94. <view class="storebox-map" v-if="storeInfo.phone">
  95. <u-icon name="phone" color="#ccc" size="18"></u-icon>
  96. <view style="margin-left: 10rpx;">{{storeInfo.phone || "--"}}</view>
  97. </view>
  98. <view class="storebox-qualifications" v-if="storeInfo.descs">
  99. <u-icon name="volume" color="#ccc" size="18"></u-icon>
  100. <view style="margin-left: 10rpx;">{{storeInfo.descs || "--"}}</view>
  101. </view>
  102. <view class="storebox-qualifications">
  103. <u-icon name="file-text" color="#ccc" size="18"></u-icon>
  104. <view style="margin-left: 10rpx;">商家资质</view>
  105. </view>
  106. <view class="qualifications">
  107. <view v-for="(img,i) in licenseImagesList" :key="i">
  108. <u-image shape="square" lazyLoad :src="img" width="100%" mode="widthFix" radius="6"
  109. @click="previewImage(i)"></u-image>
  110. </view>
  111. </view>
  112. </view> -->
  113. </view>
  114. </view>
  115. </view>
  116. </template>
  117. <script>
  118. import {
  119. queryStore, //查询店铺
  120. store // 小黄车查询店铺,
  121. } from '@/api/live'
  122. // import {getProductCate} from '@/api/product';
  123. // import {getAdv} from '@/api/adv';
  124. // import { getStoreById } from "@/api/store.js";
  125. export default {
  126. data() {
  127. return {
  128. page: 1, // 当前页码,初始为1
  129. pageSize: 6, // 每页条数(和之前保持一致)
  130. isLoading: false, // 是否正在加载数据,防止重复请求
  131. hasMore: true, // 是否还有更多数据
  132. inputInfo: '',
  133. searchTimer: null,
  134. tabList: [{
  135. name: '推荐',
  136. }, {
  137. name: '分类',
  138. }],
  139. products: [],
  140. liveId: null,
  141. storeId: null,
  142. statusBarHeight: uni.getWindowInfo().statusBarHeight,
  143. // 右侧的胶囊距离右侧屏幕距离-px
  144. menuRight: uni.getStorageSync('menuInfo').menuRight,
  145. // 右侧的胶囊宽度-px
  146. menuWidth: uni.getStorageSync('menuInfo').menuWidth,
  147. opacity: 0,
  148. opacityTxt: 0,
  149. tabbar: [{
  150. name: '商品',
  151. }, {
  152. name: '商家',
  153. }],
  154. current: 0,
  155. storeInfo: {},
  156. // logoUrl: "/static/images/adfd21c004854c9b8997d371d7a0ce8c.jpg",
  157. // 商家资质图片
  158. // licenseImagesList: ["/static/images/sjzz.jpg"],
  159. divHeight: '0px',
  160. allCates: [],
  161. cates: [],
  162. subCates: [],
  163. // 选中药品分类
  164. cateSelect: 0,
  165. // 轮播图
  166. advs: [],
  167. // 'company'表示销售管理的进来的
  168. from: ""
  169. }
  170. },
  171. onLoad(options) {
  172. console.log("接收到的options:", options);
  173. if (options.liveId) {
  174. this.liveId = options.liveId;
  175. // this.getliveStore() // 获取小黄车 店铺展示
  176. console.log("接收到的liveId:", this.liveId);
  177. }
  178. if (options.storeId) {
  179. this.storeId = options.storeId || ""
  180. } else {
  181. uni.showToast({
  182. title: "storeId不存在~",
  183. icon: "none"
  184. })
  185. }
  186. },
  187. mounted() {
  188. this.queryStore() //查询店铺
  189. this.queryCollect()
  190. },
  191. onShow() {
  192. this.divHeight = `calc(100vh - 44px - 88rpx - ${this.statusBarHeight}px)`
  193. },
  194. onPageScroll(e) {
  195. if (e.scrollTop <= 44) {
  196. this.opacityTxt = 0
  197. this.opacity = e.scrollTop > this.statusBarHeight ? 0.6 : 0
  198. } else if (e.scrollTop > 50) {
  199. this.opacity = 1
  200. this.opacityTxt = 1
  201. }
  202. // 监听滚动到底部(核心逻辑)
  203. if (this.isLoading || !this.hasMore) return; // 过滤无效状态
  204. // 获取页面可滚动高度、当前滚动位置、窗口高度
  205. const {
  206. scrollHeight,
  207. scrollTop,
  208. windowHeight
  209. } = uni.getSystemInfoSync();
  210. // 计算距离底部的距离(单位:px,1rpx ≈ 0.5px,这里按300rpx判断)
  211. const distanceToBottom = scrollHeight - scrollTop - windowHeight;
  212. // 当距离底部小于300rpx时,加载下一页
  213. if (distanceToBottom < 300) {
  214. this.page++; // 页码+1
  215. this.queryStore(); // 触发下一页请求
  216. }
  217. },
  218. methods: {
  219. handleSearchInput() {
  220. // 搜索时重置分页(关键词变了,重新从第1页加载)
  221. clearTimeout(this.searchTimer);
  222. this.searchTimer = setTimeout(() => {
  223. this.page = 1; // 重置页码为1
  224. this.hasMore = true; // 重置是否有更多数据
  225. this.queryStore(); // 重新请求第一页
  226. }, 500);
  227. },
  228. getPureDecimal(num, precision = 6) {
  229. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  230. return decimalPart?.replace(/0+$/, '') || ''; // 移除末尾多余的0
  231. },
  232. // // 店铺商品展示(支持分页)
  233. // getliveStore() {
  234. // // 如果正在加载或没有更多数据,直接返回
  235. // if (this.isLoading || !this.hasMore) return;
  236. // this.isLoading = true; // 标记为加载中
  237. // const data = {
  238. // pageSize: this.pageSize,
  239. // page: this.page // 使用当前页码
  240. // };
  241. // liveStore(this.liveId, this.inputInfo, data)
  242. // .then(res => {
  243. // this.isLoading = false; // 结束加载状态
  244. // if (res.code === 200) {
  245. // const newProducts = res.data || [];
  246. // // 如果是第一页,直接替换数据;否则合并数据
  247. // if (this.page === 1) {
  248. // this.products = newProducts;
  249. // } else {
  250. // this.products = [...this.products, ...newProducts];
  251. // }
  252. // // 判断是否还有更多数据(如果返回的数量小于每页条数,说明没有更多了)
  253. // this.hasMore = newProducts.length >= this.pageSize;
  254. // } else {
  255. // uni.showToast({
  256. // title: res.msg,
  257. // icon: 'none'
  258. // });
  259. // }
  260. // })
  261. // .catch(rej => {
  262. // this.isLoading = false; // 异常时也要结束加载状态
  263. // uni.showToast({
  264. // title: '加载失败',
  265. // icon: 'none'
  266. // });
  267. // });
  268. // },
  269. //查询店铺
  270. queryStore() {
  271. if (!this.storeId) return;
  272. if (this.isLoading || !this.hasMore) return;
  273. this.isLoading = true; // 标记为加载中
  274. queryStore(this.storeId, this.pageSize, this.page,this.inputInfo).then(res => {
  275. this.isLoading = false; // 结束加载状态
  276. if (res.code == 200) {
  277. const newProducts = res.rows || [];
  278. // 如果是第一页,直接替换数据;否则合并数据
  279. if (this.page === 1) {
  280. this.products = newProducts;
  281. } else {
  282. this.products = [...this.products, ...newProducts];
  283. }
  284. // 判断是否还有更多数据(如果返回的数量小于每页条数,说明没有更多了)
  285. this.hasMore = newProducts.length >= this.pageSize;
  286. } else {
  287. uni.showToast({
  288. title: res.msg,
  289. icon: 'none'
  290. });
  291. }
  292. },
  293. rej => {}
  294. );
  295. },
  296. // 小黄车查询店铺
  297. queryCollect() {
  298. if (!this.storeId) return;
  299. store(this.storeId, '').then(res => {
  300. if (res.code == 200) {
  301. console.log("查询店铺>>", res)
  302. this.storeInfo = res.data
  303. } else {
  304. uni.showToast({
  305. title: res.msg,
  306. icon: 'none'
  307. });
  308. }
  309. },
  310. rej => {}
  311. );
  312. },
  313. rightClick() {
  314. // 获取页面栈
  315. const pages = getCurrentPages();
  316. // 如果页面栈长度大于1,说明有上一页可以返回
  317. if (pages.length > 1) {
  318. uni.navigateBack();
  319. } else {
  320. // 如果没有上一页,跳转到默认页面(比如首页)
  321. uni.redirectTo({
  322. url: '/pages/home/living' // 替换为你的首页路径
  323. });
  324. }
  325. },
  326. clickTab(item) {
  327. this.current = item.index
  328. },
  329. // 预览图片
  330. previewImage(index) {
  331. uni.previewImage({
  332. current: index,
  333. urls: this.licenseImagesList
  334. });
  335. },
  336. // getStoreInfo() {
  337. // getStoreById({
  338. // storeId: this.storeId
  339. // }).then(
  340. // res => {
  341. // if (res.code == 200) {
  342. // this.storeInfo = res.data || {}
  343. // // this.licenseImagesList = this.storeInfo.licenseImages ? this.storeInfo.licenseImages.split(',') : []
  344. // } else {
  345. // uni.showToast({
  346. // icon: 'none',
  347. // title: res.msg,
  348. // });
  349. // }
  350. // },
  351. // rej => {}
  352. // );
  353. // },
  354. handleAdvClick(item) {
  355. if (item.showType == 1) {
  356. uni.setStorageSync('url', item.advUrl);
  357. uni.navigateTo({
  358. url: "/pages/home/h5?storeId=" + this.storeId || ""
  359. })
  360. } else if (item.showType == 2) {
  361. uni.navigateTo({
  362. url: item.advUrl
  363. })
  364. } else if (item.showType == 3) {
  365. uni.setStorageSync('content', item.content);
  366. uni.navigateTo({
  367. url: "/pages/home/content?storeId=" + this.storeId || ""
  368. })
  369. }
  370. },
  371. // getAdv() {
  372. // let data = {
  373. // advType: 2
  374. // };
  375. // getAdv(data).then(
  376. // res => {
  377. // if (res.code == 200) {
  378. // this.advs = res.data;
  379. // }
  380. // },
  381. // rej => {}
  382. // );
  383. // },
  384. // getProductCate() {
  385. // let data = {};
  386. // getProductCate(data).then(
  387. // res => {
  388. // if (res.code == 200) {
  389. // this.allCates = res.data;
  390. // this.cates = this.allCates.filter(function(item) {
  391. // return item.pid == 0
  392. // });
  393. // if (this.cates != null && this.cates.length > 0) {
  394. // this.cateSelect = this.cates[0].cateId;
  395. // this.getSubCate()
  396. // }
  397. // } else {
  398. // uni.showToast({
  399. // icon: 'none',
  400. // title: "请求失败",
  401. // });
  402. // }
  403. // },
  404. // rej => {}
  405. // );
  406. // },
  407. // 药品分类选择
  408. choseCate(item) {
  409. this.cateSelect = item.cateId;
  410. this.getSubCate()
  411. },
  412. getSubCate() {
  413. var that = this;
  414. this.subCates = this.allCates.filter(function(item) {
  415. // let subList = that.allCates.filter(child => {
  416. // //返回每一项的子级数组
  417. // return child.pid === item.cateId
  418. // });
  419. // subList.length > 0 ? item.children = subList : [];
  420. return item.pid == that.cateSelect
  421. });
  422. },
  423. // 查看药品详情
  424. showProductList(item) {
  425. uni.navigateTo({
  426. url: '/pages_shop/goods?productId=' + item.productId + '&liveId=' + this.liveId + '&goodsId=' +
  427. item.goodsId + '&storeId=' + this.storeId
  428. })
  429. }
  430. }
  431. }
  432. </script>
  433. <style scoped lang="scss">
  434. :deep(.u-tabs__wrapper__nav) {
  435. margin: 0 auto;
  436. }
  437. .load-more {
  438. text-align: center;
  439. padding: 30rpx 0;
  440. color: #999;
  441. font-size: 26rpx;
  442. }
  443. @mixin u-flex($flexD, $alignI, $justifyC) {
  444. display: flex;
  445. flex-direction: $flexD;
  446. align-items: $alignI;
  447. justify-content: $justifyC;
  448. }
  449. .inputbox {
  450. height: 60rpx;
  451. padding: 0 20rpx;
  452. @include u-flex(row, center, flex-start);
  453. border-radius: 40rpx;
  454. line-height: 60rpx;
  455. font-size: 28rpx;
  456. color: #ffffff;
  457. .icon-search {
  458. width: 28rpx;
  459. height: 28rpx;
  460. margin-right: 20rpx;
  461. }
  462. }
  463. .uni-nav-bar {
  464. position: fixed;
  465. top: 0;
  466. left: 0;
  467. width: 100%;
  468. z-index: 999;
  469. overflow: hidden;
  470. font-weight: 500;
  471. .uni-nav-barbox {
  472. width: 100%;
  473. height: 88rpx;
  474. @include u-flex(row, center, flex-start);
  475. position: relative;
  476. font-size: 24rpx;
  477. }
  478. .uni-nav-title {
  479. /* #ifdef APP-PLUS */
  480. font-size: 34rpx;
  481. /* #endif */
  482. /* #ifndef APP-PLUS */
  483. font-size: 14px;
  484. /* #endif */
  485. overflow: hidden;
  486. white-space: nowrap;
  487. width: 100%;
  488. text-overflow: ellipsis;
  489. }
  490. .uni-nav-back {
  491. margin-left: 20rpx;
  492. margin-right: 20rpx;
  493. height: 88rpx;
  494. @include u-flex(row, center, flex-start);
  495. }
  496. }
  497. .content {
  498. width: 100%;
  499. position: relative;
  500. // .bg {
  501. // width: 100%;
  502. // height: auto;
  503. // position: absolute;
  504. // top: 0;
  505. // left: 0;
  506. // height: 388rpx;
  507. // background: #3A1101;
  508. // }
  509. &-body {
  510. position: relative;
  511. padding-top: calc(var(--status-bar-height) + 88rpx);
  512. }
  513. }
  514. .store-head {
  515. margin-top: 40rpx;
  516. padding: 32rpx;
  517. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  518. color: #ffffff;
  519. &-top {
  520. display: flex;
  521. align-items: center;
  522. }
  523. &-logo {
  524. flex-shrink: 0;
  525. margin-right: 24rpx;
  526. }
  527. &-name {
  528. font-weight: 600;
  529. font-size: 32rpx;
  530. }
  531. &-desc {
  532. margin-top: 16rpx;
  533. display: flex;
  534. align-items: center;
  535. flex-wrap: wrap;
  536. gap: 20rpx;
  537. position: relative;
  538. z-index: 2;
  539. view {
  540. padding-right: 20rpx;
  541. font-size: 26rpx;
  542. position: relative;
  543. &::after {
  544. content: "";
  545. width: 0;
  546. height: 28rpx;
  547. border-right: 1rpx solid #eee;
  548. position: absolute;
  549. right: 0;
  550. top: 50%;
  551. transform: translate(0, -50%);
  552. }
  553. &:last-child::after {
  554. border: none;
  555. }
  556. }
  557. }
  558. }
  559. .border_bottom_line {
  560. position: relative;
  561. &::after {
  562. content: "";
  563. position: absolute;
  564. bottom: 0;
  565. left: 0;
  566. border-bottom: 1px solid #F5F7FA;
  567. width: 100%;
  568. transform: scaleY(0.5);
  569. border-top-color: #F5F7FA;
  570. border-right-color: #F5F7FA;
  571. border-left-color: #F5F7FA;
  572. }
  573. }
  574. .storebox {
  575. width: 100%;
  576. position: relative;
  577. z-index: 1;
  578. &-info {
  579. padding: 24rpx 24rpx 0 24rpx;
  580. background-color: #fff;
  581. font-family: PingFang SC, PingFang SC;
  582. font-size: 28rpx;
  583. color: #333333;
  584. position: relative;
  585. border-top: 4px solid #F5F7FA;
  586. }
  587. &-map {
  588. display: flex;
  589. align-items: center;
  590. word-break: break-all;
  591. padding: 24rpx 0;
  592. }
  593. &-qualifications {
  594. display: flex;
  595. align-items: center;
  596. padding: 24rpx 0;
  597. }
  598. .qualifications {
  599. padding: 24rpx 0;
  600. }
  601. }
  602. .medic-box {
  603. display: flex;
  604. .medic {
  605. box-sizing: border-box;
  606. height: 100%;
  607. // .banner-box {
  608. // margin-top: 30rpx;
  609. // width: 100%;
  610. // height: 160upx;
  611. // border-radius: 10upx;
  612. // overflow: hidden;
  613. // .swiper,
  614. // .swiper-item,
  615. // .swiper-item image {
  616. // width: 100%;
  617. // height: 100%;
  618. // }
  619. // }
  620. .medic-list {
  621. width: 100%;
  622. padding: 20upx 24upx;
  623. box-sizing: border-box;
  624. overflow-y: auto;
  625. height: calc(100% - 220upx);
  626. position: relative;
  627. .inner-list {
  628. display: flex;
  629. flex-wrap: wrap;
  630. .definite {
  631. width: 342rpx;
  632. margin-right: 18upx;
  633. margin-bottom: 30upx;
  634. background: #ffffff;
  635. border-radius: 16rpx;
  636. .img-box {
  637. width: 100%;
  638. height: 343upx;
  639. border-radius: 16rpx 16rpx 0rpx 0rpx;
  640. overflow: hidden;
  641. display: flex;
  642. align-items: center;
  643. image {
  644. width: 100%;
  645. }
  646. }
  647. .name {
  648. width: 100%;
  649. margin-top: 12upx;
  650. font-size: 28rpx;
  651. color: #222222;
  652. padding: 0 20rpx;
  653. box-sizing: border-box;
  654. }
  655. .price {
  656. padding: 0 20rpx 32rpx;
  657. box-sizing: border-box;
  658. margin-top: 12rpx;
  659. .red {
  660. font-weight: bold;
  661. font-size: 26rpx;
  662. color: #FF5C03;
  663. }
  664. .del {
  665. margin-left: 16rpx;
  666. text-decoration: line-through;
  667. font-size: 24rpx;
  668. color: #999999;
  669. }
  670. }
  671. &:nth-child(2n) {
  672. margin-right: 0;
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. </style>