activityDetail.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. // this.popup4.showPopup();
  305. //报名满了
  306. if(this.data.detail.statusName != '报名中'){
  307. return ;
  308. }
  309. let that = this;
  310. if (util.UserLoginStatus()) {
  311. // 活动,会员免费,用户是会员用户 或者活动金额是0元 直接报名
  312. if(this.data.detail.isNeedVip == 1 && (that.data.member.memberState > 0) || that.data.detail.money == 0){
  313. that.signUp();
  314. // 活动,会员免费,用户是普通用户
  315. }else if(this.data.detail.isNeedVip == 1 && (that.data.member.memberState == 0)){
  316. if(this.data.isDev){
  317. wx.showToast({
  318. title: '暂未开始报名,请关注进度!',
  319. icon: 'none',
  320. duration: 2000
  321. })
  322. return
  323. }
  324. that.popup4.showPopup();
  325. }else{
  326. // 所有用户付费
  327. that.popup5.showPopup();
  328. }
  329. // if((this.data.detail.isNeedVip && (this.data.member.memberState > 0)) || !this.data.detail.isNeedVip){
  330. // wx.showModal({
  331. // title: '提示',
  332. // content: '您确定要报名该活动吗',
  333. // success (res) {
  334. // if (res.confirm) {
  335. // that.signUp();
  336. // }
  337. // }
  338. // })
  339. // that.popup5.showPopup();
  340. // }else if(that.data.detail.isNeedVip == 0 && (that.data.member.memberState == 0)){
  341. // that.popup4.showPopup();
  342. // }
  343. // this.setData({
  344. // maskShow: true
  345. // })
  346. }
  347. },
  348. confirmPay() {
  349. this.popup5.hidePopup();
  350. this.singPay()
  351. },
  352. singPay() {
  353. let that = this;
  354. let money = that.data.open ? that.data.actualPrice : that.data.detail.money
  355. console.log(money)
  356. if(money == 0) {
  357. return that.signUp()
  358. }
  359. wx.showLoading({
  360. title: '提交中...',
  361. })
  362. let isDeductiblePrice = that.data.open ? 1 : 0
  363. // act/register/wx 支付时用这个
  364. app._post_form('act/register/wx', "", {
  365. aid:that.data.options.id,
  366. sid: that.data.options.stuId,
  367. isDeductiblePrice: isDeductiblePrice
  368. }, function(res) {
  369. if (res.code === 0) {
  370. wx.showActionSheet({
  371. itemList: ["微信支付"],
  372. success: (response) => {
  373. if (response.tapIndex === 0) {
  374. wx.showLoading({
  375. title: "正在处理...",
  376. mask: true,
  377. });
  378. wx.requestPayment({
  379. timeStamp: res.map.timestamp,
  380. nonceStr: res.map.nonce_str,
  381. package: "prepay_id=" + res.map.prepay_id,
  382. signType: "MD5",
  383. paySign: res.map.sign,
  384. success: (result) => {
  385. if (result.errMsg == "requestPayment:ok") {
  386. wx.showLoading({
  387. title: "正在处理...",
  388. mask: true,
  389. });
  390. console.log(result, 11111111);
  391. wx.hideLoading();
  392. that.popup3.showPopup();
  393. wx.showModal({
  394. title: "温馨提示",
  395. content: "报名成功!",
  396. showCancel: false,
  397. });
  398. // setTimeout(()=>{
  399. // wx.redirectTo({
  400. // url: '/pages/my/myPlay/myPlay',
  401. // })
  402. // },2000)
  403. } else {
  404. wx.hideLoading();
  405. wx.showToast({
  406. title: "支付失败!",
  407. icon: "none",
  408. duration: 1500,
  409. });
  410. }
  411. },
  412. fail: (error) => {
  413. wx.hideLoading();
  414. wx.showToast({
  415. title: "支付失败!",
  416. icon: "none",
  417. duration: 1500,
  418. });
  419. },
  420. });
  421. }
  422. },
  423. fail(errors) {},
  424. })
  425. }else if(res.msg == '请完善资料后进行报名操作'){
  426. wx.hideToast();
  427. that.popup2.showPopup();
  428. }else if(res.msg.indexOf('冻结阶段') > -1){
  429. wx.hideToast();
  430. wx.showToast({
  431. title: res.msg,
  432. icon: 'none',
  433. duration: 3000
  434. })
  435. }
  436. })
  437. },
  438. signUp(){
  439. let that = this;
  440. wx.showLoading({
  441. title: '提交中...',
  442. })
  443. let isDeductiblePrice = that.data.open ? 1 : 0
  444. // act/register/wx 支付时用这个
  445. app._post_form('act/register/wx', "", {
  446. aid:that.data.options.id,
  447. sid: that.data.options.stuId,
  448. isDeductiblePrice: isDeductiblePrice
  449. }, function(res) {
  450. if (res.code === 0) {
  451. wx.showToast({
  452. title: "报名成功!",
  453. icon: "none",
  454. duration: 1500,
  455. });
  456. // that.popup5.hidePopup();
  457. that.popup3.showPopup();
  458. // setTimeout(()=>{
  459. // wx.redirectTo({
  460. // url: '/pages/my/myPlay/myPlay',
  461. // })
  462. // },2000)
  463. }else if(res.msg == '请完善资料后进行报名操作'){
  464. wx.hideToast();
  465. that.popup2.showPopup();
  466. }else if(res.msg.indexOf('冻结阶段') > -1){
  467. wx.hideToast();
  468. wx.showToast({
  469. title: res.msg,
  470. icon: 'none',
  471. duration: 3000
  472. })
  473. }
  474. })
  475. },
  476. loadVipSel() {
  477. let _this = this;
  478. wx.showLoading({
  479. title: '努力加载中...',
  480. })
  481. app._post_form('wgfillinfo/apiSelectwgfillinfo', 'application/json',
  482. null,
  483. function(res) {
  484. if (res.code === 0) {
  485. setTimeout(function() {
  486. wxParse.wxParse('vipActivityMessage', 'html', res.wgFillInfo.vipActivityMessage, _this, 5)
  487. }, 300)
  488. }
  489. }
  490. )
  491. },
  492. showShareMenu: function() {
  493. wx.showShareMenu();
  494. this.setData({
  495. show: true
  496. })
  497. },
  498. // 校园代理人详情
  499. perDetail() {
  500. // console.log(e)
  501. let that = this
  502. let role = that.data.roleList[that.data.schoolInfo.memberRoleStatus - 1]
  503. wx.navigateTo({
  504. url: '/expert/agentdetail/agentdetail?id=' + that.data.schoolInfo.id + '&activityId=' + that.data.detail.id + '&name=' + role
  505. })
  506. },
  507. hideShareMenu() {
  508. wx.hideShareMenu();
  509. this.setData({
  510. show: false
  511. })
  512. },
  513. /**
  514. * 用户点击右上角分享
  515. */
  516. onShareAppMessage(){
  517. this.addScore();
  518. return {
  519. title: '活动详情',
  520. path: '/pages/home/index/activityDetail/activityDetail?id=' + pageid,
  521. desc: '欢迎大家踊跃报名',
  522. }
  523. },
  524. //统计积分(每日小程序分享)
  525. addScore: function() {
  526. if(!util.getUserId()){
  527. return ;
  528. }
  529. wx.showLoading({
  530. title: '努力加载中...',
  531. })
  532. app._post_form('scoreStu/share', "", {
  533. stuId: util.getUserId()
  534. }, function(res) {
  535. if (res.code === 0) {}
  536. })
  537. },
  538. // 查询积分抵扣
  539. getPoint(id) {
  540. app._get(`activity/eventRegistrationPayPrice`, {
  541. activityId: id,
  542. id: util.getUserId()
  543. }, res => {
  544. if (res.code === 0) {
  545. this.setData({
  546. dmoney: res.data.deductiblePrice,
  547. point: res.data.remainingPoints,
  548. actualPrice: res.data.actualPrice,
  549. usePoints: res.data.usePoints
  550. })
  551. }
  552. })
  553. },
  554. //取消事件
  555. _error(e) {
  556. this[e.currentTarget.dataset.name].hidePopup();
  557. if(e.currentTarget.dataset.name=='popup4') {
  558. this.popup5.showPopup();
  559. }else {
  560. this.setData({
  561. maskShow: false
  562. })
  563. }
  564. },
  565. _error2(e) {
  566. this[e.currentTarget.dataset.name].hidePopup();
  567. this.setData({
  568. maskShow: false
  569. })
  570. },
  571. //确认事件
  572. _success(e) {
  573. let that = this
  574. if(e.currentTarget.dataset.name=='popup3'){
  575. }else if(e.currentTarget.dataset.name=='popup5'){
  576. that.singPay();
  577. }else if(e.currentTarget.dataset.name=='popup4'){
  578. wx.navigateTo({
  579. url: '/pages/myMember/myMember'
  580. })
  581. }else if(e.currentTarget.dataset.name=='popup2'){
  582. wx.navigateTo({
  583. // url: '/pages/my/myStudy/myStudy'
  584. url: '/pages/my/myData/myData',
  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. seeBigCode(e) {
  597. let arr = [this.data.detail.qrCodePicture];
  598. wx.previewImage({
  599. urls: arr, // 需要预览的图片http链接列表
  600. });
  601. },
  602. })