studyGoodsDetail.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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 @monthSwitch="chnageMonth" :date="selectDate" :selected="selected" clearDate 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. selectDate: "",
  147. }
  148. },
  149. methods: {
  150. choose(index) {
  151. this.active = index
  152. },
  153. filterMsg(val, name) {
  154. let msg = val.replace(/\n/g, "<br>")
  155. if (name == 'validDay') {
  156. msg = val + '天'
  157. }
  158. return msg
  159. },
  160. jump(url) {
  161. uni.navigateTo({
  162. url
  163. })
  164. },
  165. handleTab(val) {
  166. this.tab = val
  167. },
  168. handleQuery() {
  169. uni.showToast({
  170. title: '请选择需要咨询的日期',
  171. icon: 'none'
  172. });
  173. this.isSubscribe = true
  174. this.openCalendar()
  175. },
  176. handleBuy() {
  177. if (!this.reserveTime) {
  178. uni.showToast({
  179. title: '请选择出发日期',
  180. icon: 'none'
  181. });
  182. this.openCalendar()
  183. return
  184. }
  185. this.info.reserveTime = this.reserveTime
  186. if (!this.info.realStockNum) return
  187. let that = this
  188. if (uni.getStorageSync('token')) {
  189. uni.navigateTo({
  190. url: `/study/pay/order`,
  191. success: function (res) {
  192. // 通过eventChannel向被打开页面传送数据
  193. res.eventChannel.emit('pay', that.info)
  194. }
  195. })
  196. } else {
  197. uni.showModal({
  198. title: '请登录',
  199. confirmText: '去登录',
  200. success(res) {
  201. console.log(res);
  202. if (res.confirm) {
  203. uni.navigateTo({
  204. url: `/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  205. })
  206. }
  207. }
  208. })
  209. }
  210. },
  211. detail(goodsId) {
  212. this.pageLoading = true
  213. this.goodsId = goodsId
  214. detail({ goodsId, resource: 2 }).then(res => {
  215. this.pageLoading = false
  216. if (res.state == 'Success') {
  217. this.info = res.content
  218. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  219. this.shopId = res.content.shopId
  220. uni.setNavigationBarTitle({
  221. title: this.info.goodsName
  222. })
  223. this.chnageMonth({
  224. year: new Date().getFullYear(),
  225. month: new Date().getMonth() + 1
  226. })
  227. getStudyAbout({ goodsId }).then(({ content }) => {
  228. try {
  229. this.urls = content.buyStatisVo?.list?.map(e => e.imgPath);
  230. } catch (error) {
  231. }
  232. this.info.reservationDate = content.msg
  233. const { communityVo } = content
  234. const { list, total } = communityVo
  235. this.total = total
  236. const [item] = list
  237. this.info.share = {
  238. communityDetail: item.communityDetail,
  239. coverImg: item.coverImg,
  240. nickname: item.nickname,
  241. imgPath: item.imgPath,
  242. showTime: item.showTime,
  243. urls: item.urls
  244. }
  245. this.$forceUpdate()
  246. })
  247. }
  248. })
  249. },
  250. goShopDetail(shopInfo) {
  251. uni.setStorageSync('shopInfo', JSON.stringify(shopInfo))
  252. uni.navigateTo({
  253. url: `/detail/shopDetail/shopDetail`
  254. })
  255. },
  256. openCalendar() {
  257. this.$refs.calendar.open();
  258. },
  259. closeCalendar() {
  260. this.isSubscribe = false
  261. },
  262. confirm({ fulldate }) {
  263. this.reserveTime = fulldate
  264. try {
  265. const user = JSON.parse(uni.getStorageSync('userInfo'))
  266. if (this.isSubscribe) {
  267. this.isSubscribe = false
  268. subscribe({
  269. userId: user.userId,
  270. goodsId: this.goodsId,
  271. shopId: this.shopId,
  272. reservationTime: fulldate,
  273. }).then(res => {
  274. if (res.state == 'Success') {
  275. uni.showToast({
  276. title: '预约成功,请您耐心等待客服电话',
  277. icon: 'none'
  278. });
  279. }
  280. })
  281. }
  282. } catch (error) {
  283. }
  284. },
  285. // 更改月份后获取新月份的可售卖日期
  286. chnageMonth({ year, month }) {
  287. goodsBuyStatistic({
  288. goodsId: this.info.goodsId,
  289. year,
  290. month
  291. }).then(res => {
  292. // console.log(res)
  293. this.selected = res.content.map(e => {
  294. if (e.isOpenSeal) {
  295. return {
  296. date: `${e.year}-${e.month}-${e.day}`,
  297. info: '可选',
  298. disable: false,
  299. notic: false,
  300. color: '#2979ff'
  301. }
  302. } else {
  303. return {
  304. date: `${e.year}-${e.month}-${e.day}`,
  305. disable: true,
  306. notic: false,
  307. color: '#2979ff'
  308. }
  309. }
  310. })
  311. this.selectDate = this.selected.find(e => !e.disable)?.date;
  312. console.log('this.selectDate', this.selectDate);
  313. if (!this.selectDate) {
  314. // 看下个月
  315. let dateTime = new Date();
  316. dateTime = dateTime.setMonth(d.getMonth() + 1);
  317. dateTime = new Date(dateTime);
  318. this.chnageMonth({
  319. year: dateTime.getFullYear(),
  320. month: dateTime.getMonth() + 1
  321. })
  322. }
  323. })
  324. },
  325. clickImg() {
  326. uni.previewImage({
  327. urls: this.info.share.urls,
  328. longPressActions: {
  329. itemList: ['发送给朋友', '保存图片', '收藏'],
  330. success: function (data) {
  331. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  332. },
  333. fail: function (err) {
  334. console.log(err.errMsg);
  335. }
  336. }
  337. });
  338. },
  339. toShare() {
  340. uni.navigateTo({
  341. url: '/share/index?goodsId=' + this.goodsId
  342. });
  343. }
  344. },
  345. onLoad(option) {
  346. try {
  347. this.shopInfo = JSON.parse(uni.getStorageSync('shopInfo'))
  348. } catch (error) {
  349. console.log("未读取到对应缓存")
  350. }
  351. this.detail(option.id)
  352. },
  353. }
  354. </script>
  355. <style lang="scss">
  356. .goodsDetail {
  357. background: #F9F9F9;
  358. padding-bottom: 200rpx;
  359. min-height: 100vh;
  360. .good-img {
  361. width: 100%;
  362. height: 750rpx;
  363. vertical-align: bottom;
  364. }
  365. .content {
  366. background-color: #FFFFFF;
  367. padding: 20rpx;
  368. border-radius: 16rpx 16rpx 0rpx 0rpx;
  369. margin-top: -16rpx;
  370. overflow: overlay;
  371. .price-box {
  372. display: flex;
  373. align-items: center;
  374. .price {
  375. display: flex;
  376. align-items: baseline;
  377. font-weight: bold;
  378. .unit {
  379. font-size: 20rpx;
  380. color: #FF4D3A;
  381. }
  382. .price {
  383. font-size: 56rpx;
  384. color: #FF4D3A;
  385. }
  386. }
  387. .old-price {
  388. font-size: 24rpx;
  389. color: #AAAAAA;
  390. text-decoration: line-through;
  391. margin-left: 22rpx;
  392. }
  393. }
  394. .title {
  395. margin-top: 16rpx;
  396. font-size: 36rpx;
  397. color: #222222;
  398. font-weight: bold;
  399. display: -webkit-box;
  400. -webkit-box-orient: vertical;
  401. -webkit-line-clamp: 2;
  402. /* 显示的最大行数 */
  403. overflow: hidden;
  404. }
  405. .desc {
  406. margin-top: 16rpx;
  407. font-size: 24rpx;
  408. color: #AAAAAA;
  409. display: -webkit-box;
  410. -webkit-box-orient: vertical;
  411. -webkit-line-clamp: 2;
  412. /* 显示的最大行数 */
  413. overflow: hidden;
  414. }
  415. .ag {
  416. margin: 28rpx 0;
  417. display: flex;
  418. justify-content: space-between;
  419. align-items: center;
  420. font-size: 24rpx;
  421. color: #AAAAAA;
  422. }
  423. .subtitle {
  424. margin-bottom: 20rpx;
  425. font-size: 32rpx;
  426. font-weight: bold;
  427. }
  428. .reservation {
  429. display: flex;
  430. justify-content: space-between;
  431. align-items: center;
  432. font-size: 28rpx;
  433. padding: 28rpx;
  434. background-color: #F9F9F9;
  435. // margin-bottom: 28rpx;
  436. border-radius: 8rpx;
  437. .text {
  438. color: #222222;
  439. }
  440. .more {
  441. width: 16rpx;
  442. height: 16rpx;
  443. }
  444. }
  445. .share {
  446. padding: 24rpx;
  447. background-color: #F9F9F9;
  448. .top {
  449. display: flex;
  450. justify-content: space-between;
  451. align-items: center;
  452. .title {
  453. color: #222222;
  454. font-weight: bold;
  455. font-size: 32rpx;
  456. margin-top: 0;
  457. }
  458. .more {
  459. color: #AAAAAA;
  460. font-size: 24rpx;
  461. .img {
  462. width: 16rpx;
  463. height: 16rpx;
  464. margin-left: 20rpx;
  465. }
  466. }
  467. margin-bottom: 20rpx;
  468. }
  469. .user {
  470. display: flex;
  471. justify-content: space-between;
  472. align-items: center;
  473. margin-bottom: 16rpx;
  474. .userinfo {
  475. display: flex;
  476. align-items: center;
  477. .avatar {
  478. width: 60rpx;
  479. height: 60rpx;
  480. }
  481. .username {
  482. margin-left: 16rpx;
  483. font-size: 28rpx;
  484. color: #222222;
  485. }
  486. }
  487. .date {
  488. font-size: 20rpx;
  489. color: #AAAAAA;
  490. }
  491. }
  492. }
  493. .share-content {
  494. display: flex;
  495. justify-content: space-between;
  496. .content-text {
  497. padding: 8rpx;
  498. width: 70%;
  499. font-size: 24rpx;
  500. color: #222222;
  501. word-break: break-all;
  502. display: -webkit-box;
  503. -webkit-box-orient: vertical;
  504. -webkit-line-clamp: 4;
  505. /* 显示的最大行数 */
  506. overflow: hidden;
  507. }
  508. .content-image {
  509. position: relative;
  510. width: 160rpx;
  511. height: 160rpx;
  512. margin-left: 28rpx;
  513. border-radius: 16rpx 16rpx 16rpx 16rpx;
  514. }
  515. .overlay {
  516. position: absolute;
  517. bottom: 10rpx;
  518. right: 0rpx;
  519. background: rgba(0, 0, 0, 0.6);
  520. color: white;
  521. border-radius: 16rpx 0 16rpx 0;
  522. text-align: center;
  523. line-height: 52rpx;
  524. font-size: 24rpx;
  525. font-weight: bold;
  526. width: 52rpx;
  527. height: 52rpx;
  528. }
  529. }
  530. }
  531. .tab-group {
  532. display: flex;
  533. background: #fff;
  534. .tab {
  535. flex: 1;
  536. padding: 0 0 24rpx 0;
  537. text-align: center;
  538. font-size: 28rpx;
  539. color: #222222;
  540. }
  541. .tab.active {
  542. font-weight: 600;
  543. }
  544. }
  545. .desc-box {
  546. .goods-desc {
  547. color: #222222;
  548. font-size: 24rpx;
  549. .img_class {
  550. max-width: 100% !important;
  551. vertical-align: bottom;
  552. }
  553. }
  554. }
  555. .list {
  556. background: #fff;
  557. .item {
  558. padding: 24rpx;
  559. border-top: 1rpx solid #F0F0F0;
  560. .label {
  561. font-weight: 600;
  562. font-size: 28rpx;
  563. color: #222222;
  564. }
  565. .value {
  566. font-size: 24rpx;
  567. color: #AAAAAA;
  568. margin-top: 16rpx;
  569. line-height: 40rpx;
  570. }
  571. }
  572. }
  573. .buy-box {
  574. position: fixed;
  575. bottom: 0%;
  576. left: 0%;
  577. width: 100%;
  578. background: #fff;
  579. padding: 10rpx 24rpx 76rpx;
  580. display: flex;
  581. justify-content: space-between;
  582. box-sizing: border-box;
  583. .head {
  584. width: 80rpx;
  585. height: 80rpx;
  586. background: #aaa;
  587. border-radius: 50%;
  588. }
  589. .btn-box {
  590. width: 100%;
  591. display: flex;
  592. text-align: center;
  593. justify-content: space-between;
  594. .group-btn {
  595. width: 280rpx;
  596. height: 80rpx;
  597. background: #6499FF;
  598. border-radius: 40rpx 0rpx 0rpx 40rpx;
  599. display: flex;
  600. flex-direction: column;
  601. justify-content: space-around;
  602. .label {
  603. font-weight: 600;
  604. font-size: 28rpx;
  605. color: #FFFFFF;
  606. }
  607. .price {
  608. font-size: 24rpx;
  609. color: #FFFFFF;
  610. }
  611. }
  612. .buy-btn.none {
  613. filter: grayscale(1);
  614. }
  615. .buy-btn {
  616. width: 344rpx;
  617. // width: 560rpx;
  618. height: 80rpx;
  619. background: #3B83FF;
  620. border-radius: 40rpx;
  621. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  622. display: flex;
  623. flex-direction: column;
  624. justify-content: space-around;
  625. &:nth-child(1) {
  626. background: transparent;
  627. border: 1rpx solid #3B83FF;
  628. .label {
  629. color: #3B83FF;
  630. }
  631. }
  632. .label {
  633. font-weight: 600;
  634. font-size: 28rpx;
  635. color: #FFFFFF;
  636. }
  637. .price {
  638. font-size: 24rpx;
  639. color: #FFFFFF;
  640. }
  641. }
  642. }
  643. }
  644. }
  645. </style>