productList.vue 14 KB

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