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