commodityList.vue 14 KB

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