commodityList.vue 12 KB

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