productList.vue 11 KB

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