productList.vue 11 KB

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