productList.vue 10 KB

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