productList.vue 10 KB

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