1
0

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