productList.vue 12 KB

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