productList.vue 11 KB

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