commodityList.vue 12 KB

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