productList.vue 11 KB

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