studyGoodsDetail.vue 15 KB

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