commodityList.vue 11 KB

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