activity_deatil.vue 13 KB

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