commodityList.vue 13 KB

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