store.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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. <view class="empty-text">暂无商品数据</view>
  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: false, // 关闭下拉自动刷新
  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&&options.storeId) {
  128. this.liveId = options.liveId;
  129. this.storeId = options.storeId || ""
  130. this.queryCollect();
  131. }
  132. },
  133. mounted() {
  134. // 初始化时不手动调用,由mescroll触发
  135. },
  136. onShow() {
  137. this.divHeight = `calc(100vh - 44px - 88rpx - ${this.statusBarHeight}px)`
  138. },
  139. methods: {
  140. // 初始化mescroll
  141. mescrollInit(mescroll) {
  142. this.mescroll = mescroll;
  143. console.log('mescroll初始化完成');
  144. },
  145. // 下拉刷新回调
  146. async downCallback(mescroll) {
  147. this.loading = true;
  148. try {
  149. // 重置页码,重新加载数据
  150. this.page = 1;
  151. await this.queryStore();
  152. // 结束下拉刷新
  153. mescroll.endSuccess();
  154. // 重置上拉加载状态
  155. mescroll.resetUpScroll();
  156. } catch (error) {
  157. console.error('下拉刷新失败:', error);
  158. mescroll.endErr();
  159. } finally {
  160. this.loading = false;
  161. }
  162. },
  163. // 上拉加载回调
  164. async upCallback(page) {
  165. this.loading = true;
  166. try {
  167. const pageNum = page.num;
  168. const pageSize = page.size;
  169. const res = await this.queryStore(pageNum, pageSize);
  170. // 当前页数据
  171. const curPageData = res.rows || [];
  172. // 设置列表数据
  173. if (pageNum == 1) {
  174. this.products = []; // 如果是第一页需手动置空列表
  175. }
  176. // 追加新数据
  177. this.products = this.products.concat(curPageData);
  178. // 方法一(推荐): 后台接口有返回列表的总数据量 total
  179. this.mescroll.endBySize(curPageData.length, res.total);
  180. // 方法二(推荐): 后台接口有返回列表的总页数 pageCount
  181. // this.mescroll.endByPage(curPageData.length, res.pageCount);
  182. } catch (error) {
  183. console.error('上拉加载失败:', error);
  184. this.mescroll.endErr();
  185. } finally {
  186. this.loading = false;
  187. }
  188. },
  189. handleSearchInput() {
  190. // 搜索时重置分页
  191. clearTimeout(this.searchTimer);
  192. this.searchTimer = setTimeout(() => {
  193. // 重置mescroll,重新加载第一页
  194. this.page = 1;
  195. this.mescroll.resetUpScroll(true);
  196. }, 500);
  197. },
  198. getPureDecimal(num, precision = 6) {
  199. if (!num && num !== 0) return '00';
  200. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  201. return decimalPart?.replace(/0+$/, '') || '00';
  202. },
  203. // 查询店铺商品
  204. async queryStore(pageNum = 1, pageSize = 10) {
  205. return new Promise((resolve, reject) => {
  206. if (!this.storeId) {
  207. reject('storeId不存在');
  208. return;
  209. }
  210. queryStore(this.storeId, pageSize, pageNum, this.inputInfo)
  211. .then(res => {
  212. if (res.code == 200) {
  213. resolve(res);
  214. } else {
  215. uni.showToast({
  216. title: res.msg || '加载失败',
  217. icon: 'none'
  218. });
  219. reject(res.msg);
  220. }
  221. })
  222. .catch(rej => {
  223. uni.showToast({
  224. title: '加载失败',
  225. icon: 'none'
  226. });
  227. reject(rej);
  228. });
  229. });
  230. },
  231. // 小黄车查询店铺
  232. queryCollect() {
  233. if (!this.storeId) return;
  234. let key = ''
  235. store(this.storeId, key,this.liveId).then(res => {
  236. if (res.code == 200) {
  237. console.log("查询店铺>>", res)
  238. this.storeInfo = res.data
  239. } else {
  240. uni.showToast({
  241. title: res.msg,
  242. icon: 'none'
  243. });
  244. }
  245. }).catch(err => {
  246. console.error('查询店铺信息失败:', err);
  247. });
  248. },
  249. rightClick() {
  250. const pages = getCurrentPages();
  251. if (pages.length > 1) {
  252. uni.navigateBack();
  253. } else {
  254. uni.redirectTo({
  255. url: '/pages/home/living'
  256. });
  257. }
  258. },
  259. showProductList(item) {
  260. console.log("跳到商品详情",item)
  261. uni.navigateTo({
  262. url: '/pages_shop/goods?productId=' + item.productId + '&liveId=' + this.liveId + '&storeId=' + this.storeId
  263. })
  264. }
  265. }
  266. }
  267. </script>
  268. <style scoped lang="scss">
  269. :deep(.u-tabs__wrapper__nav) {
  270. margin: 0 auto;
  271. }
  272. .load-more {
  273. text-align: center;
  274. padding: 30rpx 0;
  275. color: #999;
  276. font-size: 26rpx;
  277. }
  278. @mixin u-flex($flexD, $alignI, $justifyC) {
  279. display: flex;
  280. flex-direction: $flexD;
  281. align-items: $alignI;
  282. justify-content: $justifyC;
  283. }
  284. .inputbox {
  285. height: 60rpx;
  286. padding: 0 20rpx;
  287. @include u-flex(row, center, flex-start);
  288. border-radius: 40rpx;
  289. line-height: 60rpx;
  290. font-size: 28rpx;
  291. color: #ffffff;
  292. .icon-search {
  293. width: 28rpx;
  294. height: 28rpx;
  295. margin-right: 20rpx;
  296. }
  297. }
  298. .uni-nav-bar {
  299. position: fixed;
  300. top: 0;
  301. left: 0;
  302. width: 100%;
  303. z-index: 999;
  304. overflow: hidden;
  305. font-weight: 500;
  306. .uni-nav-barbox {
  307. width: 100%;
  308. height: 88rpx;
  309. @include u-flex(row, center, flex-start);
  310. position: relative;
  311. font-size: 24rpx;
  312. }
  313. .uni-nav-title {
  314. /* #ifdef APP-PLUS */
  315. font-size: 34rpx;
  316. /* #endif */
  317. /* #ifndef APP-PLUS */
  318. font-size: 14px;
  319. /* #endif */
  320. overflow: hidden;
  321. white-space: nowrap;
  322. width: 100%;
  323. text-overflow: ellipsis;
  324. }
  325. .uni-nav-back {
  326. margin-left: 20rpx;
  327. margin-right: 20rpx;
  328. height: 88rpx;
  329. @include u-flex(row, center, flex-start);
  330. }
  331. }
  332. .content {
  333. width: 100%;
  334. position: relative;
  335. // .bg {
  336. // width: 100%;
  337. // height: auto;
  338. // position: absolute;
  339. // top: 0;
  340. // left: 0;
  341. // height: 388rpx;
  342. // background: #3A1101;
  343. // }
  344. &-body {
  345. position: relative;
  346. padding-top: calc(var(--status-bar-height) + 88rpx);
  347. }
  348. }
  349. .store-head {
  350. margin-top: 40rpx;
  351. padding: 32rpx;
  352. background: linear-gradient(270deg, #FF5C03 0%, #FFAC64 100%);
  353. color: #ffffff;
  354. &-top {
  355. display: flex;
  356. align-items: center;
  357. }
  358. &-logo {
  359. flex-shrink: 0;
  360. margin-right: 24rpx;
  361. }
  362. &-name {
  363. font-weight: 600;
  364. font-size: 32rpx;
  365. }
  366. &-desc {
  367. margin-top: 16rpx;
  368. display: flex;
  369. align-items: center;
  370. flex-wrap: wrap;
  371. gap: 20rpx;
  372. position: relative;
  373. z-index: 2;
  374. view {
  375. padding-right: 20rpx;
  376. font-size: 26rpx;
  377. position: relative;
  378. &::after {
  379. content: "";
  380. width: 0;
  381. height: 28rpx;
  382. border-right: 1rpx solid #eee;
  383. position: absolute;
  384. right: 0;
  385. top: 50%;
  386. transform: translate(0, -50%);
  387. }
  388. &:last-child::after {
  389. border: none;
  390. }
  391. }
  392. }
  393. }
  394. .border_bottom_line {
  395. position: relative;
  396. &::after {
  397. content: "";
  398. position: absolute;
  399. bottom: 0;
  400. left: 0;
  401. border-bottom: 1px solid #F5F7FA;
  402. width: 100%;
  403. transform: scaleY(0.5);
  404. border-top-color: #F5F7FA;
  405. border-right-color: #F5F7FA;
  406. border-left-color: #F5F7FA;
  407. }
  408. }
  409. .storebox {
  410. width: 100%;
  411. position: relative;
  412. z-index: 1;
  413. &-info {
  414. padding: 24rpx 24rpx 0 24rpx;
  415. background-color: #fff;
  416. font-size: 28rpx;
  417. color: #333333;
  418. position: relative;
  419. border-top: 4px solid #F5F7FA;
  420. }
  421. &-map {
  422. display: flex;
  423. align-items: center;
  424. word-break: break-all;
  425. padding: 24rpx 0;
  426. }
  427. &-qualifications {
  428. display: flex;
  429. align-items: center;
  430. padding: 24rpx 0;
  431. }
  432. .qualifications {
  433. padding: 24rpx 0;
  434. }
  435. }
  436. .medic-box {
  437. display: flex;
  438. .medic {
  439. box-sizing: border-box;
  440. height: 100%;
  441. width: 100%;
  442. .medic-list {
  443. width: 100%;
  444. padding: 20upx 24upx;
  445. box-sizing: border-box;
  446. overflow-y: auto;
  447. height: calc(100% - 220upx);
  448. position: relative;
  449. .empty-data {
  450. text-align: center;
  451. }
  452. .inner-list {
  453. display: flex;
  454. flex-wrap: wrap;
  455. .definite {
  456. width: 342rpx;
  457. margin-right: 18upx;
  458. margin-bottom: 30upx;
  459. background: #ffffff;
  460. border-radius: 16rpx;
  461. .img-box {
  462. width: 100%;
  463. height: 343upx;
  464. border-radius: 16rpx 16rpx 0rpx 0rpx;
  465. overflow: hidden;
  466. display: flex;
  467. align-items: center;
  468. image {
  469. width: 100%;
  470. }
  471. }
  472. .name {
  473. width: 100%;
  474. margin-top: 12upx;
  475. font-size: 28rpx;
  476. color: #222222;
  477. padding: 0 20rpx;
  478. box-sizing: border-box;
  479. }
  480. .price {
  481. padding: 0 20rpx 32rpx;
  482. box-sizing: border-box;
  483. margin-top: 12rpx;
  484. .red {
  485. font-weight: bold;
  486. font-size: 26rpx;
  487. color: #FF5C03;
  488. }
  489. .del {
  490. margin-left: 16rpx;
  491. text-decoration: line-through;
  492. font-size: 24rpx;
  493. color: #999999;
  494. }
  495. }
  496. &:nth-child(2n) {
  497. margin-right: 0;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. }
  504. </style>