studyGoodsDetail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <template>
  2. <view class="goodsDetail">
  3. <zs-skeleton type="goodsDetail" :loading="pageLoading"></zs-skeleton>
  4. <image class="good-img" :src="info.goodsPath" mode="aspectFit"></image>
  5. <view class="content">
  6. <view class="price-box">
  7. <view class="price">
  8. <view class="unit">¥</view>
  9. <view class="price">
  10. {{ info.realPrice }}
  11. </view>
  12. </view>
  13. <view class="old-price">
  14. 市场价{{ info.marketPrice }}
  15. </view>
  16. </view>
  17. <view class="title">
  18. {{ info.goodsName }}
  19. </view>
  20. <view class="desc">
  21. {{ info.goodsDescribe }}
  22. </view>
  23. <view class="ag">
  24. <u-avatar-group :urls="urls" size="44" gap="0.1" maxCount="10"></u-avatar-group>
  25. <view class="">{{ info.saleNum || 0 }} 人已购</view>
  26. </view>
  27. <view class="subtitle">
  28. 出发日期
  29. </view>
  30. <view class="reservation" @click="openCalendar">
  31. <view class="text">
  32. <text style="color:#AAAAAA;margin-right:28rpx;"> 已预定 </text> {{ reserveTime ? '预定' + reserveTime + '出发' :
  33. info.reservationDate || '' }}
  34. </view>
  35. <view>
  36. <image class="more" src="../static/jiantou-icon.png" mode=""></image>
  37. </view>
  38. </view>
  39. <view class="share" v-if="total > 0">
  40. <view class="top">
  41. <view class="title">研学分享</view>
  42. <view class="more" @click="toShare">{{ total }}分享<image class="img" src="../static/jiantou-icon.png" mode="">
  43. </image>
  44. </view>
  45. </view>
  46. <view class="user">
  47. <view class="userinfo">
  48. <view class="avatar">
  49. <u-avatar size="60" :src="info.share.imgPath"></u-avatar>
  50. </view>
  51. <view class="username">{{ info.share.nickname }}</view>
  52. </view>
  53. <view class="date">{{ info.share.showTime }}</view>
  54. </view>
  55. <view class="share-content">
  56. <view class="content-text">{{ info.share.communityDetail }}</view>
  57. <view style="position: relative;" @click="clickImg">
  58. <image class="content-image" :src="info.share.coverImg">
  59. </image>
  60. <view class="overlay">+{{ info.share.urls.length }}</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="tab-group">
  66. <view class="tab" :class="[tab == 1 ? 'active' : '']" @click="handleTab(1)">
  67. 商品详情
  68. </view>
  69. <view class="tab" :class="[tab == 2 ? 'active' : '']" @click="handleTab(2)">
  70. 购买须知
  71. </view>
  72. </view>
  73. <view class="desc-box" v-show="tab == 1">
  74. <rich-text class="goods-desc" :nodes="info.goodsDetail"></rich-text>
  75. </view>
  76. <view class="list" v-show="tab == 2">
  77. <view class="item" v-for="(item, index) in info.attrs" :key="index">
  78. <view class="label">
  79. {{ item.attrName == 'validDay' ? '有效期' : item.attrName }}
  80. </view>
  81. <view class="value" v-html="filterMsg(item.attrValue, item.attrName)">
  82. </view>
  83. </view>
  84. <!-- <view class="item">
  85. <view class="label">
  86. 使用时间
  87. </view>
  88. <view class="value">
  89. 营业时间内可用
  90. </view>
  91. </view> -->
  92. </view>
  93. <view class="buy-box">
  94. <!-- <image class="head" :src="shopInfo.logoPath" @click="goShopDetail(shopInfo)" mode=""></image> -->
  95. <view class="btn-box">
  96. <view class="buy-btn" :class="[info.realStockNum ? '' : 'none']" @click="handleBuy">
  97. <view class="label">
  98. 预约咨询
  99. </view>
  100. </view>
  101. <view class="buy-btn" :class="[info.realStockNum ? '' : 'none']" @click="handleBuy">
  102. <view class="label">
  103. {{ info.realStockNum ? '报名支付' : '售罄' }}
  104. </view>
  105. </view>
  106. </view>
  107. </view>
  108. <uni-calendar @monthSwitch="chnageMonth" :selected="selected" ref="calendar" :showMonth="false"
  109. style="z-index: 999;" :insert="false" @confirm="confirm">
  110. </uni-calendar>
  111. </view>
  112. </template>
  113. <script>
  114. import { detail, getStudyAbout, goodsBuyStatistic } from '@/api/goods.js'
  115. export default {
  116. data() {
  117. return {
  118. pageLoading: false,
  119. active: 0,
  120. tab: 1,
  121. shopList: [],
  122. info: {
  123. share: {
  124. urls: []
  125. }
  126. },
  127. total: 0,
  128. shopInfo: {},
  129. urls: [
  130. "https://fakeimg.pl/22x22/?text=🫡&font_size=22",
  131. "https://fakeimg.pl/22x22/?text=🤣&font_size=22",
  132. "https://fakeimg.pl/22x22/?text=😍&font_size=22",
  133. "https://fakeimg.pl/22x22/?text=😒&font_size=22",
  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. ],
  139. goodsId: "",
  140. selected: [],
  141. reserveTime: "",
  142. }
  143. },
  144. methods: {
  145. choose(index) {
  146. this.active = index
  147. },
  148. filterMsg(val, name) {
  149. let msg = val.replace(/\n/g, "<br>")
  150. if (name == 'validDay') {
  151. msg = val + '天'
  152. }
  153. return msg
  154. },
  155. jump(url) {
  156. uni.navigateTo({
  157. url
  158. })
  159. },
  160. handleTab(val) {
  161. this.tab = val
  162. },
  163. handleBuy() {
  164. if (!this.reserveTime) {
  165. uni.showToast({
  166. title: '请选择出发日期',
  167. icon: 'none'
  168. });
  169. this.openCalendar()
  170. return
  171. }
  172. this.info.reserveTime = this.reserveTime
  173. if (!this.info.realStockNum) return
  174. let that = this
  175. if (uni.getStorageSync('token')) {
  176. uni.navigateTo({
  177. url: `/study/pay/order`,
  178. success: function (res) {
  179. // 通过eventChannel向被打开页面传送数据
  180. res.eventChannel.emit('pay', that.info)
  181. }
  182. })
  183. } else {
  184. uni.showModal({
  185. title: '请登录',
  186. confirmText: '去登录',
  187. success(res) {
  188. console.log(res);
  189. if (res.confirm) {
  190. uni.navigateTo({
  191. url: `/login/login/login?redirect=/detail/goodsDetail/index&id=${that.info.goodsId}`
  192. })
  193. }
  194. }
  195. })
  196. }
  197. },
  198. detail(goodsId) {
  199. this.pageLoading = true
  200. this.goodsId = goodsId
  201. detail({ goodsId, resource: 2 }).then(res => {
  202. this.pageLoading = false
  203. if (res.state == 'Success') {
  204. this.info = res.content
  205. this.info.goodsDetail = res.content.goodsDetail.replace(/<img/gi, '<img class="img_class" ')
  206. uni.setNavigationBarTitle({
  207. title: this.info.goodsName
  208. })
  209. this.chnageMonth({
  210. year: new Date().getFullYear(),
  211. month: new Date().getMonth() + 1
  212. })
  213. getStudyAbout({ goodsId }).then(({ content }) => {
  214. try {
  215. this.urls = content.buyStatisVo?.list?.map(e => e.imgPath);
  216. } catch (error) {
  217. }
  218. this.info.reservationDate = content.msg
  219. const { communityVo } = content
  220. const { list, total } = communityVo
  221. this.total = total
  222. const [item] = list
  223. this.info.share = {
  224. communityDetail: item.communityDetail,
  225. coverImg: item.coverImg,
  226. nickname: item.nickname,
  227. imgPath: item.imgPath,
  228. showTime: item.showTime,
  229. urls: item.urls
  230. }
  231. this.$forceUpdate()
  232. })
  233. }
  234. })
  235. },
  236. goShopDetail(shopInfo) {
  237. uni.setStorageSync('shopInfo', JSON.stringify(shopInfo))
  238. uni.navigateTo({
  239. url: `/detail/shopDetail/shopDetail`
  240. })
  241. },
  242. openCalendar() {
  243. this.$refs.calendar.open();
  244. },
  245. confirm({ fulldate }) {
  246. this.reserveTime = fulldate + " 00:00:00"
  247. },
  248. // 更改月份后获取新月份的可售卖日期
  249. chnageMonth({ year, month }) {
  250. goodsBuyStatistic({
  251. goodsId: this.info.goodsId,
  252. year,
  253. month
  254. }).then(res => {
  255. // console.log(res)
  256. this.selected = res.content.map(e => {
  257. if (e.isOpenSeal) {
  258. return {
  259. date: `${e.year}-${e.month}-${e.day}`,
  260. info: '可选',
  261. notic: false,
  262. color: '#2979ff'
  263. }
  264. } else {
  265. return {
  266. date: `${e.year}-${e.month}-${e.day}`,
  267. disable: true,
  268. notic: false,
  269. color: '#2979ff'
  270. }
  271. }
  272. })
  273. })
  274. },
  275. clickImg() {
  276. uni.previewImage({
  277. urls: this.info.share.urls,
  278. longPressActions: {
  279. itemList: ['发送给朋友', '保存图片', '收藏'],
  280. success: function (data) {
  281. console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
  282. },
  283. fail: function (err) {
  284. console.log(err.errMsg);
  285. }
  286. }
  287. });
  288. },
  289. toShare() {
  290. uni.navigateTo({
  291. url: '/share/index?goodsId=' + this.goodsId
  292. });
  293. }
  294. },
  295. onLoad(option) {
  296. try {
  297. this.shopInfo = JSON.parse(uni.getStorageSync('shopInfo'))
  298. } catch (error) {
  299. console.log("未读取到对应缓存")
  300. }
  301. this.detail(option.id)
  302. }
  303. }
  304. </script>
  305. <style lang="scss">
  306. .goodsDetail {
  307. background: #F9F9F9;
  308. padding-bottom: 200rpx;
  309. min-height: 100vh;
  310. .good-img {
  311. width: 100%;
  312. height: 750rpx;
  313. vertical-align: bottom;
  314. }
  315. .content {
  316. background-color: #FFFFFF;
  317. padding: 20rpx;
  318. border-radius: 16rpx 16rpx 0rpx 0rpx;
  319. margin-top: -16rpx;
  320. overflow: overlay;
  321. .price-box {
  322. display: flex;
  323. align-items: center;
  324. .price {
  325. display: flex;
  326. align-items: baseline;
  327. font-weight: bold;
  328. .unit {
  329. font-size: 20rpx;
  330. color: #FF4D3A;
  331. }
  332. .price {
  333. font-size: 56rpx;
  334. color: #FF4D3A;
  335. }
  336. }
  337. .old-price {
  338. font-size: 24rpx;
  339. color: #AAAAAA;
  340. text-decoration: line-through;
  341. margin-left: 22rpx;
  342. }
  343. }
  344. .title {
  345. margin-top: 16rpx;
  346. font-size: 36rpx;
  347. color: #222222;
  348. font-weight: bold;
  349. display: -webkit-box;
  350. -webkit-box-orient: vertical;
  351. -webkit-line-clamp: 2;
  352. /* 显示的最大行数 */
  353. overflow: hidden;
  354. }
  355. .desc {
  356. margin-top: 16rpx;
  357. font-size: 24rpx;
  358. color: #AAAAAA;
  359. display: -webkit-box;
  360. -webkit-box-orient: vertical;
  361. -webkit-line-clamp: 2;
  362. /* 显示的最大行数 */
  363. overflow: hidden;
  364. }
  365. .ag {
  366. margin: 28rpx 0;
  367. display: flex;
  368. justify-content: space-between;
  369. align-items: center;
  370. font-size: 24rpx;
  371. color: #AAAAAA;
  372. }
  373. .subtitle {
  374. margin-bottom: 20rpx;
  375. font-size: 32rpx;
  376. font-weight: bold;
  377. }
  378. .reservation {
  379. display: flex;
  380. justify-content: space-between;
  381. align-items: center;
  382. font-size: 28rpx;
  383. padding: 28rpx;
  384. background-color: #F9F9F9;
  385. margin-bottom: 28rpx;
  386. border-radius: 8rpx;
  387. .text {
  388. color: #222222;
  389. }
  390. .more {
  391. width: 16rpx;
  392. height: 16rpx;
  393. }
  394. }
  395. .share {
  396. padding: 24rpx;
  397. background-color: #F9F9F9;
  398. .top {
  399. display: flex;
  400. justify-content: space-between;
  401. align-items: center;
  402. .title {
  403. color: #222222;
  404. font-weight: bold;
  405. font-size: 32rpx;
  406. margin-top: 0;
  407. }
  408. .more {
  409. color: #AAAAAA;
  410. font-size: 24rpx;
  411. .img {
  412. width: 16rpx;
  413. height: 16rpx;
  414. margin-left: 20rpx;
  415. }
  416. }
  417. margin-bottom: 20rpx;
  418. }
  419. .user {
  420. display: flex;
  421. justify-content: space-between;
  422. align-items: center;
  423. margin-bottom: 16rpx;
  424. .userinfo {
  425. display: flex;
  426. align-items: center;
  427. .avatar {
  428. width: 60rpx;
  429. height: 60rpx;
  430. }
  431. .username {
  432. margin-left: 16rpx;
  433. font-size: 28rpx;
  434. color: #222222;
  435. }
  436. }
  437. .date {
  438. font-size: 20rpx;
  439. color: #AAAAAA;
  440. }
  441. }
  442. }
  443. .share-content {
  444. display: flex;
  445. justify-content: space-between;
  446. .content-text {
  447. padding: 8rpx;
  448. width: 70%;
  449. font-size: 24rpx;
  450. color: #222222;
  451. word-break: break-all;
  452. display: -webkit-box;
  453. -webkit-box-orient: vertical;
  454. -webkit-line-clamp: 4;
  455. /* 显示的最大行数 */
  456. overflow: hidden;
  457. }
  458. .content-image {
  459. position: relative;
  460. width: 160rpx;
  461. height: 160rpx;
  462. margin-left: 28rpx;
  463. border-radius: 16rpx 16rpx 16rpx 16rpx;
  464. }
  465. .overlay {
  466. position: absolute;
  467. bottom: 10rpx;
  468. right: 0rpx;
  469. background: rgba(0, 0, 0, 0.6);
  470. color: white;
  471. border-radius: 16rpx 0 16rpx 0;
  472. text-align: center;
  473. line-height: 52rpx;
  474. font-size: 24rpx;
  475. font-weight: bold;
  476. width: 52rpx;
  477. height: 52rpx;
  478. }
  479. }
  480. }
  481. .tab-group {
  482. display: flex;
  483. background: #fff;
  484. .tab {
  485. flex: 1;
  486. padding: 24rpx 0;
  487. text-align: center;
  488. font-size: 28rpx;
  489. color: #222222;
  490. }
  491. .tab.active {
  492. font-weight: 600;
  493. }
  494. }
  495. .desc-box {
  496. .goods-desc {
  497. color: #222222;
  498. font-size: 24rpx;
  499. .img_class {
  500. max-width: 100% !important;
  501. vertical-align: bottom;
  502. }
  503. }
  504. }
  505. .list {
  506. background: #fff;
  507. .item {
  508. padding: 24rpx;
  509. border-top: 1rpx solid #F0F0F0;
  510. .label {
  511. font-weight: 600;
  512. font-size: 28rpx;
  513. color: #222222;
  514. }
  515. .value {
  516. font-size: 24rpx;
  517. color: #AAAAAA;
  518. margin-top: 16rpx;
  519. line-height: 40rpx;
  520. }
  521. }
  522. }
  523. .buy-box {
  524. position: fixed;
  525. bottom: 0%;
  526. left: 0%;
  527. width: 100%;
  528. background: #fff;
  529. padding: 10rpx 24rpx 76rpx;
  530. display: flex;
  531. justify-content: space-between;
  532. box-sizing: border-box;
  533. .head {
  534. width: 80rpx;
  535. height: 80rpx;
  536. background: #aaa;
  537. border-radius: 50%;
  538. }
  539. .btn-box {
  540. width: 100%;
  541. display: flex;
  542. text-align: center;
  543. justify-content: space-between;
  544. .group-btn {
  545. width: 280rpx;
  546. height: 80rpx;
  547. background: #6499FF;
  548. border-radius: 40rpx 0rpx 0rpx 40rpx;
  549. display: flex;
  550. flex-direction: column;
  551. justify-content: space-around;
  552. .label {
  553. font-weight: 600;
  554. font-size: 28rpx;
  555. color: #FFFFFF;
  556. }
  557. .price {
  558. font-size: 24rpx;
  559. color: #FFFFFF;
  560. }
  561. }
  562. .buy-btn.none {
  563. filter: grayscale(1);
  564. }
  565. .buy-btn {
  566. width: 344rpx;
  567. // width: 560rpx;
  568. height: 80rpx;
  569. background: #3B83FF;
  570. border-radius: 40rpx;
  571. // border-radius: 0rpx 40rpx 40rpx 0rpx;
  572. display: flex;
  573. flex-direction: column;
  574. justify-content: space-around;
  575. &:nth-child(1) {
  576. background: transparent;
  577. border: 1rpx solid #3B83FF;
  578. .label {
  579. color: #3B83FF;
  580. }
  581. }
  582. .label {
  583. font-weight: 600;
  584. font-size: 28rpx;
  585. color: #FFFFFF;
  586. }
  587. .price {
  588. font-size: 24rpx;
  589. color: #FFFFFF;
  590. }
  591. }
  592. }
  593. }
  594. }
  595. </style>