productList.vue 11 KB

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