productList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  1. <template>
  2. <view
  3. class="container commodity-list-wrapper"
  4. :style="{ overflow: showSkeleton ? 'hidden' : 'auto', height: showSkeleton ? windowHeight + 'px' : 'auto' }"
  5. >
  6. <list-skeleton v-if="showSkeleton" :listType="0"></list-skeleton>
  7. <view class="product-container" v-if="!isShowEmpty">
  8. <scroll-view
  9. :style="{ height: scrollHeight + 'px' }"
  10. @scrolltolower="scrolltolower"
  11. scroll-y
  12. v-if="productList.length > 0"
  13. >
  14. <view
  15. v-for="(item, index) in productList"
  16. :key="index"
  17. :id="item.id"
  18. class="all-type-list-content commodity-list"
  19. @click.stop="navToDetailPage(item.productId)"
  20. >
  21. <image mode="widthFix" :src="item.image" class="list-img" alt="list-img"></image>
  22. <view class="list-details-info">
  23. <text class="list-details-title">{{ item.name }}</text>
  24. <text class="list-details-specs">规格:{{ item.unit != null ? item.unit : '' }}</text>
  25. <text class="list-details-miniQuantity"
  26. >起订量:{{ item.ladderPriceFlag == '1' ? item.maxBuyNumber : item.minBuyNumber }}</text
  27. >
  28. <view class="list-details-price" v-if="item.priceFlag == 1">
  29. <view class="list-none"><view class="price-small">¥未公开价格</view></view>
  30. </view>
  31. <view class="list-details-price" v-else-if="item.priceFlag == 2">
  32. <view class="list-none"><view class="price-small">¥价格仅会员可见</view></view>
  33. </view>
  34. <view class="list-details-price" v-else-if="item.priceFlag == 3">
  35. <view class="list-none"><view class="price-small">¥仅医美机构可见</view></view>
  36. </view>
  37. <view class="list-details-price" v-else>
  38. <view class="list-shop">
  39. <view class="list-price-none" v-if="item.repurchaseFlag == 1">
  40. <text class="price-none">¥{{ item.originalPrice }}</text>
  41. <text class="iconfont icon-wenhao" @click.stop="repurchModel"></text>
  42. </view>
  43. <view class="list-price" v-else>
  44. <text
  45. class="price-larger"
  46. :class="
  47. PromotionsFormat(item.promotions) || item.svipProductFlag == 1 ? 'none' : ''
  48. "
  49. >
  50. ¥{{
  51. (PromotionsFormat(item.promotions) ? item.originalPrice : item.price)
  52. | NumFormat
  53. }}
  54. </text>
  55. </view>
  56. </view>
  57. <button class="add-cart-btn" @click.stop="operationHanld(item)">数量</button>
  58. </view>
  59. <view class="list-details-price">
  60. <view class="floor-item-act">
  61. <view class="coupon-tags" v-if="item.couponsLogo">优惠券</view>
  62. <template v-if="item.actStatus == 1">
  63. <view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
  64. {{ item.promotions.name }}<text>:¥{{ item.price | NumFormat }}</text>
  65. </view>
  66. <view class="floor-tags" v-else>{{ item.promotions.name }}</view>
  67. </template>
  68. <template v-if="item.svipProductFlag == 1">
  69. <view class="svip-tags">
  70. <view class="tags">SVIP</view>
  71. <view class="price">{{ item.svipPriceTag }}</view>
  72. </view>
  73. </template>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
  79. <view v-if="showLoading && productList.length > 4 && !showRegularBtn">
  80. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow"
  81. >{{ loadingText }}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view
  82. >
  83. <view class="loading-wrapper loading-wrapper-btm" v-else
  84. >———<text class="btm-text">已至底部</text>———</view
  85. >
  86. </view>
  87. </scroll-view>
  88. </view>
  89. <view class="empty-container" v-else>
  90. <image
  91. class="empty-container-image"
  92. src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png"
  93. mode="aspectFit"
  94. ></image>
  95. <text class="error-text">您还没有购买过任何商品哟~</text>
  96. <button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
  97. </view>
  98. <!-- 可拖动悬浮按钮 -->
  99. <cm-drag
  100. v-if="!isShowEmpty"
  101. :cartNum="cartQuantity"
  102. :isDock="true"
  103. :existTabBar="true"
  104. @btnClick="btnClick"
  105. @btnTouchstart="btnTouchstart"
  106. @btnTouchend="btnTouchend"
  107. >
  108. </cm-drag>
  109. <!-- 透明模态层 -->
  110. <modal-layer v-if="isModallayer"></modal-layer>
  111. </view>
  112. </template>
  113. <script>
  114. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  115. import modalLayer from '@/components/modal-layer'
  116. import uniStars from '@/components/uni-stars/uni-stars.vue'
  117. import cmDrag from '@/components/cm-custom/cm-drag.vue'
  118. import { mapState, mapMutations } from 'vuex'
  119. export default {
  120. name: 'productList',
  121. components: {
  122. listSkeleton,
  123. modalLayer,
  124. uniStars,
  125. cmDrag
  126. },
  127. props: {
  128. emptyText: {
  129. type: String
  130. }
  131. },
  132. data() {
  133. return {
  134. isModallayer: false,
  135. windowHeight: '',
  136. showSkeleton: true,
  137. isShowEmpty: false,
  138. userId: 0,
  139. scrollHeight: '',
  140. productList: [],
  141. showLoading: false,
  142. loadingNow: true,
  143. loadingText: '上拉加载更多',
  144. pageSize: 10,
  145. pageNum: 1,
  146. hasNextPage: false,
  147. pullFlag: true,
  148. fromRegularPurchasePage: false,
  149. cartQuantity: 0,
  150. showRegularBtn: false,
  151. isPrecedence: false
  152. }
  153. },
  154. created() {
  155. this.setScrollHeight()
  156. this.initGetStotage()
  157. },
  158. filters: {
  159. NumFormat: function(text) {
  160. //处理金额
  161. return Number(text).toFixed(2)
  162. }
  163. },
  164. computed: {
  165. ...mapState(['hasLogin', 'userInfo', 'identity'])
  166. },
  167. methods: {
  168. async initGetStotage() {
  169. // 初始化
  170. const userInfo = await this.$api.getStorage()
  171. this.userId = userInfo.userId ? userInfo.userId : 0
  172. this.getProductAgainInfo()
  173. this.GetUserCartNumber()
  174. },
  175. scrolltolower() {
  176. if (this.hasNextPage && this.pullFlag) {
  177. this.getProductAgainInfo(true)
  178. }
  179. },
  180. setScrollHeight() {
  181. const { windowHeight, pixelRatio } = wx.getSystemInfoSync()
  182. this.windowHeight = windowHeight - 1
  183. this.scrollHeight = windowHeight - 1
  184. },
  185. getProductAgainInfo(loadMore) {
  186. this.showLoading = true
  187. this.loadingNow = true
  188. this.loadingText = '加载中'
  189. this.isShowEmpty = false
  190. if (loadMore) {
  191. this.pageNum += 1
  192. }
  193. this.ProductService.GetRepeatBuyAgainProductList({
  194. userId: this.userId,
  195. identity: this.identity,
  196. pageNum: this.pageNum,
  197. pageSize: this.pageSize
  198. })
  199. .then(response => {
  200. this.isShowWrapper = true
  201. this.cartQuantity = response.data.cartQuantity
  202. const listData = response.data.results
  203. if (listData && listData.length > 0) {
  204. this.hasNextPage = response.data.hasNextPage
  205. this.isShowEmpty = false
  206. if (loadMore) {
  207. this.productList = [...this.productList, ...listData]
  208. } else {
  209. this.productList = listData
  210. this.showSkeleton = false
  211. }
  212. //价格显示处理
  213. let isActFlg,
  214. newProductList = []
  215. this.productList.map((item, index) => {
  216. if (item.actStatus == 1) {
  217. isActFlg = true
  218. } else if (item.actStatus == 1 && item.ladderPriceFlag == '1') {
  219. isActFlg = true
  220. } else {
  221. isActFlg = false
  222. }
  223. newProductList.push(Object.assign({}, item, { isShowActFlg: isActFlg }))
  224. })
  225. this.productList = newProductList
  226. // 防上拉暴滑
  227. this.pullFlag = false
  228. setTimeout(() => {
  229. this.pullFlag = true
  230. }, 500)
  231. // 底部提示文案
  232. if (this.hasNextPage) {
  233. this.loadingText = '上拉加载更多'
  234. } else {
  235. this.showLoading = true
  236. this.loadingNow = false
  237. }
  238. } else {
  239. if (!loadMore) {
  240. this.isShowEmpty = true
  241. }
  242. }
  243. })
  244. .catch(response => {
  245. this.$util.msg(response.msg, 2000)
  246. })
  247. },
  248. GetUserCartNumber() {
  249. this.OrderService.ShoppingCartCount({ userId: this.userId })
  250. .then(response => {
  251. this.cartQuantity = response.data
  252. })
  253. .catch(error => {
  254. console.log('查询用户购物车数量失败')
  255. })
  256. },
  257. operationHanld(prop) {
  258. this.$emit('operationConfim', prop)
  259. },
  260. navToDetailPage(id) {
  261. this.isModallayer = true
  262. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  263. this.isModallayer = false
  264. },
  265. toIndexPage() {
  266. uni.switchTab({
  267. url: '/pages/tabBar/home/index'
  268. })
  269. },
  270. repurchModel() {
  271. this.$util.modal('', '此商品的价格有变化,原来的购买价已不适用', '知道了', '', false, () => {})
  272. },
  273. PromotionsFormat(promo) {
  274. //促销活动类型数据处理
  275. if (promo != null) {
  276. if (promo.type == 1 && promo.mode == 1) {
  277. return true
  278. } else {
  279. return false
  280. }
  281. }
  282. return false
  283. },
  284. btnClick() {
  285. this.$api.navigateTo('/pages/goods/cart')
  286. },
  287. btnTouchstart() {
  288. // console.log('btnTouchstart');
  289. },
  290. btnTouchend() {
  291. // console.log('btnTouchend');
  292. }
  293. }
  294. }
  295. </script>
  296. <style lang="scss">
  297. .commodity-list-wrapper {
  298. scroll-view {
  299. height: 100%;
  300. border-top: 2rpx solid rgba(0, 0, 0, 0.07);
  301. }
  302. .empty-container-image {
  303. margin-top: -300rpx;
  304. }
  305. .toIndexPage {
  306. bottom: 390rpx;
  307. }
  308. .show-more-btn {
  309. width: 276rpx;
  310. height: 52rpx;
  311. line-height: 52rpx;
  312. border: 2rpx solid #d8d8d8;
  313. background: #f7f7f7;
  314. font-size: 26rpx;
  315. margin: 26rpx 0;
  316. position: absolute;
  317. left: 50%;
  318. margin-left: -138rpx;
  319. }
  320. }
  321. .all-type-list-content {
  322. height: auto;
  323. padding: 24rpx;
  324. background: #fff;
  325. margin-bottom: 2rpx;
  326. display: flex;
  327. flex-direction: row;
  328. box-sizing: content-box;
  329. .list-img {
  330. width: 240rpx;
  331. height: 240rpx !important;
  332. margin-right: 26rpx;
  333. border-radius: 10rpx;
  334. border: 2rpx solid #f3f3f3;
  335. }
  336. }
  337. .list-details-info {
  338. width: 442rpx;
  339. flex-direction: column;
  340. font-size: 26rpx;
  341. position: relative;
  342. .list-details-title {
  343. line-height: 38rpx;
  344. text-overflow: ellipsis;
  345. overflow: hidden;
  346. display: -webkit-box;
  347. -webkit-line-clamp: 2;
  348. line-clamp: 2;
  349. -webkit-box-orient: vertical;
  350. }
  351. .list-details-specs {
  352. width: 100%;
  353. display: inline-block;
  354. margin-top: 8rpx;
  355. color: #999999;
  356. }
  357. .list-details-miniQuantity {
  358. width: 100%;
  359. display: inline-block;
  360. margin-top: 7rpx;
  361. }
  362. }
  363. .list-details-price {
  364. width: 100%;
  365. line-height: 54rpx;
  366. float: left;
  367. .floor-item-act {
  368. height: 54rpx;
  369. text-align: center;
  370. box-sizing: border-box;
  371. float: left;
  372. padding: 11rpx 0;
  373. }
  374. .price-icon {
  375. width: 22rpx;
  376. height: 28rpx;
  377. vertical-align: middle;
  378. margin-right: 10rpx;
  379. }
  380. .price-icon + text {
  381. font-size: 25rpx;
  382. vertical-align: middle;
  383. }
  384. .list-login-now {
  385. width: 375rpx;
  386. color: #f8c499;
  387. position: absolute;
  388. bottom: 0;
  389. .p-no {
  390. float: left;
  391. font-size: $font-size-24;
  392. color: $color-system;
  393. margin-right: 10rpx;
  394. }
  395. }
  396. .login-now {
  397. padding: 10rpx 10rpx 10rpx 0;
  398. }
  399. .list-none {
  400. margin-top: 30rpx;
  401. .price-small {
  402. font-size: $font-size-24;
  403. line-height: 40rpx;
  404. color: #ff2a2a;
  405. }
  406. }
  407. .list-shop {
  408. height: auto;
  409. float: left;
  410. .list-price {
  411. width: 100%;
  412. color: #ff2a2a;
  413. float: left;
  414. line-height: 54rpx;
  415. align-items: center;
  416. justify-content: center;
  417. .price-larger {
  418. font-size: $font-size-30;
  419. display: inline-block;
  420. &.none {
  421. text-decoration: line-through;
  422. color: #999999;
  423. }
  424. }
  425. }
  426. .list-price-none {
  427. width: 100%;
  428. .price-none {
  429. text-decoration: line-through;
  430. color: #999999;
  431. display: inline-block;
  432. }
  433. .icon-wenhao {
  434. font-size: $font-size-32;
  435. color: #0091ff;
  436. margin-left: 6rpx;
  437. }
  438. }
  439. }
  440. .add-cart-btn {
  441. float: right;
  442. width: 140rpx;
  443. height: 54rpx;
  444. line-height: 54rpx;
  445. border-radius: 27rpx;
  446. color: #fff;
  447. font-size: 24rpx;
  448. margin-right: 0;
  449. background: #ffffff;
  450. border: 1px solid #c9c9c9;
  451. color: $text-color;
  452. }
  453. }
  454. </style>