store.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. <template>
  2. <view class="content">
  3. <view class="uni-nav-bar" style="background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);">
  4. <view :style="{height: statusBarHeight + 'px',width: '100%'}"></view>
  5. <view class="uni-nav-barbox">
  6. <view class="uni-nav-back">
  7. <u-icon name="arrow-left" color="#ffffff" size="20" @click="rightClick"></u-icon>
  8. </view>
  9. <view class="uni-nav-title">
  10. <view class="inputbox" style="background: rgba(255, 255, 255, 0.4);width:70%;">
  11. <image class="icon-search" src="/static/images/search_white.png"></image>
  12. <input placeholder="搜索本店" placeholder-style="color: #ffffff;" v-model="inputInfo"
  13. @input="handleSearchInput" />
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. <view class="content-body">
  19. <view class="store-head" v-show="storeInfo.storeName">
  20. <view class="store-head-top">
  21. <view class="store-head-logo">
  22. <u-image shape="square" :src="storeInfo?.logoUrl" width="100rpx" height="100rpx"
  23. radius="6"></u-image>
  24. </view>
  25. <view class="store-head-name">{{storeInfo.storeName || ''}}</view>
  26. </view>
  27. <view class="store-head-desc">
  28. <view>销售{{storeInfo.salesCount }}</view>
  29. <view>24小时营业</view>
  30. <view>支持预订</view>
  31. </view>
  32. </view>
  33. <view class="storebox">
  34. <view class="medic-box">
  35. <view class="medic">
  36. <!-- 使用mescroll-body实现分页和刷新 -->
  37. <mescroll-body :top="`calc(${statusBarHeight}px + 88rpx + 240rpx)`" bottom="0" ref="mescrollRef"
  38. @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
  39. :up="upOption">
  40. <view class="medic-list">
  41. <view class="inner-list">
  42. <view class="definite" v-for="(subItem,index) in products" :key="index"
  43. @click="showProductList(subItem)">
  44. <view class="img-box">
  45. <image :src="subItem.imgUrl" mode="widthFix"></image>
  46. </view>
  47. <view class="name ellipsis2">{{subItem.productName}}</view>
  48. <view class="price">
  49. <text class="red"><text style="font-size: 20rpx;">¥</text><text
  50. style="font-size: 36rpx;">{{Math.trunc(subItem.price)}}</text>.{{getPureDecimal(subItem.price)?getPureDecimal(subItem.price):'00'}}</text>
  51. <text class="del">¥19.80</text>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 空数据提示 -->
  56. <view v-if="products.length === 0 && !loading" class="empty-data">
  57. <image
  58. src="https://cos.his.cdwjyyh.com/fs/20240423/cf4a86b913a04341bb44e34bb4d37aa2.png"
  59. mode="aspectFit" class="empty-icon"></image>
  60. <text class="empty-text">暂无商品数据</text>
  61. </view>
  62. </view>
  63. </mescroll-body>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 加载提示 -->
  69. <view v-if="loading" class="loading-mask">
  70. <u-loading mode="circle" size="40" color="#FF5C03"></u-loading>
  71. <text class="loading-text">加载中...</text>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import {
  77. queryStore, //查询店铺
  78. store // 小黄车查询店铺,
  79. } from '@/api/live'
  80. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  81. export default {
  82. mixins: [MescrollMixin],
  83. data() {
  84. return {
  85. // 分页相关配置
  86. page: 1, // 当前页码
  87. pageSize: 6, // 每页条数
  88. total: 0, // 总数据量
  89. loading: false, // 加载状态
  90. // mescroll配置
  91. mescroll: null,
  92. downOption: {
  93. use: true,
  94. auto: true, // 改为true,进入页面自动刷新
  95. offset: 80,
  96. textinoffset: '下拉刷新',
  97. textoutoffset: '释放更新',
  98. textloading: '加载中...'
  99. },
  100. upOption: {
  101. use: true, // 启用上拉加载
  102. auto: true, // 进入页面自动加载
  103. page: {
  104. num: 0, // 初始页码
  105. size: 6 // 每页数量
  106. },
  107. noMoreSize: 6, // 小于6条时显示无更多
  108. textLoading: '加载中...',
  109. textNoMore: '-- 没有更多数据了 --',
  110. empty: {
  111. use: false, // 不使用mescroll的空布局,使用自定义的
  112. icon: '',
  113. tip: ''
  114. }
  115. },
  116. inputInfo: '',
  117. searchTimer: null,
  118. products: [],
  119. liveId: null,
  120. storeId: '',
  121. statusBarHeight: uni.getWindowInfo().statusBarHeight,
  122. storeInfo: {},
  123. }
  124. },
  125. onLoad(options) {
  126. console.log("接收到的options:", options);
  127. if (options.liveId) {
  128. this.liveId = options.liveId;
  129. }
  130. if (options.storeId) {
  131. this.storeId = options.storeId || ""
  132. // 加载店铺信息
  133. this.queryCollect();
  134. } else {
  135. uni.showToast({
  136. title: "storeId不存在~",
  137. icon: "none"
  138. })
  139. }
  140. },
  141. mounted() {
  142. // 初始化时不手动调用,由mescroll触发
  143. },
  144. onShow() {
  145. this.divHeight = `calc(100vh - 44px - 88rpx - ${this.statusBarHeight}px)`
  146. },
  147. methods: {
  148. // 初始化mescroll
  149. mescrollInit(mescroll) {
  150. this.mescroll = mescroll;
  151. console.log('mescroll初始化完成');
  152. },
  153. // 下拉刷新回调
  154. async downCallback(mescroll) {
  155. this.loading = true;
  156. try {
  157. // 重置页码,重新加载数据
  158. this.page = 1;
  159. await this.queryStore();
  160. // 结束下拉刷新
  161. mescroll.endSuccess();
  162. // 重置上拉加载状态
  163. mescroll.resetUpScroll();
  164. } catch (error) {
  165. console.error('下拉刷新失败:', error);
  166. mescroll.endErr();
  167. } finally {
  168. this.loading = false;
  169. }
  170. },
  171. // 上拉加载回调
  172. async upCallback(page) {
  173. this.loading = true;
  174. try {
  175. const pageNum = page.num;
  176. const pageSize = page.size;
  177. const res = await this.queryStore(pageNum, pageSize);
  178. // 当前页数据
  179. const curPageData = res.rows || [];
  180. // 设置列表数据
  181. if (pageNum == 1) {
  182. this.products = []; // 如果是第一页需手动置空列表
  183. }
  184. // 追加新数据
  185. this.products = this.products.concat(curPageData);
  186. // 方法一(推荐): 后台接口有返回列表的总数据量 total
  187. this.mescroll.endBySize(curPageData.length, res.total);
  188. // 方法二(推荐): 后台接口有返回列表的总页数 pageCount
  189. // this.mescroll.endByPage(curPageData.length, res.pageCount);
  190. } catch (error) {
  191. console.error('上拉加载失败:', error);
  192. this.mescroll.endErr();
  193. } finally {
  194. this.loading = false;
  195. }
  196. },
  197. handleSearchInput() {
  198. // 搜索时重置分页
  199. clearTimeout(this.searchTimer);
  200. this.searchTimer = setTimeout(() => {
  201. // 重置mescroll,重新加载第一页
  202. this.page = 1;
  203. this.mescroll.resetUpScroll(true);
  204. }, 500);
  205. },
  206. getPureDecimal(num, precision = 6) {
  207. if (!num && num !== 0) return '00';
  208. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  209. return decimalPart?.replace(/0+$/, '') || '00';
  210. },
  211. // 查询店铺商品
  212. async queryStore(pageNum = 1, pageSize = 6) {
  213. return new Promise((resolve, reject) => {
  214. if (!this.storeId) {
  215. reject('storeId不存在');
  216. return;
  217. }
  218. queryStore(this.storeId, pageSize, pageNum, this.inputInfo)
  219. .then(res => {
  220. if (res.code == 200) {
  221. resolve(res);
  222. } else {
  223. uni.showToast({
  224. title: res.msg || '加载失败',
  225. icon: 'none'
  226. });
  227. reject(res.msg);
  228. }
  229. })
  230. .catch(rej => {
  231. uni.showToast({
  232. title: '加载失败',
  233. icon: 'none'
  234. });
  235. reject(rej);
  236. });
  237. });
  238. },
  239. // 小黄车查询店铺
  240. queryCollect() {
  241. if (!this.storeId) return;
  242. let key = ''
  243. store(this.storeId, key).then(res => {
  244. if (res.code == 200) {
  245. console.log("查询店铺>>", res)
  246. this.storeInfo = res.data
  247. } else {
  248. uni.showToast({
  249. title: res.msg,
  250. icon: 'none'
  251. });
  252. }
  253. }).catch(err => {
  254. console.error('查询店铺信息失败:', err);
  255. });
  256. },
  257. rightClick() {
  258. const pages = getCurrentPages();
  259. if (pages.length > 1) {
  260. uni.navigateBack();
  261. } else {
  262. uni.redirectTo({
  263. url: '/pages/home/living'
  264. });
  265. }
  266. },
  267. showProductList(item) {
  268. uni.navigateTo({
  269. url: '/pages_shop/goods?productId=' + item.productId + '&liveId=' + this.liveId + '&goodsId=' +
  270. item.goodsId + '&storeId=' + this.storeId
  271. })
  272. }
  273. }
  274. }
  275. </script>
  276. <style scoped lang="scss">
  277. :deep(.u-tabs__wrapper__nav) {
  278. margin: 0 auto;
  279. }
  280. .load-more {
  281. text-align: center;
  282. padding: 30rpx 0;
  283. color: #999;
  284. font-size: 26rpx;
  285. }
  286. @mixin u-flex($flexD, $alignI, $justifyC) {
  287. display: flex;
  288. flex-direction: $flexD;
  289. align-items: $alignI;
  290. justify-content: $justifyC;
  291. }
  292. .inputbox {
  293. height: 60rpx;
  294. padding: 0 20rpx;
  295. @include u-flex(row, center, flex-start);
  296. border-radius: 40rpx;
  297. line-height: 60rpx;
  298. font-size: 28rpx;
  299. color: #ffffff;
  300. .icon-search {
  301. width: 28rpx;
  302. height: 28rpx;
  303. margin-right: 20rpx;
  304. }
  305. }
  306. .uni-nav-bar {
  307. position: fixed;
  308. top: 0;
  309. left: 0;
  310. width: 100%;
  311. z-index: 999;
  312. overflow: hidden;
  313. font-weight: 500;
  314. .uni-nav-barbox {
  315. width: 100%;
  316. height: 88rpx;
  317. @include u-flex(row, center, flex-start);
  318. position: relative;
  319. font-size: 24rpx;
  320. }
  321. .uni-nav-title {
  322. /* #ifdef APP-PLUS */
  323. font-size: 34rpx;
  324. /* #endif */
  325. /* #ifndef APP-PLUS */
  326. font-size: 14px;
  327. /* #endif */
  328. overflow: hidden;
  329. white-space: nowrap;
  330. width: 100%;
  331. text-overflow: ellipsis;
  332. }
  333. .uni-nav-back {
  334. margin-left: 20rpx;
  335. margin-right: 20rpx;
  336. height: 88rpx;
  337. @include u-flex(row, center, flex-start);
  338. }
  339. }
  340. .content {
  341. width: 100%;
  342. position: relative;
  343. // .bg {
  344. // width: 100%;
  345. // height: auto;
  346. // position: absolute;
  347. // top: 0;
  348. // left: 0;
  349. // height: 388rpx;
  350. // background: #3A1101;
  351. // }
  352. &-body {
  353. position: relative;
  354. padding-top: calc(var(--status-bar-height) + 88rpx);
  355. }
  356. }
  357. .store-head {
  358. margin-top: 40rpx;
  359. padding: 32rpx;
  360. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  361. color: #ffffff;
  362. &-top {
  363. display: flex;
  364. align-items: center;
  365. }
  366. &-logo {
  367. flex-shrink: 0;
  368. margin-right: 24rpx;
  369. }
  370. &-name {
  371. font-weight: 600;
  372. font-size: 32rpx;
  373. }
  374. &-desc {
  375. margin-top: 16rpx;
  376. display: flex;
  377. align-items: center;
  378. flex-wrap: wrap;
  379. gap: 20rpx;
  380. position: relative;
  381. z-index: 2;
  382. view {
  383. padding-right: 20rpx;
  384. font-size: 26rpx;
  385. position: relative;
  386. &::after {
  387. content: "";
  388. width: 0;
  389. height: 28rpx;
  390. border-right: 1rpx solid #eee;
  391. position: absolute;
  392. right: 0;
  393. top: 50%;
  394. transform: translate(0, -50%);
  395. }
  396. &:last-child::after {
  397. border: none;
  398. }
  399. }
  400. }
  401. }
  402. .border_bottom_line {
  403. position: relative;
  404. &::after {
  405. content: "";
  406. position: absolute;
  407. bottom: 0;
  408. left: 0;
  409. border-bottom: 1px solid #F5F7FA;
  410. width: 100%;
  411. transform: scaleY(0.5);
  412. border-top-color: #F5F7FA;
  413. border-right-color: #F5F7FA;
  414. border-left-color: #F5F7FA;
  415. }
  416. }
  417. .storebox {
  418. width: 100%;
  419. position: relative;
  420. z-index: 1;
  421. &-info {
  422. padding: 24rpx 24rpx 0 24rpx;
  423. background-color: #fff;
  424. font-size: 28rpx;
  425. color: #333333;
  426. position: relative;
  427. border-top: 4px solid #F5F7FA;
  428. }
  429. &-map {
  430. display: flex;
  431. align-items: center;
  432. word-break: break-all;
  433. padding: 24rpx 0;
  434. }
  435. &-qualifications {
  436. display: flex;
  437. align-items: center;
  438. padding: 24rpx 0;
  439. }
  440. .qualifications {
  441. padding: 24rpx 0;
  442. }
  443. }
  444. .medic-box {
  445. display: flex;
  446. .medic {
  447. box-sizing: border-box;
  448. height: 100%;
  449. // .banner-box {
  450. // margin-top: 30rpx;
  451. // width: 100%;
  452. // height: 160upx;
  453. // border-radius: 10upx;
  454. // overflow: hidden;
  455. // .swiper,
  456. // .swiper-item,
  457. // .swiper-item image {
  458. // width: 100%;
  459. // height: 100%;
  460. // }
  461. // }
  462. .medic-list {
  463. width: 100%;
  464. padding: 20upx 24upx;
  465. box-sizing: border-box;
  466. overflow-y: auto;
  467. height: calc(100% - 220upx);
  468. position: relative;
  469. .inner-list {
  470. display: flex;
  471. flex-wrap: wrap;
  472. .definite {
  473. width: 342rpx;
  474. margin-right: 18upx;
  475. margin-bottom: 30upx;
  476. background: #ffffff;
  477. border-radius: 16rpx;
  478. .img-box {
  479. width: 100%;
  480. height: 343upx;
  481. border-radius: 16rpx 16rpx 0rpx 0rpx;
  482. overflow: hidden;
  483. display: flex;
  484. align-items: center;
  485. image {
  486. width: 100%;
  487. }
  488. }
  489. .name {
  490. width: 100%;
  491. margin-top: 12upx;
  492. font-size: 28rpx;
  493. color: #222222;
  494. padding: 0 20rpx;
  495. box-sizing: border-box;
  496. }
  497. .price {
  498. padding: 0 20rpx 32rpx;
  499. box-sizing: border-box;
  500. margin-top: 12rpx;
  501. .red {
  502. font-weight: bold;
  503. font-size: 26rpx;
  504. color: #FF5C03;
  505. }
  506. .del {
  507. margin-left: 16rpx;
  508. text-decoration: line-through;
  509. font-size: 24rpx;
  510. color: #999999;
  511. }
  512. }
  513. &:nth-child(2n) {
  514. margin-right: 0;
  515. }
  516. }
  517. }
  518. }
  519. }
  520. }
  521. </style>