activity_deatil.vue 12 KB

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