commodityList.vue 11 KB

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