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