activityDetail.vue 16 KB

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