commodityList.vue 10 KB

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