productList.vue 11 KB

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