list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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" />
  43. <tui-nomore :visible="!pullUpOn" :backgroundColor="'#ffffff'" :text="nomoreText" />
  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. this.loadding = false
  181. } else {
  182. this.pullUpOn = false
  183. this.loadding = false
  184. this.nomoreText = '已至底部'
  185. }
  186. }
  187. } else {
  188. this.isEmpty = true
  189. }
  190. } catch (error) {
  191. this.$util.msg(error.msg, 2000)
  192. }
  193. },
  194. async onReachBottomData(index) {
  195. //上拉加载
  196. try {
  197. this.listQuery.pageNum += 1
  198. const res = await this.SellerService.mallProduct(this.listQuery)
  199. const data = res.data
  200. if (data.results && data.results.length > 0) {
  201. this.hasNextPage = data.hasNextPage
  202. this.productList = this.productList.concat(data.results)
  203. this.pullFlag = false // 防上拉暴滑
  204. setTimeout(() => {
  205. this.pullFlag = true
  206. }, 500)
  207. if (this.hasNextPage) {
  208. this.pullUpOn = false
  209. this.nomoreText = '上拉显示更多'
  210. } else {
  211. this.pullUpOn = false
  212. this.loadding = false
  213. this.nomoreText = '已至底部'
  214. }
  215. }
  216. } catch (error) {
  217. this.$util.msg(error.msg, 2000)
  218. }
  219. },
  220. handleAddClubCart(data) {
  221. //增加购物车成功和toast弹窗提示成功
  222. this.addParams = { ...this.addParams, ...data }
  223. this.shoppingAddCart(this.addParams)
  224. },
  225. async shoppingAddCart(params) {
  226. try {
  227. await this.SellerService.sellerAddCart(params)
  228. this.$util.msg('加入购物车成功', 1500, true, 'success')
  229. this.getClubProductNum()
  230. } catch (error) {
  231. console.log('error', error.msg)
  232. }
  233. },
  234. handleSkuClick(sku) {
  235. // this.handleData.price = sku.price
  236. },
  237. async getClubProductNum() {
  238. // 获取协销下机构购物车数量
  239. try {
  240. const res = await this.SellerService.clubCartCount({
  241. clubId: this.addParams.clubId,
  242. serviceProviderId: this.addParams.serviceProviderId
  243. })
  244. this.cartQuantity = res.data
  245. } catch (error) {
  246. console.log('获取机构购物车数量失败')
  247. }
  248. },
  249. handleClick(e) {
  250. //取消收藏
  251. if (e.index == 1) {
  252. this.handleDeleteUserLike()
  253. }
  254. this.modal = false
  255. },
  256. handleDeleteUserLike() {
  257. //操作取消收藏
  258. this.ProductService.getDeleteUserLike({
  259. productIds: this.productIds,
  260. userId: this.listQuery.userId
  261. })
  262. .then(response => {
  263. this.$util.msg('取消收藏成功', 2000, true, 'success')
  264. setTimeout(() => {
  265. this.getMallProduct()
  266. }, 2000)
  267. })
  268. .catch(error => {
  269. this.$util.msg(error.msg, 2000)
  270. })
  271. },
  272. hideMobel() {
  273. this.modal = false
  274. },
  275. showPopup(pros) {
  276. // 弹窗显示
  277. this.popupShow1 = true
  278. this.handleData = pros
  279. },
  280. navToDetailPage(id) {
  281. this.isModallayer = true
  282. this.$api.navigateTo(`/pages/goods/product?id=${id}`)
  283. this.isModallayer = false
  284. },
  285. btnClick() {
  286. this.$api.navigateTo('/pages/seller/cart/index')
  287. },
  288. btnTouchstart() {
  289. // console.log('btnTouchstart');
  290. },
  291. btnTouchend() {
  292. // console.log('btnTouchend');
  293. }
  294. },
  295. onPageScroll(e) {
  296. //实时获取到滚动的值
  297. },
  298. onReachBottom() {
  299. if (this.hasNextPage) {
  300. this.loadding = true
  301. this.pullUpOn = true
  302. this.onReachBottomData()
  303. }
  304. },
  305. onPullDownRefresh() {
  306. setTimeout(() => {
  307. this.listQuery.pageNum = 1
  308. uni.stopPullDownRefresh()
  309. }, 200)
  310. },
  311. onShow() {}
  312. }
  313. </script>
  314. <style lang="scss">
  315. @import '@/uni.scss';
  316. page {
  317. background: #fff;
  318. }
  319. .empty-container {
  320. z-index: 9999;
  321. }
  322. .club-search {
  323. height: 114rpx;
  324. width: 100%;
  325. padding: 24rpx;
  326. box-sizing: border-box;
  327. background: #ffffff;
  328. display: flex;
  329. align-items: center;
  330. position: fixed;
  331. top: 0;
  332. left: 0;
  333. z-index: 99999;
  334. .search-from {
  335. width: 100%;
  336. height: 66rpx;
  337. background: #f7f7f7;
  338. border-radius: 34rpx;
  339. float: left;
  340. position: relative;
  341. box-sizing: border-box;
  342. padding: 0 24rpx 0 80rpx;
  343. .icon-iconfonticonfontsousuo1 {
  344. width: 80rpx;
  345. height: 66rpx;
  346. line-height: 66rpx;
  347. text-align: center;
  348. display: block;
  349. font-size: $font-size-38;
  350. color: #999999;
  351. position: absolute;
  352. left: 0;
  353. top: 0;
  354. }
  355. .input {
  356. width: 100%;
  357. height: 66rpx;
  358. float: left;
  359. line-height: 66rpx;
  360. color: $text-color;
  361. font-size: $font-size-24;
  362. }
  363. }
  364. }
  365. .mine {
  366. width: 100%;
  367. height: 100%;
  368. position: relative;
  369. }
  370. .product-content {
  371. width: 100%;
  372. height: auto;
  373. position: relative;
  374. padding: 0;
  375. padding-top: 114rpx;
  376. box-sizing: border-box;
  377. .empty-container-image {
  378. width: 386rpx;
  379. height: 286rpx;
  380. margin-top: -300rpx;
  381. }
  382. }
  383. .tui-goods-item {
  384. padding: 30rpx 20rpx 0 20rpx;
  385. box-sizing: border-box;
  386. position: relative;
  387. .tui-goods-main {
  388. display: flex;
  389. width: 100%;
  390. height: 100%;
  391. border-bottom: 1px solid #f0f0f0;
  392. padding-bottom: 24rpx;
  393. }
  394. }
  395. .tui-goods-image {
  396. width: 180rpx;
  397. height: 180rpx !important;
  398. border: 2rpx solid #f3f3f3;
  399. border-radius: 12rpx;
  400. position: relative;
  401. border: 2rpx solid #f3f3f3;
  402. .tui-goods-img {
  403. width: 180rpx;
  404. height: 180rpx !important;
  405. border-radius: 12rpx;
  406. flex-shrink: 0;
  407. display: block;
  408. }
  409. }
  410. .tui-goods-info {
  411. padding-left: 20rpx;
  412. box-sizing: border-box;
  413. position: relative;
  414. width: 540rpx;
  415. .list-details-title {
  416. line-height: 38rpx;
  417. text-overflow: ellipsis;
  418. overflow: hidden;
  419. display: -webkit-box;
  420. -webkit-line-clamp: 2;
  421. line-clamp: 2;
  422. -webkit-box-orient: vertical;
  423. font-size: 26rpx;
  424. color: #333333;
  425. }
  426. .list-details-price {
  427. width: 100%;
  428. line-height: 54rpx;
  429. float: left;
  430. margin-top: 98rpx;
  431. .list-price {
  432. color: #ff2a2a;
  433. float: left;
  434. line-height: 54rpx;
  435. align-items: center;
  436. justify-content: center;
  437. .price-larger {
  438. font-size: $font-size-30;
  439. display: inline-block;
  440. &.none {
  441. text-decoration: line-through;
  442. color: #999999;
  443. }
  444. }
  445. }
  446. .add-cart-btn {
  447. float: right;
  448. width: 160rpx;
  449. height: 56rpx;
  450. line-height: 56rpx;
  451. border-radius: 30rpx;
  452. color: #fff;
  453. font-size: 24rpx;
  454. margin-right: 0;
  455. background: #f3b574;
  456. color: #ffffff;
  457. text-align: center;
  458. }
  459. }
  460. }
  461. .tui-popup-box {
  462. position: relative;
  463. box-sizing: border-box;
  464. min-height: 168rpx;
  465. padding: 6rpx 24rpx;
  466. .tui-popup-content {
  467. padding-top: 30rpx;
  468. }
  469. }
  470. .layer-smimg {
  471. width: 114rpx;
  472. height: 114rpx;
  473. float: left;
  474. border-radius: 10rpx;
  475. margin-right: 24rpx;
  476. image {
  477. width: 114rpx;
  478. height: 114rpx;
  479. border-radius: 10rpx;
  480. }
  481. }
  482. .layer-nunbox {
  483. justify-content: space-between;
  484. align-items: center;
  485. width: 536rpx;
  486. height: 88rpx;
  487. padding: 13rpx 0 0 0;
  488. float: left;
  489. .layer-nunbox-t {
  490. width: 100%;
  491. height: 44rpx;
  492. position: relative;
  493. display: flex;
  494. .layer-nunbox-text {
  495. line-height: 44rpx;
  496. font-size: $font-size-28;
  497. }
  498. .number-box {
  499. display: flex;
  500. justify-content: center;
  501. align-items: center;
  502. border: 2rpx solid #ffe6dc;
  503. border-radius: 30rpx;
  504. height: 48rpx;
  505. margin-left: 20rpx;
  506. .iconfont {
  507. font-size: $font-size-24;
  508. padding: 0 18rpx;
  509. color: #333333;
  510. text-align: center;
  511. line-height: 48rpx;
  512. font-weight: bold;
  513. background: #fef6f3;
  514. &.icon-jianhao {
  515. border-radius: 30rpx 0 0 30rpx;
  516. }
  517. &.icon-jiahao {
  518. border-radius: 0 30rpx 30rpx 0;
  519. }
  520. }
  521. .btn-input {
  522. width: 62rpx;
  523. height: 48rpx;
  524. line-height: 48rpx;
  525. background: #ffffff;
  526. border-radius: 4rpx;
  527. text-align: center;
  528. font-size: $font-size-28;
  529. }
  530. }
  531. .product-step {
  532. position: absolute;
  533. left: 45rpx;
  534. bottom: 0;
  535. height: 44rpx;
  536. background: #ffffff;
  537. }
  538. }
  539. .layer-nunbox-b {
  540. width: 100%;
  541. height: 44rpx;
  542. margin-top: 13rpx;
  543. }
  544. .text {
  545. line-height: 44rpx;
  546. font-size: $font-size-28;
  547. .p {
  548. color: #ff2a2a;
  549. }
  550. .p:first-child {
  551. margin-left: 30rpx;
  552. }
  553. .p.sm {
  554. font-size: $font-size-24;
  555. }
  556. }
  557. }
  558. .tui-popup-btn {
  559. width: 100%;
  560. height: auto;
  561. float: left;
  562. box-sizing: border-box;
  563. margin-top: 30rpx;
  564. .superv-header-checked {
  565. float: left;
  566. font-size: $font-size-30;
  567. .oltext {
  568. width: 120rpx;
  569. float: left;
  570. color: #666666;
  571. display: flex;
  572. margin-left: 10rpx;
  573. .checkbox {
  574. display: flex;
  575. margin: 0;
  576. padding: 0;
  577. display: flex;
  578. flex-direction: column;
  579. align-items: center;
  580. box-sizing: border-box;
  581. text-align: center;
  582. text-decoration: none;
  583. border-radius: 0;
  584. -webkit-tap-highlight-color: transparent;
  585. overflow: hidden;
  586. font-size: 34rpx;
  587. color: $color-system;
  588. line-height: 80rpx;
  589. }
  590. .text {
  591. float: left;
  592. line-height: 80rpx;
  593. margin-left: 15rpx;
  594. }
  595. }
  596. .ortext {
  597. width: 120rpx;
  598. float: right;
  599. color: $color-system;
  600. text-align: right;
  601. }
  602. }
  603. .tui-button {
  604. width: 210rpx;
  605. height: 88rpx;
  606. float: right;
  607. background: #e1e1e1;
  608. line-height: 88rpx;
  609. text-align: center;
  610. color: #ffffff;
  611. font-size: $font-size-28;
  612. border-radius: 44rpx;
  613. &.active {
  614. background: $btn-confirm;
  615. }
  616. }
  617. .tui-flex-btn {
  618. width: 100%;
  619. height: 88rpx;
  620. display: flex;
  621. box-sizing: border-box;
  622. padding: 0 34rpx;
  623. .button {
  624. width: 280rpx;
  625. height: 88rpx;
  626. color: #fff;
  627. display: flex;
  628. align-items: center;
  629. justify-content: center;
  630. font-size: $font-size-28;
  631. border-radius: 44rpx;
  632. &.buy {
  633. background: $btn-confirm;
  634. margin-left: 78rpx;
  635. }
  636. &.add {
  637. background: #ffe6dc;
  638. color: #f3b574;
  639. }
  640. }
  641. }
  642. }
  643. </style>