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" @click="handleGoShop(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.stop="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.stop="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. >
  90. 去购买
  91. </view>
  92. <view v-else-if="item.status == 0" class="shop-btn">已下架</view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </template>
  98. </scroll-view>
  99. </view>
  100. </u-popup>
  101. </template>
  102. <script>
  103. export default {
  104. name: 'ShoppingCartPopup',
  105. props: {
  106. // 控制显示/隐藏
  107. show: {
  108. type: Boolean,
  109. default: false
  110. },
  111. // 搜索关键词
  112. searchKeyword: {
  113. type: String,
  114. default: ''
  115. },
  116. // 商品列表
  117. products: {
  118. type: Array,
  119. default: () => []
  120. },
  121. // 加载状态
  122. loading: {
  123. type: Boolean,
  124. default: false
  125. },
  126. // 滚动区域高度
  127. boxHeight: {
  128. type: Number,
  129. default: 300
  130. }
  131. },
  132. methods: {
  133. /**
  134. * 关闭弹窗
  135. */
  136. handleClose() {
  137. this.$emit('close');
  138. },
  139. /**
  140. * 处理搜索输入
  141. */
  142. handleSearchInput(e) {
  143. this.$emit('search', e.detail.value);
  144. },
  145. /**
  146. * 处理订单点击
  147. */
  148. handleOrderClick() {
  149. this.$emit('navigate-to-order');
  150. },
  151. /**
  152. * 处理更多点击
  153. */
  154. handleMoreClick() {
  155. this.$emit('show-more');
  156. },
  157. /**
  158. * 处理收藏点击
  159. */
  160. handleCollect(item) {
  161. this.$emit('collect', item);
  162. },
  163. /**
  164. * 处理去购买点击
  165. */
  166. handleGoShop(item) {
  167. this.$emit('go-shop', item);
  168. },
  169. /**
  170. * 获取价格小数部分
  171. */
  172. getPureDecimal(num, precision = 6) {
  173. const decimalPart = Math.abs(num).toFixed(precision).split('.')[1];
  174. return decimalPart?.replace(/0+$/, '') || '';
  175. }
  176. }
  177. };
  178. </script>
  179. <style scoped lang="scss">
  180. .shoppop {
  181. padding: 22rpx 16rpx;
  182. .shoppop-top {
  183. display: flex;
  184. justify-content: space-between;
  185. align-items: center;
  186. padding: 0 16rpx 22rpx;
  187. .search-input {
  188. width: 414rpx;
  189. height: 76rpx;
  190. background: #ffffff;
  191. border-radius: 36rpx;
  192. margin-left: 20rpx;
  193. padding: 0 32rpx;
  194. box-sizing: border-box;
  195. font-size: 24rpx;
  196. margin-right: 24rpx;
  197. }
  198. .search-top {
  199. font-size: 20rpx;
  200. color: #222222;
  201. text-align: center;
  202. }
  203. }
  204. .shop-list {
  205. overflow: hidden;
  206. .list-item {
  207. display: flex;
  208. align-items: center;
  209. padding: 20rpx 16rpx;
  210. background: #ffffff;
  211. border-radius: 16rpx;
  212. margin-bottom: 16rpx;
  213. .goods-img {
  214. width: 200rpx;
  215. height: 200rpx;
  216. border-radius: 16rpx;
  217. overflow: hidden;
  218. position: relative;
  219. margin-right: 24rpx;
  220. .img {
  221. width: 100%;
  222. height: 100%;
  223. }
  224. .goods-label {
  225. position: absolute;
  226. top: 0;
  227. width: 64rpx;
  228. height: 40rpx;
  229. background: rgba(0, 0, 0, 0.5);
  230. border-radius: 16rpx 0rpx 16rpx 0rpx;
  231. text-align: center;
  232. font-weight: 500;
  233. font-size: 28rpx;
  234. color: #ffffff;
  235. }
  236. }
  237. .goods-right {
  238. flex: 1;
  239. .goods-title {
  240. font-weight: 500;
  241. font-size: 30rpx;
  242. color: #000000;
  243. margin-bottom: 10rpx;
  244. }
  245. .goods-people {
  246. font-size: 22rpx;
  247. color: #e69a22;
  248. height: 56rpx;
  249. }
  250. .goods-shop {
  251. display: flex;
  252. justify-content: space-between;
  253. .nummber {
  254. color: #ff5c03;
  255. font-size: 22rpx;
  256. font-weight: 500;
  257. }
  258. .btn-group {
  259. text-align: center;
  260. line-height: 56rpx;
  261. .collect-btn {
  262. width: 72rpx;
  263. height: 100%;
  264. background: #f5f7fa;
  265. border-radius: 8rpx 0rpx 0rpx 8rpx;
  266. }
  267. .shop-btn {
  268. width: 152rpx;
  269. background: linear-gradient(270deg, #ff5c03 0%, #ffac64 100%);
  270. border-radius: 0rpx 8rpx 8rpx 0rpx;
  271. font-weight: 500;
  272. font-size: 30rpx;
  273. color: #ffffff;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. /* 骨架屏样式 */
  282. .skeleton-list {
  283. .skeleton-item {
  284. display: flex;
  285. padding: 20rpx;
  286. background: #fff;
  287. margin-bottom: 16rpx;
  288. border-radius: 16rpx;
  289. }
  290. .skeleton-img {
  291. width: 200rpx;
  292. height: 200rpx;
  293. background: #f0f0f0;
  294. border-radius: 8rpx;
  295. margin-right: 24rpx;
  296. animation: pulse 1.5s ease-in-out infinite;
  297. }
  298. .skeleton-content {
  299. flex: 1;
  300. }
  301. .skeleton-line {
  302. height: 20rpx;
  303. background: #f0f0f0;
  304. margin-bottom: 16rpx;
  305. border-radius: 4rpx;
  306. animation: pulse 1.5s ease-in-out infinite;
  307. }
  308. .skeleton-line.short {
  309. width: 60%;
  310. }
  311. .skeleton-line.medium {
  312. width: 80%;
  313. }
  314. .skeleton-line.long {
  315. width: 95%;
  316. }
  317. }
  318. @keyframes pulse {
  319. 0% {
  320. opacity: 1;
  321. }
  322. 50% {
  323. opacity: 0.5;
  324. }
  325. 100% {
  326. opacity: 1;
  327. }
  328. }
  329. </style>