classifyProductList.vue 12 KB

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