studyGoodsDetail.vue 17 KB

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