studyGoodsDetail.vue 15 KB

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