list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. <template>
  2. <view class="container product clearfix">
  3. <view class="club-search clearfix">
  4. <view class="search-from name">
  5. <text class="iconfont icon-iconfonticonfontsousuo1"></text>
  6. <input
  7. class="input"
  8. type="text"
  9. confirm-type="search"
  10. v-model="listQuery.productName"
  11. @confirm="getMallProduct"
  12. placeholder="搜索商品"
  13. maxlength="12"
  14. />
  15. </view>
  16. </view>
  17. <view class="product-content">
  18. <view :class="{ 'tui-order-list': scrollTop >= 0 }" class="clearfix">
  19. <!-- 空白页 -->
  20. <view class="empty-container" v-if="isEmpty">
  21. <image class="empty-container-image" :src="staticUrl + 'icon_like_empty@2x.png'"></image>
  22. <text class="error-text">暂无相关商品~</text>
  23. </view>
  24. <!-- 列表 -->
  25. <view class="tui-cart-cell tui-mtop" v-for="(pros, index) in productList" :key="index">
  26. <view class="tui-goods-item" @click.stop="navToDetailPage(pros.productId)">
  27. <view class="tui-goods-main">
  28. <view class="tui-goods-image"> <image :src="pros.mainImage" class="tui-goods-img" /> </view>
  29. <view class="tui-goods-info">
  30. <text class="list-details-title">{{ pros.name }}</text>
  31. <view class="list-details-price">
  32. <view class="list-price">
  33. <text class="price-larger"> ¥{{ pros.price | NumFormat }} </text>
  34. </view>
  35. <view class="add-cart-btn" @click.stop="showPopup(pros)">数量</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. <!--加载loadding-->
  42. <tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
  43. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#ffffff'" :text="nomoreText"></tui-nomore>
  44. <!--加载loadding-->
  45. </view>
  46. </view>
  47. <!-- 选择规格弹窗 -->
  48. <cm-unit-popup
  49. v-if="popupShow1"
  50. :popupShow="popupShow1"
  51. :skuProduct="handleData"
  52. @skuClick="handleSkuClick"
  53. @addCart="handleAddClubCart"
  54. />
  55. <!-- 弹窗提示 -->
  56. <tui-modal
  57. :show="modal"
  58. @click="handleClick"
  59. @cancel="hideMobel"
  60. :content="contentModalText"
  61. :button="modalButton"
  62. color="#333"
  63. :size="32"
  64. shape="circle"
  65. :maskClosable="false"
  66. >
  67. </tui-modal>
  68. <!-- 可拖动悬浮按钮 -->
  69. <cm-drag
  70. :cartNum="cartQuantity"
  71. :isDock="true"
  72. :existTabBar="true"
  73. @btnClick="btnClick"
  74. @btnTouchstart="btnTouchstart"
  75. @btnTouchend="btnTouchend"
  76. />
  77. </view>
  78. </template>
  79. <script>
  80. import cmDrag from '@/components/cm-custom/cm-drag.vue'
  81. import cmUnitPopup from './components/cm-unit-popup.vue'
  82. import { mapState, mapMutations } from 'vuex'
  83. const defaultListQuery = {
  84. productName: '',
  85. pageNum: 1,
  86. pageSize: 10
  87. }
  88. export default {
  89. components: {
  90. cmDrag,
  91. cmUnitPopup
  92. },
  93. data() {
  94. return {
  95. staticUrl: this.global.staticUrl,
  96. isIphoneX: this.$store.state.isIphoneX,
  97. modalButton: [
  98. {
  99. text: '取消',
  100. type: 'gray',
  101. plain: true //是否空心
  102. },
  103. {
  104. text: '确认',
  105. customStyle: {
  106. color: '#fff',
  107. bgColor: 'linear-gradient(90deg, #F28F31 0%, #F3B574 100%)'
  108. },
  109. plain: false
  110. }
  111. ],
  112. cartQuantity: 0,
  113. popupShow1: false,
  114. listQuery: Object.assign({}, defaultListQuery),
  115. productList: [],
  116. handleData: {},
  117. scrollTop: 0,
  118. isEmpty: false,
  119. loadding: false,
  120. pullUpOn: true,
  121. pullFlag: true,
  122. hasNextPage: false,
  123. navbarHeight: '',
  124. nomoreText: '上拉显示更多',
  125. contentModalText: '', //操作文字提示语句
  126. modal: false,
  127. addParams: {
  128. serviceProviderId: 0, //协销Id
  129. skuId: 0,
  130. clubId: 0,
  131. productCount: 1,
  132. type: 1
  133. }
  134. }
  135. },
  136. onLoad() {
  137. this.initGetStotage()
  138. },
  139. filters: {
  140. NumFormat: function(value) {
  141. //处理金额
  142. if (!value) return '0.00'
  143. let number = Number(value).toFixed(2)
  144. return number
  145. }
  146. },
  147. computed: {
  148. ...mapState(['hasLogin', 'userInfo'])
  149. },
  150. methods: {
  151. ...mapMutations(['login', 'logout']),
  152. async initGetStotage() {
  153. const clubInfo = await this.$api.getComStorage('orderUserInfo')
  154. const userInfo = await this.$api.getStorage()
  155. this.addParams.clubId = clubInfo.clubId ? clubInfo.clubId : 0
  156. this.addParams.serviceProviderId = userInfo.serviceProviderId ? userInfo.serviceProviderId : 0
  157. this.getMallProduct()
  158. this.getClubProductNum()
  159. },
  160. async getMallProduct() {
  161. try {
  162. this.productList = []
  163. this.listQuery.pageNum = 1
  164. const res = await this.SellerService.mallProduct(this.listQuery)
  165. const data = res.data
  166. if (data.results && data.results.length > 0) {
  167. this.isEmpty = false
  168. this.hasNextPage = data.hasNextPage
  169. this.productList = data.results
  170. this.pullFlag = false
  171. setTimeout(() => {
  172. this.pullFlag = true
  173. }, 500)
  174. if (this.hasNextPage) {
  175. this.pullUpOn = false
  176. this.nomoreText = '上拉显示更多'
  177. } else {
  178. if (this.productList.length < 8) {
  179. this.pullUpOn = true
  180. } else {
  181. this.pullUpOn = false
  182. this.loadding = false
  183. this.nomoreText = '已至底部'
  184. }
  185. }
  186. } else {
  187. this.isEmpty = true
  188. }
  189. } catch (error) {
  190. this.$util.msg(error.msg, 2000)
  191. }
  192. },
  193. async onReachBottomData(index) {
  194. //上拉加载
  195. try {
  196. this.listQuery.pageNum += 1
  197. const res = await this.SellerService.mallProduct(this.listQuery)
  198. const data = res.data
  199. if (data.results && data.results.length > 0) {
  200. this.hasNextPage = data.hasNextPage
  201. this.productList = this.productList.concat(data.results)
  202. this.pullFlag = false // 防上拉暴滑
  203. setTimeout(() => {
  204. this.pullFlag = true
  205. }, 500)
  206. if (this.hasNextPage) {
  207. this.pullUpOn = false
  208. this.nomoreText = '上拉显示更多'
  209. } else {
  210. this.pullUpOn = false
  211. this.loadding = false
  212. this.nomoreText = '已至底部'
  213. }
  214. }
  215. } catch (error) {
  216. this.$util.msg(error.msg, 2000)
  217. }
  218. },
  219. handleAddClubCart(data) {
  220. //增加购物车成功和toast弹窗提示成功
  221. this.addParams = { ...this.addParams, ...data }
  222. this.shoppingAddCart(this.addParams)
  223. },
  224. async shoppingAddCart(params) {
  225. try {
  226. await this.SellerService.sellerAddCart(params)
  227. this.$util.msg('加入购物车成功', 1500, true, 'success')
  228. this.getClubProductNum()
  229. } catch (error) {
  230. console.log('error', error.msg)
  231. }
  232. },
  233. handleSkuClick(sku) {
  234. // this.handleData.price = sku.price
  235. },
  236. async getClubProductNum() {
  237. // 获取协销下机构购物车数量
  238. try {
  239. const res = await this.SellerService.clubCartCount({
  240. clubId: this.addParams.clubId,
  241. serviceProviderId: this.addParams.serviceProviderId
  242. })
  243. this.cartQuantity = res.data
  244. } catch (error) {
  245. console.log('获取机构购物车数量失败')
  246. }
  247. },
  248. handleClick(e) {
  249. //取消收藏
  250. if (e.index == 1) {
  251. this.handleDeleteUserLike()
  252. }
  253. this.modal = false
  254. },
  255. handleDeleteUserLike() {
  256. //操作取消收藏
  257. this.ProductService.getDeleteUserLike({
  258. productIds: this.productIds,
  259. userId: this.listQuery.userId
  260. })
  261. .then(response => {
  262. this.$util.msg('取消收藏成功', 2000, true, 'success')
  263. setTimeout(() => {
  264. this.getMallProduct()
  265. }, 2000)
  266. })
  267. .catch(error => {
  268. this.$util.msg(error.msg, 2000)
  269. })
  270. },
  271. hideMobel() {
  272. this.modal = false
  273. },
  274. showPopup(pros) {
  275. // 弹窗显示
  276. this.popupShow1 = true
  277. this.handleData = pros
  278. },
  279. navToDetailPage(id) {
  280. this.isModallayer = true
  281. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  282. this.isModallayer = false
  283. },
  284. btnClick() {
  285. this.$api.navigateTo('/pages/seller/cart/index')
  286. },
  287. btnTouchstart() {
  288. // console.log('btnTouchstart');
  289. },
  290. btnTouchend() {
  291. // console.log('btnTouchend');
  292. }
  293. },
  294. onPageScroll(e) {
  295. //实时获取到滚动的值
  296. },
  297. onReachBottom() {
  298. if (this.hasNextPage) {
  299. this.loadding = true
  300. this.pullUpOn = true
  301. this.onReachBottomData()
  302. }
  303. },
  304. onPullDownRefresh() {
  305. setTimeout(() => {
  306. this.listQuery.pageNum = 1
  307. uni.stopPullDownRefresh()
  308. }, 200)
  309. },
  310. onShow() {}
  311. }
  312. </script>
  313. <style lang="scss">
  314. @import '@/uni.scss';
  315. page {
  316. background: #fff;
  317. }
  318. .empty-container {
  319. z-index: 9999;
  320. }
  321. .club-search {
  322. height: 114rpx;
  323. width: 100%;
  324. padding: 24rpx;
  325. box-sizing: border-box;
  326. background: #ffffff;
  327. display: flex;
  328. align-items: center;
  329. position: fixed;
  330. top: 0;
  331. left: 0;
  332. z-index: 99999;
  333. .search-from {
  334. width: 100%;
  335. height: 66rpx;
  336. background: #f7f7f7;
  337. border-radius: 34rpx;
  338. float: left;
  339. position: relative;
  340. box-sizing: border-box;
  341. padding: 0 24rpx 0 80rpx;
  342. .icon-iconfonticonfontsousuo1 {
  343. width: 80rpx;
  344. height: 66rpx;
  345. line-height: 66rpx;
  346. text-align: center;
  347. display: block;
  348. font-size: $font-size-38;
  349. color: #999999;
  350. position: absolute;
  351. left: 0;
  352. top: 0;
  353. }
  354. .input {
  355. width: 100%;
  356. height: 66rpx;
  357. float: left;
  358. line-height: 66rpx;
  359. color: $text-color;
  360. font-size: $font-size-24;
  361. }
  362. }
  363. }
  364. .mine {
  365. width: 100%;
  366. height: 100%;
  367. position: relative;
  368. }
  369. .product-content {
  370. width: 100%;
  371. height: auto;
  372. position: relative;
  373. padding: 0;
  374. padding-top: 114rpx;
  375. box-sizing: border-box;
  376. .empty-container-image {
  377. width: 386rpx;
  378. height: 286rpx;
  379. margin-top: -300rpx;
  380. }
  381. }
  382. .tui-goods-item {
  383. padding: 30rpx 20rpx 0 20rpx;
  384. box-sizing: border-box;
  385. position: relative;
  386. .tui-goods-main {
  387. display: flex;
  388. width: 100%;
  389. height: 100%;
  390. border-bottom: 1px solid #f0f0f0;
  391. padding-bottom: 24rpx;
  392. }
  393. }
  394. .tui-goods-image {
  395. width: 180rpx;
  396. height: 180rpx !important;
  397. border: 2rpx solid #f3f3f3;
  398. border-radius: 12rpx;
  399. position: relative;
  400. border: 2rpx solid #f3f3f3;
  401. .tui-goods-img {
  402. width: 180rpx;
  403. height: 180rpx !important;
  404. border-radius: 12rpx;
  405. flex-shrink: 0;
  406. display: block;
  407. }
  408. }
  409. .tui-goods-info {
  410. padding-left: 20rpx;
  411. box-sizing: border-box;
  412. position: relative;
  413. width: 540rpx;
  414. .list-details-title {
  415. line-height: 38rpx;
  416. text-overflow: ellipsis;
  417. overflow: hidden;
  418. display: -webkit-box;
  419. -webkit-line-clamp: 2;
  420. line-clamp: 2;
  421. -webkit-box-orient: vertical;
  422. font-size: 26rpx;
  423. color: #333333;
  424. }
  425. .list-details-price {
  426. width: 100%;
  427. line-height: 54rpx;
  428. float: left;
  429. margin-top: 98rpx;
  430. .list-price {
  431. color: #ff2a2a;
  432. float: left;
  433. line-height: 54rpx;
  434. align-items: center;
  435. justify-content: center;
  436. .price-larger {
  437. font-size: $font-size-30;
  438. display: inline-block;
  439. &.none {
  440. text-decoration: line-through;
  441. color: #999999;
  442. }
  443. }
  444. }
  445. .add-cart-btn {
  446. float: right;
  447. width: 160rpx;
  448. height: 56rpx;
  449. line-height: 56rpx;
  450. border-radius: 30rpx;
  451. color: #fff;
  452. font-size: 24rpx;
  453. margin-right: 0;
  454. background: #f3b574;
  455. color: #ffffff;
  456. text-align: center;
  457. }
  458. }
  459. }
  460. .tui-popup-box {
  461. position: relative;
  462. box-sizing: border-box;
  463. min-height: 168rpx;
  464. padding: 6rpx 24rpx;
  465. .tui-popup-content {
  466. padding-top: 30rpx;
  467. }
  468. }
  469. .layer-smimg {
  470. width: 114rpx;
  471. height: 114rpx;
  472. float: left;
  473. border-radius: 10rpx;
  474. margin-right: 24rpx;
  475. image {
  476. width: 114rpx;
  477. height: 114rpx;
  478. border-radius: 10rpx;
  479. }
  480. }
  481. .layer-nunbox {
  482. justify-content: space-between;
  483. align-items: center;
  484. width: 536rpx;
  485. height: 88rpx;
  486. padding: 13rpx 0 0 0;
  487. float: left;
  488. .layer-nunbox-t {
  489. width: 100%;
  490. height: 44rpx;
  491. position: relative;
  492. display: flex;
  493. .layer-nunbox-text {
  494. line-height: 44rpx;
  495. font-size: $font-size-28;
  496. }
  497. .number-box {
  498. display: flex;
  499. justify-content: center;
  500. align-items: center;
  501. border: 2rpx solid #ffe6dc;
  502. border-radius: 30rpx;
  503. height: 48rpx;
  504. margin-left: 20rpx;
  505. .iconfont {
  506. font-size: $font-size-24;
  507. padding: 0 18rpx;
  508. color: #333333;
  509. text-align: center;
  510. line-height: 48rpx;
  511. font-weight: bold;
  512. background: #fef6f3;
  513. &.icon-jianhao {
  514. border-radius: 30rpx 0 0 30rpx;
  515. }
  516. &.icon-jiahao {
  517. border-radius: 0 30rpx 30rpx 0;
  518. }
  519. }
  520. .btn-input {
  521. width: 62rpx;
  522. height: 48rpx;
  523. line-height: 48rpx;
  524. background: #ffffff;
  525. border-radius: 4rpx;
  526. text-align: center;
  527. font-size: $font-size-28;
  528. }
  529. }
  530. .product-step {
  531. position: absolute;
  532. left: 45rpx;
  533. bottom: 0;
  534. height: 44rpx;
  535. background: #ffffff;
  536. }
  537. }
  538. .layer-nunbox-b {
  539. width: 100%;
  540. height: 44rpx;
  541. margin-top: 13rpx;
  542. }
  543. .text {
  544. line-height: 44rpx;
  545. font-size: $font-size-28;
  546. .p {
  547. color: #ff2a2a;
  548. }
  549. .p:first-child {
  550. margin-left: 30rpx;
  551. }
  552. .p.sm {
  553. font-size: $font-size-24;
  554. }
  555. }
  556. }
  557. .tui-popup-btn {
  558. width: 100%;
  559. height: auto;
  560. float: left;
  561. box-sizing: border-box;
  562. margin-top: 30rpx;
  563. .superv-header-checked {
  564. float: left;
  565. font-size: $font-size-30;
  566. .oltext {
  567. width: 120rpx;
  568. float: left;
  569. color: #666666;
  570. display: flex;
  571. margin-left: 10rpx;
  572. .checkbox {
  573. display: flex;
  574. margin: 0;
  575. padding: 0;
  576. display: flex;
  577. flex-direction: column;
  578. align-items: center;
  579. box-sizing: border-box;
  580. text-align: center;
  581. text-decoration: none;
  582. border-radius: 0;
  583. -webkit-tap-highlight-color: transparent;
  584. overflow: hidden;
  585. font-size: 34rpx;
  586. color: $color-system;
  587. line-height: 80rpx;
  588. }
  589. .text {
  590. float: left;
  591. line-height: 80rpx;
  592. margin-left: 15rpx;
  593. }
  594. }
  595. .ortext {
  596. width: 120rpx;
  597. float: right;
  598. color: $color-system;
  599. text-align: right;
  600. }
  601. }
  602. .tui-button {
  603. width: 210rpx;
  604. height: 88rpx;
  605. float: right;
  606. background: #e1e1e1;
  607. line-height: 88rpx;
  608. text-align: center;
  609. color: #ffffff;
  610. font-size: $font-size-28;
  611. border-radius: 44rpx;
  612. &.active {
  613. background: $btn-confirm;
  614. }
  615. }
  616. .tui-flex-btn {
  617. width: 100%;
  618. height: 88rpx;
  619. display: flex;
  620. box-sizing: border-box;
  621. padding: 0 34rpx;
  622. .button {
  623. width: 280rpx;
  624. height: 88rpx;
  625. color: #fff;
  626. display: flex;
  627. align-items: center;
  628. justify-content: center;
  629. font-size: $font-size-28;
  630. border-radius: 44rpx;
  631. &.buy {
  632. background: $btn-confirm;
  633. margin-left: 78rpx;
  634. }
  635. &.add {
  636. background: #ffe6dc;
  637. color: #f3b574;
  638. }
  639. }
  640. }
  641. }
  642. </style>