studyGoodsDetail.vue 15 KB

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