studyGoodsDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. <template>
  2. <view class="goodsDetail">
  3. <zs-skeleton type="goodsDetail" :loading="pageLoading"></zs-skeleton>
  4. <image class="good-img" :src="info.goodsPath + '?x-oss-process=image/resize,h_750,w_750,m_fixed'" mode="aspectFit">
  5. </image>
  6. <view class="content">
  7. <view class="price-box">
  8. <view class="price">
  9. <view class="unit">¥</view>
  10. <view class="price">
  11. {{ info.realPrice }}
  12. </view>
  13. </view>
  14. <view class="old-price">
  15. 市场价{{ info.marketPrice }}
  16. </view>
  17. </view>
  18. <view class="title">
  19. {{ info.goodsName }}
  20. </view>
  21. <view class="desc">
  22. {{ info.goodsDescribe }}
  23. </view>
  24. <view class="ag">
  25. <u-avatar-group :urls="urls" size="44" gap="0.1" maxCount="10"></u-avatar-group>
  26. <view class="">{{ info.saleNum || 0 }} 人已购</view>
  27. </view>
  28. <view class="subtitle">
  29. 出发日期
  30. </view>
  31. <view class="reservation" @click="openCalendar">
  32. <view class="text">
  33. <text style="color:#AAAAAA;margin-right:28rpx;"> 预定 </text> {{ reserveTime ? '预定' + $u.timeFormat(new
  34. Date(reserveTime), 'yyyy年mm月dd日') + '出发' :
  35. info.reservationDate || '' }}
  36. </view>
  37. <view>
  38. <image class="more" src="../static/jiantou-icon.png" mode=""></image>
  39. </view>
  40. </view>
  41. <!-- <view class="share" v-if="total > 0">
  42. <view class="top">
  43. <view class="title">研学分享</view>
  44. <view class="more" @click="toShare">{{ total }}分享<image class="img" src="../static/jiantou-icon.png" mode="">
  45. </image>
  46. </view>
  47. </view>
  48. <view class="user">
  49. <view class="userinfo">
  50. <view class="avatar">
  51. <u-avatar size="60" :src="info.share.imgPath"></u-avatar>
  52. </view>
  53. <view class="username">{{ info.share.nickname }}</view>
  54. </view>
  55. <view class="date">{{ info.share.showTime }}</view>
  56. </view>
  57. <view class="share-content">
  58. <view class="content-text">{{ info.share.communityDetail }}</view>
  59. <view style="position: relative;" @click="clickImg">
  60. <image class="content-image" :src="info.share.coverImg">
  61. </image>
  62. <view class="overlay">+{{ info.share.urls.length }}</view>
  63. </view>
  64. </view>
  65. </view> -->
  66. </view>
  67. <view class="tab-group">
  68. <view class="tab" :class="[tab == 1 ? 'active' : '']" @click="handleTab(1)">
  69. 详情介绍
  70. </view>
  71. <view class="tab" :class="[tab == 2 ? 'active' : '']" @click="handleTab(2)">
  72. 购买须知
  73. </view>
  74. </view>
  75. <view class="desc-box" v-show="tab == 1">
  76. <rich-text class="goods-desc" :nodes="info.goodsDetail"></rich-text>
  77. </view>
  78. <view class="list" v-show="tab == 2">
  79. <view class="item" v-for="(item, index) in info.attrs" :key="index">
  80. <view class="label">
  81. {{ item.attrName == 'validDay' ? '有效期' : item.attrName }}
  82. </view>
  83. <view class="value" v-html="filterMsg(item.attrValue, item.attrName)">
  84. </view>
  85. </view>
  86. <!-- <view class="item">
  87. <view class="label">
  88. 使用时间
  89. </view>
  90. <view class="value">
  91. 营业时间内可用
  92. </view>
  93. </view> -->
  94. </view>
  95. <view class="buy-box">
  96. <!-- <image class="head" :src="shopInfo.logoPath" @click="goShopDetail(shopInfo)" mode=""></image> -->
  97. <view class="btn-box">
  98. <view class="buy-btn" :class="[info.realStockNum ? '' : 'none']" @click="handleQuery">
  99. <view class="label">
  100. 预约咨询
  101. </view>
  102. </view>
  103. <view class="buy-btn" :class="[info.realStockNum ? '' : 'none']" @click="handleBuy">
  104. <view class="label">
  105. {{ info.realStockNum ? '报名支付' : '售罄' }}
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <uni-calendar nextDay @monthSwitch="chnageMonth" :selected="selected" ref="calendar"
  111. :showMonth="false" style="z-index: 999;" :insert="false" @confirm="confirm" @close="closeCalendar">
  112. </uni-calendar>
  113. </view>
  114. </template>
  115. <script>
  116. import { detail, getStudyAbout, goodsBuyStatistic } from '@/api/goods.js'
  117. import { subscribe } from "@/api/study"
  118. export default {
  119. data() {
  120. return {
  121. pageLoading: false,
  122. active: 0,
  123. tab: 1,
  124. shopList: [],
  125. isSubscribe: false,
  126. info: {
  127. share: {
  128. urls: []
  129. }
  130. },
  131. total: 0,
  132. shopInfo: {},
  133. urls: [
  134. "https://fakeimg.pl/22x22/?text=🫡&font_size=22",
  135. "https://fakeimg.pl/22x22/?text=🤣&font_size=22",
  136. "https://fakeimg.pl/22x22/?text=😍&font_size=22",
  137. "https://fakeimg.pl/22x22/?text=😒&font_size=22",
  138. "https://fakeimg.pl/22x22/?text=😉&font_size=22",
  139. "https://fakeimg.pl/22x22/?text=😎&font_size=22",
  140. "https://fakeimg.pl/22x22/?text=😁&font_size=22",
  141. "https://fakeimg.pl/22x22/?text=😘&font_size=22",
  142. ],
  143. goodsId: "",
  144. selected: [],
  145. reserveTime: "",
  146. }
  147. },
  148. methods: {
  149. choose(index) {
  150. this.active = index
  151. },
  152. filterMsg(val, name) {
  153. let msg = val.replace(/\n/g, "<br>")
  154. if (name == 'validDay') {
  155. msg = val + '天'
  156. }
  157. return msg
  158. },
  159. jump(url) {
  160. uni.navigateTo({
  161. url
  162. })
  163. },
  164. handleTab(val) {
  165. this.tab = val
  166. },
  167. handleQuery() {
  168. uni.showToast({
  169. title: '请选择需要咨询的日期',
  170. icon: 'none'
  171. });
  172. this.isSubscribe = true
  173. this.openCalendar()
  174. },
  175. handleBuy() {
  176. if (!this.reserveTime) {
  177. uni.showToast({
  178. title: '请选择出发日期',
  179. icon: 'none'
  180. });
  181. this.openCalendar()
  182. return
  183. }
  184. this.info.reserveTime = this.reserveTime
  185. if (!this.info.realStockNum) return
  186. let that = this
  187. if (uni.getStorageSync('token')) {
  188. uni.navigateTo({
  189. url: `/study/pay/order`,
  190. success: function (res) {
  191. // 通过eventChannel向被打开页面传送数据
  192. res.eventChannel.emit('pay', that.info)
  193. }
  194. })
  195. } else {
  196. uni.showModal({
  197. title: '请登录',
  198. confirmText: '去登录',
  199. success(res) {
  200. console.log(res);
  201. if (res.confirm) {
  202. uni.navigateTo({
  203. url: `/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  204. })
  205. }
  206. }
  207. })
  208. }
  209. },
  210. detail(goodsId) {
  211. this.pageLoading = true
  212. this.goodsId = goodsId
  213. detail({ goodsId, resource: 2 }).then(res => {
  214. this.pageLoading = false
  215. if (res.state == 'Success') {
  216. this.info = res.content
  217. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  218. this.shopId = res.content.shopId
  219. uni.setNavigationBarTitle({
  220. title: this.info.goodsName
  221. })
  222. this.chnageMonth({
  223. year: new Date().getFullYear(),
  224. month: new Date().getMonth() + 1
  225. })
  226. getStudyAbout({ goodsId }).then(({ content }) => {
  227. try {
  228. this.urls = content.buyStatisVo?.list?.map(e => e.imgPath);
  229. } catch (error) {
  230. }
  231. this.info.reservationDate = content.msg
  232. const { communityVo } = content
  233. const { list, total } = communityVo
  234. this.total = total
  235. const [item] = list
  236. this.info.share = {
  237. communityDetail: item.communityDetail,
  238. coverImg: item.coverImg,
  239. nickname: item.nickname,
  240. imgPath: item.imgPath,
  241. showTime: item.showTime,
  242. urls: item.urls
  243. }
  244. this.$forceUpdate()
  245. })
  246. }
  247. })
  248. },
  249. goShopDetail(shopInfo) {
  250. uni.setStorageSync('shopInfo', JSON.stringify(shopInfo))
  251. uni.navigateTo({
  252. url: `/detail/shopDetail/shopDetail`
  253. })
  254. },
  255. openCalendar() {
  256. this.$refs.calendar.open();
  257. },
  258. closeCalendar() {
  259. this.isSubscribe = false
  260. },
  261. confirm({ fulldate }) {
  262. this.reserveTime = fulldate
  263. try {
  264. const user = JSON.parse(uni.getStorageSync('userInfo'))
  265. if (this.isSubscribe) {
  266. this.isSubscribe = false
  267. subscribe({
  268. userId: user.userId,
  269. goodsId: this.goodsId,
  270. shopId: this.shopId,
  271. reservationTime: fulldate,
  272. }).then(res => {
  273. if (res.state == 'Success') {
  274. uni.showToast({
  275. title: '预约成功,请您耐心等待客服电话',
  276. icon: 'none'
  277. });
  278. }
  279. })
  280. }
  281. } catch (error) {
  282. }
  283. },
  284. // 更改月份后获取新月份的可售卖日期
  285. chnageMonth({ year, month }) {
  286. goodsBuyStatistic({
  287. goodsId: this.info.goodsId,
  288. year,
  289. month
  290. }).then(res => {
  291. // console.log(res)
  292. this.selected = res.content.map(e => {
  293. if (e.isOpenSeal) {
  294. return {
  295. date: `${e.year}-${e.month}-${e.day}`,
  296. info: '可选',
  297. notic: false,
  298. color: '#2979ff'
  299. }
  300. } else {
  301. return {
  302. date: `${e.year}-${e.month}-${e.day}`,
  303. disable: true,
  304. notic: false,
  305. color: '#2979ff'
  306. }
  307. }
  308. })
  309. })
  310. },
  311. clickImg() {
  312. uni.previewImage({
  313. urls: this.info.share.urls,
  314. longPressActions: {
  315. itemList: ['发送给朋友', '保存图片', '收藏'],
  316. success: function (data) {
  317. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  318. },
  319. fail: function (err) {
  320. console.log(err.errMsg);
  321. }
  322. }
  323. });
  324. },
  325. toShare() {
  326. uni.navigateTo({
  327. url: '/share/index?goodsId=' + this.goodsId
  328. });
  329. }
  330. },
  331. onLoad(option) {
  332. try {
  333. this.shopInfo = JSON.parse(uni.getStorageSync('shopInfo'))
  334. } catch (error) {
  335. console.log("未读取到对应缓存")
  336. }
  337. this.detail(option.id)
  338. },
  339. }
  340. </script>
  341. <style lang="scss">
  342. .goodsDetail {
  343. background: #F9F9F9;
  344. padding-bottom: 200rpx;
  345. min-height: 100vh;
  346. .good-img {
  347. width: 100%;
  348. height: 750rpx;
  349. vertical-align: bottom;
  350. }
  351. .content {
  352. background-color: #FFFFFF;
  353. padding: 20rpx;
  354. border-radius: 16rpx 16rpx 0rpx 0rpx;
  355. margin-top: -16rpx;
  356. overflow: overlay;
  357. .price-box {
  358. display: flex;
  359. align-items: center;
  360. .price {
  361. display: flex;
  362. align-items: baseline;
  363. font-weight: bold;
  364. .unit {
  365. font-size: 20rpx;
  366. color: #FF4D3A;
  367. }
  368. .price {
  369. font-size: 56rpx;
  370. color: #FF4D3A;
  371. }
  372. }
  373. .old-price {
  374. font-size: 24rpx;
  375. color: #AAAAAA;
  376. text-decoration: line-through;
  377. margin-left: 22rpx;
  378. }
  379. }
  380. .title {
  381. margin-top: 16rpx;
  382. font-size: 36rpx;
  383. color: #222222;
  384. font-weight: bold;
  385. display: -webkit-box;
  386. -webkit-box-orient: vertical;
  387. -webkit-line-clamp: 2;
  388. /* 显示的最大行数 */
  389. overflow: hidden;
  390. }
  391. .desc {
  392. margin-top: 16rpx;
  393. font-size: 24rpx;
  394. color: #AAAAAA;
  395. display: -webkit-box;
  396. -webkit-box-orient: vertical;
  397. -webkit-line-clamp: 2;
  398. /* 显示的最大行数 */
  399. overflow: hidden;
  400. }
  401. .ag {
  402. margin: 28rpx 0;
  403. display: flex;
  404. justify-content: space-between;
  405. align-items: center;
  406. font-size: 24rpx;
  407. color: #AAAAAA;
  408. }
  409. .subtitle {
  410. margin-bottom: 20rpx;
  411. font-size: 32rpx;
  412. font-weight: bold;
  413. }
  414. .reservation {
  415. display: flex;
  416. justify-content: space-between;
  417. align-items: center;
  418. font-size: 28rpx;
  419. padding: 28rpx;
  420. background-color: #F9F9F9;
  421. // margin-bottom: 28rpx;
  422. border-radius: 8rpx;
  423. .text {
  424. color: #222222;
  425. }
  426. .more {
  427. width: 16rpx;
  428. height: 16rpx;
  429. }
  430. }
  431. .share {
  432. padding: 24rpx;
  433. background-color: #F9F9F9;
  434. .top {
  435. display: flex;
  436. justify-content: space-between;
  437. align-items: center;
  438. .title {
  439. color: #222222;
  440. font-weight: bold;
  441. font-size: 32rpx;
  442. margin-top: 0;
  443. }
  444. .more {
  445. color: #AAAAAA;
  446. font-size: 24rpx;
  447. .img {
  448. width: 16rpx;
  449. height: 16rpx;
  450. margin-left: 20rpx;
  451. }
  452. }
  453. margin-bottom: 20rpx;
  454. }
  455. .user {
  456. display: flex;
  457. justify-content: space-between;
  458. align-items: center;
  459. margin-bottom: 16rpx;
  460. .userinfo {
  461. display: flex;
  462. align-items: center;
  463. .avatar {
  464. width: 60rpx;
  465. height: 60rpx;
  466. }
  467. .username {
  468. margin-left: 16rpx;
  469. font-size: 28rpx;
  470. color: #222222;
  471. }
  472. }
  473. .date {
  474. font-size: 20rpx;
  475. color: #AAAAAA;
  476. }
  477. }
  478. }
  479. .share-content {
  480. display: flex;
  481. justify-content: space-between;
  482. .content-text {
  483. padding: 8rpx;
  484. width: 70%;
  485. font-size: 24rpx;
  486. color: #222222;
  487. word-break: break-all;
  488. display: -webkit-box;
  489. -webkit-box-orient: vertical;
  490. -webkit-line-clamp: 4;
  491. /* 显示的最大行数 */
  492. overflow: hidden;
  493. }
  494. .content-image {
  495. position: relative;
  496. width: 160rpx;
  497. height: 160rpx;
  498. margin-left: 28rpx;
  499. border-radius: 16rpx 16rpx 16rpx 16rpx;
  500. }
  501. .overlay {
  502. position: absolute;
  503. bottom: 10rpx;
  504. right: 0rpx;
  505. background: rgba(0, 0, 0, 0.6);
  506. color: white;
  507. border-radius: 16rpx 0 16rpx 0;
  508. text-align: center;
  509. line-height: 52rpx;
  510. font-size: 24rpx;
  511. font-weight: bold;
  512. width: 52rpx;
  513. height: 52rpx;
  514. }
  515. }
  516. }
  517. .tab-group {
  518. display: flex;
  519. background: #fff;
  520. .tab {
  521. flex: 1;
  522. padding: 0 0 24rpx 0;
  523. text-align: center;
  524. font-size: 28rpx;
  525. color: #222222;
  526. }
  527. .tab.active {
  528. font-weight: 600;
  529. }
  530. }
  531. .desc-box {
  532. .goods-desc {
  533. color: #222222;
  534. font-size: 24rpx;
  535. .img_class {
  536. max-width: 100% !important;
  537. vertical-align: bottom;
  538. }
  539. }
  540. }
  541. .list {
  542. background: #fff;
  543. .item {
  544. padding: 24rpx;
  545. border-top: 1rpx solid #F0F0F0;
  546. .label {
  547. font-weight: 600;
  548. font-size: 28rpx;
  549. color: #222222;
  550. }
  551. .value {
  552. font-size: 24rpx;
  553. color: #AAAAAA;
  554. margin-top: 16rpx;
  555. line-height: 40rpx;
  556. }
  557. }
  558. }
  559. .buy-box {
  560. position: fixed;
  561. bottom: 0%;
  562. left: 0%;
  563. width: 100%;
  564. background: #fff;
  565. padding: 10rpx 24rpx 76rpx;
  566. display: flex;
  567. justify-content: space-between;
  568. box-sizing: border-box;
  569. .head {
  570. width: 80rpx;
  571. height: 80rpx;
  572. background: #aaa;
  573. border-radius: 50%;
  574. }
  575. .btn-box {
  576. width: 100%;
  577. display: flex;
  578. text-align: center;
  579. justify-content: space-between;
  580. .group-btn {
  581. width: 280rpx;
  582. height: 80rpx;
  583. background: #6499FF;
  584. border-radius: 40rpx 0rpx 0rpx 40rpx;
  585. display: flex;
  586. flex-direction: column;
  587. justify-content: space-around;
  588. .label {
  589. font-weight: 600;
  590. font-size: 28rpx;
  591. color: #FFFFFF;
  592. }
  593. .price {
  594. font-size: 24rpx;
  595. color: #FFFFFF;
  596. }
  597. }
  598. .buy-btn.none {
  599. filter: grayscale(1);
  600. }
  601. .buy-btn {
  602. width: 344rpx;
  603. // width: 560rpx;
  604. height: 80rpx;
  605. background: #3B83FF;
  606. border-radius: 40rpx;
  607. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  608. display: flex;
  609. flex-direction: column;
  610. justify-content: space-around;
  611. &:nth-child(1) {
  612. background: transparent;
  613. border: 1rpx solid #3B83FF;
  614. .label {
  615. color: #3B83FF;
  616. }
  617. }
  618. .label {
  619. font-weight: 600;
  620. font-size: 28rpx;
  621. color: #FFFFFF;
  622. }
  623. .price {
  624. font-size: 24rpx;
  625. color: #FFFFFF;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. </style>