productList.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
  3. <list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
  4. <!-- 搜索框 -->
  5. <fuzzy-search placeholder="搜索商品名称" @fuzzyClick="fuzzyClickHandle" :fixed="true" @input="fuzzyInputHandle"></fuzzy-search>
  6. <!-- 内容区域 -->
  7. <view class="product-container" v-if="!isShowEmpty">
  8. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="scrolltolower" scroll-y v-if="productList.length > 0">
  9. <view v-for="(item,index) in productList" :key="index" :id="item.id" class="all-type-list-content commodity-list goods-item" @click.stop="navToDetailPage(item.productID)">
  10. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  11. <view class="list-details-info">
  12. <text class="list-details-title">{{item.name}}</text>
  13. <!-- 商品标签 -->
  14. <!-- <view class="list-details-tags">
  15. <tui-tag type="red" class="tag" padding="6rpx" size="20rpx" plain>商品标签</tui-tag>
  16. <tui-tag type="red" class="tag" padding="6rpx" size="20rpx" plain>商品标签</tui-tag>
  17. </view> -->
  18. <text class="list-details-specs">规格:{{item.unit !=null ? item.unit : ''}}</text>
  19. <text class="list-details-specs">商品编码:{{item.productCode !=null ? item.productCode : ''}}</text>
  20. <!-- <text class="list-details-miniQuantity">起订量:{{ item.ladderPriceFlag == '1' ? item.maxBuyNumber : item.minBuyNumber}}</text> -->
  21. <!-- 价格 -->
  22. <view class="list-details-price">
  23. <view class="list-shop">
  24. <view class="list-price-none" v-if="item.repurchasePriceState">
  25. <text class="price-none">¥{{item.discountPrice}}</text>
  26. <text class="iconfont icon-wenhao" @click.stop="repurchModel"></text>
  27. </view>
  28. <view class="list-price" v-else>
  29. <text class="price-larger" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
  30. ¥{{ (PromotionsFormat(item.promotions) ? item.price1 : item.retailPrice) | NumFormat }}
  31. </text>
  32. </view>
  33. </view>
  34. <button class="add-cart-btn" @click.stop="operationHanld(item)">购买</button>
  35. </view>
  36. <!-- 活动标签 -->
  37. <view class="list-details-price" v-if="item.actStatus==1">
  38. <view class="floor-item-act">
  39. <view class="floor-tags" v-if="PromotionsFormat(item.promotions)">
  40. {{item.promotions.name}}<text v-if="item.price1TextFlag != 1">:¥{{ item.retailPrice | NumFormat }}</text>
  41. </view>
  42. <view class="floor-tags" v-else>{{item.promotions.name}}</view>
  43. </view>
  44. <view class="floor-item-act" v-if="item.actStatus ==0 && item.ladderPriceFlag==1">
  45. <view class="floor-tags">阶梯价格</view>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
  51. <view v-if="showLoading && productList.length > 4 && !showRegularBtn">
  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>
  57. <!-- 商品列表为空时 -->
  58. <view class="empty-container" v-else>
  59. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  60. <text class="error-text">暂时没有商品哦,尽请期待!~</text>
  61. </view>
  62. <!-- 可拖动悬浮按钮 -->
  63. <cm-drag v-if="!isShowEmpty"
  64. :cartNum="cartQuantity"
  65. :isDock="true"
  66. :existTabBar="true"
  67. @btnClick="btnClick"
  68. @btnTouchstart="btnTouchstart"
  69. @btnTouchend="btnTouchend">
  70. </cm-drag>
  71. <!-- 透明模态层 -->
  72. <modal-layer v-if='isModallayer'></modal-layer>
  73. </view>
  74. </template>
  75. <script>
  76. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  77. import modalLayer from "@/components/modal-layer"
  78. import uniStars from '@/components/uni-stars/uni-stars.vue'
  79. import cmDrag from '@/components/cm-custom/cm-drag.vue'
  80. import fuzzySearch from '@/components/cm-module/search/fuzzySearch.vue'
  81. // 引入测试数据
  82. import {productList} from '@/common/json/data.json.js'
  83. import { mapState,mapMutations } from 'vuex';
  84. export default{
  85. name:'productList',
  86. components:{
  87. listSkeleton,
  88. modalLayer,
  89. uniStars,
  90. cmDrag,
  91. fuzzySearch
  92. },
  93. props: {
  94. emptyText: {
  95. type: String
  96. },
  97. },
  98. data(){
  99. return{
  100. isModallayer:false,
  101. windowHeight: '',
  102. // 是否显示骨架
  103. showSkeleton: false,
  104. isShowEmpty: false,
  105. userID: '',
  106. scrollHeight: '',
  107. productList: [],
  108. showLoading: false,
  109. loadingNow: true,
  110. loadingText: '上拉加载更多',
  111. pageSize: 10,
  112. pageNum: 1,
  113. hasNextPage: false,
  114. pullFlag: true,
  115. fromRegularPurchasePage: false,
  116. cartQuantity: 0,
  117. showRegularBtn: true,
  118. isPrecedence:false
  119. }
  120. },
  121. created() {
  122. // 设置测试数据
  123. this.productList = productList
  124. this.setScrollHeight();
  125. this.$api.getStorage().then((resolve) =>{
  126. this.userID = resolve.userID
  127. // 获取产品数据
  128. // this.getProductAgainInfo()
  129. })
  130. },
  131. filters: {
  132. NumFormat:function(text) {//处理金额
  133. return Number(text).toFixed(2);
  134. },
  135. },
  136. computed: {
  137. ...mapState(['hasLogin','userInfo','identity'])
  138. },
  139. methods:{
  140. // 模糊框单击事件
  141. fuzzyClickHandle(e){
  142. console.log(e);
  143. },
  144. // 模糊搜索框输入时
  145. fuzzyInputHandle(e){
  146. console.log(e);
  147. },
  148. scrolltolower() {
  149. if(this.hasNextPage && this.pullFlag) {
  150. this.getProductAgainInfo(true);
  151. }
  152. },
  153. setScrollHeight() {
  154. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  155. this.windowHeight = windowHeight - 1;
  156. this.scrollHeight = windowHeight - 1;
  157. },
  158. getProductAgainInfo(loadMore) {
  159. this.showLoading = true;
  160. this.loadingNow = true;
  161. this.loadingText = '加载中';
  162. this.isShowEmpty = false;
  163. if(loadMore) {this.pageNum += 1;}
  164. let params = {userId:this.userID,identity:this.identity,pageNum:this.pageNum,pageSize:this.pageSize}
  165. this.ProductService.GetRepeatBuyAgainProductList(params).then(response =>{
  166. this.isShowWrapper = true
  167. this.cartQuantity = response.data.cartQuantity
  168. const responseData = response.data.pageDate;
  169. if(responseData.results && responseData.results.length > 0){
  170. this.hasNextPage = responseData.hasNextPage;
  171. this.isShowEmpty = false;
  172. if(loadMore) {
  173. this.productList = [...this.productList,...responseData.results];
  174. } else {
  175. this.productList = [...responseData.results];
  176. this.showSkeleton = false;
  177. }
  178. //价格显示处理
  179. let isActFlg,newProductList=[];
  180. this.productList.map((item, index)=> {
  181. if(item.actStatus == 1){
  182. isActFlg = true
  183. }else if(item.actStatus == 1 && item.ladderPriceFlag == '1'){
  184. isActFlg = true
  185. }else{
  186. isActFlg = false
  187. }
  188. newProductList.push(Object.assign({},item,{isShowActFlg:isActFlg}))
  189. })
  190. this.productList = newProductList
  191. // 防上拉暴滑
  192. this.pullFlag = false;
  193. setTimeout(()=>{
  194. this.pullFlag = true;
  195. },500)
  196. // 底部提示文案
  197. if(this.hasNextPage) {
  198. this.loadingText = '上拉加载更多';
  199. } else {
  200. this.showLoading = true;
  201. this.loadingNow = false;
  202. }
  203. } else {
  204. if(!loadMore) {
  205. this.isShowEmpty = true;
  206. }
  207. }
  208. }).catch(response =>{
  209. this.$util.msg(response.msg,2000);
  210. })
  211. },
  212. operationHanld(prop){
  213. this.$emit('operationConfim',prop)
  214. },
  215. navToDetailPage(id) {
  216. this.isModallayer = true;
  217. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  218. this.isModallayer = false;
  219. },
  220. toIndexPage() {
  221. uni.switchTab({
  222. url: '/pages/tabBar/home/index'
  223. })
  224. },
  225. repurchModel(){
  226. this.$util.modal('','此商品的价格有变化,原来的购买价已不适用','知道了','',false,() =>{})
  227. },
  228. PromotionsFormat(promo){//促销活动类型数据处理
  229. if(promo!=null){
  230. if(promo.type == 1 && promo.mode == 1){
  231. return true
  232. }else{
  233. return false
  234. }
  235. }
  236. return false
  237. },
  238. btnClick() {
  239. this.$api.navigateTo('/pages/goods/cart')
  240. },
  241. btnTouchstart() {
  242. // console.log('btnTouchstart');
  243. },
  244. btnTouchend() {
  245. // console.log('btnTouchend');
  246. }
  247. }
  248. }
  249. </script>
  250. <style lang="scss">
  251. .commodity-list-wrapper {
  252. scroll-view {
  253. height: 100%;
  254. border-top: 2rpx solid rgba(0,0,0,0.07);
  255. }
  256. .empty-container-image {
  257. margin-top: -300rpx;
  258. }
  259. .toIndexPage {
  260. bottom: 390rpx;
  261. }
  262. .show-more-btn {
  263. width: 276rpx;
  264. height: 52rpx;
  265. line-height: 52rpx;
  266. border: 2rpx solid #D8D8D8;
  267. background: #F7F7F7;
  268. font-size: 26rpx;
  269. margin: 26rpx 0;
  270. position: absolute;
  271. left: 50%;
  272. margin-left: -138rpx;
  273. }
  274. }
  275. .all-type-list-content {
  276. height: auto;
  277. padding: 24rpx;
  278. background: #fff;
  279. margin-bottom: 2rpx;
  280. display: flex;
  281. flex-direction: row;
  282. box-sizing: content-box;
  283. .list-img {
  284. width: 240rpx;
  285. height: 240rpx !important;
  286. margin-right: 26rpx;
  287. border-radius: 10rpx;
  288. border: 2rpx solid #f3f3f3;
  289. }
  290. }
  291. .list-details-info {
  292. width: 442rpx;
  293. flex-direction: column;
  294. font-size: 26rpx;
  295. position: relative;
  296. .list-details-title {
  297. line-height: 38rpx;
  298. text-overflow: ellipsis;
  299. overflow: hidden;
  300. display: -webkit-box;
  301. -webkit-line-clamp: 2;
  302. line-clamp: 2;
  303. -webkit-box-orient: vertical;
  304. }
  305. .list-details-specs {
  306. width: 100%;
  307. display: inline-block;
  308. margin-top: 14rpx;
  309. color: #999999;
  310. }
  311. .list-details-miniQuantity {
  312. width: 100%;
  313. display: inline-block;
  314. margin-top: 7rpx;
  315. }
  316. }
  317. .list-details-price {
  318. width: 100%;
  319. line-height: 54rpx;
  320. float: left;
  321. .floor-item-act{
  322. height: 54rpx;
  323. text-align: center;
  324. box-sizing: border-box;
  325. float: left;
  326. .floor-tags{
  327. height: 28rpx;
  328. border-radius: 6rpx;
  329. background-color: #FFFFFF;
  330. line-height: 28rpx;
  331. color: $color-system;
  332. text-align: center;
  333. display: inline-block;
  334. padding:0 16rpx;
  335. font-size: $font-size-20;
  336. margin-left: 15rpx;
  337. border: 1px solid #E15616;
  338. }
  339. }
  340. .price-icon {
  341. width: 22rpx;
  342. height: 28rpx;
  343. vertical-align: middle;
  344. margin-right: 10rpx;
  345. }
  346. .price-icon + text {
  347. font-size: 25rpx;
  348. vertical-align: middle;
  349. }
  350. .list-login-now {
  351. width: 375rpx;
  352. color: #F8C499;
  353. position: absolute;
  354. bottom: 0;
  355. .p-no{
  356. float: left;
  357. font-size: $font-size-24;
  358. color: $color-system;
  359. margin-right: 10rpx;
  360. }
  361. }
  362. .login-now {
  363. padding: 10rpx 10rpx 10rpx 0;
  364. }
  365. .list-none{
  366. margin-top: 30rpx;
  367. .price-small{
  368. font-size:$font-size-24;
  369. line-height: 40rpx;
  370. color: #FF2A2A;
  371. }
  372. }
  373. .list-shop{
  374. height: auto;
  375. float: left;
  376. .list-price {
  377. width: 100%;
  378. color: #FF2A2A;
  379. float: left;
  380. line-height:54rpx ;
  381. align-items: center;
  382. justify-content: center;
  383. .price-larger {
  384. font-size: $font-size-30;
  385. display: inline-block;
  386. font-weight: bold;
  387. &.none{
  388. text-decoration: line-through;
  389. color: #999999;
  390. }
  391. }
  392. }
  393. .list-price-none{
  394. width: 100%;
  395. .price-none{
  396. text-decoration: line-through;
  397. color: #999999;
  398. display: inline-block;
  399. }
  400. .icon-wenhao{
  401. font-size: $font-size-32;
  402. color: #0091FF;
  403. margin-left: 6rpx;
  404. }
  405. }
  406. }
  407. .add-cart-btn {
  408. float: right;
  409. width: 140rpx;
  410. height: 54rpx;
  411. line-height: 54rpx;
  412. border-radius: 27rpx;
  413. color: #fff;
  414. font-size: 24rpx;
  415. margin-right: 0;
  416. background:#FFFFFF;
  417. border: 1px solid #C9C9C9;
  418. color: $text-color;
  419. }
  420. }
  421. .list-details-tags {
  422. display: flex;
  423. justify-content: flex-start;
  424. margin: 14rpx 0;
  425. height: 34rpx;
  426. .tag{
  427. margin-right: 5rpx;
  428. }
  429. }
  430. .product-container .goods-item:first-child{
  431. margin-top: 100rpx;
  432. }
  433. </style>