commodityList.vue 9.5 KB

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