classifyProductList.vue 13 KB

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