activity_deatil.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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">
  36. <image src="../../static/share_icon.png"></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(model.status)"
  44. :disabled="!(model.status == 0 && model.type == 2)"
  45. :class="{
  46. start: model.status == 0 && model.type == 2,
  47. begun: model.status == 1,
  48. ended: model.status == 2,
  49. falseStart: model.status == 0 && 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 == 0) {
  233. if (data.type == 2) {
  234. this.model.activiteState = "我要参加";
  235. } else {
  236. this.model.activiteState = "活动待开始";
  237. }
  238. } else if (data.status == 1) {
  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. return (
  256. "<img src=" +
  257. getApp().globalData.shareUrl +
  258. capture +
  259. ' style="max-width:100%;height:auto;display:block;margin:10px 0;"/>'
  260. );
  261. }
  262. );
  263. return result;
  264. },
  265. getRich() {
  266. uni.request({
  267. url:
  268. getApp().globalData.shareUrl +
  269. `content/activity/${Math.floor(this.id / 1000)}/${this.id}.html`,
  270. method: "GET",
  271. header: {
  272. "content-type": "application/x-www-form-urlencoded",
  273. },
  274. success: (res) => {
  275. if (res.statusCode === 200) {
  276. this.textModel.text = this.replaceImg(res.data);
  277. }
  278. },
  279. fail: () => {
  280. console.log("连接失败");
  281. },
  282. });
  283. },
  284. subscribeActivity(status) {
  285. if (this.model.person_count >= this.model.max_person) {
  286. uni.showToast({
  287. title: "报名人数已上限",
  288. icon: "error",
  289. duration: 2000,
  290. });
  291. return;
  292. }
  293. console.log(status);
  294. let that = this;
  295. uni.requestSubscribeMessage({
  296. tmplIds: [
  297. "bSg5tUWHE4qWDeyK31GBejogT1uRgkuBD1_n2I5ptAc",
  298. "T_ORLiW2C_UM6nZiEerYAokltHgHRGxWCid8eElujus",
  299. ],
  300. success(res) {
  301. console.log(res);
  302. that.signUpActivity();
  303. },
  304. });
  305. },
  306. signUpActivity() {
  307. let md5Sign = md5(
  308. "method=" +
  309. "activity" +
  310. "&timestamp=" +
  311. getApp().globalData.globalTimestamp +
  312. "&secret=" +
  313. getApp().globalData.secret
  314. );
  315. let url =
  316. getApp().globalData.shareUrl +
  317. "api/api.php" +
  318. "?method=activity&source=activity&action=active&timestamp=" +
  319. getApp().globalData.globalTimestamp +
  320. "&sign=" +
  321. md5Sign;
  322. let postData = {
  323. openId: getApp().globalData.open_id,
  324. id: this.id,
  325. };
  326. uni.request({
  327. url: url,
  328. method: "POST",
  329. header: {
  330. "content-type": "application/x-www-form-urlencoded",
  331. },
  332. data: postData,
  333. success: (res) => {
  334. if (res.data.code == 200) {
  335. this.isJoin = true;
  336. uni.showToast({
  337. title: "报名成功",
  338. icon: "none",
  339. duration: 2500,
  340. });
  341. }
  342. },
  343. fail: () => {
  344. console.log("连接失败");
  345. },
  346. });
  347. },
  348. },
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. .content {
  353. display: flex;
  354. flex-direction: column;
  355. .header {
  356. display: flex;
  357. height: 150rpx;
  358. padding: 20rpx;
  359. .title-read {
  360. height: 100%;
  361. display: flex;
  362. flex-direction: column;
  363. justify-content: space-evenly;
  364. .title {
  365. font-weight: 600;
  366. letter-spacing: 2rpx;
  367. font-size: 32rpx;
  368. }
  369. .read {
  370. margin-top: 20rpx;
  371. font-size: 22rpx;
  372. color: $uni-text-color-grey;
  373. }
  374. }
  375. .header-image {
  376. height: 100%;
  377. width: 50%;
  378. image {
  379. width: 100%;
  380. height: 100%;
  381. border-radius: 10%;
  382. }
  383. }
  384. }
  385. .active-deatil {
  386. padding: 20rpx;
  387. ul {
  388. padding: 30rpx;
  389. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  390. border-radius: 32rpx;
  391. li {
  392. margin-bottom: 30rpx;
  393. list-style: none;
  394. .name {
  395. margin-bottom: 10rpx;
  396. font-size: 30rpx;
  397. color: $uni-text-color-grey;
  398. }
  399. .deatil-content {
  400. font-size: 27rpx;
  401. }
  402. }
  403. }
  404. }
  405. .rich {
  406. margin-bottom: 150rpx;
  407. padding: 20rpx;
  408. }
  409. .share-box {
  410. box-sizing: border-box;
  411. height: 150rpx;
  412. width: 100%;
  413. align-items: center;
  414. justify-content: space-evenly;
  415. position: fixed;
  416. bottom: 0;
  417. display: flex;
  418. background: #ffffff;
  419. .share {
  420. display: flex;
  421. justify-content: center;
  422. align-items: center;
  423. width: 50rpx;
  424. height: 50rpx;
  425. position: relative;
  426. button::after {
  427. border: none;
  428. }
  429. image {
  430. width: 100%;
  431. height: 100%;
  432. position: absolute;
  433. }
  434. .shareCount {
  435. display: flex;
  436. justify-content: center;
  437. align-items: center;
  438. position: absolute;
  439. top: -30%;
  440. right: -30%;
  441. color: #ffffff;
  442. height: 30rpx;
  443. width: 30rpx;
  444. padding: 3rpx;
  445. font-size: 16rpx;
  446. border-radius: 50%;
  447. background: #fe3637;
  448. }
  449. }
  450. .button {
  451. height: 100rpx;
  452. width: 70%;
  453. display: flex;
  454. justify-content: center;
  455. button {
  456. width: 80%;
  457. height: 90%;
  458. border: 1px solid;
  459. outline: none;
  460. background: none;
  461. }
  462. .start {
  463. //待开始
  464. background-color: #00a8ea;
  465. color: #ffffff;
  466. border-color: none;
  467. }
  468. .begun {
  469. //已开始
  470. border-color: #00a8ea;
  471. color: #00a8ea;
  472. }
  473. .ended {
  474. //已结束
  475. color: #aaaaaa;
  476. border-color: #aaaaaa;
  477. }
  478. .falseStart {
  479. color: #70b603;
  480. border-color: #70b603;
  481. }
  482. }
  483. }
  484. }
  485. </style>