invite.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. const app=getApp(),utils=require("../../../utils/http");
  2. let arr2=[];
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. realname:"",
  9. realphone:'',
  10. orgshow:false,
  11. rootid:1,
  12. loginFlag:true,
  13. canIUseGetUserProfile: false,
  14. orgarr:[],
  15. nowarr:[],
  16. nowtext:[],
  17. nowidx:'',
  18. nowid:'',
  19. endflag:false,
  20. realorg:"",
  21. type:0,//1是管理层,0是员工
  22. root:'',
  23. focus:false,
  24. othercompanyflag:false,
  25. recruit:'',
  26. useversion:app.globalData.useversion
  27. },
  28. /**
  29. * 生命周期函数--监听页面加载
  30. */
  31. onLoad: function (options) {
  32. const that=this;
  33. if (wx.getUserProfile) {
  34. this.setData({
  35. canIUseGetUserProfile: true
  36. })
  37. }
  38. this.setData({
  39. orgshow:false,
  40. nowarr:[],
  41. nowtext:[],
  42. nowidx:'',
  43. nowid:'',
  44. realorg:'',
  45. useversion:app.globalData.useversion
  46. })
  47. if(!!options.scene){
  48. options=unescape(options.scene);
  49. let arr=options.split('&');
  50. console.log(arr)
  51. let flag=false;
  52. for(let i=0;i<arr.length;i++){
  53. let str=arr[i].split('=');
  54. if(str[0]=='manager'){
  55. flag=true;
  56. that.setData({
  57. type:1,
  58. root:str[1]
  59. })
  60. }
  61. if(str[0]=='employee'){
  62. flag=true;
  63. that.setData({
  64. type:0,
  65. root:str[1]
  66. })
  67. }
  68. if(str[0]=='cgi'){
  69. // that.setData({
  70. // othercompanyflag:true
  71. // })
  72. app.globalData.clientype=str[1];
  73. }
  74. if(str[0]=='r'){
  75. this.setData({
  76. recruit:str[1]
  77. })
  78. }
  79. }
  80. this.login();
  81. }
  82. },
  83. suretap:function(){
  84. let str="";
  85. for(let i=0;i<this.data.nowtext.length;i++){
  86. str+=this.data.nowtext[i].name+',';
  87. }
  88. str=str.substring(0,str.length-1);
  89. this.setData({
  90. realorg:str,
  91. orgshow:false,
  92. nowtext:[]
  93. })
  94. },
  95. dothis:function(){},
  96. setnametap:function(e){
  97. this.setData({
  98. realname:e.detail.value
  99. })
  100. },
  101. setphonetap:function(e){
  102. this.setData({
  103. realphone:e.detail.value
  104. })
  105. },
  106. radioChange(e) {
  107. const that=this;
  108. let nowidx=that.data.nowidx,nowtext=that.data.nowtext,nowid=that.data.nowid,orgarr=that.data.orgarr,nowarr=that.data.nowarr;
  109. let obj={};
  110. obj.name=nowarr[e.detail.value].title;
  111. obj.id=nowarr[e.detail.value].id;
  112. nowid=nowarr[e.detail.value].id;
  113. // children的长度为0是说明没有子元素,endflag=true说明上一次的
  114. if(that.data.endflag==true){
  115. nowtext[nowtext.length-1]=obj;
  116. }else{
  117. nowtext.push(obj);
  118. }
  119. if(nowarr[e.detail.value].children.length>0){
  120. that.setData({
  121. endflag:false
  122. })
  123. }else{
  124. that.setData({
  125. endflag:true
  126. })
  127. }
  128. if(nowarr[e.detail.value].children.length>0){
  129. nowarr=nowarr[e.detail.value].children;
  130. }
  131. if(nowidx===''){
  132. nowidx=0;
  133. }else{
  134. nowidx=nowtext.length-1;
  135. }
  136. that.setData({
  137. nowtext:nowtext,
  138. nowid:nowid,
  139. nowarr:nowarr,
  140. nowidx:nowidx
  141. })
  142. },
  143. changeorgtap:function(e){
  144. const that=this;
  145. if(e.currentTarget.dataset.type==(that.data.nowtext.length-1)){
  146. return false;
  147. }
  148. that.setData({
  149. endflag:false
  150. })
  151. let nowidx=that.data.nowidx,nowtext=that.data.nowtext,nowid=that.data.nowid,orgarr=that.data.orgarr,nowarr=that.data.nowarr;
  152. const cid=nowtext[e.currentTarget.dataset.type].id;
  153. that.forfun(orgarr,cid);
  154. let arr1=arr2;
  155. for(let i=0;i<arr1.length;i++){
  156. if(arr1[i].id==cid){
  157. if(e.currentTarget.dataset.type==0){
  158. that.setData({
  159. nowtext:[]
  160. })
  161. let obj1={};
  162. obj1.name=arr1[i].title;
  163. obj1.id=arr1[i].id;
  164. nowtext=[];
  165. }else{
  166. nowtext=nowtext.slice(0,e.currentTarget.dataset.type);
  167. // nowtext[nowtext.length]=[];
  168. }
  169. nowid=arr1[i].id;
  170. }
  171. }
  172. nowarr=arr1;
  173. nowidx=nowtext.length-1;
  174. that.setData({
  175. nowtext:nowtext,
  176. nowid:nowid,
  177. nowarr:nowarr,
  178. nowidx:nowidx
  179. })
  180. },
  181. forfun:function(arr,idx){
  182. let that=this,i=0;
  183. for(i;i<arr.length;i++){
  184. if(arr[i].id==idx){
  185. arr2=arr;
  186. return arr;
  187. }else if(arr[i].children.length>0){
  188. that.forfun(arr[i].children,idx)
  189. }
  190. }
  191. },
  192. setorgtap:function(){
  193. const that=this;
  194. that.setData({
  195. orgshow:true,
  196. focus:true,
  197. nowarr:this.data.orgarr
  198. })
  199. },
  200. closetap:function(){
  201. const that=this;
  202. that.setData({
  203. orgshow:false,
  204. nowarr:[],
  205. nowtext:[],
  206. nowidx:'',
  207. })
  208. },
  209. login:function(){
  210. var that=this;
  211. wx.showLoading();
  212. wx.login({
  213. success: function (data) {
  214. if (data.errMsg == 'login:ok') {
  215. utils.$post({
  216. url: app.globalData.webUrl + 'api/users/code2sessionmini',
  217. data: {
  218. code:data.code,
  219. share:''
  220. },
  221. success: function (r) {
  222. if(r.data.code=='0'){
  223. that.orgfun();
  224. if(!!r.data.user.phone){
  225. if(!!r.data.user.binded&&r.data.user.binded.state!='驳回'&&r.data.user.binded.state!='离职'){
  226. wx.reLaunch({
  227. url: '/pages/index/index',
  228. })
  229. }
  230. app.globalData.personMsg=r.data.user;
  231. app.globalData.use_id=r.data.user.id;
  232. app.globalData.userflag=true;//有个人信息
  233. }
  234. that.setData({
  235. loginFlag:true
  236. })
  237. wx.hideLoading()
  238. }
  239. }
  240. })
  241. }
  242. }
  243. })
  244. },
  245. orgfun: function () {
  246. const that=this;
  247. if(!!app.globalData.personMsg.phone){
  248. that.setData({
  249. realphone:app.globalData.personMsg.phone
  250. })
  251. }
  252. utils.$post({
  253. url: app.globalData.webUrl + 'api/users/org',
  254. header: {
  255. 'Authorization':'bearer '+app.globalData.token
  256. },
  257. data:{
  258. root:that.data.root
  259. },
  260. success: function (res) {
  261. if(res.data.code=='0'){
  262. let arr=JSON.parse(res.data.data);
  263. that.setData({
  264. orgarr:arr,
  265. nowarr:arr
  266. })
  267. }
  268. }
  269. })
  270. },
  271. getUserInfoTap:function(res){
  272. var that=this;
  273. if(res.detail.errMsg=='getUserInfo:ok'){
  274. utils.$post({
  275. method: "POST",//TESTAPIURL APIURL/users/auth
  276. url: app.globalData.webUrl + 'api/users/setUserInfo',
  277. data: {
  278. encryptedData:res.detail.encryptedData,
  279. iv:res.detail.iv,
  280. rawData:res.detail.rawData,
  281. signature:res.detail.signature,
  282. },
  283. header: {
  284. 'Authorization':'bearer '+app.globalData.token
  285. },
  286. success: function (r) {
  287. if(r.data.code=='0'){
  288. that.setData({
  289. loginFlag:true
  290. })
  291. app.globalData.userflag=true;//有个人信息
  292. }else{
  293. wx.showToast({
  294. title: r.data.msg,
  295. icon: "none",
  296. duration:2000
  297. });
  298. }
  299. }
  300. })
  301. }
  302. },
  303. getUserProfile:function(){
  304. var that=this;
  305. wx.getUserProfile({
  306. lang:'zh_CN',
  307. desc: '为了更好的体验申请获取以下信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  308. success: (res) => {
  309. if(res.errMsg=="getUserProfile:ok"){
  310. utils.$post({
  311. method: "POST",//TESTAPIURL APIURL/users/auth
  312. url: app.globalData.webUrl + 'api/users/setUserInfo',
  313. data: {
  314. encryptedData:res.encryptedData,
  315. iv:res.iv,
  316. rawData:res.rawData,
  317. signature:res.signature,
  318. },
  319. header: {
  320. 'Authorization':'bearer '+app.globalData.token
  321. },
  322. success: function (r) {
  323. if(r.data.code=='0'){
  324. that.setData({
  325. loginFlag:true
  326. })
  327. app.globalData.userflag=true;//有个人信息
  328. }else{
  329. wx.showToast({
  330. title: r.data.msg,
  331. icon: "none",
  332. duration:2000
  333. });
  334. }
  335. }
  336. })
  337. }
  338. }
  339. })
  340. },
  341. getPhoneNumberTap:function(res){
  342. var that=this;
  343. if(res.detail.errMsg=='getPhoneNumber:ok'){
  344. utils.$post({
  345. method: "POST",//TESTAPIURL APIURL/users/auth
  346. url: app.globalData.webUrl + 'api/users/setUserMobile',
  347. data: {
  348. encryptedData:res.detail.encryptedData,
  349. iv:res.detail.iv
  350. },
  351. header: {
  352. 'Authorization':'bearer '+app.globalData.token
  353. },
  354. success: function (r) {
  355. if(r.data.code=='0'){
  356. app.globalData.personMsg.phone=r.data.mobile;
  357. that.setData({
  358. realphone:r.data.mobile
  359. })
  360. app.globalData.phone=true;
  361. that.logintap();
  362. }else{
  363. wx.showToast({
  364. title: r.data.msg,
  365. icon: "none",
  366. duration:2000
  367. });
  368. }
  369. }
  370. })
  371. }
  372. },
  373. logintap: function () {
  374. const that=this;
  375. if(!that.data.realname){
  376. wx.showToast({
  377. title: "姓名不能为空",
  378. icon: "none",
  379. duration: 2000
  380. });
  381. return false;
  382. }
  383. if(!that.data.nowid){
  384. wx.showToast({
  385. title: "部门不能为空",
  386. icon: "none",
  387. duration: 2000
  388. });
  389. return false;
  390. }
  391. utils.$post({
  392. url: app.globalData.webUrl + 'api/users/register',
  393. header: {
  394. 'Authorization':'bearer '+app.globalData.token
  395. },
  396. data:{
  397. is_manager:that.data.type,
  398. phone:that.data.realphone,
  399. name:that.data.realname,
  400. orgid:that.data.nowid,
  401. recruit:that.data.recruit
  402. },
  403. success: function (res) {
  404. if(res.data.code=='0'){
  405. wx.showToast({
  406. title: res.data.msg,
  407. icon: "none",
  408. duration: 2000
  409. });
  410. setTimeout(function () {
  411. wx.reLaunch({
  412. url: '/pages/index/index',
  413. })
  414. }, 2000)
  415. }
  416. }
  417. })
  418. },
  419. /**
  420. * 生命周期函数--监听页面初次渲染完成
  421. */
  422. onReady: function () {
  423. },
  424. /**
  425. * 生命周期函数--监听页面显示
  426. */
  427. onShow: function () {
  428. this.setData({
  429. useversion:app.globalData.useversion
  430. })
  431. },
  432. /**
  433. * 生命周期函数--监听页面隐藏
  434. */
  435. onHide: function () {
  436. },
  437. /**
  438. * 生命周期函数--监听页面卸载
  439. */
  440. onUnload: function () {
  441. this.setData({
  442. orgshow:false,
  443. nowarr:[],
  444. nowtext:[],
  445. nowidx:'',
  446. nowid:'',
  447. realorg:'',
  448. })
  449. },
  450. /**
  451. * 页面相关事件处理函数--监听用户下拉动作
  452. */
  453. onPullDownRefresh: function () {
  454. },
  455. /**
  456. * 页面上拉触底事件的处理函数
  457. */
  458. onReachBottom: function () {
  459. },
  460. /**
  461. * 用户点击右上角分享
  462. */
  463. // onShareAppMessage: function () {
  464. // }
  465. })