activityDetail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. var app = getApp();
  2. var util = require("../../../../utils/util.js")
  3. let wxParse = require("../../../../wxParse/wxParse.js");
  4. let pageid = ""
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. bottomLeft: app.bottomLeft,
  11. appAssetsUrl: app.appAssetsUrl,
  12. appAssetsUrl2: app.appAssetsUrl2,
  13. appAssetsUrl3: app.appAssetsUrl3,
  14. maskShow: false,
  15. options: {},
  16. detail: {},
  17. member: {},
  18. content: '',
  19. vipActivityMessage: '',
  20. peopleList: [],
  21. people6: [],
  22. isMore: true,
  23. dotLeft: 0,
  24. open: true,
  25. schoolInfo: {},
  26. roleList: ['平台管理员', '校园代理人', '行家', '行家;平台管理员', '行家;校园代理人'],
  27. dmoney: 0,
  28. point: 0,
  29. usePoints: 0,
  30. isWx: false,
  31. activeDetail: '',
  32. actualPrice: 0, // 实付价格
  33. isDev: true //审核
  34. },
  35. /**
  36. * 生命周期函数--监听页面加载
  37. */
  38. onLoad: function (options) {
  39. pageid = this.options.id;
  40. let _this = this;
  41. let user = util.getUser();
  42. this.setData({
  43. options: {
  44. ...options,
  45. type: 2, //类型(1兼职 2活动)
  46. stuId: user ? user.id : ''
  47. }
  48. })
  49. _this.loadData();
  50. _this.loadVipSel();
  51. _this.addRead();
  52. _this.env()
  53. },
  54. joinVip() {
  55. wx.navigateTo({
  56. url: '/pages/myMember/myMember',
  57. })
  58. },
  59. collect: function () {
  60. let that = this
  61. if (util.getUserId()) {
  62. app._post_form('favorite/addOrCancelFavorite', "application/json", {
  63. sid: that.data.options.id,
  64. vipid: that.data.options.stuId,
  65. type: 2 //1:兼职 2:活动
  66. },
  67. function (res) {
  68. if (res.code == 0) {
  69. that.setData({
  70. detail: {
  71. ...that.data.detail,
  72. collect: !that.data.detail.collect
  73. }
  74. })
  75. wx.showToast({
  76. title: that.data.detail.collect ? '收藏成功' : '取消收藏',
  77. icon: 'success',
  78. duration: 2000
  79. })
  80. }
  81. })
  82. } else {
  83. wx.showToast({
  84. title: '没有登录,操作失败',
  85. icon: 'fail',
  86. duration: 2000
  87. })
  88. }
  89. },
  90. // 获取参与人员
  91. getUser(id) {
  92. app._get(`activitystu/list`, {
  93. pid: id
  94. }, res => {
  95. if (res.code === 0) {
  96. this.setData({
  97. people6: res.page.list.slice(0, 6),
  98. peopleList: res.page.list
  99. })
  100. }
  101. })
  102. },
  103. //获取支付价格
  104. getPayPrice() {
  105. let that = this
  106. // let actualPrice = this.data.open ? this.data.detail.money - this.data.dmoney : this.data.detail.money
  107. let id = util.getUserId();
  108. app._get(`activity/eventRegistrationPayPrice`, {
  109. id: id,
  110. activityId: that.data.detail.id
  111. // actualPrice: actualPrice
  112. }, res => {
  113. if (res.code === 0) {
  114. this.setData({
  115. actualPrice: res.data.actualPrice,
  116. })
  117. }
  118. })
  119. },
  120. // 查看地图
  121. goLocal() {
  122. let that = this
  123. let [latitude, longitude] = [this.data.detail.coordinate.split(',')[0], this.data.detail.coordinate.split(',')[1]]
  124. console.log(Number(latitude), Number(longitude))
  125. wx.openLocation({
  126. latitude: Number(longitude),
  127. longitude: Number(latitude),
  128. name: that.data.title,
  129. address: that.data.address,
  130. success: function () {
  131. console.log("success");
  132. },
  133. });
  134. },
  135. // 校园代理人信息
  136. schoolUser(id) {
  137. app._get(`activity/activeCampusAgent`, {
  138. activityId: id
  139. }, res => {
  140. if (res.code === 0) {
  141. this.setData({
  142. schoolInfo: res.data
  143. })
  144. }
  145. })
  146. },
  147. showMore() {
  148. this.setData({
  149. isMore: !this.data.isMore
  150. })
  151. },
  152. // 查看二维码
  153. seeCode() {
  154. let that = this
  155. if (!that.data.detail.activityStuYN) {
  156. wx.showToast({
  157. title: '报名后查看!',
  158. icon: 'none'
  159. })
  160. return
  161. }
  162. this.popup3.showPopup();
  163. this.setData({
  164. maskShow: true
  165. })
  166. },
  167. // 报名是否抵扣积分
  168. changeSwitch() {
  169. this.setData({
  170. open: !this.data.open
  171. })
  172. },
  173. loadData: function () {
  174. let _this = this;
  175. wx.showLoading({
  176. title: '努力加载中...',
  177. })
  178. app._post_form('act/one', "", _this.data.options, function (res) {
  179. if (res.code === 0) {
  180. _this.setData({
  181. detail: {
  182. ...res.data,
  183. startDate: res.data.startTime.replace(/-/g, '.').split(' ')[0],
  184. endDate: res.data.endTime.replace(/-/g, '.').split(' ')[0],
  185. startTime: res.data.startTime.split(' ')[1],
  186. endTime: res.data.endTime.split(' ')[1],
  187. registrationEnd: res.data.registrationEnd.replace(/-/g, '.'),
  188. meetingTime: res.data.meetingTime.replace(/-/g, '.')
  189. }
  190. })
  191. _this.getUser(res.data.id)
  192. _this.schoolUser(res.data.id)
  193. _this.getPoint(res.data.id)
  194. // _this.getPayPrice()
  195. if (res.data.isAppletsRelease == 1) {
  196. // let str = Array.from(res.data.appletsDetails)
  197. _this.setData({
  198. isWx: true
  199. })
  200. } else {
  201. _this.setData({
  202. isWx: false
  203. })
  204. wxParse.wxParse('content', 'html', res.data.content, _this, 0);
  205. // wxParse.wxParse('content', 'html', res.data.content.replace(/&lt;/g,'<'), _this, 0);
  206. // wxParse.wxParse('content', 'html', res.data.content.replace(/(.*)&lt;/,'$1< '), _this, 0);
  207. }
  208. }
  209. })
  210. },
  211. /**
  212. * 生命周期函数--监听页面初次渲染完成
  213. */
  214. onReady: function () {
  215. //获得popup组件
  216. this.popup = this.selectComponent("#popup");
  217. this.popup2 = this.selectComponent("#popup2");
  218. this.popup3 = this.selectComponent("#popup3"); // 二维码
  219. this.popup4 = this.selectComponent("#popup4"); // 提示升级开通会员/升级会员
  220. this.popup5 = this.selectComponent("#popup5"); // 报名
  221. this.popup6 = this.selectComponent("#popup6"); // 报名
  222. },
  223. addRead() {
  224. app._post_form('read/num', '', {
  225. id: this.data.options.id,
  226. type: 2
  227. })
  228. },
  229. /**
  230. * 生命周期函数--监听页面显示
  231. */
  232. onShow: function () {
  233. this.PushVipInfo();
  234. let user = util.getUser();
  235. this.setData({
  236. options: {
  237. ...this.data.options,
  238. stuId: user ? user.id : ''
  239. }
  240. })
  241. },
  242. /**
  243. * 生命周期函数--监听页面隐藏
  244. */
  245. onHide: function () { },
  246. /**
  247. * 生命周期函数--监听页面卸载
  248. */
  249. onUnload: function () {
  250. return
  251. let _this = this
  252. if (_this.data.isyn) {
  253. app._post_form('favorite/addFavorite', "application/json", JSON.stringify(_this.data.parm),
  254. function (res) {
  255. console.log(res)
  256. })
  257. } else {
  258. app._post_form('favorite/removeFavoriteByVipid', "application/json", JSON.stringify(_this.data
  259. .parm),
  260. function (res) {
  261. console.log(res)
  262. })
  263. }
  264. },
  265. /**
  266. * 页面相关事件处理函数--监听用户下拉动作
  267. */
  268. onPullDownRefresh: function () {
  269. },
  270. /**
  271. * 页面上拉触底事件的处理函数
  272. */
  273. onReachBottom: function () {
  274. },
  275. //查询会员信息
  276. PushVipInfo() {
  277. let _this = this;
  278. let id = util.getUserId();
  279. if (id) {
  280. app._post_form('member/apiSelectMeberInfo', 'application/json', { id }, function (
  281. res) {
  282. if (res.code === 0) {
  283. _this.setData({
  284. member: res.member
  285. })
  286. }
  287. })
  288. }
  289. },
  290. // 判断是否开发huanjing
  291. env() {
  292. let that = this
  293. app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  294. null,
  295. function (res) {
  296. if (res.code === 0) {
  297. that.setData({
  298. isDev: res.wgFillInfo.isDev
  299. })
  300. }
  301. }
  302. )
  303. },
  304. submit() {
  305. // console.log('submit', this.data.detail.statusName)
  306. // this.popup4.showPopup();
  307. //报名满了
  308. if (this.data.detail.statusName != '报名中') {
  309. wx.showToast({
  310. title: `活动${this.data.detail.statusName}`,
  311. icon: 'none'
  312. })
  313. return;
  314. }
  315. let that = this;
  316. if (util.UserLoginStatus()) {
  317. // 活动,会员免费,用户是会员用户 或者活动金额是0元 直接报名
  318. if (this.data.detail.isNeedVip == 1 && (that.data.member.memberState > 0) || that.data.detail.money == 0) {
  319. that.signUp();
  320. // 活动,会员免费,用户是普通用户
  321. } else if (this.data.detail.isNeedVip == 1 && (that.data.member.memberState == 0)) {
  322. if (this.data.isDev) {
  323. wx.showToast({
  324. title: '暂未开始报名,请关注进度!',
  325. icon: 'none',
  326. duration: 2000
  327. })
  328. return
  329. }
  330. that.popup4.showPopup();
  331. } else {
  332. // 所有用户付费
  333. that.popup5.showPopup();
  334. }
  335. // if((this.data.detail.isNeedVip && (this.data.member.memberState > 0)) || !this.data.detail.isNeedVip){
  336. // wx.showModal({
  337. // title: '提示',
  338. // content: '您确定要报名该活动吗',
  339. // success (res) {
  340. // if (res.confirm) {
  341. // that.signUp();
  342. // }
  343. // }
  344. // })
  345. // that.popup5.showPopup();
  346. // }else if(that.data.detail.isNeedVip == 0 && (that.data.member.memberState == 0)){
  347. // that.popup4.showPopup();
  348. // }
  349. // this.setData({
  350. // maskShow: true
  351. // })
  352. }
  353. },
  354. confirmPay() {
  355. this.popup5.hidePopup();
  356. this.singPay()
  357. },
  358. singPay() {
  359. let that = this;
  360. let money = that.data.open ? that.data.actualPrice : that.data.detail.money
  361. console.log(money)
  362. if (money == 0) {
  363. return that.signUp()
  364. }
  365. wx.showLoading({
  366. title: '提交中...',
  367. mask: true,
  368. })
  369. let isDeductiblePrice = that.data.open ? 1 : 0
  370. // act/register/wx 支付时用这个
  371. app._post_form('act/register/wx', "", {
  372. aid: that.data.options.id,
  373. sid: that.data.options.stuId,
  374. isDeductiblePrice: isDeductiblePrice
  375. }, function (res) {
  376. if (res.code === 0) {
  377. wx.hideLoading();
  378. if (!res.map) {
  379. wx.showToast({
  380. title: "支付参数获取失败",
  381. icon: "none",
  382. duration: 1500,
  383. });
  384. return;
  385. }
  386. wx.showLoading({
  387. title: "正在处理...",
  388. mask: true,
  389. });
  390. wx.requestPayment({
  391. timeStamp: res.map.timestamp,
  392. nonceStr: res.map.nonce_str,
  393. package: "prepay_id=" + res.map.prepay_id,
  394. signType: "MD5",
  395. paySign: res.map.sign,
  396. success: (result) => {
  397. if (result.errMsg == "requestPayment:ok") {
  398. wx.showLoading({
  399. title: "正在处理...",
  400. mask: true,
  401. });
  402. // console.log(result, 11111111);
  403. wx.hideLoading();
  404. that.popup3.showPopup();
  405. wx.showModal({
  406. title: "温馨提示",
  407. content: "报名成功!",
  408. showCancel: false,
  409. });
  410. // that.loadData();
  411. // setTimeout(()=>{
  412. // wx.redirectTo({
  413. // url: '/pages/my/myPlay/myPlay',
  414. // })
  415. // },2000)
  416. } else {
  417. wx.hideLoading();
  418. wx.showToast({
  419. title: "支付失败!",
  420. icon: "none",
  421. duration: 1500,
  422. });
  423. }
  424. },
  425. fail: (error) => {
  426. wx.hideLoading();
  427. wx.showToast({
  428. title: "支付失败!",
  429. icon: "none",
  430. duration: 1500,
  431. });
  432. },
  433. });
  434. // wx.showActionSheet({
  435. // itemList: ["微信支付"],
  436. // success: (response) => {
  437. // if (response.tapIndex === 0) {
  438. // }
  439. // },
  440. // fail(errors) {},
  441. // })
  442. } else if (res.msg == '请完善资料后进行报名操作') {
  443. wx.hideToast();
  444. that.popup2.showPopup();
  445. } else if (res.msg.indexOf('冻结阶段') > -1) {
  446. wx.hideToast();
  447. wx.showToast({
  448. title: res.msg,
  449. icon: 'none',
  450. duration: 3000
  451. })
  452. } else if (res.msg.indexOf('请完善真实姓名资料') > -1) {
  453. console.log(111111111111)
  454. that.popup6.showPopup();
  455. }
  456. })
  457. },
  458. signUp() {
  459. let that = this;
  460. wx.showLoading({
  461. title: '提交中...',
  462. })
  463. let isDeductiblePrice = that.data.open ? 1 : 0
  464. // act/register/wx 支付时用这个
  465. app._post_form('act/register/wx', "", {
  466. aid: that.data.options.id,
  467. sid: that.data.options.stuId,
  468. isDeductiblePrice: isDeductiblePrice
  469. }, function (res) {
  470. if (res.code === 0) {
  471. wx.showToast({
  472. title: "报名成功!",
  473. icon: "none",
  474. duration: 1500,
  475. });
  476. // that.popup5.hidePopup();
  477. that.popup3.showPopup();
  478. // setTimeout(()=>{
  479. // wx.redirectTo({
  480. // url: '/pages/my/myPlay/myPlay',
  481. // })
  482. // },2000)
  483. } else if (res.msg == '请完善资料后进行报名操作') {
  484. wx.hideToast();
  485. that.popup2.showPopup();
  486. } else if (res.msg.indexOf('冻结阶段') > -1) {
  487. console.log(res.msg)
  488. wx.hideToast();
  489. wx.showToast({
  490. title: res.msg,
  491. icon: 'none',
  492. duration: 3000
  493. })
  494. } else if (res.msg.indexOf('请完善真实姓名资料') > -1) {
  495. // console.log(111111111111)
  496. that.popup6.showPopup();
  497. }
  498. })
  499. },
  500. loadVipSel() {
  501. let _this = this;
  502. wx.showLoading({
  503. title: '努力加载中...',
  504. })
  505. app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  506. null,
  507. function (res) {
  508. if (res.code === 0) {
  509. setTimeout(function () {
  510. wxParse.wxParse('vipActivityMessage', 'html', res.wgFillInfo.vipActivityMessage, _this, 5)
  511. }, 300)
  512. }
  513. }
  514. )
  515. },
  516. showShareMenu: function () {
  517. wx.showShareMenu();
  518. this.setData({
  519. show: true
  520. })
  521. },
  522. // 校园代理人详情
  523. perDetail() {
  524. // console.log(e)
  525. let that = this
  526. let role = that.data.roleList[that.data.schoolInfo.memberRoleStatus - 1]
  527. wx.navigateTo({
  528. url: '/expert/agentdetail/agentdetail?id=' + that.data.schoolInfo.id + '&activityId=' + that.data.detail.id + '&name=' + role
  529. })
  530. },
  531. hideShareMenu() {
  532. wx.hideShareMenu();
  533. this.setData({
  534. show: false
  535. })
  536. },
  537. /**
  538. * 用户点击右上角分享
  539. */
  540. onShareAppMessage() {
  541. this.addScore();
  542. return {
  543. title: '活动详情',
  544. path: '/pages/home/index/activityDetail/activityDetail?id=' + pageid,
  545. desc: '欢迎大家踊跃报名',
  546. }
  547. },
  548. //统计积分(每日小程序分享)
  549. addScore: function () {
  550. if (!util.getUserId()) {
  551. return;
  552. }
  553. wx.showLoading({
  554. title: '努力加载中...',
  555. })
  556. app._post_form('scoreStu/share', "", {
  557. stuId: util.getUserId()
  558. }, function (res) {
  559. if (res.code === 0) { }
  560. })
  561. },
  562. // 查询积分抵扣
  563. getPoint(id) {
  564. app._get(`activity/eventRegistrationPayPrice`, {
  565. activityId: id,
  566. id: util.getUserId()
  567. }, res => {
  568. if (res.code === 0) {
  569. this.setData({
  570. dmoney: res.data.deductiblePrice,
  571. point: res.data.remainingPoints,
  572. actualPrice: res.data.actualPrice,
  573. usePoints: res.data.usePoints,
  574. open: res.data.usePoints > 0 ? true : false
  575. })
  576. }
  577. })
  578. },
  579. //取消事件
  580. _error(e) {
  581. this[e.currentTarget.dataset.name].hidePopup();
  582. if (e.currentTarget.dataset.name == 'popup4') {
  583. this.popup5.showPopup();
  584. } else {
  585. this.setData({
  586. maskShow: false
  587. })
  588. }
  589. },
  590. _error2(e) {
  591. this[e.currentTarget.dataset.name].hidePopup();
  592. this.setData({
  593. maskShow: false
  594. })
  595. },
  596. //确认事件
  597. _success(e) {
  598. let that = this
  599. if (e.currentTarget.dataset.name == 'popup3') {
  600. } else if (e.currentTarget.dataset.name == 'popup5') {
  601. that.singPay();
  602. } else if (e.currentTarget.dataset.name == 'popup4') {
  603. wx.navigateTo({
  604. url: '/pages/myMember/myMember'
  605. })
  606. } else if (e.currentTarget.dataset.name == 'popup2' || e.currentTarget.dataset.name == 'popup6') {
  607. wx.navigateTo({
  608. // url: '/pages/my/myStudy/myStudy'
  609. url: '/pages/my/myData/myData',
  610. })
  611. } else {
  612. wx.navigateTo({
  613. url: e.currentTarget.dataset.name == 'popup' ? '/pages/myMember/myMember' : '/pages/my/myData/myData',
  614. })
  615. }
  616. this.setData({
  617. maskShow: false
  618. })
  619. this[e.currentTarget.dataset.name].hidePopup();
  620. },
  621. seeBigCode(e) {
  622. let arr = [this.data.detail.qrCodePicture];
  623. wx.previewImage({
  624. urls: arr, // 需要预览的图片http链接列表
  625. });
  626. },
  627. })