commodityList.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/cm-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. this.$api.getStorage().then((resolve) =>{
  119. this.userID = resolve.userID ? resolve.userID : '';
  120. this.getQueryGoodslist(loadMore)
  121. }).catch(error =>{
  122. this.getQueryGoodslist(loadMore)
  123. })
  124. },
  125. getQueryGoodslist(loadMore){
  126. const thisServerurl = this.$parent.serverUrl;
  127. this.showLoading = true;
  128. this.loadingNow = true;
  129. this.loadingText = '加载中';
  130. if(loadMore) {
  131. this.pageNum += 1;
  132. }
  133. if(this.$parent.lastPageType === '再次购买') {
  134. this.fromRegularPurchasePage = true;
  135. }
  136. queryGoodslist(thisServerurl,{userId:this.userID,pageNum:this.pageNum,pageSize:this.pageSize}).then(response=>{
  137. const resData = this.fromRegularPurchasePage ?response.data.page :response.data;
  138. const resList = resData.results,
  139. getCartNum = response.data.count;
  140. this.cartNum = getCartNum > 99 ?'99+' :getCartNum;
  141. if(!loadMore && this.fromRegularPurchasePage && resData.hasNextPage) {
  142. this.showRegularBtn = true;
  143. }
  144. if(resList && resList.length > 0){
  145. this.hasNextPage = resData.hasNextPage;
  146. this.totalPage = resData.totalPage;
  147. if(loadMore) {
  148. this.commodityList = [...this.commodityList,...resList];
  149. this.showRegularBtn = false;
  150. } else {
  151. this.commodityList = [...resList];
  152. this.showSkeleton = false;
  153. }
  154. // 防上拉暴滑
  155. this.pullFlag = false;
  156. setTimeout(()=>{
  157. this.pullFlag = true;
  158. },500)
  159. // 底部提示文案
  160. if(this.hasNextPage) {
  161. this.loadingText = '上拉加载更多';
  162. } else {
  163. this.showLoading = true;
  164. this.loadingNow = false;
  165. }
  166. } else {
  167. if(!loadMore) {
  168. this.showEmpty = true;
  169. }
  170. }
  171. }).catch(error =>{
  172. this.$util.msg(error.msg,2000);
  173. })
  174. },
  175. operationHanld(prop){
  176. this.$emit('operationConfim',prop)
  177. },
  178. navToDetailPage(id) {
  179. this.isModallayer = true;
  180. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  181. this.isModallayer = false;
  182. },
  183. toCartPage() {
  184. uni.switchTab({
  185. url: '/pages/tabBar/cart/cart'
  186. })
  187. },
  188. toIndexPage() {
  189. uni.switchTab({
  190. url: '/pages/tabBar/home/home'
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. .commodity-list-wrapper {
  198. scroll-view {
  199. height: 100%;
  200. border-top: 2rpx solid rgba(0,0,0,0.07);
  201. }
  202. .empty-container-image {
  203. margin-top: -300rpx;
  204. }
  205. .toIndexPage {
  206. bottom: 390rpx;
  207. }
  208. .show-more-btn {
  209. width: 276rpx;
  210. height: 52rpx;
  211. line-height: 52rpx;
  212. border: 2rpx solid #D8D8D8;
  213. background: #F7F7F7;
  214. font-size: 26rpx;
  215. margin: 26rpx 0;
  216. position: absolute;
  217. left: 50%;
  218. margin-left: -138rpx;
  219. }
  220. }
  221. .all-type-list-content {
  222. height: 216rpx;
  223. padding: 24rpx;
  224. background: #fff;
  225. margin-bottom: 2rpx;
  226. display: flex;
  227. flex-direction: row;
  228. box-sizing: content-box;
  229. .list-img {
  230. width: 210rpx;
  231. height: 218rpx !important;
  232. margin-right: 26rpx;
  233. border-radius: 10rpx;
  234. border: 2rpx solid #f3f3f3;
  235. }
  236. }
  237. .list-details-info {
  238. width: 466rpx;
  239. display: flex;
  240. flex-direction: column;
  241. font-size: 26rpx;
  242. position: relative;
  243. .list-details-title {
  244. line-height: 38rpx;
  245. text-overflow: ellipsis;
  246. overflow: hidden;
  247. display: -webkit-box;
  248. -webkit-line-clamp: 2;
  249. line-clamp: 2;
  250. -webkit-box-orient: vertical;
  251. }
  252. .list-details-specs {
  253. margin-top: 8rpx;
  254. color: #999999;
  255. }
  256. .list-details-miniQuantity {
  257. margin-top: 7rpx;
  258. }
  259. }
  260. .list-details-price {
  261. width: 100%;
  262. display: flex;
  263. flex-direction: row;
  264. justify-content: space-between;
  265. position: absolute;
  266. bottom: 0;
  267. right: 0;
  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-price {
  294. color: #FF2A2A;
  295. .price-larger {
  296. font-size: 32rpx;
  297. .txt{
  298. font-size: $font-size-24;
  299. display: inline-block;
  300. line-height: 30rpx;
  301. text-align: left;
  302. }
  303. }
  304. }
  305. .add-cart-btn {
  306. width: 156rpx;
  307. height: 64rpx;
  308. line-height: 64rpx;
  309. border-radius: 32rpx;
  310. color: #fff;
  311. font-size: 26rpx;
  312. margin-right: 0;
  313. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  314. }
  315. }
  316. .cart-icon {
  317. width: 92rpx;
  318. height: 92rpx;
  319. border-radius: 50%;
  320. background: rgba(255, 147, 0, 0.5);
  321. position: fixed;
  322. right: 24rpx;
  323. bottom: 30%;
  324. display: flex;
  325. align-items: center;
  326. justify-content: center;
  327. cursor: pointer;
  328. image {
  329. width: 58rpx;
  330. height: 58rpx;
  331. }
  332. text {
  333. font-size: 28rpx;
  334. position: absolute;
  335. top: -10rpx;
  336. right: 0;
  337. }
  338. }
  339. </style>