classifyProductList.vue 12 KB

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