productList.vue 11 KB

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