activity_deatil.vue 9.7 KB

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