classifyProductList.vue 11 KB

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