classifyProductList.vue 12 KB

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