productList.vue 10 KB

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