productList.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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 && (firstClubType!=1)">
  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" :class="{ none: !isShowVipFlag(item) }">SVIP</view>
  71. <view class="price" v-if="isShowVipFlag(item)">{{ 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. vipFlag:0,
  153. firstClubType:0
  154. }
  155. },
  156. created() {
  157. this.setScrollHeight()
  158. this.initGetStotage()
  159. },
  160. filters: {
  161. NumFormat: function(text) {
  162. //处理金额
  163. return Number(text).toFixed(2)
  164. }
  165. },
  166. computed: {
  167. ...mapState(['hasLogin', 'userInfo', 'identity','clubType'])
  168. },
  169. methods: {
  170. async initGetStotage() {
  171. // 初始化
  172. const userInfo = await this.$api.getStorage()
  173. this.vipFlag = userInfo.vipFlag ? userInfo.vipFlag : 0
  174. this.userId = userInfo.userId ? userInfo.userId : 0
  175. this.firstClubType = this.clubType
  176. this.getProductAgainInfo()
  177. this.GetUserCartNumber()
  178. },
  179. scrolltolower() {
  180. if (this.hasNextPage && this.pullFlag) {
  181. this.getProductAgainInfo(true)
  182. }
  183. },
  184. setScrollHeight() {
  185. const { windowHeight, pixelRatio } = wx.getSystemInfoSync()
  186. this.windowHeight = windowHeight - 1
  187. this.scrollHeight = windowHeight - 1
  188. },
  189. getProductAgainInfo(loadMore) {
  190. this.showLoading = true
  191. this.loadingNow = true
  192. this.loadingText = '加载中'
  193. this.isShowEmpty = false
  194. if (loadMore) {
  195. this.pageNum += 1
  196. }
  197. this.ProductService.GetRepeatBuyAgainProductList({
  198. userId: this.userId,
  199. identity: this.identity,
  200. pageNum: this.pageNum,
  201. pageSize: this.pageSize
  202. })
  203. .then(response => {
  204. this.isShowWrapper = true
  205. this.cartQuantity = response.data.cartQuantity
  206. const listData = response.data.results
  207. if (listData && listData.length > 0) {
  208. this.hasNextPage = response.data.hasNextPage
  209. this.isShowEmpty = false
  210. if (loadMore) {
  211. this.productList = [...this.productList, ...listData]
  212. } else {
  213. this.productList = listData
  214. this.showSkeleton = false
  215. }
  216. //价格显示处理
  217. let isActFlg,
  218. newProductList = []
  219. this.productList.map((item, index) => {
  220. if (item.actStatus == 1) {
  221. isActFlg = true
  222. } else if (item.actStatus == 1 && item.ladderPriceFlag == '1') {
  223. isActFlg = true
  224. } else {
  225. isActFlg = false
  226. }
  227. newProductList.push(Object.assign({}, item, { isShowActFlg: isActFlg }))
  228. })
  229. this.productList = newProductList
  230. // 防上拉暴滑
  231. this.pullFlag = false
  232. setTimeout(() => {
  233. this.pullFlag = true
  234. }, 500)
  235. // 底部提示文案
  236. if (this.hasNextPage) {
  237. this.loadingText = '上拉加载更多'
  238. } else {
  239. this.showLoading = true
  240. this.loadingNow = false
  241. }
  242. } else {
  243. if (!loadMore) {
  244. this.isShowEmpty = true
  245. }
  246. }
  247. })
  248. .catch(response => {
  249. this.$util.msg(response.msg, 2000)
  250. })
  251. },
  252. GetUserCartNumber() {
  253. this.OrderService.ShoppingCartCount({ userId: this.userId })
  254. .then(response => {
  255. this.cartQuantity = response.data
  256. })
  257. .catch(error => {
  258. console.log('查询用户购物车数量失败')
  259. })
  260. },
  261. operationHanld(prop) {
  262. this.$emit('operationConfim', prop)
  263. },
  264. navToDetailPage(id) {
  265. this.isModallayer = true
  266. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  267. this.isModallayer = false
  268. },
  269. toIndexPage() {
  270. uni.switchTab({
  271. url: '/pages/tabBar/home/index'
  272. })
  273. },
  274. repurchModel() {
  275. this.$util.modal('', '此商品的价格有变化,原来的购买价已不适用', '知道了', '', false, () => {})
  276. },
  277. PromotionsFormat(promo) {
  278. //促销活动类型数据处理
  279. if (promo != null) {
  280. if (promo.type == 1 && promo.mode == 1) {
  281. return true
  282. } else {
  283. return false
  284. }
  285. }
  286. return false
  287. },
  288. isShowVipFlag(pros) {
  289. /**
  290. *显示SVIP和超级会员价格:
  291. * 个人机构(不是超级会员,但价格所有机构可见),
  292. * 资质机构(不是超级会员,但价格所有机构可见或仅会员可见),
  293. * 超级会员(价格所有机构可见或仅会员可见),超级会员(是医美机构,价格仅医美可见)
  294. *商品价格是否可见:priceFlag 0:所有机构可见 1:未公开价格 2:仅会员可见 3:仅医美机构可见
  295. * 普通机构
  296. * 超级会员 && priceFlag === 0
  297. * 资质机构
  298. * priceFlag !== 1 ||
  299. * 超级会员
  300. * 商品priceFlag === 3 && 是否是医美机构
  301. */
  302. // 未登录 || 非会员
  303. if(!this.hasLogin || !this.vipFlag === 1) return false
  304. // 商品所有机构可见
  305. if(pros.priceFlag === 0 ) return true
  306. // 商品价格仅资质机构可见
  307. if(pros.priceFlag === 2 && this.userIdentity === 2) return true
  308. // 商品价格仅医美机构可见
  309. if(pros.priceFlag === 3 && this.userIdentity === 2 && this.firstClubType == 1) return true
  310. // 其它
  311. return false
  312. },
  313. btnClick() {
  314. this.$api.navigateTo('/pages/goods/cart')
  315. },
  316. btnTouchstart() {
  317. // console.log('btnTouchstart');
  318. },
  319. btnTouchend() {
  320. // console.log('btnTouchend');
  321. }
  322. }
  323. }
  324. </script>
  325. <style lang="scss">
  326. .commodity-list-wrapper {
  327. scroll-view {
  328. height: 100%;
  329. border-top: 2rpx solid rgba(0, 0, 0, 0.07);
  330. }
  331. .empty-container-image {
  332. margin-top: -300rpx;
  333. }
  334. .toIndexPage {
  335. bottom: 390rpx;
  336. }
  337. .show-more-btn {
  338. width: 276rpx;
  339. height: 52rpx;
  340. line-height: 52rpx;
  341. border: 2rpx solid #d8d8d8;
  342. background: #f7f7f7;
  343. font-size: 26rpx;
  344. margin: 26rpx 0;
  345. position: absolute;
  346. left: 50%;
  347. margin-left: -138rpx;
  348. }
  349. }
  350. .all-type-list-content {
  351. height: auto;
  352. padding: 24rpx;
  353. background: #fff;
  354. margin-bottom: 2rpx;
  355. display: flex;
  356. flex-direction: row;
  357. box-sizing: content-box;
  358. .list-img {
  359. width: 240rpx;
  360. height: 240rpx !important;
  361. margin-right: 26rpx;
  362. border-radius: 10rpx;
  363. border: 2rpx solid #f3f3f3;
  364. }
  365. }
  366. .list-details-info {
  367. width: 442rpx;
  368. flex-direction: column;
  369. font-size: 26rpx;
  370. position: relative;
  371. .list-details-title {
  372. line-height: 38rpx;
  373. text-overflow: ellipsis;
  374. overflow: hidden;
  375. display: -webkit-box;
  376. -webkit-line-clamp: 2;
  377. line-clamp: 2;
  378. -webkit-box-orient: vertical;
  379. }
  380. .list-details-specs {
  381. width: 100%;
  382. display: inline-block;
  383. margin-top: 8rpx;
  384. color: #999999;
  385. }
  386. .list-details-miniQuantity {
  387. width: 100%;
  388. display: inline-block;
  389. margin-top: 7rpx;
  390. }
  391. }
  392. .list-details-price {
  393. width: 100%;
  394. line-height: 54rpx;
  395. float: left;
  396. .floor-item-act {
  397. height: 54rpx;
  398. text-align: center;
  399. box-sizing: border-box;
  400. float: left;
  401. padding: 11rpx 0;
  402. }
  403. .price-icon {
  404. width: 22rpx;
  405. height: 28rpx;
  406. vertical-align: middle;
  407. margin-right: 10rpx;
  408. }
  409. .price-icon + text {
  410. font-size: 25rpx;
  411. vertical-align: middle;
  412. }
  413. .list-login-now {
  414. width: 375rpx;
  415. color: #f8c499;
  416. position: absolute;
  417. bottom: 0;
  418. .p-no {
  419. float: left;
  420. font-size: $font-size-24;
  421. color: $color-system;
  422. margin-right: 10rpx;
  423. }
  424. }
  425. .login-now {
  426. padding: 10rpx 10rpx 10rpx 0;
  427. }
  428. .list-none {
  429. margin-top: 30rpx;
  430. .price-small {
  431. font-size: $font-size-24;
  432. line-height: 40rpx;
  433. color: #ff2a2a;
  434. }
  435. }
  436. .list-shop {
  437. height: auto;
  438. float: left;
  439. .list-price {
  440. width: 100%;
  441. color: #ff2a2a;
  442. float: left;
  443. line-height: 54rpx;
  444. align-items: center;
  445. justify-content: center;
  446. .price-larger {
  447. font-size: $font-size-30;
  448. display: inline-block;
  449. &.none {
  450. text-decoration: line-through;
  451. color: #999999;
  452. }
  453. }
  454. }
  455. .list-price-none {
  456. width: 100%;
  457. .price-none {
  458. text-decoration: line-through;
  459. color: #999999;
  460. display: inline-block;
  461. }
  462. .icon-wenhao {
  463. font-size: $font-size-32;
  464. color: #0091ff;
  465. margin-left: 6rpx;
  466. }
  467. }
  468. }
  469. .add-cart-btn {
  470. float: right;
  471. width: 140rpx;
  472. height: 54rpx;
  473. line-height: 54rpx;
  474. border-radius: 27rpx;
  475. color: #fff;
  476. font-size: 24rpx;
  477. margin-right: 0;
  478. background: #ffffff;
  479. border: 1px solid #c9c9c9;
  480. color: $text-color;
  481. }
  482. }
  483. </style>