activity_deatil.vue 13 KB

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