productList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  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. this.cartQuantity = res.data
  173. })
  174. },
  175. // 上拉加载更多
  176. async scrolltolower() {
  177. if (!this.hasNextPage) {
  178. // 没有更多了
  179. this.loadingNow = false
  180. return
  181. }
  182. if (this.pullFlag) {
  183. this.loadingNow = true
  184. // 页码加1
  185. this.pageNum += 1
  186. const addGoods = await this.getGoodsList()
  187. this.productList = [...this.productList, ...addGoods]
  188. this.pullFlag = false
  189. setTimeout(() => {
  190. this.pullFlag = true
  191. }, 1500)
  192. }
  193. },
  194. // 获取商品列表
  195. async getGoodsList() {
  196. // 参数
  197. const params = {
  198. organizeId: this.organizeId,
  199. pageNum: this.pageNum,
  200. pageSize: this.pageSize,
  201. productName: this.searchVal
  202. }
  203. // 获取商品数据
  204. const { code, data: result } = await this.SellerService.GoodList(params).catch(
  205. error => {
  206. console.log(error)
  207. }
  208. )
  209. // 如果获取失败 返回上一页
  210. if (code !== 0) {
  211. uni.navigateBack({
  212. delta: 1
  213. })
  214. return
  215. }
  216. // 是否还有下一页
  217. this.hasNextPage = result.hasNextPage
  218. this.loadingNow = false
  219. // 返回列表
  220. return result.list
  221. },
  222. // 关键字搜索
  223. async searchKeyWords() {
  224. this.pageNum = 1
  225. this.productList = await this.getGoodsList()
  226. },
  227. searchValChange(val) {
  228. this.searchVal = val
  229. },
  230. searchValBlur() {
  231. this.searchKeyWords()
  232. },
  233. async searchValClear() {
  234. this.searchVal = ''
  235. this.searchKeyWords()
  236. },
  237. // 搜索按钮点击事件
  238. async searchValHandle(val) {
  239. // 如果输入框内容为空
  240. if (val.trim().length <= 0) {
  241. this.searchVal = ''
  242. return
  243. }
  244. this.searchKeyWords()
  245. },
  246. operationHanld(prop) {
  247. this.$emit('operationConfim', prop)
  248. },
  249. // 跳转详情
  250. navToDetailPage(id) {
  251. this.isModallayer = true
  252. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  253. this.isModallayer = false
  254. },
  255. repurchModel() {
  256. this.$util.modal(
  257. '',
  258. '此商品的价格有变化,原来的购买价已不适用',
  259. '知道了',
  260. '',
  261. false,
  262. () => {}
  263. )
  264. },
  265. PromotionsFormat(promo) {
  266. //促销活动类型数据处理
  267. if (promo != null) {
  268. if (promo.type == 1 && promo.mode == 1) {
  269. return true
  270. } else {
  271. return false
  272. }
  273. }
  274. return false
  275. },
  276. btnClick() {
  277. this.$api.navigateTo('/pages/user/cart/cart')
  278. },
  279. btnTouchstart() {
  280. // console.log('btnTouchstart');
  281. },
  282. btnTouchend() {
  283. // console.log('btnTouchend');
  284. }
  285. }
  286. }
  287. </script>
  288. <style lang="scss">
  289. .commodity-list-wrapper {
  290. .empty-container-image {
  291. margin-top: -300rpx;
  292. }
  293. .toIndexPage {
  294. bottom: 390rpx;
  295. }
  296. .show-more-btn {
  297. width: 276rpx;
  298. height: 52rpx;
  299. line-height: 52rpx;
  300. border: 2rpx solid #d8d8d8;
  301. background: #f7f7f7;
  302. font-size: 26rpx;
  303. margin: 26rpx 0;
  304. position: absolute;
  305. left: 50%;
  306. margin-left: -138rpx;
  307. }
  308. }
  309. .all-type-list-content {
  310. height: auto;
  311. padding: 24rpx;
  312. background: #fff;
  313. margin-bottom: 2rpx;
  314. display: flex;
  315. flex-direction: row;
  316. box-sizing: content-box;
  317. .list-img {
  318. width: 240rpx;
  319. height: 240rpx !important;
  320. margin-right: 26rpx;
  321. border-radius: 10rpx;
  322. border: 2rpx solid #f3f3f3;
  323. }
  324. }
  325. .list-details-info {
  326. width: 442rpx;
  327. flex-direction: column;
  328. font-size: 26rpx;
  329. position: relative;
  330. .list-details-title {
  331. line-height: 38rpx;
  332. text-overflow: ellipsis;
  333. overflow: hidden;
  334. display: -webkit-box;
  335. -webkit-line-clamp: 2;
  336. line-clamp: 2;
  337. -webkit-box-orient: vertical;
  338. }
  339. .list-details-specs {
  340. width: 100%;
  341. display: inline-block;
  342. margin-top: 14rpx;
  343. color: #999999;
  344. }
  345. .list-details-miniQuantity {
  346. width: 100%;
  347. display: inline-block;
  348. margin-top: 7rpx;
  349. }
  350. }
  351. .list-details-price {
  352. width: 100%;
  353. line-height: 54rpx;
  354. margin-top: 10rpx;
  355. height: 54rpx;
  356. float: left;
  357. &.prom{
  358. height: auto;
  359. margin-top: 20rpx;
  360. }
  361. .floor-item-act{
  362. width: 100%;
  363. height: 56rpx;
  364. text-align: center;
  365. box-sizing: border-box;
  366. float: left;
  367. padding:0 0 10rpx 0;
  368. .floor-tags{
  369. height: 28rpx;
  370. border-radius: 6rpx;
  371. background-color: #FFFFFF;
  372. line-height: 28rpx;
  373. color: #ff2a2a;
  374. text-align: center;
  375. display: inline-block;
  376. padding:0 16rpx;
  377. font-size: $font-size-20;
  378. border: 1px solid #ff2a2a;
  379. float: left;
  380. }
  381. }
  382. .price-icon {
  383. width: 22rpx;
  384. height: 28rpx;
  385. vertical-align: middle;
  386. margin-right: 10rpx;
  387. }
  388. .price-icon + text {
  389. font-size: 25rpx;
  390. vertical-align: middle;
  391. }
  392. .list-login-now {
  393. width: 375rpx;
  394. color: #f8c499;
  395. position: absolute;
  396. bottom: 0;
  397. .p-no {
  398. float: left;
  399. font-size: $font-size-24;
  400. color: $color-system;
  401. margin-right: 10rpx;
  402. }
  403. }
  404. .login-now {
  405. padding: 10rpx 10rpx 10rpx 0;
  406. }
  407. .list-none {
  408. margin-top: 30rpx;
  409. .price-small {
  410. font-size: $font-size-24;
  411. line-height: 40rpx;
  412. color: #ff2a2a;
  413. }
  414. }
  415. .list-shop {
  416. height: auto;
  417. float: left;
  418. .list-price {
  419. width: 100%;
  420. color: #ff2a2a;
  421. float: left;
  422. line-height: 54rpx;
  423. align-items: center;
  424. justify-content: center;
  425. .price-larger {
  426. font-size: $font-size-30;
  427. display: inline-block;
  428. font-weight: bold;
  429. &.none {
  430. text-decoration: line-through;
  431. color: #999999;
  432. }
  433. }
  434. }
  435. .list-price-none {
  436. width: 100%;
  437. .price-none {
  438. text-decoration: line-through;
  439. color: #999999;
  440. display: inline-block;
  441. }
  442. .icon-wenhao {
  443. font-size: $font-size-32;
  444. color: #0091ff;
  445. margin-left: 6rpx;
  446. }
  447. }
  448. }
  449. .add-cart-btn {
  450. float: right;
  451. width: 140rpx;
  452. height: 54rpx;
  453. line-height: 54rpx;
  454. border-radius: 27rpx;
  455. color: #fff;
  456. font-size: 24rpx;
  457. margin-right: 0;
  458. background: #ffffff;
  459. border: 1px solid #c9c9c9;
  460. color: $text-color;
  461. }
  462. }
  463. .list-details-tags {
  464. display: flex;
  465. justify-content: flex-start;
  466. margin: 14rpx 0;
  467. height: 34rpx;
  468. .tag {
  469. margin-right: 5rpx;
  470. }
  471. }
  472. .product-container {
  473. width: 100%;
  474. height: 100vh;
  475. overflow: hidden;
  476. padding-top: 100rpx;
  477. box-sizing: border-box;
  478. }
  479. </style>