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