activityDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <view style="height: 100%; background: #F8F9FA;">
  3. <van-image
  4. class="huodongText2-img"
  5. height="360rpx"
  6. :src="activityInfo.pic"
  7. width="100%"
  8. style="display: flex;align-items: center;"
  9. />
  10. <view class="huodong-ccontent" >
  11. <view class="activity-content">
  12. <view class="activity-title">{{ activityInfo.name }}</view>
  13. <view class="activity-price"><span style="font-size: 24rpx">¥&nbsp;</span>{{ activityInfo.fee }}</view>
  14. <view class="activity-date">
  15. <van-image
  16. class="huodongText2-img"
  17. height="28rpx"
  18. src="/static/hd-time.png"
  19. width="28rpx"
  20. style="display: flex;align-items: center;"
  21. />
  22. <view class="activity-date-text">
  23. 距报名截止仅剩:
  24. </view>
  25. <van-count-down :time="entry_end" format="DD 天 HH 时 mm 分 ss 秒"/>
  26. </view>
  27. <view class="activity-start-time" style="margin-top: 40rpx;">
  28. <van-image
  29. height="28rpx"
  30. src="/static/huodong-a.png"
  31. width="28rpx"
  32. style="display: flex;align-items: center;"
  33. />
  34. <view style="margin-left: 16rpx; width: 100rpx;margin-right: 30rpx;">
  35. 活动时间
  36. </view>
  37. <view style="color: #444444;width: 474rpx">
  38. {{ activityInfo.start_time }}&nbsp;到&nbsp;{{ activityInfo.end_time }}
  39. </view>
  40. </view>
  41. <view class="activity-start-time" style="margin-top: 30rpx;">
  42. <van-image
  43. height="28rpx"
  44. src="/static/hd-if-b.png"
  45. width="28rpx"
  46. style="display: flex;align-items: center;"
  47. />
  48. <view style="margin-left: 16rpx; width: 100rpx;margin-right: 30rpx;">
  49. 活动地点
  50. </view>
  51. <view style="color: #444444;width: 474rpx ">
  52. {{ activityInfo.address }}
  53. </view>
  54. </view>
  55. <view class="activity-describe" style="margin-top: 30rpx; ">
  56. <bm-view style="height:28rpx;width:28rpx;padding-top: 5rpx; ">
  57. <van-image
  58. height="28rpx"
  59. src="/static/hd-if-c.png"
  60. width="28rpx"
  61. />
  62. </bm-view>
  63. <view style="margin-left: 16rpx; width: 100rpx;margin-right: 30rpx;">
  64. 活动描述
  65. </view>
  66. <view style="color: #444444; width: 474rpx">
  67. {{ activityInfo.remark }}
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <view class="huodong-ccontent" style="height: 80rpx;display: flex; position: relative; /* 相对定位 */">
  73. <view>
  74. <view class="baoming-num">
  75. <span >{{activityInfo.entry_num}} </span> 人已报名
  76. </view >
  77. <view class="baoming-num2" v-if="activityInfo.entry_max>0">
  78. 剩余{{ entry_balance }}个名额
  79. </view>
  80. <view class="baoming-num2" v-else>
  81. 人数无限制
  82. </view>
  83. </view>
  84. <view :style="[getStyles(index)]" v-for="(image, index) in remainingImages" :key="index">
  85. <van-image
  86. height="84rpx"
  87. :src="image"
  88. width="84rpx"
  89. round
  90. />
  91. </view>
  92. </view>
  93. <view class="activity-content-title">
  94. 报名信息
  95. </view>
  96. <view id="activity-content" ref="activityContent" style="width: 95%;margin: 0 auto;" v-html="activityInfo.content">
  97. </view>
  98. <view style="width: 100%;height: 165rpx" > </view>
  99. <van-toast id="van-toast"/>
  100. <view class="bottom-navigation">
  101. <view class="bottom-navigation-div">
  102. <view style="width: 40rpx;margin-right: 30rpx" @click="toJump( 1)" >
  103. <van-image
  104. height="36rpx"
  105. src="/static/hd-icon-a.png"
  106. width="36rpx"
  107. style="display: flex;align-items: center; justify-content: center;"
  108. />
  109. <span>
  110. 首页
  111. </span>
  112. </view>
  113. <view style="width: 80rpx;margin-right: 30rpx" @click="toJump( 2)" >
  114. <van-image
  115. height="36rpx"
  116. src="/static/hd-icon-b.png"
  117. width="36rpx"
  118. style="display: flex;align-items: center; justify-content: center;"
  119. />
  120. <span>
  121. 报名信息
  122. </span>
  123. </view>
  124. <view style="width: 40rpx;position:relative" open-type="contact">
  125. <van-image
  126. height="36rpx"
  127. src="/static/hd-icon-c.png"
  128. width="36rpx"
  129. style="display: flex;align-items: center; justify-content: center;"
  130. />
  131. <span>
  132. 客服
  133. </span>
  134. <button style="position: absolute;width: 100%;height: 100%;z-index: 999;opacity: 0;top:0;"
  135. open-type="contact" ></button>
  136. </view>
  137. </view>
  138. <button class="activity-button" @click="handleRegister">立即报名</button>
  139. </view>
  140. </view>
  141. </template>
  142. <script>
  143. import tabbarCom from "@/components/tabbar/tabbar.vue";
  144. import {getConfigData} from '@/common/api/common.js';
  145. import {getActivityDetail} from "@/common/api/activity";
  146. import Toast from "../../wxcomponents/vant/dist/toast/toast";
  147. export default {
  148. components: {
  149. tabbarCom,
  150. },
  151. data() {
  152. return {
  153. page: 1,
  154. pageSize: 10,
  155. total: 0,
  156. search: "",
  157. sort: "",
  158. cateid: "",
  159. subCateId: '',
  160. sortType: "",
  161. data: [],
  162. active: 0,
  163. activityTypeList: [],
  164. activityId: 0,
  165. progressPercentage: 24.01,
  166. progressText: '24.01%',
  167. enrolledCount: 23,
  168. totalSlots: 100,
  169. activityInfo: {},
  170. entry_end: 0,
  171. remainingImages: [],
  172. entry_num:0,
  173. entry_max:0,
  174. entry_balance:0,
  175. is_entry:false,
  176. };
  177. },
  178. onLoad: function (option) {
  179. this.activityId = option.activityId
  180. this.getActivityDetail()
  181. this.setImgWidth()
  182. },
  183. onShow() {
  184. this.$nextTick(() => {
  185. });
  186. },
  187. onReachBottom() {
  188. },
  189. onShareAppMessage(res) {
  190. let params = {};
  191. params = {
  192. activityId: this.activityId
  193. };
  194. let configs = uni.getStorageSync('configs') || {};
  195. return {
  196. title: configs.shop_share_title,
  197. imageUrl: configs.shop_share_img,
  198. path: `/subPages/activityDetail/activityDetail${this.$stringPageOptions(params)}`
  199. };
  200. },
  201. onShareTimeline(res) {
  202. let params = {};
  203. params = {
  204. activityId: this.activityId
  205. };
  206. let configs = uni.getStorageSync('configs') || {};
  207. return {
  208. title: configs.shop_share_title,
  209. imageUrl: configs.shop_share_img,
  210. path: `/subPages/activityDetail/activityDetail${this.$stringPageOptions(params)}`
  211. };
  212. },
  213. computed: {},
  214. watch: {},
  215. methods: {
  216. getConfigDatalist() {
  217. getConfigData({dict_id: 36}).then(({data}) => {
  218. this.activityTypeList = data.reverse();
  219. });
  220. },
  221. handleRegister() {
  222. if (this.is_entry){
  223. uni.showToast({
  224. title: '您已报名,请勿重复报名!',
  225. icon: 'none'
  226. })
  227. return
  228. }
  229. uni.navigateTo({url: `/subPages/activityDetail/activitySave?activityId=${ this.activityId}`,})
  230. },
  231. getActivityDetail() {
  232. getActivityDetail({id: this.activityId}).then(({data}) => {
  233. this.activityInfo = data
  234. // 计算 activityInfo.entry_end 格式是2025-01-20 20:00:00这样的 到现在时间的时间戳 毫秒
  235. const entryEnd = new Date(data.entry_end.replace(' ', 'T'));
  236. this.entry_end = entryEnd.getTime();// 我想获取 现在到entryEnd时间戳
  237. const now = new Date().getTime();
  238. // 计算从现在到 entryEnd 的时间差(毫秒)
  239. this.entry_end = entryEnd.getTime() - now;
  240. this.entry_num = data.entry_num?data.entry_num:0
  241. this.entry_max = data.entry_max?data.entry_max:0
  242. this.entry_balance=this.entry_max-this.entry_num
  243. this.activityInfo.start_time = (new Date(this.activityInfo.start_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  244. this.activityInfo.end_time = (new Date(this.activityInfo.end_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  245. this.activityInfo.entry_end = entryEnd.toISOString().slice(0, 16).replace('T', ' ');
  246. if (data.entry_info &&data.entry_info[data.entry_info.length-1]&&data.entry_info[data.entry_info.length-1].id &&!( data.entry_info[data.entry_info.length-1].status==0|| data.entry_info[data.entry_info.length-1].status==-1)) {
  247. this.is_entry=true
  248. }
  249. if (data.entry_num&&data.entry_num>0){
  250. if (data.entry_num>5){
  251. this.entry_num=5
  252. }else{
  253. this.entry_num=data.entry_num
  254. }
  255. for (let i = 0; i < this.entry_num; i++) {
  256. // 生成 1 到 4 之间的随机数
  257. const randomNum = Math.floor(Math.random() * 4)+1
  258. this.remainingImages.push("/static/tx-"+randomNum+".png");
  259. }
  260. }
  261. // 修正 activityInfo.content 中的 src 属性值
  262. if (this.activityInfo.content) {
  263. this.activityInfo.content = this.activityInfo.content.replace(/\/apihttps:/g, 'https:');
  264. }
  265. // 修正 activityInfo.content 中的 src 属性值
  266. if (this.activityInfo.content) {
  267. this.activityInfo.content = this.activityInfo.content.replace(/\/apihttps:/g, 'https:');
  268. // 使用正则表达式匹配和修改 img 标签的 style 属性
  269. this.activityInfo.content = this.activityInfo.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  270. // 检查是否已经存在 style 属性
  271. if (attributes.includes('style')) {
  272. // 如果存在 style 属性,添加 width: 100%;
  273. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  274. if (!styleContent.includes('width: 100%')) {
  275. return `style="${styleContent}; width: 100%;"`;
  276. }
  277. return styleMatch;
  278. });
  279. } else {
  280. // 如果不存在 style 属性,添加 style="width: 100%;"
  281. return match.replace(/<img/i, '<img style="width: 100%;"');
  282. }
  283. });
  284. }
  285. // 确保在数据更新后调用 setImgWidth
  286. this.$nextTick(() => {
  287. this.setImgWidth();
  288. });
  289. });
  290. },
  291. setImgWidth() {
  292. this.$nextTick(() => {
  293. if (this.$refs.activityContent) {
  294. const imgElements = this.$refs.activityContent.querySelectorAll('img');
  295. imgElements.forEach(img => {
  296. img.style.width = '100%';
  297. });
  298. } else {
  299. console.log(this.$refs)
  300. }
  301. });
  302. },
  303. getStyles(index=0) {
  304. let le =28
  305. let py=30
  306. if (this.entry_num%2==1){
  307. py+= 224/2-(84/2)-(le*Math.floor(this.entry_num / 2 ))-le/2
  308. }else{
  309. py+=224/2-(84/2)-(le*this.entry_num/2)
  310. }
  311. let right= index*le+py
  312. var newVar = {
  313. position: 'absolute',
  314. width: '84rpx',
  315. height: '84rpx',
  316. borderRadius: '84rpx',
  317. top: '30rpx',
  318. right: right+'rpx',
  319. };
  320. return newVar
  321. },
  322. toJump( index) {
  323. if(index===1){
  324. uni.switchTab({
  325. url:'/pages/home/index'
  326. });
  327. }else if(index===2){
  328. console.log('toJump',this.activityInfo)
  329. if (!this.is_entry){
  330. Toast.fail('你暂未报名,无法查询报名信息!');
  331. return
  332. }
  333. uni.navigateTo({url: `/subPages/activityDetail/activitySave?activityId=${ this.activityId}`,})
  334. }
  335. },
  336. },
  337. };
  338. </script>
  339. <style lang="scss" scoped>
  340. .common-page {
  341. height: 100%;
  342. padding: 30rpx;
  343. }
  344. .huodong-ccontent {
  345. position: relative; /* 相对定位 */
  346. width: 650rpx;
  347. padding: 0rpx;
  348. margin: 30rpx auto;
  349. margin-bottom: 0;
  350. padding: 30rpx;
  351. background: #FFFFFF;
  352. border-radius: 16rpx 16rpx 16rpx 16rpx;
  353. .baoming-num{
  354. font-family: 苹方, 苹方;
  355. font-weight: 400;
  356. font-size: 24rpx;
  357. color: #333333;
  358. line-height: 32rpx;
  359. font-style: normal;
  360. text-transform: none;
  361. span{
  362. font-family: D-DIN, D-DIN;
  363. font-weight: 700;
  364. font-size: 36rpx;
  365. color: #C29556;
  366. line-height: 40rpx;
  367. text-align: left;
  368. font-style: normal;
  369. text-transform: none;
  370. }
  371. }
  372. }
  373. .baoming-num2{
  374. font-family: 苹方, 苹方;
  375. font-weight: 400;
  376. font-size: 24rpx;
  377. color: #888888;
  378. line-height: 32rpx;
  379. text-align: center;
  380. font-style: normal;
  381. text-transform: none;
  382. }
  383. .remaining-seats-images {
  384. display: flex;
  385. gap: 10rpx;
  386. position: absolute;
  387. top: 30rpx;
  388. right: 30rpx;
  389. }
  390. .activity-content {
  391. margin-top: 30 rp;
  392. .activity-title {
  393. font-family: PingFang SC, PingFang SC;
  394. font-weight: 400;
  395. font-size: 32rpx;
  396. color: #333333;
  397. line-height: 40rpx;
  398. text-align: left;
  399. font-style: normal;
  400. text-transform: none;
  401. font-weight: bold;
  402. margin-bottom: 16rpx;
  403. }
  404. .activity-date {
  405. background: #F4F4F4;
  406. border-radius: 16rpx 16rpx 16rpx 16rpx;
  407. width: 630rpx;
  408. height: 68rpx;
  409. padding-left: 20rpx;
  410. // 垂直居中
  411. display: flex;
  412. align-items: center;
  413. &-text {
  414. font-family: 苹方, 苹方;
  415. font-weight: 400;
  416. font-size: 24rpx;
  417. color: #777777;
  418. line-height: 36rpx;
  419. text-align: center;
  420. font-style: normal;
  421. text-transform: none;
  422. margin: 0 32rpx 0 24rpx;
  423. }
  424. }
  425. .activity-start-time {
  426. // 垂直居中
  427. display: flex;
  428. align-items: center;
  429. width: 650rpx;
  430. font-family: 苹方, 苹方;
  431. font-weight: 400;
  432. font-size: 24rpx;
  433. color: #777777;
  434. line-height: 36rpx;
  435. font-style: normal;
  436. text-transform: none;
  437. }
  438. .activity-describe {
  439. // 垂直居中
  440. display: flex;
  441. width: 650rpx;
  442. font-family: 苹方, 苹方;
  443. font-weight: 400;
  444. font-size: 24rpx;
  445. color: #777777;
  446. line-height: 36rpx;
  447. font-style: normal;
  448. text-transform: none;
  449. }
  450. .activity-price {
  451. font-family: 苹方, 苹方;
  452. font-weight: 400;
  453. font-size: 36rpx;
  454. color: #C29556;
  455. line-height: 40rpx;
  456. text-align: left;
  457. font-style: normal;
  458. text-transform: none;
  459. margin-bottom: 30rpx;
  460. }
  461. .activity-stats-and-button {
  462. display: flex;
  463. align-items: center;
  464. justify-content: space-between;
  465. height: 128rpx;
  466. }
  467. .activity-stats {
  468. width: 330rpx;
  469. font-size: 24rpx;
  470. color: #666666;
  471. }
  472. /* 水平分割线 */
  473. .horizontal-line {
  474. width: 630rpx;
  475. height: 0rpx;
  476. border: 1rpx dashed #DDDDDD;
  477. margin: 20rpx 0 0rpx 0;
  478. }
  479. }
  480. /* 分割线样式 */
  481. .separator {
  482. height: 1px;
  483. background-color: #e0e0e0;
  484. margin: 20rpx 0;
  485. }
  486. .bottom-navigation{
  487. position: fixed;
  488. // 文字垂直居中
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. bottom: 0;
  493. height: 100rpx;
  494. width: calc(100% - 40rpx);
  495. background: #FFFFFF;
  496. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  497. border-radius: 24rpx 24rpx 0rpx 0rpx;
  498. border: 0rpx solid #979797;
  499. padding: 20rpx 20rpx 68rpx 20rpx ;
  500. &-div{
  501. height: 76rpx;
  502. padding-top: 10rpx;
  503. width: 404rpx;
  504. // 文字垂直居中
  505. display: flex;
  506. align-items: center;
  507. padding-left: 30rpx;
  508. span{
  509. font-family: PingFang SC, PingFang SC;
  510. font-weight: 400;
  511. font-size: 20rpx;
  512. color: #333333;
  513. line-height: 32rpx;
  514. text-align: left;
  515. font-style: normal;
  516. text-transform: none;
  517. }
  518. }
  519. .activity-button {
  520. width: 264rpx;
  521. height: 80rpx;
  522. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  523. border-radius: 292rpx 292rpx 292rpx 292rpx;
  524. font-family: PingFang SC, PingFang SC;
  525. font-weight: 400;
  526. font-size: 28rpx;
  527. color: #FFFFFF;
  528. line-height: 36rpx;
  529. text-align: center;
  530. font-style: normal;
  531. text-transform: none;
  532. // 文字垂直居中
  533. display: flex;
  534. align-items: center;
  535. justify-content: center;
  536. }
  537. }
  538. /* 设置 v-html 渲染的内容中的 img 标签宽度为 100% */
  539. [v-html] img {
  540. width: 100%!important;
  541. }
  542. /* 定义 CSS 变量 */
  543. :root {
  544. --nav-bar-icon-color: black;
  545. --nav-bar-arrow-size: 16px;
  546. --tab-font-size: 28rpx;
  547. }
  548. .activity-content-title {
  549. margin: 30rpx auto;
  550. width: 680rpx;
  551. // 垂直居中
  552. font-family: PingFang SC, PingFang SC;
  553. font-weight: 400;
  554. font-size: 28rpx;
  555. color: #333333;
  556. line-height: 40rpx;
  557. font-style: normal;
  558. text-transform: none;
  559. margin-bottom: 20rpx;
  560. // 加粗
  561. font-weight: bold;
  562. }
  563. /* 确保 van-nav-bar 内部的内容能够正确适应新的高度 */
  564. /deep/ .van-nav-bar__title {
  565. font-family: PingFang SC, PingFang SC !important;
  566. font-weight: 400 !important;
  567. font-size: 36rpx !important;
  568. color: #333333 !important;
  569. text-align: center;
  570. // 加粗
  571. // font-weight: bold;
  572. }
  573. /deep/ .van-nav-bar__content {
  574. text-align: center;
  575. }
  576. #activity-content img{
  577. width: 100%!important;
  578. }
  579. /* 添加 van-tab 标题的字体大小样式 */
  580. /deep/ .van-tab__text {
  581. font-family: PingFang SC, PingFang SC;
  582. font-weight: 400;
  583. font-size: 28rpx;
  584. }
  585. </style>