activity_deatil.vue 15 KB

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