commodityList.vue 9.5 KB

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