productList.vue 12 KB

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