activityDetail.js 14 KB

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