productList.vue 11 KB

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