commodityList.vue 9.6 KB

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