activityDetail.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. },
  222. addRead() {
  223. app._post_form('read/num', '', {
  224. id: this.data.options.id,
  225. type: 2
  226. })
  227. },
  228. /**
  229. * 生命周期函数--监听页面显示
  230. */
  231. onShow: function() {
  232. this.PushVipInfo();
  233. let user = util.getUser();
  234. this.setData({
  235. options: {
  236. ...this.data.options,
  237. stuId: user ? user.id : ''
  238. }
  239. })
  240. },
  241. /**
  242. * 生命周期函数--监听页面隐藏
  243. */
  244. onHide: function() {},
  245. /**
  246. * 生命周期函数--监听页面卸载
  247. */
  248. onUnload: function() {
  249. return
  250. let _this = this
  251. if (_this.data.isyn) {
  252. app._post_form('favorite/addFavorite', "application/json", JSON.stringify(_this.data.parm),
  253. function(res) {
  254. console.log(res)
  255. })
  256. } else {
  257. app._post_form('favorite/removeFavoriteByVipid', "application/json", JSON.stringify(_this.data
  258. .parm),
  259. function(res) {
  260. console.log(res)
  261. })
  262. }
  263. },
  264. /**
  265. * 页面相关事件处理函数--监听用户下拉动作
  266. */
  267. onPullDownRefresh: function() {
  268. },
  269. /**
  270. * 页面上拉触底事件的处理函数
  271. */
  272. onReachBottom: function() {
  273. },
  274. //查询会员信息
  275. PushVipInfo() {
  276. let _this = this;
  277. let id = util.getUserId();
  278. if (id) {
  279. app._post_form('member/apiSelectMeberInfo', 'application/json', {id}, function(
  280. res) {
  281. if (res.code === 0) {
  282. _this.setData({
  283. member:res.member
  284. })
  285. }
  286. })
  287. }
  288. },
  289. // 判断是否开发huanjing
  290. env(){
  291. let that = this
  292. app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  293. null,
  294. function (res) {
  295. if (res.code === 0) {
  296. that.setData({
  297. isDev: res.wgFillInfo.isDev
  298. })
  299. }
  300. }
  301. )
  302. },
  303. submit() {
  304. // console.log('submit', this.data.detail.statusName)
  305. // this.popup4.showPopup();
  306. //报名满了
  307. if(this.data.detail.statusName != '报名中'){
  308. wx.showToast({
  309. title: `活动${this.data.detail.statusName}`,
  310. icon: 'none'
  311. })
  312. return ;
  313. }
  314. let that = this;
  315. if (util.UserLoginStatus()) {
  316. // 活动,会员免费,用户是会员用户 或者活动金额是0元 直接报名
  317. if(this.data.detail.isNeedVip == 1 && (that.data.member.memberState > 0) || that.data.detail.money == 0){
  318. that.signUp();
  319. // 活动,会员免费,用户是普通用户
  320. }else if(this.data.detail.isNeedVip == 1 && (that.data.member.memberState == 0)){
  321. if(this.data.isDev){
  322. wx.showToast({
  323. title: '暂未开始报名,请关注进度!',
  324. icon: 'none',
  325. duration: 2000
  326. })
  327. return
  328. }
  329. that.popup4.showPopup();
  330. }else{
  331. // 所有用户付费
  332. that.popup5.showPopup();
  333. }
  334. // if((this.data.detail.isNeedVip && (this.data.member.memberState > 0)) || !this.data.detail.isNeedVip){
  335. // wx.showModal({
  336. // title: '提示',
  337. // content: '您确定要报名该活动吗',
  338. // success (res) {
  339. // if (res.confirm) {
  340. // that.signUp();
  341. // }
  342. // }
  343. // })
  344. // that.popup5.showPopup();
  345. // }else if(that.data.detail.isNeedVip == 0 && (that.data.member.memberState == 0)){
  346. // that.popup4.showPopup();
  347. // }
  348. // this.setData({
  349. // maskShow: true
  350. // })
  351. }
  352. },
  353. confirmPay() {
  354. this.popup5.hidePopup();
  355. this.singPay()
  356. },
  357. singPay() {
  358. let that = this;
  359. let money = that.data.open ? that.data.actualPrice : that.data.detail.money
  360. console.log(money)
  361. if(money == 0) {
  362. return that.signUp()
  363. }
  364. wx.showLoading({
  365. title: '提交中...',
  366. mask: true,
  367. })
  368. let isDeductiblePrice = that.data.open ? 1 : 0
  369. // act/register/wx 支付时用这个
  370. app._post_form('act/register/wx', "", {
  371. aid:that.data.options.id,
  372. sid: that.data.options.stuId,
  373. isDeductiblePrice: isDeductiblePrice
  374. }, function(res) {
  375. if (res.code === 0) {
  376. wx.hideLoading();
  377. if (!res.map) {
  378. wx.showToast({
  379. title: "支付参数获取失败",
  380. icon: "none",
  381. duration: 1500,
  382. });
  383. return;
  384. }
  385. wx.showActionSheet({
  386. itemList: ["微信支付"],
  387. success: (response) => {
  388. if (response.tapIndex === 0) {
  389. wx.showLoading({
  390. title: "正在处理...",
  391. mask: true,
  392. });
  393. wx.requestPayment({
  394. timeStamp: res.map.timestamp,
  395. nonceStr: res.map.nonce_str,
  396. package: "prepay_id=" + res.map.prepay_id,
  397. signType: "MD5",
  398. paySign: res.map.sign,
  399. success: (result) => {
  400. if (result.errMsg == "requestPayment:ok") {
  401. wx.showLoading({
  402. title: "正在处理...",
  403. mask: true,
  404. });
  405. // console.log(result, 11111111);
  406. wx.hideLoading();
  407. that.popup3.showPopup();
  408. wx.showModal({
  409. title: "温馨提示",
  410. content: "报名成功!",
  411. showCancel: false,
  412. });
  413. // that.loadData();
  414. // setTimeout(()=>{
  415. // wx.redirectTo({
  416. // url: '/pages/my/myPlay/myPlay',
  417. // })
  418. // },2000)
  419. } else {
  420. wx.hideLoading();
  421. wx.showToast({
  422. title: "支付失败!",
  423. icon: "none",
  424. duration: 1500,
  425. });
  426. }
  427. },
  428. fail: (error) => {
  429. wx.hideLoading();
  430. wx.showToast({
  431. title: "支付失败!",
  432. icon: "none",
  433. duration: 1500,
  434. });
  435. },
  436. });
  437. }
  438. },
  439. fail(errors) {},
  440. })
  441. }else if(res.msg == '请完善资料后进行报名操作'){
  442. wx.hideToast();
  443. that.popup2.showPopup();
  444. }else if(res.msg.indexOf('冻结阶段') > -1){
  445. wx.hideToast();
  446. wx.showToast({
  447. title: res.msg,
  448. icon: 'none',
  449. duration: 3000
  450. })
  451. }
  452. })
  453. },
  454. signUp(){
  455. let that = this;
  456. wx.showLoading({
  457. title: '提交中...',
  458. })
  459. let isDeductiblePrice = that.data.open ? 1 : 0
  460. // act/register/wx 支付时用这个
  461. app._post_form('act/register/wx', "", {
  462. aid:that.data.options.id,
  463. sid: that.data.options.stuId,
  464. isDeductiblePrice: isDeductiblePrice
  465. }, function(res) {
  466. if (res.code === 0) {
  467. wx.showToast({
  468. title: "报名成功!",
  469. icon: "none",
  470. duration: 1500,
  471. });
  472. // that.popup5.hidePopup();
  473. that.popup3.showPopup();
  474. // setTimeout(()=>{
  475. // wx.redirectTo({
  476. // url: '/pages/my/myPlay/myPlay',
  477. // })
  478. // },2000)
  479. }else if(res.msg == '请完善资料后进行报名操作'){
  480. wx.hideToast();
  481. that.popup2.showPopup();
  482. } else if (res.msg.indexOf('冻结阶段') > -1) {
  483. console.log(res.msg)
  484. wx.hideToast();
  485. wx.showToast({
  486. title: res.msg,
  487. icon: 'none',
  488. duration: 3000
  489. })
  490. }
  491. })
  492. },
  493. loadVipSel() {
  494. let _this = this;
  495. wx.showLoading({
  496. title: '努力加载中...',
  497. })
  498. app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  499. null,
  500. function(res) {
  501. if (res.code === 0) {
  502. setTimeout(function() {
  503. wxParse.wxParse('vipActivityMessage', 'html', res.wgFillInfo.vipActivityMessage, _this, 5)
  504. }, 300)
  505. }
  506. }
  507. )
  508. },
  509. showShareMenu: function() {
  510. wx.showShareMenu();
  511. this.setData({
  512. show: true
  513. })
  514. },
  515. // 校园代理人详情
  516. perDetail() {
  517. // console.log(e)
  518. let that = this
  519. let role = that.data.roleList[that.data.schoolInfo.memberRoleStatus - 1]
  520. wx.navigateTo({
  521. url: '/expert/agentdetail/agentdetail?id=' + that.data.schoolInfo.id + '&activityId=' + that.data.detail.id + '&name=' + role
  522. })
  523. },
  524. hideShareMenu() {
  525. wx.hideShareMenu();
  526. this.setData({
  527. show: false
  528. })
  529. },
  530. /**
  531. * 用户点击右上角分享
  532. */
  533. onShareAppMessage(){
  534. this.addScore();
  535. return {
  536. title: '活动详情',
  537. path: '/pages/home/index/activityDetail/activityDetail?id=' + pageid,
  538. desc: '欢迎大家踊跃报名',
  539. }
  540. },
  541. //统计积分(每日小程序分享)
  542. addScore: function() {
  543. if(!util.getUserId()){
  544. return ;
  545. }
  546. wx.showLoading({
  547. title: '努力加载中...',
  548. })
  549. app._post_form('scoreStu/share', "", {
  550. stuId: util.getUserId()
  551. }, function(res) {
  552. if (res.code === 0) {}
  553. })
  554. },
  555. // 查询积分抵扣
  556. getPoint(id) {
  557. app._get(`activity/eventRegistrationPayPrice`, {
  558. activityId: id,
  559. id: util.getUserId()
  560. }, res => {
  561. if (res.code === 0) {
  562. this.setData({
  563. dmoney: res.data.deductiblePrice,
  564. point: res.data.remainingPoints,
  565. actualPrice: res.data.actualPrice,
  566. usePoints: res.data.usePoints
  567. })
  568. }
  569. })
  570. },
  571. //取消事件
  572. _error(e) {
  573. this[e.currentTarget.dataset.name].hidePopup();
  574. if(e.currentTarget.dataset.name=='popup4') {
  575. this.popup5.showPopup();
  576. }else {
  577. this.setData({
  578. maskShow: false
  579. })
  580. }
  581. },
  582. _error2(e) {
  583. this[e.currentTarget.dataset.name].hidePopup();
  584. this.setData({
  585. maskShow: false
  586. })
  587. },
  588. //确认事件
  589. _success(e) {
  590. let that = this
  591. if(e.currentTarget.dataset.name=='popup3'){
  592. }else if(e.currentTarget.dataset.name=='popup5'){
  593. that.singPay();
  594. }else if(e.currentTarget.dataset.name=='popup4'){
  595. wx.navigateTo({
  596. url: '/pages/myMember/myMember'
  597. })
  598. }else if(e.currentTarget.dataset.name=='popup2'){
  599. wx.navigateTo({
  600. // url: '/pages/my/myStudy/myStudy'
  601. url: '/pages/my/myData/myData',
  602. })
  603. }else{
  604. wx.navigateTo({
  605. url: e.currentTarget.dataset.name=='popup'?'/pages/myMember/myMember':'/pages/my/myData/myData',
  606. })
  607. }
  608. this.setData({
  609. maskShow: false
  610. })
  611. this[e.currentTarget.dataset.name].hidePopup();
  612. },
  613. seeBigCode(e) {
  614. let arr = [this.data.detail.qrCodePicture];
  615. wx.previewImage({
  616. urls: arr, // 需要预览的图片http链接列表
  617. });
  618. },
  619. })