productList.vue 10 KB

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