productList.vue 11 KB

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