activityDetail.js 14 KB

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