studyGoodsDetail.vue 16 KB

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