studyGoodsDetail.vue 16 KB

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