productList.vue 11 KB

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