productList.vue 11 KB

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