productList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  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 v-if="item.actStatus==0">
  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. })
  117. },
  118. filters: {
  119. NumFormat:function(text) {//处理金额
  120. return Number(text).toFixed(2);
  121. },
  122. },
  123. computed: {
  124. ...mapState(['hasLogin','userInfo','identity'])
  125. },
  126. methods:{
  127. scrolltolower() {
  128. if(this.hasNextPage && this.pullFlag) {
  129. this.getProductAgainInfo(true);
  130. }
  131. },
  132. setScrollHeight() {
  133. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  134. this.windowHeight = windowHeight - 1;
  135. this.scrollHeight = windowHeight - 1;
  136. },
  137. getProductAgainInfo(loadMore) {
  138. this.showLoading = true;
  139. this.loadingNow = true;
  140. this.loadingText = '加载中';
  141. this.isShowEmpty = false;
  142. if(loadMore) {this.pageNum += 1;}
  143. this.ProductService.GetRepeatBuyAgainProductList(
  144. {
  145. userId:this.userId,
  146. identity:this.identity,
  147. pageNum:this.pageNum,
  148. pageSize:this.pageSize,
  149. }
  150. )
  151. .then(response =>{
  152. this.isShowWrapper = true
  153. this.cartQuantity = response.data.cartQuantity
  154. const listData = response.data.results;
  155. if(listData && listData.length > 0){
  156. this.hasNextPage = response.data.hasNextPage;
  157. this.isShowEmpty = false;
  158. if(loadMore) {
  159. this.productList = [...this.productList,...listData];
  160. } else {
  161. this.productList = listData;
  162. this.showSkeleton = false;
  163. }
  164. //价格显示处理
  165. let isActFlg,newProductList=[];
  166. this.productList.map((item, index)=> {
  167. if(item.actStatus == 1){
  168. isActFlg = true
  169. }else if(item.actStatus == 1 && item.ladderPriceFlag == '1'){
  170. isActFlg = true
  171. }else{
  172. isActFlg = false
  173. }
  174. newProductList.push(Object.assign({},item,{isShowActFlg:isActFlg}))
  175. })
  176. this.productList = newProductList
  177. // 防上拉暴滑
  178. this.pullFlag = false;
  179. setTimeout(()=>{
  180. this.pullFlag = true;
  181. },500)
  182. // 底部提示文案
  183. if(this.hasNextPage) {
  184. this.loadingText = '上拉加载更多';
  185. } else {
  186. this.showLoading = true;
  187. this.loadingNow = false;
  188. }
  189. } else {
  190. if(!loadMore) {
  191. this.isShowEmpty = true;
  192. }
  193. }
  194. }).catch(response =>{
  195. this.$util.msg(response.msg,2000);
  196. })
  197. },
  198. operationHanld(prop){
  199. this.$emit('operationConfim',prop)
  200. },
  201. navToDetailPage(id) {
  202. this.isModallayer = true;
  203. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  204. this.isModallayer = false;
  205. },
  206. toIndexPage() {
  207. uni.switchTab({
  208. url: '/pages/tabBar/home/index'
  209. })
  210. },
  211. repurchModel(){
  212. this.$util.modal('','此商品的价格有变化,原来的购买价已不适用','知道了','',false,() =>{})
  213. },
  214. PromotionsFormat(promo){//促销活动类型数据处理
  215. if(promo!=null){
  216. if(promo.type == 1 && promo.mode == 1){
  217. return true
  218. }else{
  219. return false
  220. }
  221. }
  222. return false
  223. },
  224. btnClick() {
  225. this.$api.navigateTo('/pages/goods/cart')
  226. },
  227. btnTouchstart() {
  228. // console.log('btnTouchstart');
  229. },
  230. btnTouchend() {
  231. // console.log('btnTouchend');
  232. }
  233. }
  234. }
  235. </script>
  236. <style lang="scss">
  237. .commodity-list-wrapper {
  238. scroll-view {
  239. height: 100%;
  240. border-top: 2rpx solid rgba(0,0,0,0.07);
  241. }
  242. .empty-container-image {
  243. margin-top: -300rpx;
  244. }
  245. .toIndexPage {
  246. bottom: 390rpx;
  247. }
  248. .show-more-btn {
  249. width: 276rpx;
  250. height: 52rpx;
  251. line-height: 52rpx;
  252. border: 2rpx solid #D8D8D8;
  253. background: #F7F7F7;
  254. font-size: 26rpx;
  255. margin: 26rpx 0;
  256. position: absolute;
  257. left: 50%;
  258. margin-left: -138rpx;
  259. }
  260. }
  261. .all-type-list-content {
  262. height: auto;
  263. padding: 24rpx;
  264. background: #fff;
  265. margin-bottom: 2rpx;
  266. display: flex;
  267. flex-direction: row;
  268. box-sizing: content-box;
  269. .list-img {
  270. width: 240rpx;
  271. height: 240rpx !important;
  272. margin-right: 26rpx;
  273. border-radius: 10rpx;
  274. border: 2rpx solid #f3f3f3;
  275. }
  276. }
  277. .list-details-info {
  278. width: 442rpx;
  279. flex-direction: column;
  280. font-size: 26rpx;
  281. position: relative;
  282. .list-details-title {
  283. line-height: 38rpx;
  284. text-overflow: ellipsis;
  285. overflow: hidden;
  286. display: -webkit-box;
  287. -webkit-line-clamp: 2;
  288. line-clamp: 2;
  289. -webkit-box-orient: vertical;
  290. }
  291. .list-details-specs {
  292. width: 100%;
  293. display: inline-block;
  294. margin-top: 8rpx;
  295. color: #999999;
  296. }
  297. .list-details-miniQuantity {
  298. width: 100%;
  299. display: inline-block;
  300. margin-top: 7rpx;
  301. }
  302. }
  303. .list-details-price {
  304. width: 100%;
  305. line-height: 54rpx;
  306. float: left;
  307. .floor-item-act{
  308. height: 54rpx;
  309. text-align: center;
  310. box-sizing: border-box;
  311. float: left;
  312. padding: 11rpx 0;
  313. .coupon-tags{
  314. height: 32rpx;
  315. box-sizing: border-box;
  316. border-radius: 8rpx;
  317. background-color: #fff1eb;
  318. line-height: 28rpx;
  319. color: #f94b4b;
  320. text-align: center;
  321. display: inline-block;
  322. padding:0 10rpx;
  323. font-size: $font-size-20;
  324. border: 1px solid #f94b4b;
  325. float: left;
  326. margin-right: 12rpx;
  327. }
  328. .floor-tags{
  329. height: 32rpx;
  330. box-sizing: border-box;
  331. border-radius: 8rpx;
  332. background-color: #FFFFFF;
  333. line-height: 28rpx;
  334. color: $color-system;
  335. text-align: center;
  336. display: inline-block;
  337. padding:0 16rpx;
  338. font-size: $font-size-20;
  339. border: 1px solid #E15616;
  340. float: left;
  341. }
  342. }
  343. .price-icon {
  344. width: 22rpx;
  345. height: 28rpx;
  346. vertical-align: middle;
  347. margin-right: 10rpx;
  348. }
  349. .price-icon + text {
  350. font-size: 25rpx;
  351. vertical-align: middle;
  352. }
  353. .list-login-now {
  354. width: 375rpx;
  355. color: #F8C499;
  356. position: absolute;
  357. bottom: 0;
  358. .p-no{
  359. float: left;
  360. font-size: $font-size-24;
  361. color: $color-system;
  362. margin-right: 10rpx;
  363. }
  364. }
  365. .login-now {
  366. padding: 10rpx 10rpx 10rpx 0;
  367. }
  368. .list-none{
  369. margin-top: 30rpx;
  370. .price-small{
  371. font-size:$font-size-24;
  372. line-height: 40rpx;
  373. color: #FF2A2A;
  374. }
  375. }
  376. .list-shop{
  377. height: auto;
  378. float: left;
  379. .list-price {
  380. width: 100%;
  381. color: #FF2A2A;
  382. float: left;
  383. line-height:54rpx ;
  384. align-items: center;
  385. justify-content: center;
  386. .price-larger {
  387. font-size: $font-size-30;
  388. display: inline-block;
  389. &.none{
  390. text-decoration: line-through;
  391. color: #999999;
  392. }
  393. }
  394. }
  395. .list-price-none{
  396. width: 100%;
  397. .price-none{
  398. text-decoration: line-through;
  399. color: #999999;
  400. display: inline-block;
  401. }
  402. .icon-wenhao{
  403. font-size: $font-size-32;
  404. color: #0091FF;
  405. margin-left: 6rpx;
  406. }
  407. }
  408. }
  409. .add-cart-btn {
  410. float: right;
  411. width: 140rpx;
  412. height: 54rpx;
  413. line-height: 54rpx;
  414. border-radius: 27rpx;
  415. color: #fff;
  416. font-size: 24rpx;
  417. margin-right: 0;
  418. background:#FFFFFF;
  419. border: 1px solid #C9C9C9;
  420. color: $text-color;
  421. }
  422. }
  423. </style>