productList.vue 11 KB

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