commodityList.vue 10 KB

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