viewDetail.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <view class="content">
  3. <view class="header">
  4. <view class="title-read">
  5. <view class="title">
  6. <view>{{ model.title }}</view>
  7. <view>整体参观</view>
  8. </view>
  9. <button>今日已满</button>
  10. </view>
  11. <!-- <view class="header-image">
  12. <image :src="model.url" alt="" />
  13. </view> -->
  14. </view>
  15. <view class="active-deatil">
  16. <ul>
  17. <li>
  18. <p class="name">开放时间</p>
  19. <p class="deatil-content">周一至周五:08:00~17:00</p>
  20. </li>
  21. <li style="margin-bottom: 0;">
  22. <p class="name">容纳人数</p>
  23. <p class="deatil-content">50</p>
  24. </li>
  25. </ul>
  26. </view>
  27. <view class="rich">
  28. <activityRichCard :model="textModel" :isFold="true" />
  29. </view>
  30. <view class="share-box">
  31. <view class="button">
  32. <button @click="subscribeActivity()" class="start" >
  33. <!-- {{ model.activiteState }} -->
  34. 提交资料
  35. </button>
  36. <!-- <button disabled="true" class="ended" v-if="isJoin">已报名</button> -->
  37. </view>
  38. <!-- "status":"活动状态 0:待开始;1:已开始; 2:已结束
  39. "type":"活动类型 1:线上;2 线下"} -->
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import md5 from "@/common/md5.js";
  45. import activity_rich_card from "../policy/policy_rich_card";
  46. export default {
  47. filters: {
  48. formDateTime(value) {
  49. if (value) {
  50. const time = new Date(value * 1000);
  51. const y = time.getFullYear();
  52. const m =
  53. time.getMonth() + 1 < 10
  54. ? "0" + (time.getMonth() + 1)
  55. : time.getMonth() + 1;
  56. const d = time.getDate() < 10 ? "0" + time.getDate() : time.getDate();
  57. // const h = time.getHours()
  58. // const mm = time.getMinutes();
  59. // const s = time.getSeconds();
  60. return y + "." + m + "." + d;
  61. } else {
  62. return "";
  63. }
  64. },
  65. formDateTimeSecond(value) {
  66. if (value) {
  67. const time = new Date(value * 1000);
  68. // const y = time.getFullYear();
  69. // const m = (time.getMonth() + 1) < 10 ? '0' + (time.getMonth() + 1) : (time.getMonth() + 1);
  70. // const d = time.getDate() < 10 ? '0' + time.getDate(): time.getDate();
  71. const h =
  72. time.getHours() < 10 ? "0" + time.getHours() : time.getHours();
  73. const mm =
  74. time.getMinutes() < 10 ? "0" + time.getMinutes() : time.getMinutes();
  75. return h + ":" + mm;
  76. } else {
  77. return "";
  78. }
  79. },
  80. },
  81. components: {
  82. activityRichCard: activity_rich_card,
  83. },
  84. data() {
  85. return {
  86. id: "",
  87. isJoin: false,
  88. activityInfoList:[],
  89. sexValue:'男',
  90. model: {
  91. title: "",
  92. read: 123,
  93. url: "",
  94. date: "",
  95. type: 1,
  96. status: 0,
  97. way: "",
  98. share: 0,
  99. activiteState: "",
  100. max_person: "",
  101. person_count: "",
  102. },
  103. textModel: {
  104. title: "活动内容",
  105. text: "",
  106. },
  107. };
  108. },
  109. onLoad(op) {
  110. this.id = op.id
  111. this.getActivityDeatil();
  112. },
  113. methods: {
  114. checkboxChange(e){
  115. this.sexValue = e.detail.value;
  116. },
  117. shareRequest() {
  118. let md5Sign = md5(
  119. "method=" +
  120. "user" +
  121. "&timestamp=" +
  122. getApp().globalData.globalTimestamp +
  123. "&secret=" +
  124. getApp().globalData.secret
  125. );
  126. let url =
  127. getApp().globalData.shareUrl +
  128. "api/api.php" +
  129. "?method=user&source=activity&action=repost&timestamp=" +
  130. getApp().globalData.globalTimestamp +
  131. "&sign=" +
  132. md5Sign;
  133. uni.request({
  134. url: url,
  135. method: "POST",
  136. header: {
  137. "content-type": "application/x-www-form-urlencoded",
  138. },
  139. data: {
  140. openId: getApp().globalData.open_id,
  141. source_id: this.id,
  142. source: "activity",
  143. },
  144. success: (res) => {
  145. if (res.data.code === 200) {
  146. console.log(res);
  147. this.model.share = this.model.share + 1;
  148. }
  149. },
  150. fail: () => {
  151. console.log("连接失败");
  152. },
  153. });
  154. },
  155. shareActive() {
  156. let that = this;
  157. uni.showShareMenu({
  158. title: that.model.title,
  159. path: "pages/activity/activity_detail?id=" + that.id,
  160. success(res) {
  161. that.shareRequest();
  162. },
  163. });
  164. },
  165. getActivityDeatil() {
  166. let md5Sign = md5(
  167. "method=" +
  168. "activity" +
  169. "&timestamp=" +
  170. getApp().globalData.globalTimestamp +
  171. "&secret=" +
  172. getApp().globalData.secret
  173. );
  174. let url =
  175. getApp().globalData.shareUrl +
  176. "api/api.php" +
  177. "?method=activity&source=activity&action=info_by_id&timestamp=" +
  178. getApp().globalData.globalTimestamp +
  179. "&sign=" +
  180. md5Sign;
  181. let postData = {
  182. id: this.id,
  183. openId: getApp().globalData.open_id,
  184. };
  185. //获取文章
  186. uni.request({
  187. url: url,
  188. method: "POST",
  189. header: {
  190. "content-type": "application/x-www-form-urlencoded",
  191. },
  192. data: postData,
  193. success: (res) => {
  194. if (res.data.code == 200) {
  195. let data = res.data.data;
  196. this.isJoin = data.active ? true : false;
  197. if(data.category_list && data.category_list.length > 0){
  198. this.activityInfoList = data.category_list;
  199. this.activityInfoList.forEach((item)=>{
  200. if(item.name === '性别'){
  201. item.value = '男'
  202. }else {
  203. item.value = '';
  204. }
  205. })
  206. }
  207. this.model.title = data.name;
  208. this.model.read = parseInt(data.base_read_count) + parseInt(data.real_read_count);
  209. this.model.url = getApp().globalData.shareUrl + data.pic_url;
  210. let arr = ["start_time", "end_time"];
  211. let ans = [];
  212. for (const item of arr) {
  213. let time = this.$options.filters["formDateTime"](data[item]);
  214. let timeSecond = this.$options.filters["formDateTimeSecond"](data[item]);
  215. ans.push(time + " " + timeSecond);
  216. }
  217. this.model.date = ans.join(" - ");
  218. this.model.type = data.type;
  219. this.model.status = data.status;
  220. this.model.way = data.sponsor;
  221. this.model.max_person = data.max_person;
  222. this.model.person_count = data.person_count;
  223. this.model.share = parseInt(data.real_repost_count) + parseInt(data.base_repost_count);
  224. if (data.status == '待开始') {
  225. if (data.type == 2) {
  226. this.model.activiteState = "我要参加";
  227. } else {
  228. this.model.activiteState = "活动待开始";
  229. }
  230. } else if (data.status == '已开始') {
  231. this.model.activiteState = "活动进行中";
  232. } else {
  233. this.model.activiteState = "活动已结束";
  234. }
  235. }
  236. this.getRich();
  237. },
  238. fail: () => {
  239. console.log("连接失败");
  240. },
  241. });
  242. },
  243. replaceImg(html) {
  244. let result = html.replace(
  245. /<img [^>]*src=['"]([^'"]+)[^>]*>/gi,
  246. function (match, capture) {
  247. if(capture.includes('http')){
  248. return (
  249. "<img src=" +
  250. capture +
  251. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  252. );
  253. }else {
  254. return (
  255. "<img src=" +
  256. getApp().globalData.shareUrl +
  257. capture +
  258. ' style="max-width:100%;height:auto;display:block;margin:10px auto;"/>'
  259. );
  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`+'?version='+ Math.random(),
  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() {
  285. if(!getApp().globalData.user_phone){
  286. uni.showToast({
  287. title: "您还没有登录授权",
  288. duration: 2500,
  289. icon: "none",
  290. });
  291. uni.navigateTo({
  292. url:'/pages/auth/index'
  293. })
  294. }
  295. uni.navigateTo({
  296. url:'/pages/makeField/fieldForm'
  297. })
  298. // if (Number(this.model.person_count) >= Number(this.model.max_person)) {
  299. // uni.showToast({
  300. // title: "报名人数已达上限",
  301. // icon: "error",
  302. // duration: 2000,
  303. // });
  304. // return;
  305. // }
  306. // if(this.activityInfoList.length > 0 && getApp().globalData.user_phone){
  307. // this.open();
  308. // }
  309. // if(this.activityInfoList.length === 0 && getApp().globalData.user_phone){
  310. // this.subscribeFn(this.activityInfoList)
  311. // }
  312. },
  313. signUpActivity(infoList) {
  314. let md5Sign = md5(
  315. "method=" +
  316. "activity" +
  317. "&timestamp=" +
  318. getApp().globalData.globalTimestamp +
  319. "&secret=" +
  320. getApp().globalData.secret
  321. );
  322. let url =
  323. getApp().globalData.shareUrl +
  324. "api/api.php" +
  325. "?method=activity&source=activity&action=active&timestamp=" +
  326. getApp().globalData.globalTimestamp +
  327. "&sign=" +
  328. md5Sign;
  329. let postData = {
  330. openId: getApp().globalData.open_id,
  331. id: this.id,
  332. category_json:JSON.stringify(infoList)
  333. };
  334. uni.request({
  335. url: url,
  336. method: "POST",
  337. header: {
  338. "content-type": "application/x-www-form-urlencoded",
  339. },
  340. data: postData,
  341. success: (res) => {
  342. if (res.data.code == 200) {
  343. this.isJoin = true;
  344. uni.showToast({
  345. title: "报名成功",
  346. icon: "none",
  347. duration: 2500,
  348. });
  349. }
  350. },
  351. fail: () => {
  352. console.log("连接失败");
  353. },
  354. });
  355. },
  356. subscribeFn(info){
  357. let that = this;
  358. uni.requestSubscribeMessage({
  359. tmplIds: [
  360. "bSg5tUWHE4qWDeyK31GBejogT1uRgkuBD1_n2I5ptAc",
  361. "T_ORLiW2C_UM6nZiEerYAokltHgHRGxWCid8eElujus",
  362. // "XPULJQ64YrS-5sAnfMTJj3S9iV8-8X_mb3r_H5dgAgE",
  363. // "RWq7TE266RYr8DX2IHZ2F_zKbOnSfZDgh_xovBh0UiI" //测试环境模板id
  364. ],
  365. success(res) {
  366. that.signUpActivity(info);
  367. },
  368. });
  369. },
  370. open() {
  371. this.$refs.popup.open('top')
  372. },
  373. closePopup() {
  374. this.$refs.popup.close()
  375. },
  376. submitInfo(){
  377. let checkFlag = false;
  378. for(let i = 0; i < this.activityInfoList.length; i++){
  379. if(!this.activityInfoList[i].value){
  380. uni.showToast({
  381. title:'请填写' + this.activityInfoList[i].name,
  382. duration:2000,
  383. icon:'none'
  384. })
  385. checkFlag = false;
  386. break;
  387. }else {
  388. checkFlag = true;
  389. }
  390. }
  391. if(checkFlag){
  392. this.activityInfoList.forEach((item)=>{
  393. if(item.name === '性别'){
  394. item.value = this.sexValue;
  395. }
  396. delete item.addtime;
  397. delete item.name;
  398. delete item.parent_id;
  399. delete item.weight;
  400. })
  401. this.$refs.popup.close();
  402. this.subscribeFn(this.activityInfoList)
  403. }
  404. }
  405. },
  406. };
  407. </script>
  408. <style lang="scss" scoped>
  409. .content {
  410. display: flex;
  411. flex-direction: column;
  412. .header {
  413. display: flex;
  414. // height: 150rpx;
  415. padding: 20rpx;
  416. .title-read {
  417. width: 100%;
  418. display: flex;
  419. justify-content: space-evenly;
  420. .title {
  421. font-weight: 600;
  422. letter-spacing: 2rpx;
  423. font-size: 30rpx;
  424. width: 80%;
  425. padding: 20rpx;
  426. }
  427. button {
  428. background: #95f204;
  429. color: #fff;
  430. font-size: 18rpx;
  431. height: 46rpx;
  432. line-height: 46rpx;
  433. margin-top: 5%;
  434. width: 18%;
  435. }
  436. }
  437. .header-image {
  438. height: 100%;
  439. width: 50%;
  440. image {
  441. width: 100%;
  442. height: 100%;
  443. border-radius: 10%;
  444. }
  445. }
  446. }
  447. .active-deatil {
  448. padding: 20rpx;
  449. ul {
  450. padding: 30rpx;
  451. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  452. border-radius: 32rpx;
  453. li {
  454. margin-bottom: 30rpx;
  455. list-style: none;
  456. .name {
  457. margin-bottom: 10rpx;
  458. font-size: 30rpx;
  459. color: #7f7f7f;
  460. }
  461. .deatil-content {
  462. font-size: 28rpx;
  463. }
  464. }
  465. }
  466. }
  467. .rich {
  468. margin-bottom: 150rpx;
  469. padding: 20rpx;
  470. }
  471. .share-box {
  472. box-sizing: border-box;
  473. height: 150rpx;
  474. width: 100%;
  475. align-items: center;
  476. justify-content: space-evenly;
  477. position: fixed;
  478. bottom: 0;
  479. display: flex;
  480. background: #ffffff;
  481. .share {
  482. display: flex;
  483. justify-content: center;
  484. align-items: center;
  485. width: 60rpx;
  486. height: 60rpx;
  487. position: relative;
  488. button::after {
  489. border: none;
  490. }
  491. image {
  492. width: 100%;
  493. height: 100%;
  494. position: absolute;
  495. }
  496. .shareCount {
  497. display: flex;
  498. justify-content: center;
  499. align-items: center;
  500. position: absolute;
  501. top: -20%;
  502. right: -25%;
  503. color: #ffffff;
  504. height: 30rpx;
  505. width: 30rpx;
  506. padding: 3rpx;
  507. font-size: 16rpx;
  508. border-radius: 50%;
  509. background: #fe3637;
  510. }
  511. }
  512. .button {
  513. height: 100rpx;
  514. width: 75%;
  515. display: flex;
  516. justify-content: center;
  517. button {
  518. width: 80%;
  519. height: 80%;
  520. border: 1px solid;
  521. outline: none;
  522. background: none;
  523. font-size: 30rpx;
  524. // border-color: #00a8ea;
  525. }
  526. .start {
  527. //待开始
  528. background-color: transparent;
  529. border-color: none;
  530. color: #00a8ea;
  531. }
  532. .begun {
  533. //已开始
  534. border-color: #00a8ea;
  535. color: #00a8ea;
  536. }
  537. .ended {
  538. //已结束
  539. color: #00a8ea;
  540. border-color: #00a8ea;
  541. }
  542. .falseStart {
  543. color: #70b603;
  544. border-color: #70b603;
  545. }
  546. }
  547. }
  548. }
  549. </style>