commodityList.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="commodityList.length > 0">
  5. <view v-for="(item,index) in commodityList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  6. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  7. <view class="list-details-info">
  8. <text class="list-details-title">{{item.name}}</text>
  9. <text class="list-details-specs">规格:{{item.unit}}</text>
  10. <text class="list-details-miniQuantity" v-if="fromRegularPurchasePage">起订量:{{item.minBuyNumber}}</text>
  11. <view class="list-details-price">
  12. <view v-if="!hasLogin" class="list-login-now">
  13. <text class="p-no">价格:</text>
  14. <uni-stars :stars="parseInt(item.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
  15. </view>
  16. <view class="list-price" v-else>
  17. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  18. <text class="txt">未公开价格</text>
  19. </view>
  20. <text v-else>¥<text class="price-larger">{{item.retailPrice?item.retailPrice.toFixed(2):'0.00'}}</text></text>
  21. </view>
  22. <button v-if="fromRegularPurchasePage" class="add-cart-btn" @click.stop="operationHanld(item)">选择数量</button>
  23. </view>
  24. </view>
  25. </view>
  26. <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
  27. <view v-if="showLoading && commodityList.length > 4 && !showRegularBtn">
  28. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  29. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  30. </view>
  31. </scroll-view>
  32. <view class="cart-icon" v-if="fromRegularPurchasePage" @click="toCartPage">
  33. <text v-if="cartNum > 0" class="uni-badge uni-badge-error uni-small uni-badge--small icon-num">
  34. {{cartNum}}
  35. </text>
  36. <image src='../../../static/icon-cart-active@3x.png' mode="widthFix"></image>
  37. </view>
  38. <view class="empty-container" v-if="showEmpty && !fromRegularPurchasePage">
  39. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png"></image>
  40. <text class="error-text">{{emptyText}}</text>
  41. </view>
  42. <view class="empty-container" v-if="showEmpty && fromRegularPurchasePage">
  43. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  44. <text class="error-text">您还没有购买过任何商品哟~</text>
  45. <button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
  46. </view>
  47. <!-- 透明模态层 -->
  48. <modal-layer v-if='isModallayer'></modal-layer>
  49. </view>
  50. </template>
  51. <script>
  52. import listSkeleton from '@/components/module/listTemplate/listSkeleton'
  53. import modalLayer from "@/components/modal-layer"
  54. import uniStars from '@/components/uni-stars/uni-stars.vue'
  55. import { queryGoodslist } from "@/api/product.js"
  56. import { mapState,mapMutations } from 'vuex';
  57. export default{
  58. name:'CommodityList',
  59. components:{
  60. listSkeleton,
  61. modalLayer,
  62. uniStars
  63. },
  64. props: {
  65. emptyText: {
  66. type: String
  67. },
  68. },
  69. data(){
  70. return{
  71. isModallayer:false,
  72. windowHeight: '',
  73. showSkeleton: true,
  74. showEmpty: false,
  75. userID: '',
  76. scrollHeight: '',
  77. commodityList: [],
  78. showLoading: false,
  79. loadingNow: true,
  80. loadingText: '上拉加载更多',
  81. pageSize: 10,
  82. pageNum: 1,
  83. hasNextPage: false,
  84. totalPage: 1,
  85. pullFlag: true,
  86. fromRegularPurchasePage: false,
  87. cartNum: 0,
  88. showRegularBtn: false
  89. }
  90. },
  91. created() {
  92. this.setScrollHeight();
  93. },
  94. computed: {
  95. ...mapState(['hasLogin','userInfo'])
  96. },
  97. methods:{
  98. toLoginPage() {
  99. const {lastPageType, lastPageVal} = this.$parent;
  100. uni.navigateTo({
  101. url:`/pages/login/login-accont?listType=${lastPageType}&listVal=${lastPageVal}`
  102. })
  103. },
  104. toLower() {
  105. // 第一次加载排除常用商品
  106. if(!this.showRegularBtn) {
  107. if(this.hasNextPage && this.pullFlag) {
  108. this.getListFromServer(true);
  109. }
  110. }
  111. },
  112. setScrollHeight() {
  113. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  114. this.windowHeight = windowHeight - 1;
  115. this.scrollHeight = windowHeight - 1;
  116. },
  117. getListFromServer(loadMore) {
  118. let self = this;
  119. const thisServerurl = self.$parent.serverUrl;
  120. self.showLoading = true;
  121. self.loadingNow = true;
  122. self.loadingText = '加载中';
  123. if(loadMore) {
  124. self.pageNum += 1;
  125. }
  126. if(self.$parent.lastPageType === '再次购买') {
  127. self.fromRegularPurchasePage = true;
  128. }
  129. this.$api.getStorage().then((resolve) =>{
  130. this.userID = resolve.userID ? resolve.userID : '';
  131. queryGoodslist(thisServerurl,{userId:this.userID,pageNum:self.pageNum,pageSize:self.pageSize}).then(response=>{
  132. const resData = self.fromRegularPurchasePage ?response.data.page :response.data;
  133. const resList = resData.results,
  134. getCartNum = response.data.count;
  135. this.cartNum = getCartNum > 99 ?'99+' :getCartNum;
  136. if(!loadMore && self.fromRegularPurchasePage && resData.hasNextPage) {
  137. self.showRegularBtn = true;
  138. }
  139. if(resList && resList.length > 0){
  140. self.hasNextPage = resData.hasNextPage;
  141. self.totalPage = resData.totalPage;
  142. if(loadMore) {
  143. self.commodityList = [...self.commodityList,...resList];
  144. self.showRegularBtn = false;
  145. } else {
  146. self.commodityList = [...resList];
  147. self.showSkeleton = false;
  148. }
  149. // 防上拉暴滑
  150. self.pullFlag = false;
  151. setTimeout(()=>{
  152. self.pullFlag = true;
  153. },500)
  154. // 底部提示文案
  155. if(self.hasNextPage) {
  156. self.loadingText = '上拉加载更多';
  157. } else {
  158. self.showLoading = true;
  159. self.loadingNow = false;
  160. }
  161. } else {
  162. if(!loadMore) {
  163. self.showEmpty = true;
  164. }
  165. }
  166. }).catch(response =>{
  167. this.$util.msg(response.msg,3000);
  168. })
  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. }
  190. }
  191. </script>
  192. <style lang="scss">
  193. .commodity-list-wrapper {
  194. scroll-view {
  195. height: 100%;
  196. border-top: 2rpx solid rgba(0,0,0,0.07);
  197. }
  198. .empty-container-image {
  199. margin-top: -300rpx;
  200. }
  201. .toIndexPage {
  202. bottom: 390rpx;
  203. }
  204. .show-more-btn {
  205. width: 276rpx;
  206. height: 52rpx;
  207. line-height: 52rpx;
  208. border: 2rpx solid #D8D8D8;
  209. background: #F7F7F7;
  210. font-size: 26rpx;
  211. margin: 26rpx 0;
  212. position: absolute;
  213. left: 50%;
  214. margin-left: -138rpx;
  215. }
  216. }
  217. .all-type-list-content {
  218. height: 216rpx;
  219. padding: 24rpx;
  220. background: #fff;
  221. margin-bottom: 2rpx;
  222. display: flex;
  223. flex-direction: row;
  224. box-sizing: content-box;
  225. .list-img {
  226. width: 210rpx;
  227. height: 218rpx !important;
  228. margin-right: 26rpx;
  229. border-radius: 10rpx;
  230. border: 2rpx solid #f3f3f3;
  231. }
  232. }
  233. .list-details-info {
  234. width: 466rpx;
  235. display: flex;
  236. flex-direction: column;
  237. font-size: 26rpx;
  238. position: relative;
  239. .list-details-title {
  240. line-height: 38rpx;
  241. text-overflow: ellipsis;
  242. overflow: hidden;
  243. display: -webkit-box;
  244. -webkit-line-clamp: 2;
  245. line-clamp: 2;
  246. -webkit-box-orient: vertical;
  247. }
  248. .list-details-specs {
  249. margin-top: 8rpx;
  250. color: #999999;
  251. }
  252. .list-details-miniQuantity {
  253. margin-top: 7rpx;
  254. }
  255. }
  256. .list-details-price {
  257. width: 100%;
  258. display: flex;
  259. flex-direction: row;
  260. justify-content: space-between;
  261. position: absolute;
  262. bottom: 0;
  263. right: 0;
  264. .price-icon {
  265. width: 22rpx;
  266. height: 28rpx;
  267. vertical-align: middle;
  268. margin-right: 10rpx;
  269. }
  270. .price-icon + text {
  271. font-size: 25rpx;
  272. vertical-align: middle;
  273. }
  274. .list-login-now {
  275. width: 375rpx;
  276. color: #F8C499;
  277. position: absolute;
  278. bottom: 0;
  279. .p-no{
  280. float: left;
  281. font-size: $font-size-24;
  282. color: $color-system;
  283. margin-right: 10rpx;
  284. }
  285. }
  286. .login-now {
  287. padding: 10rpx 10rpx 10rpx 0;
  288. }
  289. .list-price {
  290. color: #FF2A2A;
  291. .price-larger {
  292. font-size: 32rpx;
  293. .txt{
  294. font-size: $font-size-24;
  295. display: inline-block;
  296. line-height: 30rpx;
  297. text-align: left;
  298. }
  299. }
  300. }
  301. .add-cart-btn {
  302. width: 156rpx;
  303. height: 64rpx;
  304. line-height: 64rpx;
  305. border-radius: 32rpx;
  306. color: #fff;
  307. font-size: 26rpx;
  308. margin-right: 0;
  309. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  310. }
  311. }
  312. .cart-icon {
  313. width: 92rpx;
  314. height: 92rpx;
  315. border-radius: 50%;
  316. background: rgba(255, 147, 0, 0.5);
  317. position: fixed;
  318. right: 24rpx;
  319. bottom: 30%;
  320. display: flex;
  321. align-items: center;
  322. justify-content: center;
  323. cursor: pointer;
  324. image {
  325. width: 58rpx;
  326. height: 58rpx;
  327. }
  328. text {
  329. font-size: 28rpx;
  330. position: absolute;
  331. top: -10rpx;
  332. right: 0;
  333. }
  334. }
  335. </style>