activitymsg.js 25 KB

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