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