commodityList.vue 14 KB

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