productList.vue 11 KB

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