list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. },
  138. filters: {
  139. NumFormat: function(value) {
  140. //处理金额
  141. if (!value) return '0.00'
  142. let number = Number(value).toFixed(2)
  143. return number
  144. }
  145. },
  146. computed: {
  147. ...mapState(['hasLogin', 'userInfo'])
  148. },
  149. methods: {
  150. ...mapMutations(['login', 'logout']),
  151. async initGetStotage() {
  152. const clubInfo = await this.$api.getComStorage('orderUserInfo')
  153. const userInfo = await this.$api.getStorage()
  154. this.addParams.clubId = clubInfo.clubId ? clubInfo.clubId : 0
  155. this.addParams.serviceProviderId = userInfo.serviceProviderId ? userInfo.serviceProviderId : 0
  156. this.getMallProduct()
  157. this.getClubProductNum()
  158. },
  159. async getMallProduct() {
  160. try {
  161. this.productList = []
  162. this.listQuery.pageNum = 1
  163. const res = await this.SellerService.mallProduct(this.listQuery)
  164. const data = res.data
  165. if (data.results && data.results.length > 0) {
  166. this.isEmpty = false
  167. this.hasNextPage = data.hasNextPage
  168. this.productList = data.results
  169. this.pullFlag = false
  170. setTimeout(() => {
  171. this.pullFlag = true
  172. }, 500)
  173. if (this.hasNextPage) {
  174. this.pullUpOn = false
  175. this.nomoreText = '上拉显示更多'
  176. } else {
  177. if (this.productList.length < 8) {
  178. this.pullUpOn = true
  179. this.loadding = false
  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. this.initGetStotage()
  312. }
  313. }
  314. </script>
  315. <style lang="scss">
  316. @import '@/uni.scss';
  317. page {
  318. background: #fff;
  319. }
  320. .empty-container {
  321. z-index: 9999;
  322. }
  323. .club-search {
  324. height: 114rpx;
  325. width: 100%;
  326. padding: 24rpx;
  327. box-sizing: border-box;
  328. background: #ffffff;
  329. display: flex;
  330. align-items: center;
  331. position: fixed;
  332. top: 0;
  333. left: 0;
  334. z-index: 99999;
  335. .search-from {
  336. width: 100%;
  337. height: 66rpx;
  338. background: #f7f7f7;
  339. border-radius: 34rpx;
  340. float: left;
  341. position: relative;
  342. box-sizing: border-box;
  343. padding: 0 24rpx 0 80rpx;
  344. .icon-iconfonticonfontsousuo1 {
  345. width: 80rpx;
  346. height: 66rpx;
  347. line-height: 66rpx;
  348. text-align: center;
  349. display: block;
  350. font-size: $font-size-38;
  351. color: #999999;
  352. position: absolute;
  353. left: 0;
  354. top: 0;
  355. }
  356. .input {
  357. width: 100%;
  358. height: 66rpx;
  359. float: left;
  360. line-height: 66rpx;
  361. color: $text-color;
  362. font-size: $font-size-24;
  363. }
  364. }
  365. }
  366. .mine {
  367. width: 100%;
  368. height: 100%;
  369. position: relative;
  370. }
  371. .product-content {
  372. width: 100%;
  373. height: auto;
  374. position: relative;
  375. padding: 0;
  376. padding-top: 114rpx;
  377. box-sizing: border-box;
  378. .empty-container-image {
  379. width: 386rpx;
  380. height: 286rpx;
  381. margin-top: -300rpx;
  382. }
  383. }
  384. .tui-goods-item {
  385. padding: 30rpx 20rpx 0 20rpx;
  386. box-sizing: border-box;
  387. position: relative;
  388. .tui-goods-main {
  389. display: flex;
  390. width: 100%;
  391. height: 100%;
  392. border-bottom: 1px solid #f0f0f0;
  393. padding-bottom: 24rpx;
  394. }
  395. }
  396. .tui-goods-image {
  397. width: 180rpx;
  398. height: 180rpx !important;
  399. border: 2rpx solid #f3f3f3;
  400. border-radius: 12rpx;
  401. position: relative;
  402. border: 2rpx solid #f3f3f3;
  403. .tui-goods-img {
  404. width: 180rpx;
  405. height: 180rpx !important;
  406. border-radius: 12rpx;
  407. flex-shrink: 0;
  408. display: block;
  409. }
  410. }
  411. .tui-goods-info {
  412. padding-left: 20rpx;
  413. box-sizing: border-box;
  414. position: relative;
  415. width: 540rpx;
  416. .list-details-title {
  417. line-height: 38rpx;
  418. text-overflow: ellipsis;
  419. overflow: hidden;
  420. display: -webkit-box;
  421. -webkit-line-clamp: 2;
  422. line-clamp: 2;
  423. -webkit-box-orient: vertical;
  424. font-size: 26rpx;
  425. color: #333333;
  426. }
  427. .list-details-price {
  428. width: 100%;
  429. line-height: 54rpx;
  430. float: left;
  431. margin-top: 98rpx;
  432. .list-price {
  433. color: #ff2a2a;
  434. float: left;
  435. line-height: 54rpx;
  436. align-items: center;
  437. justify-content: center;
  438. .price-larger {
  439. font-size: $font-size-30;
  440. display: inline-block;
  441. &.none {
  442. text-decoration: line-through;
  443. color: #999999;
  444. }
  445. }
  446. }
  447. .add-cart-btn {
  448. float: right;
  449. width: 160rpx;
  450. height: 56rpx;
  451. line-height: 56rpx;
  452. border-radius: 30rpx;
  453. color: #fff;
  454. font-size: 24rpx;
  455. margin-right: 0;
  456. background: #f3b574;
  457. color: #ffffff;
  458. text-align: center;
  459. }
  460. }
  461. }
  462. .tui-popup-box {
  463. position: relative;
  464. box-sizing: border-box;
  465. min-height: 168rpx;
  466. padding: 6rpx 24rpx;
  467. .tui-popup-content {
  468. padding-top: 30rpx;
  469. }
  470. }
  471. .layer-smimg {
  472. width: 114rpx;
  473. height: 114rpx;
  474. float: left;
  475. border-radius: 10rpx;
  476. margin-right: 24rpx;
  477. image {
  478. width: 114rpx;
  479. height: 114rpx;
  480. border-radius: 10rpx;
  481. }
  482. }
  483. .layer-nunbox {
  484. justify-content: space-between;
  485. align-items: center;
  486. width: 536rpx;
  487. height: 88rpx;
  488. padding: 13rpx 0 0 0;
  489. float: left;
  490. .layer-nunbox-t {
  491. width: 100%;
  492. height: 44rpx;
  493. position: relative;
  494. display: flex;
  495. .layer-nunbox-text {
  496. line-height: 44rpx;
  497. font-size: $font-size-28;
  498. }
  499. .number-box {
  500. display: flex;
  501. justify-content: center;
  502. align-items: center;
  503. border: 2rpx solid #ffe6dc;
  504. border-radius: 30rpx;
  505. height: 48rpx;
  506. margin-left: 20rpx;
  507. .iconfont {
  508. font-size: $font-size-24;
  509. padding: 0 18rpx;
  510. color: #333333;
  511. text-align: center;
  512. line-height: 48rpx;
  513. font-weight: bold;
  514. background: #fef6f3;
  515. &.icon-jianhao {
  516. border-radius: 30rpx 0 0 30rpx;
  517. }
  518. &.icon-jiahao {
  519. border-radius: 0 30rpx 30rpx 0;
  520. }
  521. }
  522. .btn-input {
  523. width: 62rpx;
  524. height: 48rpx;
  525. line-height: 48rpx;
  526. background: #ffffff;
  527. border-radius: 4rpx;
  528. text-align: center;
  529. font-size: $font-size-28;
  530. }
  531. }
  532. .product-step {
  533. position: absolute;
  534. left: 45rpx;
  535. bottom: 0;
  536. height: 44rpx;
  537. background: #ffffff;
  538. }
  539. }
  540. .layer-nunbox-b {
  541. width: 100%;
  542. height: 44rpx;
  543. margin-top: 13rpx;
  544. }
  545. .text {
  546. line-height: 44rpx;
  547. font-size: $font-size-28;
  548. .p {
  549. color: #ff2a2a;
  550. }
  551. .p:first-child {
  552. margin-left: 30rpx;
  553. }
  554. .p.sm {
  555. font-size: $font-size-24;
  556. }
  557. }
  558. }
  559. .tui-popup-btn {
  560. width: 100%;
  561. height: auto;
  562. float: left;
  563. box-sizing: border-box;
  564. margin-top: 30rpx;
  565. .superv-header-checked {
  566. float: left;
  567. font-size: $font-size-30;
  568. .oltext {
  569. width: 120rpx;
  570. float: left;
  571. color: #666666;
  572. display: flex;
  573. margin-left: 10rpx;
  574. .checkbox {
  575. display: flex;
  576. margin: 0;
  577. padding: 0;
  578. display: flex;
  579. flex-direction: column;
  580. align-items: center;
  581. box-sizing: border-box;
  582. text-align: center;
  583. text-decoration: none;
  584. border-radius: 0;
  585. -webkit-tap-highlight-color: transparent;
  586. overflow: hidden;
  587. font-size: 34rpx;
  588. color: $color-system;
  589. line-height: 80rpx;
  590. }
  591. .text {
  592. float: left;
  593. line-height: 80rpx;
  594. margin-left: 15rpx;
  595. }
  596. }
  597. .ortext {
  598. width: 120rpx;
  599. float: right;
  600. color: $color-system;
  601. text-align: right;
  602. }
  603. }
  604. .tui-button {
  605. width: 210rpx;
  606. height: 88rpx;
  607. float: right;
  608. background: #e1e1e1;
  609. line-height: 88rpx;
  610. text-align: center;
  611. color: #ffffff;
  612. font-size: $font-size-28;
  613. border-radius: 44rpx;
  614. &.active {
  615. background: $btn-confirm;
  616. }
  617. }
  618. .tui-flex-btn {
  619. width: 100%;
  620. height: 88rpx;
  621. display: flex;
  622. box-sizing: border-box;
  623. padding: 0 34rpx;
  624. .button {
  625. width: 280rpx;
  626. height: 88rpx;
  627. color: #fff;
  628. display: flex;
  629. align-items: center;
  630. justify-content: center;
  631. font-size: $font-size-28;
  632. border-radius: 44rpx;
  633. &.buy {
  634. background: $btn-confirm;
  635. margin-left: 78rpx;
  636. }
  637. &.add {
  638. background: #ffe6dc;
  639. color: #f3b574;
  640. }
  641. }
  642. }
  643. }
  644. </style>