activitymsg.js 24 KB

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