activityDetail.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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. Toast.fail('您已报名,请勿重复报名');
  224. return
  225. }
  226. uni.navigateTo({url: `/subPages/activityDetail/activitySave?activityId=${ this.activityId}`,})
  227. },
  228. getActivityDetail() {
  229. getActivityDetail({id: this.activityId}).then(({data}) => {
  230. this.activityInfo = data
  231. // 计算 activityInfo.entry_end 格式是2025-01-20 20:00:00这样的 到现在时间的时间戳 毫秒
  232. const entryEnd = new Date(data.entry_end.replace(' ', 'T'));
  233. this.entry_end = entryEnd.getTime();// 我想获取 现在到entryEnd时间戳
  234. const now = new Date().getTime();
  235. // 计算从现在到 entryEnd 的时间差(毫秒)
  236. this.entry_end = entryEnd.getTime() - now;
  237. this.entry_num = data.entry_num?data.entry_num:0
  238. this.entry_max = data.entry_max?data.entry_max:0
  239. this.entry_balance=this.entry_max-this.entry_num
  240. this.activityInfo.start_time = (new Date(this.activityInfo.start_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  241. this.activityInfo.end_time = (new Date(this.activityInfo.end_time.replace(' ', 'T'))).toISOString().slice(0, 16).replace('T', ' ');
  242. this.activityInfo.entry_end = entryEnd.toISOString().slice(0, 16).replace('T', ' ');
  243. if (data.entry_info != []&&data.entry_info.id) {
  244. this.is_entry=true
  245. }
  246. if (data.entry_num&&data.entry_num>0){
  247. if (data.entry_num>5){
  248. this.entry_num=5
  249. }else{
  250. this.entry_num=data.entry_num
  251. }
  252. for (let i = 0; i < this.entry_num; i++) {
  253. // 生成 1 到 4 之间的随机数
  254. const randomNum = Math.floor(Math.random() * 4)+1
  255. this.remainingImages.push("/static/tx-"+randomNum+".png");
  256. }
  257. }
  258. // 修正 activityInfo.content 中的 src 属性值
  259. if (this.activityInfo.content) {
  260. this.activityInfo.content = this.activityInfo.content.replace(/\/apihttps:/g, 'https:');
  261. }
  262. // 修正 activityInfo.content 中的 src 属性值
  263. if (this.activityInfo.content) {
  264. this.activityInfo.content = this.activityInfo.content.replace(/\/apihttps:/g, 'https:');
  265. // 使用正则表达式匹配和修改 img 标签的 style 属性
  266. this.activityInfo.content = this.activityInfo.content.replace(/<img([^>]*)>/gi, (match, attributes) => {
  267. // 检查是否已经存在 style 属性
  268. if (attributes.includes('style')) {
  269. // 如果存在 style 属性,添加 width: 100%;
  270. return match.replace(/style="([^"]*)"/i, (styleMatch, styleContent) => {
  271. if (!styleContent.includes('width: 100%')) {
  272. return `style="${styleContent}; width: 100%;"`;
  273. }
  274. return styleMatch;
  275. });
  276. } else {
  277. // 如果不存在 style 属性,添加 style="width: 100%;"
  278. return match.replace(/<img/i, '<img style="width: 100%;"');
  279. }
  280. });
  281. }
  282. // 确保在数据更新后调用 setImgWidth
  283. this.$nextTick(() => {
  284. this.setImgWidth();
  285. });
  286. });
  287. },
  288. setImgWidth() {
  289. this.$nextTick(() => {
  290. if (this.$refs.activityContent) {
  291. const imgElements = this.$refs.activityContent.querySelectorAll('img');
  292. imgElements.forEach(img => {
  293. img.style.width = '100%';
  294. });
  295. } else {
  296. console.log(this.$refs)
  297. }
  298. });
  299. },
  300. getStyles(index=0) {
  301. let le =28
  302. let py=30
  303. if (this.entry_num%2==1){
  304. py+= 224/2-(84/2)-(le*Math.floor(this.entry_num / 2 ))-le/2
  305. }else{
  306. py+=224/2-(84/2)-(le*this.entry_num/2)
  307. }
  308. let right= index*le+py
  309. var newVar = {
  310. position: 'absolute',
  311. width: '84rpx',
  312. height: '84rpx',
  313. borderRadius: '84rpx',
  314. top: '30rpx',
  315. right: right+'rpx',
  316. };
  317. return newVar
  318. },
  319. toJump( index) {
  320. if(index==1){
  321. uni.switchTab({
  322. url:'/pages/home/index'
  323. });
  324. }else if(index==2){
  325. if (!this.is_entry){
  326. Toast.fail('你暂未报名,无法查询报名信息!');
  327. return
  328. }
  329. uni.navigateTo({url: `/subPages/activityDetail/activitySave?activityId=${ this.activityId}`,})
  330. }
  331. },
  332. },
  333. };
  334. </script>
  335. <style lang="scss" scoped>
  336. .common-page {
  337. height: 100%;
  338. padding: 30rpx;
  339. }
  340. .huodong-ccontent {
  341. position: relative; /* 相对定位 */
  342. width: 650rpx;
  343. padding: 0rpx;
  344. margin: 30rpx auto;
  345. margin-bottom: 0;
  346. padding: 30rpx;
  347. background: #FFFFFF;
  348. border-radius: 16rpx 16rpx 16rpx 16rpx;
  349. .baoming-num{
  350. font-family: 苹方, 苹方;
  351. font-weight: 400;
  352. font-size: 24rpx;
  353. color: #333333;
  354. line-height: 32rpx;
  355. font-style: normal;
  356. text-transform: none;
  357. span{
  358. font-family: D-DIN, D-DIN;
  359. font-weight: 700;
  360. font-size: 36rpx;
  361. color: #C29556;
  362. line-height: 40rpx;
  363. text-align: left;
  364. font-style: normal;
  365. text-transform: none;
  366. }
  367. }
  368. }
  369. .baoming-num2{
  370. font-family: 苹方, 苹方;
  371. font-weight: 400;
  372. font-size: 24rpx;
  373. color: #888888;
  374. line-height: 32rpx;
  375. text-align: center;
  376. font-style: normal;
  377. text-transform: none;
  378. }
  379. .remaining-seats-images {
  380. display: flex;
  381. gap: 10rpx;
  382. position: absolute;
  383. top: 30rpx;
  384. right: 30rpx;
  385. }
  386. .activity-content {
  387. margin-top: 30 rp;
  388. .activity-title {
  389. font-family: PingFang SC, PingFang SC;
  390. font-weight: 400;
  391. font-size: 32rpx;
  392. color: #333333;
  393. line-height: 40rpx;
  394. text-align: left;
  395. font-style: normal;
  396. text-transform: none;
  397. font-weight: bold;
  398. margin-bottom: 16rpx;
  399. }
  400. .activity-date {
  401. background: #F4F4F4;
  402. border-radius: 16rpx 16rpx 16rpx 16rpx;
  403. width: 630rpx;
  404. height: 68rpx;
  405. padding-left: 20rpx;
  406. // 垂直居中
  407. display: flex;
  408. align-items: center;
  409. &-text {
  410. font-family: 苹方, 苹方;
  411. font-weight: 400;
  412. font-size: 24rpx;
  413. color: #777777;
  414. line-height: 36rpx;
  415. text-align: center;
  416. font-style: normal;
  417. text-transform: none;
  418. margin: 0 32rpx 0 24rpx;
  419. }
  420. }
  421. .activity-start-time {
  422. // 垂直居中
  423. display: flex;
  424. align-items: center;
  425. width: 650rpx;
  426. font-family: 苹方, 苹方;
  427. font-weight: 400;
  428. font-size: 24rpx;
  429. color: #777777;
  430. line-height: 36rpx;
  431. font-style: normal;
  432. text-transform: none;
  433. }
  434. .activity-describe {
  435. // 垂直居中
  436. display: flex;
  437. width: 650rpx;
  438. font-family: 苹方, 苹方;
  439. font-weight: 400;
  440. font-size: 24rpx;
  441. color: #777777;
  442. line-height: 36rpx;
  443. font-style: normal;
  444. text-transform: none;
  445. }
  446. .activity-price {
  447. font-family: 苹方, 苹方;
  448. font-weight: 400;
  449. font-size: 36rpx;
  450. color: #C29556;
  451. line-height: 40rpx;
  452. text-align: left;
  453. font-style: normal;
  454. text-transform: none;
  455. margin-bottom: 30rpx;
  456. }
  457. .activity-stats-and-button {
  458. display: flex;
  459. align-items: center;
  460. justify-content: space-between;
  461. height: 128rpx;
  462. }
  463. .activity-stats {
  464. width: 330rpx;
  465. font-size: 24rpx;
  466. color: #666666;
  467. }
  468. /* 水平分割线 */
  469. .horizontal-line {
  470. width: 630rpx;
  471. height: 0rpx;
  472. border: 1rpx dashed #DDDDDD;
  473. margin: 20rpx 0 0rpx 0;
  474. }
  475. }
  476. /* 分割线样式 */
  477. .separator {
  478. height: 1px;
  479. background-color: #e0e0e0;
  480. margin: 20rpx 0;
  481. }
  482. .bottom-navigation{
  483. position: fixed;
  484. // 文字垂直居中
  485. display: flex;
  486. align-items: center;
  487. justify-content: center;
  488. bottom: 0;
  489. height: 100rpx;
  490. width: calc(100% - 40rpx);
  491. background: #FFFFFF;
  492. box-shadow: 0rpx -2rpx 0rpx 0rpx #F1F3F6;
  493. border-radius: 24rpx 24rpx 0rpx 0rpx;
  494. border: 0rpx solid #979797;
  495. padding: 20rpx 20rpx 68rpx 20rpx ;
  496. &-div{
  497. height: 76rpx;
  498. width: 404rpx;
  499. // 文字垂直居中
  500. display: flex;
  501. align-items: center;
  502. padding-left: 30rpx;
  503. span{
  504. font-family: PingFang SC, PingFang SC;
  505. font-weight: 400;
  506. font-size: 20rpx;
  507. color: #333333;
  508. line-height: 32rpx;
  509. text-align: left;
  510. font-style: normal;
  511. text-transform: none;
  512. }
  513. }
  514. .activity-button {
  515. width: 264rpx;
  516. height: 80rpx;
  517. background: linear-gradient(315deg, #CA9359 0%, #E2B98E 100%);
  518. border-radius: 292rpx 292rpx 292rpx 292rpx;
  519. font-family: PingFang SC, PingFang SC;
  520. font-weight: 400;
  521. font-size: 28rpx;
  522. color: #FFFFFF;
  523. line-height: 36rpx;
  524. text-align: center;
  525. font-style: normal;
  526. text-transform: none;
  527. // 文字垂直居中
  528. display: flex;
  529. align-items: center;
  530. justify-content: center;
  531. }
  532. }
  533. /* 设置 v-html 渲染的内容中的 img 标签宽度为 100% */
  534. [v-html] img {
  535. width: 100%!important;
  536. }
  537. /* 定义 CSS 变量 */
  538. :root {
  539. --nav-bar-icon-color: black;
  540. --nav-bar-arrow-size: 16px;
  541. --tab-font-size: 28rpx;
  542. }
  543. .activity-content-title {
  544. margin: 30rpx auto;
  545. width: 680rpx;
  546. // 垂直居中
  547. font-family: PingFang SC, PingFang SC;
  548. font-weight: 400;
  549. font-size: 28rpx;
  550. color: #333333;
  551. line-height: 40rpx;
  552. font-style: normal;
  553. text-transform: none;
  554. margin-bottom: 20rpx;
  555. // 加粗
  556. font-weight: bold;
  557. }
  558. /* 确保 van-nav-bar 内部的内容能够正确适应新的高度 */
  559. /deep/ .van-nav-bar__title {
  560. font-family: PingFang SC, PingFang SC !important;
  561. font-weight: 400 !important;
  562. font-size: 36rpx !important;
  563. color: #333333 !important;
  564. text-align: center;
  565. // 加粗
  566. // font-weight: bold;
  567. }
  568. /deep/ .van-nav-bar__content {
  569. text-align: center;
  570. }
  571. #activity-content img{
  572. width: 100%!important;
  573. }
  574. /* 添加 van-tab 标题的字体大小样式 */
  575. /deep/ .van-tab__text {
  576. font-family: PingFang SC, PingFang SC;
  577. font-weight: 400;
  578. font-size: 28rpx;
  579. }
  580. </style>