productList.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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">
  13. <view class="list-none" v-if="item.price1TextFlag == 1">
  14. <view class="price-small">该商品尚未公开价格</view>
  15. <view class="price-small">购买请致电:0755-22907771</view>
  16. </view>
  17. <view class="list-shop" v-else>
  18. <view class="list-price" >
  19. <text class="price-view activity" v-if="item.isShowActFlg">活动价</text>
  20. <text class="price-view ladder" v-if="item.ladderPriceFlag == 1">阶梯价</text>
  21. <text class="price-larger">¥{{item.retailPrice.toFixed(2)}}</text>
  22. </view>
  23. <button class="add-cart-btn" @click.stop="operationHanld(item)">选择数量</button>
  24. </view>
  25. </view>
  26. <view class="list-details-price">
  27. <text v-if="item.repurchasePriceState">
  28. <text class="price-none">¥{{item.discountPrice}}</text>
  29. <text class="iconfont"></text>
  30. </text>
  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="cartNum > 0" class="uni-badge uni-badge-error uni-small uni-badge--small icon-num">
  48. {{cartNum >= 100 ? '99+' : cartNum}}
  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. cartNum: 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:10081,pageNum:this.pageNum,pageSize:this.pageSize}
  124. queryAgaingoodslist(params).then(response =>{
  125. this.isShowWrapper = true
  126. const responseData = response.data;
  127. if(responseData.results && responseData.results.length > 0){
  128. this.hasNextPage = responseData.hasNextPage;
  129. this.isShowEmpty = false;
  130. if(loadMore) {
  131. this.productList = [...this.productList,...responseData.results];
  132. } else {
  133. this.productList = [...responseData.results];
  134. this.showSkeleton = false;
  135. }
  136. let isActFlg,newArry=[];
  137. this.productList.map((item, index)=> {
  138. if(item.actFlag == 1){
  139. isActFlg = true
  140. }else if(item.actFlag == 1 && item.ladderPriceFlag == 1){
  141. isActFlg = true
  142. }else{
  143. isActFlg = false
  144. }
  145. newArry.push(Object.assign({},item,{isShowActFlg:isActFlg}))
  146. })
  147. this.productList = newArry
  148. console.log(this.productList)
  149. // 防上拉暴滑
  150. this.pullFlag = false;
  151. setTimeout(()=>{
  152. this.pullFlag = true;
  153. },500)
  154. // 底部提示文案
  155. if(this.hasNextPage) {
  156. this.loadingText = '上拉加载更多';
  157. } else {
  158. this.showLoading = true;
  159. this.loadingNow = false;
  160. }
  161. } else {
  162. if(!loadMore) {
  163. this.isShowEmpty = true;
  164. }
  165. }
  166. }).catch(response =>{
  167. this.$util.msg(response.msg,3000);
  168. })
  169. },
  170. operationHanld(prop){
  171. this.$emit('operationConfim',prop)
  172. },
  173. navToDetailPage(id) {
  174. this.isModallayer = true;
  175. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  176. this.isModallayer = false;
  177. },
  178. toCartPage() {
  179. uni.switchTab({
  180. url: '/pages/tabBar/cart/cart'
  181. })
  182. },
  183. toIndexPage() {
  184. uni.switchTab({
  185. url: '/pages/tabBar/home/home'
  186. })
  187. }
  188. }
  189. }
  190. </script>
  191. <style lang="scss">
  192. .commodity-list-wrapper {
  193. scroll-view {
  194. height: 100%;
  195. border-top: 2rpx solid rgba(0,0,0,0.07);
  196. }
  197. .empty-container-image {
  198. margin-top: -300rpx;
  199. }
  200. .toIndexPage {
  201. bottom: 390rpx;
  202. }
  203. .show-more-btn {
  204. width: 276rpx;
  205. height: 52rpx;
  206. line-height: 52rpx;
  207. border: 2rpx solid #D8D8D8;
  208. background: #F7F7F7;
  209. font-size: 26rpx;
  210. margin: 26rpx 0;
  211. position: absolute;
  212. left: 50%;
  213. margin-left: -138rpx;
  214. }
  215. }
  216. .all-type-list-content {
  217. height: 216rpx;
  218. padding: 24rpx;
  219. background: #fff;
  220. margin-bottom: 2rpx;
  221. display: flex;
  222. flex-direction: row;
  223. box-sizing: content-box;
  224. .list-img {
  225. width: 210rpx;
  226. height: 218rpx !important;
  227. margin-right: 26rpx;
  228. border-radius: 10rpx;
  229. border: 2rpx solid #f3f3f3;
  230. }
  231. }
  232. .list-details-info {
  233. width: 466rpx;
  234. display: flex;
  235. flex-direction: column;
  236. font-size: 26rpx;
  237. position: relative;
  238. .list-details-title {
  239. line-height: 38rpx;
  240. text-overflow: ellipsis;
  241. overflow: hidden;
  242. display: -webkit-box;
  243. -webkit-line-clamp: 2;
  244. line-clamp: 2;
  245. -webkit-box-orient: vertical;
  246. }
  247. .list-details-specs {
  248. margin-top: 8rpx;
  249. color: #999999;
  250. }
  251. .list-details-miniQuantity {
  252. margin-top: 7rpx;
  253. }
  254. }
  255. .list-details-price {
  256. width: 100%;
  257. display: flex;
  258. flex-direction: row;
  259. justify-content: space-between;
  260. position: absolute;
  261. bottom: 0;
  262. right: 0;
  263. .price-none{
  264. text-decoration: line-through;
  265. color: #999999;
  266. display: inline-block;
  267. }
  268. .price-icon {
  269. width: 22rpx;
  270. height: 28rpx;
  271. vertical-align: middle;
  272. margin-right: 10rpx;
  273. }
  274. .price-icon + text {
  275. font-size: 25rpx;
  276. vertical-align: middle;
  277. }
  278. .list-login-now {
  279. width: 375rpx;
  280. color: #F8C499;
  281. position: absolute;
  282. bottom: 0;
  283. .p-no{
  284. float: left;
  285. font-size: $font-size-24;
  286. color: $color-system;
  287. margin-right: 10rpx;
  288. }
  289. }
  290. .login-now {
  291. padding: 10rpx 10rpx 10rpx 0;
  292. }
  293. .list-none{
  294. .price-small{
  295. font-size:$font-size-24;
  296. line-height: 36rpx;
  297. color: #FF2A2A;
  298. }
  299. }
  300. .list-shop{
  301. width: 100%;
  302. height: auto;
  303. display: flex;
  304. .list-price {
  305. flex: 7;
  306. color: #FF2A2A;
  307. float: left;
  308. line-height:64rpx ;
  309. align-items: center;
  310. justify-content: center;
  311. .price-larger {
  312. font-size: $font-size-32;
  313. display: inline-block;
  314. }
  315. .price-view{
  316. display: inline-block;
  317. width: 78rpx;
  318. border-radius: 18rpx;
  319. font-size: $font-size-20;
  320. text-align: center;
  321. color: #FFFFFF;
  322. height: 36rpx;
  323. line-height: 36rpx;
  324. &.ladder{
  325. background: linear-gradient(135deg,rgba(255,0,0,1) 0%,rgba(242,143,49,1) 100%);
  326. }
  327. &.activity{
  328. background: linear-gradient(135deg,rgba(128,0,255,1) 0%,rgba(242,49,153,1) 100%);
  329. }
  330. }
  331. }
  332. .add-cart-btn {
  333. width: 156rpx;
  334. height: 64rpx;
  335. line-height: 64rpx;
  336. border-radius: 32rpx;
  337. color: #fff;
  338. font-size: 26rpx;
  339. margin-right: 0;
  340. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  341. }
  342. }
  343. }
  344. .cart-icon {
  345. width: 92rpx;
  346. height: 92rpx;
  347. border-radius: 50%;
  348. background: rgba(255, 147, 0, 0.5);
  349. position: fixed;
  350. right: 24rpx;
  351. bottom: 30%;
  352. display: flex;
  353. align-items: center;
  354. justify-content: center;
  355. cursor: pointer;
  356. image {
  357. width: 58rpx;
  358. height: 58rpx;
  359. }
  360. text {
  361. font-size: 28rpx;
  362. position: absolute;
  363. top: -10rpx;
  364. right: 0;
  365. }
  366. }
  367. </style>