productList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view
  3. class="container commodity-list-wrapper"
  4. :style="{
  5. overflow: showSkeleton ? 'hidden' : 'auto',
  6. height: showSkeleton ? windowHeight + 'px' : 'auto'
  7. }"
  8. >
  9. <list-skeleton v-if="showSkeleton" :listType="0"></list-skeleton>
  10. <!-- 搜索框 -->
  11. <fuzzy-search
  12. placeholder="搜索商品名称"
  13. :fixed="true"
  14. @search="searchValHandle"
  15. @input="searchValChange"
  16. @clear="searchValClear"
  17. @blur="searchValBlur"
  18. ></fuzzy-search>
  19. <!-- 内容区域 -->
  20. <scroll-view
  21. class="product-container"
  22. @scrolltolower="scrolltolower"
  23. scroll-y
  24. v-if="!isShowEmpty && productList.length > 0"
  25. >
  26. <view
  27. v-for="(item, index) in productList"
  28. :key="index"
  29. :id="item.id"
  30. class="all-type-list-content commodity-list goods-item"
  31. @click.stop="navToDetailPage(item.productId)"
  32. >
  33. <image
  34. mode="widthFix"
  35. :src="item.mainImage"
  36. class="list-img"
  37. alt="list-img"
  38. lazy-load
  39. ></image>
  40. <view class="list-details-info">
  41. <!-- 商品名称 -->
  42. <text class="list-details-title">{{ item.productName }}</text>
  43. <!-- <text class="list-details-specs">商品编码:{{ item.productCode != null ? item.productCode : '' }}</text> -->
  44. <!-- <text class="list-details-miniQuantity">起订量:{{ item.ladderPriceFlag == '1' ? item.maxBuyNumber : item.minBuyNumber}}</text> -->
  45. <!-- 价格 -->
  46. <view class="price-box">
  47. <view class="list-details-price prom">
  48. <view class="floor-item-act" v-if="item.actStatus == 1">
  49. <view class="floor-tags" v-if="PromotionsFormat(item.promotion)">
  50. {{ item.promotion.name}}
  51. <text>:¥{{ item.retailPrice | NumFormat }}</text>
  52. </view>
  53. <view class="floor-tags" v-else>{{ item.promotion.name }}</view>
  54. </view>
  55. <view class="floor-item-act" v-if="item.actStatus == 0 && item.ladderPriceFlag == 1">
  56. <view class="floor-tags">阶梯价格</view>
  57. </view>
  58. </view>
  59. <text class="list-details-specs">规格:{{ item.unit != null ? item.unit : '' }}</text>
  60. <view class="list-details-price">
  61. <view class="list-shop">
  62. <view class="list-price-none" v-if="item.repurchasePriceState">
  63. <text class="price-none">¥{{ item.discountPrice }}</text>
  64. <text class="iconfont icon-wenhao" @click.stop="repurchModel"></text>
  65. </view>
  66. <view class="list-price" v-else>
  67. <text class="price-larger" :class="PromotionsFormat(item.promotions) ? 'none' : ''">
  68. ¥{{(PromotionsFormat(item.promotions) ? item.price1 : item.retailPrice) | NumFormat }}
  69. </text>
  70. </view>
  71. </view>
  72. <button class="add-cart-btn" @click.stop="operationHanld(item)">
  73. 购买
  74. </button>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <!--加载loadding-->
  80. <tui-loadmore :visible="loadingNow" :index="3" text="加载中..."></tui-loadmore>
  81. <tui-nomore :visible="!loadingNow" text="没有更多了"></tui-nomore>
  82. <!--加载loadding END-->
  83. </scroll-view>
  84. <!-- 商品列表为空时 -->
  85. <view class="empty-container" v-else>
  86. <image
  87. class="empty-container-image"
  88. src="/static/ws/empty_product.png"
  89. mode="aspectFit"
  90. ></image>
  91. <text class="error-text">商品列表空空如也~</text>
  92. </view>
  93. <!-- 可拖动悬浮按钮 -->
  94. <cm-drag
  95. :cartNum="cartQuantity"
  96. :isDock="true"
  97. :existTabBar="true"
  98. @btnClick="btnClick"
  99. @btnTouchstart="btnTouchstart"
  100. @btnTouchend="btnTouchend"
  101. >
  102. </cm-drag>
  103. <!-- 透明模态层 -->
  104. <modal-layer v-if="isModallayer"></modal-layer>
  105. </view>
  106. </template>
  107. <script>
  108. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  109. import modalLayer from '@/components/modal-layer'
  110. import uniStars from '@/components/uni-stars/uni-stars.vue'
  111. import cmDrag from '@/components/cm-custom/cm-drag.vue'
  112. import fuzzySearch from '@/components/cm-module/search/fuzzySearch.vue'
  113. import { mapState, mapMutations } from 'vuex'
  114. export default {
  115. name: 'productList',
  116. components: {
  117. listSkeleton,
  118. modalLayer,
  119. uniStars,
  120. cmDrag,
  121. fuzzySearch
  122. },
  123. props: {
  124. emptyText: {
  125. type: String
  126. }
  127. },
  128. data() {
  129. return {
  130. isModallayer: false,
  131. windowHeight: '',
  132. // 是否显示骨架
  133. showSkeleton: false,
  134. isShowEmpty: false,
  135. scrollHeight: '',
  136. productList: [],
  137. loadingNow: false,
  138. pageSize: 10,
  139. pageNum: 1,
  140. hasNextPage: false,
  141. pullFlag: true,
  142. cartQuantity: 0,
  143. showRegularBtn: true,
  144. isPrecedence: false,
  145. searchVal: '', //搜索框
  146. organizeId: '',
  147. userId: ''
  148. }
  149. },
  150. computed: {
  151. ...mapState(['hasLogin', 'userInfo', 'identity'])
  152. },
  153. async created() {
  154. // 获取采购员组织id
  155. const userInfo = uni.getStorageSync('userInfo')
  156. this.organizeId = userInfo.organizeId
  157. // 获取商品列表
  158. this.productList = await this.getGoodsList()
  159. // 购物车数量统计
  160. this.getCartQuantity()
  161. },
  162. filters: {
  163. //处理金额
  164. NumFormat: function(text) {
  165. return Number(text).toFixed(2)
  166. }
  167. },
  168. methods: {
  169. // 获取购物车商品数量
  170. getCartQuantity() {
  171. const clubInfo = uni.getStorageSync('clubInfo')
  172. this.userId = clubInfo.userId
  173. this.SellerService.CartQuantity({ userId: this.userId }).then(res => {
  174. this.cartQuantity = res.data
  175. })
  176. },
  177. // 上拉加载更多
  178. async scrolltolower() {
  179. if (!this.hasNextPage) {
  180. // 没有更多了
  181. this.loadingNow = false
  182. return
  183. }
  184. if (this.pullFlag) {
  185. this.loadingNow = true
  186. // 页码加1
  187. this.pageNum += 1
  188. const addGoods = await this.getGoodsList()
  189. this.productList = [...this.productList, ...addGoods]
  190. this.pullFlag = false
  191. setTimeout(() => {
  192. this.pullFlag = true
  193. }, 1500)
  194. }
  195. },
  196. // 获取商品列表
  197. async getGoodsList() {
  198. // 参数
  199. const params = {
  200. organizeId: this.organizeId,
  201. pageNum: this.pageNum,
  202. pageSize: this.pageSize,
  203. productName: this.searchVal
  204. }
  205. // 获取商品数据
  206. const { code, data: result } = await this.SellerService.GoodList(params).catch(
  207. error => {
  208. console.log(error)
  209. }
  210. )
  211. // 如果获取失败 返回上一页
  212. if (code !== 0) {
  213. uni.navigateBack({
  214. delta: 1
  215. })
  216. return
  217. }
  218. // 是否还有下一页
  219. this.hasNextPage = result.hasNextPage
  220. this.loadingNow = false
  221. // 返回列表
  222. return result.list
  223. },
  224. // 关键字搜索
  225. async searchKeyWords() {
  226. this.pageNum = 1
  227. this.productList = await this.getGoodsList()
  228. },
  229. searchValChange(val) {
  230. this.searchVal = val
  231. },
  232. searchValBlur() {
  233. this.searchKeyWords()
  234. },
  235. async searchValClear() {
  236. this.searchVal = ''
  237. this.searchKeyWords()
  238. },
  239. // 搜索按钮点击事件
  240. async searchValHandle(val) {
  241. // 如果输入框内容为空
  242. if (val.trim().length <= 0) {
  243. this.searchVal = ''
  244. return
  245. }
  246. this.searchKeyWords()
  247. },
  248. operationHanld(prop) {
  249. this.$emit('operationConfim', prop)
  250. },
  251. // 跳转详情
  252. navToDetailPage(id) {
  253. this.isModallayer = true
  254. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  255. this.isModallayer = false
  256. },
  257. repurchModel() {
  258. this.$util.modal(
  259. '',
  260. '此商品的价格有变化,原来的购买价已不适用',
  261. '知道了',
  262. '',
  263. false,
  264. () => {}
  265. )
  266. },
  267. PromotionsFormat(promo) {
  268. //促销活动类型数据处理
  269. if (promo != null) {
  270. if (promo.type == 1 && promo.mode == 1) {
  271. return true
  272. } else {
  273. return false
  274. }
  275. }
  276. return false
  277. },
  278. btnClick() {
  279. this.$api.navigateTo('/pages/user/cart/cart')
  280. },
  281. btnTouchstart() {
  282. // console.log('btnTouchstart');
  283. },
  284. btnTouchend() {
  285. // console.log('btnTouchend');
  286. }
  287. }
  288. }
  289. </script>
  290. <style lang="scss">
  291. .commodity-list-wrapper {
  292. .empty-container-image {
  293. margin-top: -300rpx;
  294. }
  295. .toIndexPage {
  296. bottom: 390rpx;
  297. }
  298. .show-more-btn {
  299. width: 276rpx;
  300. height: 52rpx;
  301. line-height: 52rpx;
  302. border: 2rpx solid #d8d8d8;
  303. background: #f7f7f7;
  304. font-size: 26rpx;
  305. margin: 26rpx 0;
  306. position: absolute;
  307. left: 50%;
  308. margin-left: -138rpx;
  309. }
  310. }
  311. .all-type-list-content {
  312. height: auto;
  313. padding: 24rpx;
  314. background: #fff;
  315. margin-bottom: 2rpx;
  316. display: flex;
  317. flex-direction: row;
  318. box-sizing: content-box;
  319. .list-img {
  320. width: 240rpx;
  321. height: 240rpx !important;
  322. margin-right: 26rpx;
  323. border-radius: 10rpx;
  324. border: 2rpx solid #f3f3f3;
  325. }
  326. }
  327. .list-details-info {
  328. width: 442rpx;
  329. flex-direction: column;
  330. font-size: 26rpx;
  331. position: relative;
  332. .list-details-title {
  333. line-height: 38rpx;
  334. text-overflow: ellipsis;
  335. overflow: hidden;
  336. display: -webkit-box;
  337. -webkit-line-clamp: 2;
  338. line-clamp: 2;
  339. -webkit-box-orient: vertical;
  340. }
  341. .list-details-specs {
  342. width: 100%;
  343. font-size: 20rpx;
  344. display: inline-block;
  345. margin-top: 14rpx;
  346. color: #999999;
  347. }
  348. .list-details-miniQuantity {
  349. width: 100%;
  350. display: inline-block;
  351. margin-top: 7rpx;
  352. }
  353. }
  354. .price-box{
  355. width: 100%;
  356. position: absolute;
  357. bottom: 0;
  358. }
  359. .list-details-price {
  360. width: 100%;
  361. // line-height: 54rpx;
  362. // margin-top: 10rpx;
  363. // height: 54rpx;
  364. float: left;
  365. &.prom{
  366. min-height: 40rpx;
  367. margin-top: 20rpx;
  368. }
  369. .floor-item-act{
  370. width: 100%;
  371. // height: 56rpx;
  372. text-align: center;
  373. box-sizing: border-box;
  374. float: left;
  375. padding:0 0 10rpx 0;
  376. .floor-tags{
  377. height: 28rpx;
  378. border-radius: 6rpx;
  379. background-color: #FFFFFF;
  380. line-height: 28rpx;
  381. color: #ff2a2a;
  382. text-align: center;
  383. display: inline-block;
  384. padding:0 16rpx;
  385. font-size: $font-size-20;
  386. border: 1px solid #ff2a2a;
  387. float: left;
  388. }
  389. }
  390. .price-icon {
  391. width: 22rpx;
  392. height: 28rpx;
  393. vertical-align: middle;
  394. margin-right: 10rpx;
  395. }
  396. .price-icon + text {
  397. font-size: 25rpx;
  398. vertical-align: middle;
  399. }
  400. .list-login-now {
  401. width: 375rpx;
  402. color: #f8c499;
  403. position: absolute;
  404. bottom: 0;
  405. .p-no {
  406. float: left;
  407. font-size: $font-size-24;
  408. color: $color-system;
  409. margin-right: 10rpx;
  410. }
  411. }
  412. .login-now {
  413. padding: 10rpx 10rpx 10rpx 0;
  414. }
  415. .list-none {
  416. margin-top: 30rpx;
  417. .price-small {
  418. font-size: $font-size-24;
  419. line-height: 40rpx;
  420. color: #ff2a2a;
  421. }
  422. }
  423. .list-shop {
  424. height: auto;
  425. float: left;
  426. .list-price {
  427. width: 100%;
  428. color: #ff2a2a;
  429. float: left;
  430. line-height: 54rpx;
  431. align-items: center;
  432. justify-content: center;
  433. .price-larger {
  434. font-size: $font-size-30;
  435. display: inline-block;
  436. font-weight: bold;
  437. &.none {
  438. text-decoration: line-through;
  439. color: #999999;
  440. }
  441. }
  442. }
  443. .list-price-none {
  444. width: 100%;
  445. .price-none {
  446. text-decoration: line-through;
  447. color: #999999;
  448. display: inline-block;
  449. }
  450. .icon-wenhao {
  451. font-size: $font-size-32;
  452. color: #0091ff;
  453. margin-left: 6rpx;
  454. }
  455. }
  456. }
  457. .add-cart-btn {
  458. float: right;
  459. width: 140rpx;
  460. height: 54rpx;
  461. line-height: 54rpx;
  462. border-radius: 27rpx;
  463. color: #fff;
  464. font-size: 24rpx;
  465. margin-right: 0;
  466. background: #ffffff;
  467. border: 1px solid #c9c9c9;
  468. color: $text-color;
  469. }
  470. }
  471. .list-details-tags {
  472. display: flex;
  473. justify-content: flex-start;
  474. margin: 14rpx 0;
  475. height: 34rpx;
  476. .tag {
  477. margin-right: 5rpx;
  478. }
  479. }
  480. .product-container {
  481. width: 100%;
  482. height: 100vh;
  483. overflow: hidden;
  484. padding-top: 100rpx;
  485. box-sizing: border-box;
  486. }
  487. </style>