activity_deatil.vue 12 KB

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