activityDetail.vue 17 KB

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