activity_deatil.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <template>
  2. <view class="content">
  3. <view class="header">
  4. <view class="title-read">
  5. <view class="title">
  6. {{ model.title }}
  7. </view>
  8. <view class="read">浏览量 {{ model.read }}</view>
  9. </view>
  10. <!-- <view class="header-image">
  11. <image :src="model.url" alt="" />
  12. </view> -->
  13. </view>
  14. <view class="active-deatil">
  15. <ul>
  16. <li>
  17. <p class="name">活动时间</p>
  18. <p class="deatil-content">{{ model.date }}</p>
  19. </li>
  20. <li>
  21. <p class="name">活动类型</p>
  22. <p class="deatil-content">{{ model.type == 1 ? "线上" : "线下" }}</p>
  23. </li>
  24. <li>
  25. <p class="name">主办方</p>
  26. <p class="deatil-content">{{ model.way }}</p>
  27. </li>
  28. </ul>
  29. </view>
  30. <view class="rich">
  31. <activityRichCard :model="textModel" :isFold="true" />
  32. </view>
  33. <view class="share-box">
  34. <view class="share">
  35. <button class="share" @click="shareActive()" open-type="share" style="background: transparent;">
  36. <image src="../../static/share_icon.svg"></image>
  37. </button>
  38. <view class="shareCount">{{ model.share }}</view>
  39. </view>
  40. <view class="button">
  41. <button
  42. v-if="!isJoin"
  43. @click="subscribeActivity()"
  44. :disabled="!(model.status == '待开始' && model.type == 2)"
  45. :class="{
  46. start: model.status == '待开始' && model.type == 2,
  47. begun: model.status == '已开始',
  48. ended: model.status == '已结束',
  49. falseStart: model.status == '待开始' && model.type == 1,
  50. }"
  51. >
  52. {{ model.activiteState }}
  53. </button>
  54. <button disabled="true" class="ended" v-if="isJoin">已报名</button>
  55. </view>
  56. <!-- "status":"活动状态 0:待开始;1:已开始; 2:已结束
  57. "type":"活动类型 1:线上;2 线下"} -->
  58. </view>
  59. <uni-popup ref="popup" :mask-click="false">
  60. <view class="popup-box">
  61. <view>
  62. <view class="popup-title">活动报名信息填写</view>
  63. <view class="popup-content-box">
  64. <view class="popup-content">
  65. <view class="popup-type" v-for="(info,index) in activityInfoList" :key="info.id">
  66. <view><text style="color: red;">*</text>{{info.name}}</view>
  67. <input type="text" v-model="info.value" v-if="info.name!=='性别'&&info.name!=='年龄'"/>
  68. <input type="number" v-model="info.value" v-else-if="info.name==='年龄'"/>
  69. <radio-group v-else-if="info.name==='性别'" @change="checkboxChange">
  70. <label class="radio" style="margin-right: 20rpx;"><radio value="男" checked="true" color="#FFCC33" style="transform:scale(0.7)" />男</label>
  71. <label class="radio"><radio value="女" color="#FFCC33" style="transform:scale(0.7)" />女</label>
  72. </radio-group>
  73. </view>
  74. <!-- <view class="popup-type">
  75. <view>性别</view><input type="text" value="" />
  76. </view>
  77. <view class="popup-type">
  78. <view>年龄</view><input type="number" value="" />
  79. </view>
  80. <view class="popup-type">
  81. <view>工作单位</view><input type="text" value="" />
  82. </view>
  83. <view class="popup-type">
  84. <view>职务</view><input type="text" value="" />
  85. </view> -->
  86. </view>
  87. </view>
  88. </view>
  89. <view class="popup-footer">
  90. <button class="popup-cancel" @click="closePopup">取消</button>
  91. <button class="popup-submit" @click="submitInfo">提交</button>
  92. </view>
  93. </view>
  94. </uni-popup>
  95. </view>
  96. </template>
  97. <script>
  98. import md5 from "@/common/md5.js";
  99. import activity_rich_card from "../policy/policy_rich_card";
  100. import uniPopup from "@/components/uni-popup/uni-popup.vue"
  101. export default {
  102. filters: {
  103. formDateTime(value) {
  104. if (value) {
  105. const time = new Date(value * 1000);
  106. const y = time.getFullYear();
  107. const m =
  108. time.getMonth() + 1 < 10
  109. ? "0" + (time.getMonth() + 1)
  110. : time.getMonth() + 1;
  111. const d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
  112. // const h = time.getHours()
  113. // const mm = time.getMinutes();
  114. // const s = time.getSeconds();
  115. return y + "." + m + "." + d;
  116. } else {
  117. return "";
  118. }
  119. },
  120. formDateTimeSecond(value) {
  121. if (value) {
  122. const time = new Date(value * 1000);
  123. // const y = time.getFullYear();
  124. // const m = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1);
  125. // const d = time.getDate() < 10 ? '0' + time.getDate(): time.getDate();
  126. const h =
  127. time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
  128. const mm =
  129. time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
  130. return h + ":" + mm;
  131. } else {
  132. return "";
  133. }
  134. },
  135. },
  136. components: {
  137. activityRichCard: activity_rich_card,
  138. uniPopup
  139. },
  140. data() {
  141. return {
  142. id: "",
  143. isJoin: false,
  144. activityInfoList:[],
  145. sexValue:'男',
  146. model: {
  147. title: "",
  148. read: 123,
  149. url: "",
  150. date: "",
  151. type: 1,
  152. status: 0,
  153. way: "",
  154. share: 0,
  155. activiteState: "",
  156. max_person: "",
  157. person_count: "",
  158. },
  159. textModel: {
  160. title: "活动内容",
  161. text: "",
  162. },
  163. };
  164. },
  165. onLoad(op) {
  166. this.id = op.id;
  167. this.getActivityDeatil();
  168. },
  169. methods: {
  170. checkboxChange(e){
  171. this.sexValue = e.detail.value;
  172. },
  173. shareRequest() {
  174. let md5Sign = md5(
  175. "method=" +
  176. "user" +
  177. "&timestamp=" +
  178. getApp().globalData.globalTimestamp +
  179. "&secret=" +
  180. getApp().globalData.secret
  181. );
  182. let url =
  183. getApp().globalData.shareUrl +
  184. "api/api.php" +
  185. "?method=user&source=activity&action=repost&timestamp=" +
  186. getApp().globalData.globalTimestamp +
  187. "&sign=" +
  188. md5Sign;
  189. uni.request({
  190. url: url,
  191. method: "POST",
  192. header: {
  193. "content-type": "application/x-www-form-urlencoded",
  194. },
  195. data: {
  196. openId: getApp().globalData.open_id,
  197. source_id: this.id,
  198. source: "activity",
  199. },
  200. success: (res) => {
  201. if (res.data.code === 200) {
  202. console.log(res);
  203. this.model.share = this.model.share + 1;
  204. }
  205. },
  206. fail: () => {
  207. console.log("连接失败");
  208. },
  209. });
  210. },
  211. shareActive() {
  212. let that = this;
  213. uni.showShareMenu({
  214. title: that.model.title,
  215. path: "pages/activity/activity_detail?id=" + that.id,
  216. success(res) {
  217. that.shareRequest();
  218. },
  219. });
  220. },
  221. getActivityDeatil() {
  222. let md5Sign = md5(
  223. "method=" +
  224. "activity" +
  225. "&timestamp=" +
  226. getApp().globalData.globalTimestamp +
  227. "&secret=" +
  228. getApp().globalData.secret
  229. );
  230. let url =
  231. getApp().globalData.shareUrl +
  232. "api/api.php" +
  233. "?method=activity&source=activity&action=info_by_id&timestamp=" +
  234. getApp().globalData.globalTimestamp +
  235. "&sign=" +
  236. md5Sign;
  237. let postData = {
  238. id: this.id,
  239. openId: getApp().globalData.open_id,
  240. };
  241. //获取文章
  242. uni.request({
  243. url: url,
  244. method: "POST",
  245. header: {
  246. "content-type": "application/x-www-form-urlencoded",
  247. },
  248. data: postData,
  249. success: (res) => {
  250. if (res.data.code == 200) {
  251. let data = res.data.data;
  252. this.isJoin = data.active ? true : false;
  253. if(data.category_list && data.category_list.length > 0){
  254. this.activityInfoList = data.category_list;
  255. this.activityInfoList.forEach((item)=>{
  256. if(item.name === '性别'){
  257. item.value = '男'
  258. }else {
  259. item.value = '';
  260. }
  261. })
  262. }
  263. this.model.title = data.name;
  264. this.model.read = parseInt(data.base_read_count) + parseInt(data.real_read_count);
  265. this.model.url = getApp().globalData.shareUrl + data.pic_url;
  266. let arr = ["start_time", "end_time"];
  267. let ans = [];
  268. for (const item of arr) {
  269. let time = this.$options.filters["formDateTime"](data[item]);
  270. let timeSecond = this.$options.filters["formDateTimeSecond"](data[item]);
  271. ans.push(time + " " + timeSecond);
  272. }
  273. this.model.date = ans.join(" - ");
  274. this.model.type = data.type;
  275. this.model.status = data.status;
  276. this.model.way = data.sponsor;
  277. this.model.max_person = data.max_person;
  278. this.model.person_count = data.person_count;
  279. this.model.share = parseInt(data.real_repost_count) + parseInt(data.base_repost_count);
  280. if (data.status == '待开始') {
  281. if (data.type == 2) {
  282. this.model.activiteState = "我要参加";
  283. } else {
  284. this.model.activiteState = "活动待开始";
  285. }
  286. } else if (data.status == '已开始') {
  287. this.model.activiteState = "活动进行中";
  288. } else {
  289. this.model.activiteState = "活动已结束";
  290. }
  291. }
  292. this.getRich();
  293. },
  294. fail: () => {
  295. console.log("连接失败");
  296. },
  297. });
  298. },
  299. replaceImg(html) {
  300. let result = html.replace(
  301. /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
  302. function (match, capture) {
  303. if(capture.includes('http')){
  304. return (
  305. "<img src=" +
  306. capture +
  307. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  308. );
  309. }else {
  310. return (
  311. "<img src=" +
  312. getApp().globalData.shareUrl +
  313. capture +
  314. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  315. );
  316. }
  317. }
  318. );
  319. return result;
  320. },
  321. getRich() {
  322. uni.request({
  323. url:
  324. getApp().globalData.shareUrl +
  325. `content/activity/${Math.floor(this.id / 1000)}/${this.id}.html`+'?version='+ Math.random(),
  326. method: "GET",
  327. header: {
  328. "content-type": "application/x-www-form-urlencoded",
  329. },
  330. success: (res) => {
  331. if (res.statusCode === 200) {
  332. this.textModel.text = this.replaceImg(res.data);
  333. }
  334. },
  335. fail: () => {
  336. console.log("连接失败");
  337. },
  338. });
  339. },
  340. subscribeActivity() {
  341. if(!getApp().globalData.user_phone){
  342. uni.showToast({
  343. title: "您还没有登录授权",
  344. duration: 2500,
  345. icon: "none",
  346. });
  347. uni.navigateTo({
  348. url:'/pages/auth/index'
  349. })
  350. }
  351. if (this.model.person_count >= this.model.max_person) {
  352. uni.showToast({
  353. title: "报名人数已达上限",
  354. icon: "error",
  355. duration: 2000,
  356. });
  357. return;
  358. }
  359. if(this.activityInfoList.length > 0 && getApp().globalData.user_phone){
  360. this.open();
  361. }
  362. if(this.activityInfoList.length === 0 && getApp().globalData.user_phone){
  363. this.subscribeFn(this.activityInfoList)
  364. }
  365. },
  366. signUpActivity(infoList) {
  367. let md5Sign = md5(
  368. "method=" +
  369. "activity" +
  370. "&timestamp=" +
  371. getApp().globalData.globalTimestamp +
  372. "&secret=" +
  373. getApp().globalData.secret
  374. );
  375. let url =
  376. getApp().globalData.shareUrl +
  377. "api/api.php" +
  378. "?method=activity&source=activity&action=active&timestamp=" +
  379. getApp().globalData.globalTimestamp +
  380. "&sign=" +
  381. md5Sign;
  382. let postData = {
  383. openId: getApp().globalData.open_id,
  384. id: this.id,
  385. category_json:JSON.stringify(infoList)
  386. };
  387. uni.request({
  388. url: url,
  389. method: "POST",
  390. header: {
  391. "content-type": "application/x-www-form-urlencoded",
  392. },
  393. data: postData,
  394. success: (res) => {
  395. if (res.data.code == 200) {
  396. this.isJoin = true;
  397. uni.showToast({
  398. title: "报名成功",
  399. icon: "none",
  400. duration: 2500,
  401. });
  402. }
  403. },
  404. fail: () => {
  405. console.log("连接失败");
  406. },
  407. });
  408. },
  409. subscribeFn(info){
  410. let that = this;
  411. uni.requestSubscribeMessage({
  412. tmplIds: [
  413. // "bSg5tUWHE4qWDeyK31GBejogT1uRgkuBD1_n2I5ptAc",
  414. // "T_ORLiW2C_UM6nZiEerYAokltHgHRGxWCid8eElujus",
  415. "XPULJQ64YrS-5sAnfMTJj3S9iV8-8X_mb3r_H5dgAgE",
  416. "RWq7TE266RYr8DX2IHZ2F_zKbOnSfZDgh_xovBh0UiI" //测试环境模板id
  417. ],
  418. success(res) {
  419. that.signUpActivity(info);
  420. },
  421. });
  422. },
  423. open() {
  424. this.$refs.popup.open('top')
  425. },
  426. closePopup() {
  427. this.$refs.popup.close()
  428. },
  429. submitInfo(){
  430. let checkFlag = false;
  431. for(let i = 0; i < this.activityInfoList.length; i++){
  432. if(!this.activityInfoList[i].value){
  433. uni.showToast({
  434. title:'请填写' + this.activityInfoList[i].name,
  435. duration:2000,
  436. icon:'none'
  437. })
  438. checkFlag = false;
  439. break;
  440. }else {
  441. checkFlag = true;
  442. }
  443. }
  444. if(checkFlag){
  445. this.activityInfoList.forEach((item)=>{
  446. if(item.name === '性别'){
  447. item.value = this.sexValue;
  448. }
  449. delete item.addtime;
  450. delete item.name;
  451. delete item.parent_id;
  452. delete item.weight;
  453. })
  454. this.$refs.popup.close();
  455. this.subscribeFn(this.activityInfoList)
  456. }
  457. }
  458. },
  459. };
  460. </script>
  461. <style lang="scss" scoped>
  462. .content {
  463. display: flex;
  464. flex-direction: column;
  465. .header {
  466. display: flex;
  467. // height: 150rpx;
  468. padding: 20rpx;
  469. .title-read {
  470. height: 100%;
  471. display: flex;
  472. flex-direction: column;
  473. justify-content: space-evenly;
  474. .title {
  475. font-weight: 600;
  476. letter-spacing: 2rpx;
  477. font-size: 34rpx;
  478. }
  479. .read {
  480. margin-top: 20rpx;
  481. font-size: 26rpx;
  482. color: $uni-text-color-grey;
  483. }
  484. }
  485. .header-image {
  486. height: 100%;
  487. width: 50%;
  488. image {
  489. width: 100%;
  490. height: 100%;
  491. border-radius: 10%;
  492. }
  493. }
  494. }
  495. .active-deatil {
  496. padding: 20rpx;
  497. ul {
  498. padding: 30rpx;
  499. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  500. border-radius: 32rpx;
  501. li {
  502. margin-bottom: 30rpx;
  503. list-style: none;
  504. .name {
  505. margin-bottom: 10rpx;
  506. font-size: 30rpx;
  507. color: $uni-text-color-grey;
  508. }
  509. .deatil-content {
  510. font-size: 28rpx;
  511. }
  512. }
  513. }
  514. }
  515. .rich {
  516. margin-bottom: 150rpx;
  517. padding: 20rpx;
  518. }
  519. .share-box {
  520. box-sizing: border-box;
  521. height: 150rpx;
  522. width: 100%;
  523. align-items: center;
  524. justify-content: space-evenly;
  525. position: fixed;
  526. bottom: 0;
  527. display: flex;
  528. background: #ffffff;
  529. .share {
  530. display: flex;
  531. justify-content: center;
  532. align-items: center;
  533. width: 60rpx;
  534. height: 60rpx;
  535. position: relative;
  536. button::after {
  537. border: none;
  538. }
  539. image {
  540. width: 100%;
  541. height: 100%;
  542. position: absolute;
  543. }
  544. .shareCount {
  545. display: flex;
  546. justify-content: center;
  547. align-items: center;
  548. position: absolute;
  549. top: -20%;
  550. right: -25%;
  551. color: #ffffff;
  552. height: 30rpx;
  553. width: 30rpx;
  554. padding: 3rpx;
  555. font-size: 16rpx;
  556. border-radius: 50%;
  557. background: #fe3637;
  558. }
  559. }
  560. .button {
  561. height: 100rpx;
  562. width: 70%;
  563. display: flex;
  564. justify-content: center;
  565. button {
  566. width: 80%;
  567. height: 90%;
  568. border: 1px solid;
  569. outline: none;
  570. background: none;
  571. }
  572. .start {
  573. //待开始
  574. background-color: #00a8ea;
  575. color: #ffffff;
  576. border-color: none;
  577. }
  578. .begun {
  579. //已开始
  580. border-color: #00a8ea;
  581. color: #00a8ea;
  582. }
  583. .ended {
  584. //已结束
  585. color: #aaaaaa;
  586. border-color: #aaaaaa;
  587. }
  588. .falseStart {
  589. color: #70b603;
  590. border-color: #70b603;
  591. }
  592. }
  593. }
  594. .popup-box {
  595. height: 100%;
  596. display: flex;
  597. flex-direction: column;
  598. justify-content: space-between;
  599. }
  600. .popup-title {
  601. text-align: center;
  602. font-weight: bold;
  603. height: 30px;
  604. border-bottom: 1px solid #d8d8d8;
  605. }
  606. .popup-content {
  607. font-size: 28rpx;
  608. padding: 10rpx 0 10rpx 0;
  609. }
  610. .popup-type {
  611. display: flex;
  612. height: 80rpx;
  613. align-items: center;
  614. view {
  615. width: 25%;
  616. }
  617. input {
  618. border: 1px solid #d7d7d7;
  619. width: 70%;
  620. border-radius: 5rpx;
  621. padding-left: 10rpx;
  622. height: 56rpx;
  623. }
  624. }
  625. .popup-footer {
  626. display: flex;
  627. button{
  628. font-size: 26rpx;
  629. height: 60rpx;
  630. width: 150rpx;
  631. line-height: 60rpx;
  632. color: #FFFFFF;
  633. }
  634. }
  635. .popup-cancel {
  636. background-color: #AAAAAA;
  637. }
  638. .popup-submit {
  639. background-color: #249CD3;
  640. }
  641. }
  642. </style>