classifyProductList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. <!-- 金刚区商品模块 -->
  2. <template>
  3. <view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
  4. <list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
  5. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="listData.length > 0">
  6. <view v-for="(item,index) in listData" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  7. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  8. <view class="list-details-info">
  9. <text class="list-details-title">{{item.name}}</text>
  10. <text class="list-details-specs">规格:{{item.unit}}</text>
  11. <view class="list-details-specs" v-if="item.productCode!=''&&item.productCode!=null">商品编码:{{item.productCode}}</view>
  12. <view class="list-details-price">
  13. <template v-if="userIdentity == 3">
  14. <view class="floor-item-act" v-if="item.actStatus==1">
  15. <view class="coupon-tags">优惠券</view>
  16. <view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
  17. {{item.promotions.name}}<text v-if="item.price1TextFlag != '1' && item.supplierId === shopId">:¥{{ item.price | NumFormat }}</text>
  18. </view>
  19. <view class="floor-tags" v-else>{{item.promotions.name}}</view>
  20. </view>
  21. <view class="floor-item-act" v-if="item.actStatus ==0 && item.ladderPriceFlag==1">
  22. <view class="coupon-tags">优惠券</view>
  23. <view class="floor-tags">阶梯价格</view>
  24. </view>
  25. </template>
  26. <template v-else>
  27. <view class="floor-item-act" v-if="item.actStatus==1">
  28. <view class="coupon-tags">优惠券</view>
  29. <view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
  30. {{item.promotions.name}}<text v-if="hasLogin && item.price1TextFlag != '1'">:¥{{ item.price | NumFormat }}</text>
  31. </view>
  32. <view class="floor-tags" v-else>{{item.promotions.name}}</view>
  33. </view>
  34. <view class="floor-item-act" v-if="item.actStatus ==0 && item.ladderPriceFlag==1">
  35. <view class="floor-tags">阶梯价格</view>
  36. </view>
  37. </template>
  38. <view v-if="hasLogin" class="list-price">
  39. <view v-if="userIdentity == 1">
  40. <text class="price-larger" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
  41. ¥{{ (PromotionsFormat(item.promotions) ? item.price1 : item.retailPrice) | NumFormat }}
  42. </text>
  43. </view>
  44. <view v-if="userIdentity == 4">
  45. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  46. <text class="txt">¥未公开价格</text>
  47. </view>
  48. <view v-else>
  49. <view class="price-larger" v-if="item.price1TextFlag == '2'">
  50. <text class="txt">¥价格仅会员可见</text>
  51. </view>
  52. <template v-else>
  53. <text class="price-larger" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
  54. ¥{{ (PromotionsFormat(item.promotions) ? item.price1 : item.retailPrice) | NumFormat }}
  55. </text>
  56. </template>
  57. </view>
  58. </view>
  59. <view v-if="userIdentity == 2">
  60. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  61. <text class="txt">¥未公开价格</text>
  62. </view>
  63. <template v-else>
  64. <text class="price-larger" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
  65. ¥{{ (PromotionsFormat(item.promotions) ? item.price1 : item.retailPrice) | NumFormat }}
  66. </text>
  67. </template>
  68. </view>
  69. </view>
  70. <view v-else class="list-login-now">
  71. <text class="p-no">¥</text>
  72. <uni-stars :stars="parseInt(item.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. <view v-if="showLoading && listData.length > 4">
  78. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  79. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  80. </view>
  81. </scroll-view>
  82. <view class="empty-container" v-if="showEmpty">
  83. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png"></image>
  84. <text class="error-text">{{emptyText}}</text>
  85. </view>
  86. <!-- 透明模态层 -->
  87. <modal-layer v-if='isModallayer'></modal-layer>
  88. </view>
  89. </template>
  90. <script>
  91. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  92. import modalLayer from "@/components/modal-layer"
  93. import uniStars from '@/components/uni-stars/uni-stars.vue'
  94. import { mapState,mapMutations } from 'vuex';
  95. export default{
  96. name:'CommodityList',
  97. components:{
  98. listSkeleton,
  99. modalLayer,
  100. uniStars
  101. },
  102. props: {
  103. emptyText: {
  104. type: String
  105. },
  106. serverUrl: {
  107. type: String
  108. },
  109. classifyID: {
  110. type:Number
  111. }
  112. },
  113. data(){
  114. return{
  115. clubStatus:'',
  116. isModallayer:false,
  117. windowHeight: '',
  118. showSkeleton: true,
  119. showEmpty: false,
  120. userID: 0,
  121. userIdentity:'',
  122. scrollHeight: '',
  123. listData: [],
  124. showLoading: false,
  125. loadingNow: true,
  126. loadingText: '上拉加载更多',
  127. pageSize: 20,
  128. pageNum: 1,
  129. totalPage: 1,
  130. hasNextPage:false,
  131. pullFlag: true,
  132. cartNum: 0,
  133. }
  134. },
  135. created() {
  136. // console.log(this.typeId)
  137. this.setScrollHeight();
  138. this.$api.getComStorage('userInfo').then((resolve) =>{
  139. this.clubStatus = resolve.clubStatus
  140. this.userID = resolve.userId ? resolve.userId :0;
  141. this.userIdentity = resolve.userIdentity
  142. this.getListFromServer();
  143. }).catch(error =>{
  144. this.getListFromServer();
  145. })
  146. },
  147. filters: {
  148. NumFormat:function(text) {//处理金额
  149. return Number(text).toFixed(2);
  150. },
  151. },
  152. computed: {
  153. ...mapState(['hasLogin','userInfo'])
  154. },
  155. methods:{
  156. toLower() {
  157. if(this.hasNextPage && this.pullFlag) {
  158. this.getListFromServer(true);
  159. }
  160. },
  161. setScrollHeight() {
  162. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  163. this.windowHeight = windowHeight - 1;
  164. this.scrollHeight = windowHeight - 1;
  165. },
  166. getListFromServer(loadMore) {
  167. this.getQueryGoodslist(loadMore)
  168. },
  169. getQueryGoodslist(loadMore){
  170. this.showLoading = true;
  171. this.loadingNow = true;
  172. this.loadingText = '加载中';
  173. if(loadMore) { this.pageNum += 1; }
  174. let params ={
  175. classifyId:this.classifyID,
  176. userId:this.userID,
  177. pageNum:this.pageNum,
  178. pageSize:this.pageSize,
  179. }
  180. this.CommonService.GetHomeClassify(params).then(response =>{
  181. const resList = response.data.results;
  182. if(resList && resList.length > 0){
  183. this.showEmpty = false
  184. this.hasNextPage = response.data.hasNextPage;
  185. if(loadMore) {
  186. this.listData = [...this.listData,...resList];
  187. this.getProductPrice()
  188. this.showSkeleton = false
  189. } else {
  190. this.listData = [...resList];
  191. this.getProductPrice()
  192. this.showSkeleton = false
  193. }
  194. // 防上拉暴滑
  195. this.pullFlag = false;
  196. setTimeout(()=>{ this.pullFlag = true; },500)
  197. // 底部提示文案
  198. if(this.hasNextPage) {
  199. this.loadingText = '上拉加载更多';
  200. } else {
  201. this.showLoading = true;
  202. this.loadingNow = false;
  203. this.loadingText = '已至底部';
  204. }
  205. } else {
  206. if(!loadMore) { this.showEmpty = true; }
  207. }
  208. }).catch(error =>{
  209. this.$util.msg(error.msg,2000);
  210. })
  211. },
  212. getProductPrice(){//获取价格
  213. let productIdArr = [];
  214. this.listData.map(item=>{// 0公开价格 1不公开价格 2仅对会员机构公开
  215. productIdArr.push(item.productID)
  216. })
  217. this.productIds = productIdArr.join(",");
  218. this.ProductService.querySearchProductPrice({userId: this.userID,productIds:this.productIds}).then(response =>{
  219. if (response.data) {
  220. this.listData = this.ReturnNewProducts(this.listData,response.data);
  221. }
  222. this.priceLoading = false;
  223. }).catch(error =>{
  224. this.$util.msg(error.msg,2000)
  225. })
  226. },
  227. ReturnNewProducts(Array,list){//处理对应商品ID的商品价格
  228. let NewArray = []
  229. Array.map(item=>{
  230. for (let i = 0; i < list.length; i++) {
  231. if( item.productID == list[i].productId ){
  232. NewArray.push(Object.assign(item,list[i]))
  233. }
  234. }
  235. });
  236. return NewArray
  237. },
  238. navToDetailPage(id) {
  239. this.isModallayer = true;
  240. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  241. this.isModallayer = false;
  242. },
  243. PromotionsFormat(promo){//促销活动类型数据处理
  244. if(promo!=null){
  245. if(promo.type == 1 && promo.mode == 1){
  246. return true
  247. }else{
  248. return false
  249. }
  250. }
  251. return false
  252. }
  253. }
  254. }
  255. </script>
  256. <style lang="scss">
  257. .commodity-list-wrapper {
  258. scroll-view {
  259. height: 100%;
  260. border-top: 2rpx solid rgba(0,0,0,0.07);
  261. }
  262. .empty-container-image {
  263. margin-top: -300rpx;
  264. }
  265. .toIndexPage {
  266. bottom: 390rpx;
  267. }
  268. .show-more-btn {
  269. width: 276rpx;
  270. height: 52rpx;
  271. line-height: 52rpx;
  272. border: 2rpx solid #D8D8D8;
  273. background: #F7F7F7;
  274. font-size: 26rpx;
  275. margin: 26rpx 0;
  276. position: absolute;
  277. left: 50%;
  278. margin-left: -138rpx;
  279. }
  280. }
  281. .all-type-list-content {
  282. height: 216rpx;
  283. padding: 24rpx;
  284. background: #fff;
  285. margin-bottom: 2rpx;
  286. display: flex;
  287. flex-direction: row;
  288. box-sizing: content-box;
  289. .list-img {
  290. width: 210rpx;
  291. height: 218rpx !important;
  292. margin-right: 26rpx;
  293. border-radius: 10rpx;
  294. border: 2rpx solid #f3f3f3;
  295. }
  296. }
  297. .list-details-info {
  298. width: 466rpx;
  299. display: flex;
  300. flex-direction: column;
  301. font-size: 26rpx;
  302. position: relative;
  303. .list-details-title {
  304. line-height: 38rpx;
  305. text-overflow: ellipsis;
  306. overflow: hidden;
  307. display: -webkit-box;
  308. -webkit-line-clamp: 2;
  309. line-clamp: 2;
  310. -webkit-box-orient: vertical;
  311. }
  312. .list-details-specs {
  313. margin-top: 8rpx;
  314. color: #666666;
  315. }
  316. .list-details-miniQuantity {
  317. margin-top: 7rpx;
  318. }
  319. }
  320. .list-details-price {
  321. width: 100%;
  322. height: 54rpx;
  323. line-height: 54rpx;
  324. position: absolute;
  325. bottom: -10rpx;
  326. right: 0;
  327. .floor-item-act{
  328. height: 54rpx;
  329. text-align: center;
  330. box-sizing: border-box;
  331. float: right;
  332. padding: 11rpx 0;
  333. .coupon-tags{
  334. height: 32rpx;
  335. box-sizing: border-box;
  336. border-radius: 8rpx;
  337. background-color: #fff1eb;
  338. line-height: 28rpx;
  339. color: #f94b4b;
  340. text-align: center;
  341. display: inline-block;
  342. padding:0 10rpx;
  343. font-size: $font-size-20;
  344. border: 1px solid #f94b4b;
  345. float: left;
  346. margin-right: 12rpx;
  347. }
  348. .floor-tags{
  349. height: 32rpx;
  350. box-sizing: border-box;
  351. border-radius: 8rpx;
  352. background-color: #FFFFFF;
  353. line-height: 28rpx;
  354. color: $color-system;
  355. text-align: center;
  356. display: inline-block;
  357. padding:0 16rpx;
  358. font-size: $font-size-20;
  359. border: 1px solid #E15616;
  360. float: left;
  361. }
  362. }
  363. .price-icon {
  364. width: 22rpx;
  365. height: 28rpx;
  366. vertical-align: middle;
  367. margin-right: 10rpx;
  368. }
  369. .price-icon + text {
  370. font-size: 25rpx;
  371. vertical-align: middle;
  372. }
  373. .list-login-now {
  374. color: #F8C499;
  375. float: left;
  376. line-height: 54rpx;
  377. .p-no{
  378. float: left;
  379. font-size: $font-size-24;
  380. color: $text-color;
  381. }
  382. }
  383. .login-now {
  384. padding: 10rpx 10rpx 10rpx 0;
  385. }
  386. .list-price {
  387. color: #FF2A2A;
  388. height: 44rpx;
  389. float: left;
  390. .price-larger {
  391. width: 100%;
  392. height: 44rpx;
  393. font-size: 32rpx;
  394. &.none{
  395. text-decoration: line-through;
  396. color: #999999;
  397. }
  398. &.small{
  399. font-size: $font-size-24;
  400. }
  401. .txt{
  402. font-size: $font-size-24;
  403. display: inline-block;
  404. line-height: 44rpx;
  405. text-align: left;
  406. float: left;
  407. }
  408. }
  409. }
  410. .add-cart-btn {
  411. width: 156rpx;
  412. height: 64rpx;
  413. line-height: 64rpx;
  414. border-radius: 32rpx;
  415. color: #fff;
  416. font-size: 26rpx;
  417. margin-right: 0;
  418. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  419. }
  420. }
  421. .cart-icon {
  422. width: 92rpx;
  423. height: 92rpx;
  424. border-radius: 50%;
  425. background: rgba(255, 147, 0, 0.5);
  426. position: fixed;
  427. right: 24rpx;
  428. bottom: 30%;
  429. display: flex;
  430. align-items: center;
  431. justify-content: center;
  432. cursor: pointer;
  433. image {
  434. width: 58rpx;
  435. height: 58rpx;
  436. }
  437. text {
  438. font-size: 28rpx;
  439. position: absolute;
  440. top: -10rpx;
  441. right: 0;
  442. }
  443. }
  444. </style>