studyGoodsDetail.vue 16 KB

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