activityDetail.js 14 KB

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