classifyProductList.vue 12 KB

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