shopPopup.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <u-popup
  3. :show="show"
  4. @close="handleClose"
  5. round="20rpx"
  6. bgColor="#f3f5f9"
  7. zIndex="10075"
  8. >
  9. <view class="shoppop">
  10. <!-- 顶部搜索和操作区域 -->
  11. <view class="shoppop-top">
  12. <view class="search-input x-f">
  13. <image class="w24 mr16" src="/static/images/search.png" mode="widthFix" />
  14. <input
  15. placeholder="请搜索商品"
  16. :value="searchKeyword"
  17. @input="handleSearchInput"
  18. />
  19. </view>
  20. <view class="search-top" @click="handleOrderClick">
  21. <image class="w48 h48" src="/static/images/carts.png" />
  22. <view style="text-align: center">订单</view>
  23. </view>
  24. <view class="search-top" @click="handleMoreClick">
  25. <image class="w48 h48" src="/static/images/search2.png" />
  26. <view style="text-align: center">更多</view>
  27. </view>
  28. </view>
  29. <!-- 商品列表区域 -->
  30. <scroll-view
  31. enable-flex
  32. scroll-y
  33. class="shop-list"
  34. :style="{ height: boxHeight + 'px' }"
  35. >
  36. <!-- 骨架屏 -->
  37. <view v-if="loading && products.length === 0" class="skeleton-list">
  38. <view v-for="n in 6" :key="n" class="skeleton-item">
  39. <view class="skeleton-img"></view>
  40. <view class="skeleton-content">
  41. <view class="skeleton-line short"></view>
  42. <view class="skeleton-line medium"></view>
  43. <view class="skeleton-line long"></view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 实际商品列表 -->
  48. <template v-else>
  49. <view
  50. v-for="(item, index) in products"
  51. :key="index"
  52. class="list-item"
  53. >
  54. <view class="goods-img">
  55. <image class="img" :src="item.imgUrl" mode="widthFix" />
  56. <view class="goods-label">{{ index + 1 }}</view>
  57. </view>
  58. <view class="goods-right">
  59. <view class="goods-title">{{ item.productName }}</view>
  60. <view class="goods-people">{{ item.sales }} 人已购</view>
  61. <view class="goods-shop">
  62. <text class="nummber">
  63. <text style="font-size: 20rpx; font-weight: 600">¥</text>
  64. <text style="font-size: 36rpx; font-weight: bold">
  65. {{ Math.trunc(item.price) }}
  66. </text>
  67. .{{ getPureDecimal(item.price) ? getPureDecimal(item.price) : '00' }}
  68. </text>
  69. <view class="btn-group x-f">
  70. <view class="collect-btn">
  71. <image
  72. v-if="item.isFavorite"
  73. @click="handleCollect(item)"
  74. class="w36 h36"
  75. style="vertical-align: middle"
  76. src="/static/images/collect_select.png"
  77. />
  78. <image
  79. v-else
  80. @click="handleCollect(item)"
  81. class="w36 h36"
  82. style="vertical-align: middle"
  83. src="/static/images/collect.png"
  84. />
  85. </view>
  86. <view
  87. v-if="item.status == 1"
  88. class="shop-btn"
  89. @click="handleGoShop(item)"
  90. >
  91. 去购买
  92. </view>
  93. <view v-else-if="item.status == 0" class="shop-btn">已下架</view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. </template>
  99. </scroll-view>
  100. </view>
  101. </u-popup>
  102. </template>
  103. <script>
  104. export default {
  105. name: 'ShoppingCartPopup',
  106. props: {
  107. // 控制显示/隐藏
  108. show: {
  109. type: Boolean,
  110. default: false
  111. },
  112. // 搜索关键词
  113. searchKeyword: {
  114. type: String,
  115. default: ''
  116. },
  117. // 商品列表
  118. products: {
  119. type: Array,
  120. default: () => []
  121. },
  122. // 加载状态
  123. loading: {
  124. type: Boolean,
  125. default: false
  126. },
  127. // 滚动区域高度
  128. boxHeight: {
  129. type: Number,
  130. default: 300
  131. }
  132. },
  133. methods: {
  134. /**
  135. * 关闭弹窗
  136. */
  137. handleClose() {
  138. this.$emit('close');
  139. },
  140. /**
  141. * 处理搜索输入
  142. */
  143. handleSearchInput(e) {
  144. this.$emit('search', e.detail.value);
  145. },
  146. /**
  147. * 处理订单点击
  148. */
  149. handleOrderClick() {
  150. this.$emit('navigate-to-order');
  151. },
  152. /**
  153. * 处理更多点击
  154. */
  155. handleMoreClick() {
  156. this.$emit('show-more');
  157. },
  158. /**
  159. * 处理收藏点击
  160. */
  161. handleCollect(item) {
  162. this.$emit('collect', item);
  163. },
  164. /**
  165. * 处理去购买点击
  166. */
  167. handleGoShop(item) {
  168. this.$emit('go-shop', item);
  169. },
  170. /**
  171. * 获取价格小数部分
  172. */
  173. getPureDecimal(num, precision = 6) {
  174. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  175. return decimalPart?.replace(/0+$/, '') || '';
  176. }
  177. }
  178. };
  179. </script>
  180. <style scoped lang="scss">
  181. .shoppop {
  182. padding: 22rpx 16rpx;
  183. .shoppop-top {
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. padding: 0 16rpx 22rpx;
  188. .search-input {
  189. width: 414rpx;
  190. height: 76rpx;
  191. background: #ffffff;
  192. border-radius: 36rpx;
  193. margin-left: 20rpx;
  194. padding: 0 32rpx;
  195. box-sizing: border-box;
  196. font-size: 24rpx;
  197. margin-right: 24rpx;
  198. }
  199. .search-top {
  200. font-size: 20rpx;
  201. color: #222222;
  202. text-align: center;
  203. }
  204. }
  205. .shop-list {
  206. overflow: hidden;
  207. .list-item {
  208. display: flex;
  209. align-items: center;
  210. padding: 20rpx 16rpx;
  211. background: #ffffff;
  212. border-radius: 16rpx;
  213. margin-bottom: 16rpx;
  214. .goods-img {
  215. width: 200rpx;
  216. height: 200rpx;
  217. border-radius: 16rpx;
  218. overflow: hidden;
  219. position: relative;
  220. margin-right: 24rpx;
  221. .img {
  222. width: 100%;
  223. height: 100%;
  224. }
  225. .goods-label {
  226. position: absolute;
  227. top: 0;
  228. width: 64rpx;
  229. height: 40rpx;
  230. background: rgba(0, 0, 0, 0.5);
  231. border-radius: 16rpx 0rpx 16rpx 0rpx;
  232. text-align: center;
  233. font-weight: 500;
  234. font-size: 28rpx;
  235. color: #ffffff;
  236. }
  237. }
  238. .goods-right {
  239. flex: 1;
  240. .goods-title {
  241. font-weight: 500;
  242. font-size: 30rpx;
  243. color: #000000;
  244. margin-bottom: 10rpx;
  245. }
  246. .goods-people {
  247. font-size: 22rpx;
  248. color: #e69a22;
  249. height: 56rpx;
  250. }
  251. .goods-shop {
  252. display: flex;
  253. justify-content: space-between;
  254. .nummber {
  255. color: #ff5c03;
  256. font-size: 22rpx;
  257. font-weight: 500;
  258. }
  259. .btn-group {
  260. text-align: center;
  261. line-height: 56rpx;
  262. .collect-btn {
  263. width: 72rpx;
  264. height: 100%;
  265. background: #f5f7fa;
  266. border-radius: 8rpx 0rpx 0rpx 8rpx;
  267. }
  268. .shop-btn {
  269. width: 152rpx;
  270. background: linear-gradient(270deg, #ff5c03 0%, #ffac64 100%);
  271. border-radius: 0rpx 8rpx 8rpx 0rpx;
  272. font-weight: 500;
  273. font-size: 30rpx;
  274. color: #ffffff;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. /* 骨架屏样式 */
  283. .skeleton-list {
  284. .skeleton-item {
  285. display: flex;
  286. padding: 20rpx;
  287. background: #fff;
  288. margin-bottom: 16rpx;
  289. border-radius: 16rpx;
  290. }
  291. .skeleton-img {
  292. width: 200rpx;
  293. height: 200rpx;
  294. background: #f0f0f0;
  295. border-radius: 8rpx;
  296. margin-right: 24rpx;
  297. animation: pulse 1.5s ease-in-out infinite;
  298. }
  299. .skeleton-content {
  300. flex: 1;
  301. }
  302. .skeleton-line {
  303. height: 20rpx;
  304. background: #f0f0f0;
  305. margin-bottom: 16rpx;
  306. border-radius: 4rpx;
  307. animation: pulse 1.5s ease-in-out infinite;
  308. }
  309. .skeleton-line.short {
  310. width: 60%;
  311. }
  312. .skeleton-line.medium {
  313. width: 80%;
  314. }
  315. .skeleton-line.long {
  316. width: 95%;
  317. }
  318. }
  319. @keyframes pulse {
  320. 0% {
  321. opacity: 1;
  322. }
  323. 50% {
  324. opacity: 0.5;
  325. }
  326. 100% {
  327. opacity: 1;
  328. }
  329. }
  330. </style>