productList.vue 11 KB

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