activitymsg.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. const app = getApp();
  2. const utils = require("../../../utils/http");
  3. let time = 0;
  4. var timer = null;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgUrl: app.globalData.imgUrl,
  11. aid: '',
  12. activityobj: {},
  13. collect: 0,
  14. loading: false,
  15. loginFlag: true,
  16. phoneFlag: false,
  17. canIUseGetUserProfile: false,
  18. articlelogin: true,
  19. datashow: false,
  20. mobile: false,
  21. companyobj: [],
  22. show: false,
  23. date: '',
  24. brokerId: '',
  25. aType: '',
  26. minDate: new Date(2022, 0, 1).getTime(),
  27. maxDate: new Date(2023, 0, 1).getTime(),
  28. qrcode: '',
  29. qrcodeflag:false,
  30. employeeflag:false,
  31. top:app.globalData.statusBarHeight,
  32. hgt:app.globalData.titleBarHeight,
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  38. var that = this;
  39. wx.hideHomeButton();
  40. time = 0;
  41. if (wx.getUserProfile) {
  42. this.setData({
  43. canIUseGetUserProfile: true
  44. })
  45. }
  46. if (!!options.scene) {
  47. options = unescape(options.scene);
  48. let arr = options.split('&');
  49. let obj = {};
  50. for (let i = 0; i < arr.length; i++) {
  51. let arr1 = arr[i].split('=');
  52. obj[arr1[0]] = arr1[1];
  53. }
  54. if (!!obj.uid) {
  55. app.globalData.shareuserid = obj.uid;
  56. }
  57. if (!!obj.bid) {
  58. this.setData({
  59. brokerId: obj.bid
  60. })
  61. }
  62. if (!!obj.t) {
  63. this.setData({
  64. aType: obj.t
  65. })
  66. }
  67. app.globalData.clientype = obj.ctp;
  68. this.setData({
  69. aid: obj.aid,
  70. })
  71. } else {
  72. app.globalData.clientype = options.ctp;
  73. if (!!options.uid) {
  74. app.globalData.shareuserid = options.uid;
  75. }
  76. if (!!options.bid) {
  77. this.setData({
  78. brokerId: options.bid
  79. })
  80. }
  81. if (!!options.t) {
  82. this.setData({
  83. aType: options.t
  84. })
  85. }
  86. this.setData({
  87. aid: options.aid,
  88. })
  89. }
  90. that.logindata();
  91. },
  92. sharecompany: function () {
  93. const that = this;
  94. utils.$post({
  95. url: app.globalData.webUrl + 'client/index/content_belong_company',
  96. header: {
  97. 'Authorization': 'bearer ' + app.globalData.token
  98. },
  99. data: {
  100. client_type: app.globalData.clientype,
  101. uid: app.globalData.shareuserid
  102. },
  103. success: function (res) {
  104. if (res.data.code == '0') {
  105. app.globalData.companyobj=res.data.data;
  106. that.setData({
  107. companyobj: res.data.data
  108. })
  109. }
  110. },
  111. complete(res) {
  112. wx.hideLoading()
  113. }
  114. })
  115. },
  116. logindata: function () {
  117. var that = this;
  118. wx.showLoading();
  119. wx.login({
  120. success: function (data) {
  121. if (data.errMsg == 'login:ok') {
  122. utils.$post({
  123. url: app.globalData.webUrl + 'api/users/code2sessionmini',
  124. data: {
  125. code: data.code,
  126. share: app.globalData.shareuserid,
  127. client_type:app.globalData.clientype
  128. },
  129. success: function (r) {
  130. if (r.data.code == '0') {
  131. app.globalData.sharepersonobj = r.data.share ? r.data.share : r.data.user;
  132. app.globalData.token = r.data.token;
  133. // that.listfun();
  134. that.sharecompany();
  135. // r.data.user.headimgurl='';
  136. // r.data.user.nickname='';
  137. app.globalData.personMsg = r.data.user;
  138. app.globalData.companyname=r.data.company;
  139. app.globalData.official_openid = r.data.official_openid;
  140. app.globalData.agentEmployeEid = r.data.agent_employee_id;
  141. if (!!r.data.user.phone) {
  142. app.globalData.use_id = r.data.user.id;
  143. app.globalData.personMsg = r.data.user;
  144. that.setData({
  145. loginFlag: true,
  146. datashow: true,
  147. phoneFlag: false,
  148. employeeflag: (!!r.data.user.binded && r.data.user.binded.state == '在职') ? true : false,
  149. })
  150. that.unreadMsg();
  151. if (!!r.data.user.binded && r.data.user.binded.state == '在职'){
  152. app.globalData.currentUserId = r.data.user.binded.id;
  153. }
  154. } else {
  155. that.unreadMsg();
  156. wx.hideLoading();
  157. that.setData({
  158. articlelogin: false,
  159. loginFlag: true,
  160. phoneFlag: true,
  161. })
  162. }
  163. }
  164. }
  165. })
  166. }
  167. wx.hideLoading();
  168. }
  169. })
  170. },
  171. golastap: function () {
  172. // wx.navigateBack()
  173. wx.navigateBack({
  174. delta: 1,
  175. success:function(r){
  176. },
  177. fail:function(r){
  178. wx.reLaunch({
  179. url: '/pages/index/index?state=1',
  180. })
  181. },
  182. })
  183. },
  184. goindextap:function(){
  185. if(!this.data.employeeflag){
  186. wx.reLaunch({
  187. url: '/pages/index/index',
  188. })
  189. }else{
  190. wx.reLaunch({
  191. url: '/pages/consoledesk/consoledesk',
  192. })
  193. }
  194. },
  195. /**
  196. * 生命周期函数--监听页面初次渲染完成
  197. */
  198. onReady: function () {
  199. },
  200. getUserInfoTap: function (res) {
  201. var that = this;
  202. console.log(res)
  203. if (res.detail.errMsg == 'getUserInfo:ok') {
  204. utils.$post({
  205. method: "POST",//TESTAPIURL APIURL/users/auth
  206. url: app.globalData.webUrl + 'api/users/setUserInfo',
  207. data: {
  208. encryptedData: res.detail.encryptedData,
  209. iv: res.detail.iv,
  210. rawData: res.detail.rawData,
  211. signature: res.detail.signature,
  212. },
  213. header: {
  214. 'Authorization': 'bearer ' + app.globalData.token
  215. },
  216. success: function (r) {
  217. if (r.data.code == '0') {
  218. that.setData({
  219. loginFlag: true,
  220. phoneFlag: true
  221. })
  222. app.globalData.userflag = true;//有个人信息
  223. } else {
  224. wx.showToast({
  225. title: r.data.msg,
  226. icon: "none",
  227. duration: 2000
  228. });
  229. }
  230. }
  231. })
  232. }
  233. },
  234. getUserProfile: function () {
  235. var that = this;
  236. wx.getUserProfile({
  237. lang: 'zh_CN',
  238. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  239. success: (res) => {
  240. console.log(res)
  241. if (res.errMsg == "getUserProfile:ok") {
  242. utils.$post({
  243. method: "POST",//TESTAPIURL APIURL/users/auth
  244. url: app.globalData.webUrl + 'api/users/setUserInfo',
  245. data: {
  246. encryptedData: res.encryptedData,
  247. iv: res.iv,
  248. rawData: res.rawData,
  249. signature: res.signature,
  250. },
  251. header: {
  252. 'Authorization': 'bearer ' + app.globalData.token
  253. },
  254. success: function (r) {
  255. if (r.data.code == '0') {
  256. that.setData({
  257. loginFlag: true
  258. })
  259. app.globalData.userflag = true;//有个人信息
  260. that.setData({
  261. phoneFlag: true
  262. })
  263. } else {
  264. wx.showToast({
  265. title: r.data.msg,
  266. icon: "none",
  267. duration: 2000
  268. });
  269. }
  270. }
  271. })
  272. }
  273. }
  274. })
  275. },
  276. getPhoneNumberTap: function (res) {
  277. var that = this;
  278. if (res.detail.errMsg == 'getPhoneNumber:ok') {
  279. wx.showLoading()
  280. that.setData({
  281. phoneFlag: false
  282. })
  283. utils.$post({
  284. method: "POST",//TESTAPIURL APIURL/users/auth
  285. url: app.globalData.webUrl + 'api/users/setUserMobile',
  286. data: {
  287. encryptedData: res.detail.encryptedData,
  288. iv: res.detail.iv
  289. },
  290. header: {
  291. 'Authorization': 'bearer ' + app.globalData.token
  292. },
  293. success: function (r) {
  294. if (r.data.code == '0') {
  295. app.globalData.personMsg.phone = r.data.mobile;
  296. app.globalData.phone = true;
  297. that.bindfun();
  298. } else {
  299. that.setData({
  300. phoneFlag: true
  301. })
  302. wx.showToast({
  303. title: r.data.msg,
  304. icon: "none",
  305. duration: 2000
  306. });
  307. }
  308. }
  309. })
  310. }
  311. },
  312. onClose() {
  313. this.activitybind();
  314. this.setData({
  315. show: false
  316. })
  317. },
  318. onConfirm(event) {
  319. this.setData({
  320. show: false,
  321. date: this.formatDate(event.detail),
  322. });
  323. this.activitybind();
  324. },
  325. formatDate(date) {
  326. date = new Date(date);
  327. return `${date.getMonth() + 1}/${date.getDate()}`;
  328. },
  329. bindfun: function () {
  330. wx.showLoading({
  331. title: '报名中...',
  332. })
  333. let that = this;
  334. that.setData({
  335. loading: true
  336. })
  337. if (that.data.aType && that.data.aType == 'b') {
  338. utils.$post({
  339. url: app.globalData.webUrl + 'api/agents/add_activity_customer',
  340. header: {
  341. 'Authorization': 'bearer ' + app.globalData.token
  342. },
  343. data: {
  344. phone: app.globalData.personMsg.phone,
  345. aid: that.data.aid,
  346. agent_id: that.data.brokerId
  347. },
  348. success: function (res) {
  349. wx.hideLoading();
  350. if (res.data.code == '0') {
  351. let activityobj = that.data.activityobj;
  352. activityobj.is_activity = 1;
  353. that.setData({
  354. activityobj: activityobj,
  355. qrcode:res.data.url,
  356. })
  357. setTimeout(() => {
  358. that.setData({
  359. loading: false
  360. })
  361. },1500)
  362. wx.previewImage({
  363. current: res.data.url, // 当前显示图片的 http 链接
  364. urls: [res.data.url] // 需要预览的图片 http 链接列表
  365. })
  366. wx.showToast({
  367. title: '报名成功,请等待专业人员和您联系!',
  368. icon: 'none',
  369. duration: 2000
  370. })
  371. } else {
  372. that.setData({
  373. loading: false
  374. })
  375. wx.showToast({
  376. title: res.data.msg,
  377. icon: 'none',
  378. duration: 2000
  379. })
  380. }
  381. }
  382. })
  383. } else {
  384. utils.$post({
  385. url: app.globalData.webUrl + 'client/activity/activity_sign',
  386. header: {
  387. 'Authorization': 'bearer ' + app.globalData.token
  388. },
  389. data: {
  390. phone: app.globalData.personMsg.phone,
  391. aid: that.data.aid,
  392. employee_id: '',
  393. uid: app.globalData.shareuserid,
  394. date: '',
  395. },
  396. success: function (res) {
  397. wx.hideLoading();
  398. if (res.data.code == '0') {
  399. let activityobj = that.data.activityobj;
  400. activityobj.is_activity = 1;
  401. that.setData({
  402. activityobj: activityobj,
  403. qrcode:res.data.url,
  404. })
  405. setTimeout(() => {
  406. that.setData({
  407. loading: false
  408. })
  409. },1500)
  410. wx.previewImage({
  411. current: res.data.url, // 当前显示图片的 http 链接
  412. urls: [res.data.url] // 需要预览的图片 http 链接列表
  413. })
  414. wx.showToast({
  415. title: '报名成功,请等待专业人员和您联系!',
  416. icon: 'none',
  417. duration: 2000
  418. })
  419. } else {
  420. that.setData({
  421. loading: false
  422. })
  423. wx.showToast({
  424. title: res.data.msg,
  425. icon: 'none',
  426. duration: 2000
  427. })
  428. }
  429. }
  430. })
  431. }
  432. },
  433. lookimgtap(){
  434. this.setData({
  435. qrcodeflag:true
  436. })
  437. },
  438. closeqrcodetap(){
  439. this.setData({
  440. qrcodeflag:false
  441. })
  442. },
  443. unreadMsg: function () {
  444. this.setData({
  445. datashow: true
  446. })
  447. wx.showLoading({
  448. title: '加载中...',
  449. })
  450. this.activityfun();
  451. },
  452. activityfun: function () {
  453. var that = this;
  454. if (that.data.aType && that.data.aType == 'b') {
  455. utils.$post({
  456. url: app.globalData.webUrl + 'api/agents/activity_detail',
  457. header: {
  458. 'Authorization': 'bearer ' + app.globalData.token
  459. },
  460. data: {
  461. id: that.data.aid,
  462. uid: app.globalData.personMsg.id
  463. },
  464. success: function (res) {
  465. if (res.data.code == '0') {
  466. that.setData({
  467. qrcode:res.data.data.qrcode,
  468. activityobj: res.data.data,
  469. loginFlag: true,
  470. minDate: new Date(res.data.data.start_date.split('-')[0], res.data.data.start_date.split('-')[1] - 1, res.data.data.start_date.split('-')[2]).getTime(),
  471. maxDate: new Date(res.data.data.end_date.split('-')[0], res.data.data.end_date.split('-')[1] - 1, res.data.data.end_date.split('-')[2]).getTime(),
  472. })
  473. wx.setNavigationBarTitle({
  474. title: res.data.data.title
  475. })
  476. if (res.data.data.timestate == 2 && res.data.data.show == 1) {
  477. wx.showToast({
  478. title: "本次活动已结束",
  479. icon: "none",
  480. duration: 2000
  481. });
  482. } else if (res.data.data.show == 0) {
  483. wx.showToast({
  484. title: "本次活动已下架",
  485. icon: "none",
  486. duration: 2000
  487. });
  488. }
  489. }
  490. setTimeout(function () {
  491. wx.hideLoading()
  492. }, 300)
  493. }
  494. })
  495. } else {
  496. utils.$post({
  497. url: app.globalData.webUrl + 'client/activity/details',
  498. header: {
  499. 'Authorization': 'bearer ' + app.globalData.token
  500. },
  501. data: {
  502. id: that.data.aid,
  503. uid: app.globalData.personMsg.id
  504. },
  505. success: function (res) {
  506. if (res.data.code == '0') {
  507. that.setData({
  508. qrcode:res.data.data.qrcode,
  509. activityobj: res.data.data,
  510. loginFlag: true,
  511. minDate: new Date(res.data.data.start_date.split('-')[0], res.data.data.start_date.split('-')[1] - 1, res.data.data.start_date.split('-')[2]).getTime(),
  512. maxDate: new Date(res.data.data.end_date.split('-')[0], res.data.data.end_date.split('-')[1] - 1, res.data.data.end_date.split('-')[2]).getTime(),
  513. })
  514. wx.setNavigationBarTitle({
  515. title: res.data.data.title
  516. })
  517. if (res.data.data.timestate == 2 && res.data.data.show == 1) {
  518. wx.showToast({
  519. title: "本次活动已结束",
  520. icon: "none",
  521. duration: 2000
  522. });
  523. } else if (res.data.data.show == 0) {
  524. wx.showToast({
  525. title: "本次活动已下架",
  526. icon: "none",
  527. duration: 2000
  528. });
  529. }
  530. }
  531. setTimeout(function () {
  532. wx.hideLoading()
  533. }, 300)
  534. }
  535. })
  536. }
  537. },
  538. paytap: function () {
  539. var that = this;
  540. wx.showLoading({
  541. title: '拉起支付中...',
  542. })
  543. utils.$post({
  544. url: app.globalData.webUrl + 'client/pay/mini',
  545. header: {
  546. 'Authorization': 'bearer ' + app.globalData.token
  547. },
  548. data: {
  549. id: that.data.aid,
  550. name: app.globalData.personMsg.nickname,
  551. phone: app.globalData.personMsg.phone,
  552. type: 'activity'
  553. },
  554. success: function (rest) {
  555. if (rest.data.code == '0') {
  556. let activityobj = that.data.activityobj;
  557. wx.requestPayment({
  558. timeStamp: rest.data.data.timeStamp,
  559. nonceStr: rest.data.data.nonceStr,
  560. package: rest.data.data.package,
  561. signType: rest.data.data.signType,
  562. paySign: rest.data.data.paySign,
  563. success(rs) {
  564. wx.showToast({
  565. title: '支付成功',
  566. icon: 'success',
  567. duration: 1000
  568. })
  569. activityobj.had_pay = 1;
  570. that.setData({
  571. activityobj: activityobj
  572. })
  573. },
  574. fail(r) {
  575. console.log(r)
  576. },
  577. complete: res => {
  578. wx.hideLoading()
  579. }
  580. })
  581. }
  582. }
  583. })
  584. },
  585. getpaytap: function () {
  586. wx.showToast({
  587. title: '请勿重复交定',
  588. icon: 'success',
  589. duration: 1000
  590. })
  591. },
  592. activitytap: function () {
  593. let that = this;
  594. utils.$post({
  595. url: app.globalData.webUrl + 'api/share/addlog',
  596. header: {
  597. 'Authorization': 'bearer ' + app.globalData.token
  598. },
  599. data: {
  600. id: that.data.aid,
  601. type: 'activity',
  602. },
  603. success: function (r) {
  604. }
  605. })
  606. },
  607. /**
  608. * 生命周期函数--监听页面显示
  609. */
  610. onShow: function () {
  611. timer = setInterval(function () {
  612. time = time * 1 + 1;
  613. }, 1000)
  614. },
  615. /**
  616. * 生命周期函数--监听页面隐藏
  617. */
  618. onHide: function () {
  619. if (timer) {
  620. clearInterval(timer);
  621. }
  622. this.visitimefun();
  623. },
  624. visitimefun() {
  625. const that = this;
  626. utils.$post({
  627. url: app.globalData.webUrl + 'client/index/visit_due_time',
  628. header: {
  629. 'Authorization': 'bearer ' + app.globalData.token
  630. },
  631. data: {
  632. id: that.data.aid,
  633. pipe_type: 'activity',
  634. time: time,
  635. },
  636. success: function (res) {
  637. }
  638. })
  639. },
  640. /**
  641. * 生命周期函数--监听页面卸载
  642. */
  643. onUnload: function () {
  644. this.visitimefun();
  645. },
  646. /**
  647. * 页面相关事件处理函数--监听用户下拉动作
  648. */
  649. onPullDownRefresh: function () {
  650. },
  651. dothis(){},
  652. /**
  653. * 页面上拉触底事件的处理函数
  654. */
  655. onReachBottom: function () {
  656. },
  657. addsharetap: function (type) {
  658. let that = this;
  659. utils.$post({
  660. url: app.globalData.webUrl + 'api/share/addlog',
  661. header: {
  662. 'Authorization': 'bearer ' + app.globalData.token
  663. },
  664. data: {
  665. id: '0',
  666. type: type,
  667. },
  668. success: function (r) {}
  669. })
  670. },
  671. /**
  672. * 用户点击右上角分享
  673. */
  674. onShareAppMessage: function () {
  675. if (this.data.aType && this.data.aType == 'b') {
  676. var img = this.data.activityobj.cover;
  677. return {
  678. title: this.data.activityobj.title,
  679. imageUrl: img,
  680. path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&bid=' + this.data.brokerId + '&ctp=' + app.globalData.clientype + '&t=b',
  681. };
  682. } else {
  683. this.addsharetap('toolAll');
  684. let uid = app.globalData.shareuserid ? app.globalData.shareuserid : app.globalData.personMsg.id;
  685. var img = this.data.activityobj.poster;
  686. return {
  687. title: this.data.activityobj.title,
  688. imageUrl: img,
  689. path: '/share/pages/activitymsg/activitymsg?aid=' + this.data.aid + '&uid=' + uid + '&ctp=' + app.globalData.clientype,
  690. };
  691. }
  692. }
  693. })