chooseRole.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. const app = getApp();
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. windowHeight:wx.getSystemInfoSync().windowHeight * (750 / wx.getSystemInfoSync().windowWidth),
  8. },
  9. selectRole(e){
  10. var role = e.currentTarget.dataset.role;
  11. var that = this;
  12. app.requestP({
  13. url:'/role/changeRole',
  14. method:'post',
  15. contentType:' application/json',
  16. data:{
  17. roleCode:role
  18. }
  19. }).then(res=>{
  20. //通过token来判断是否是登录状态
  21. var token = wx.getStorageSync('token');
  22. //如果有token,则去拉取用户数据,相反则只显示界面
  23. if(token){
  24. app.requestP({
  25. url: "/user/getUserInfo",
  26. }).then(function(res){
  27. const {ifOverFlow,loginRole} = res.data.data;
  28. //移除之前缓存的用户信息,确保拿到用户最新数据
  29. wx.removeStorageSync('userInfo');
  30. wx.setStorageSync('userInfo',res.data.data);
  31. //admin 管理员 doctor 医生 register 自由注册 可申请为操作员 personnel 操作员 已选择企业未认证
  32. if(ifOverFlow == 'N'){
  33. if(loginRole == 'personnel'){
  34. that.showModel('/pages/userAuth/workerSelect');
  35. }else if(loginRole == 'doctor'){
  36. that.showModel('/pages/userAuth/doctorInfo');
  37. }else if(loginRole == 'admin'){
  38. that.showModel('/pages/userAuth/adminInfo');
  39. }
  40. }else{
  41. app.showToptip(that,'success','身份切换成功');
  42. wx.navigateBack({
  43. delta: 1
  44. });
  45. }
  46. }).catch(err=>{
  47. app.showToptip(that,'error',err.data.msg)
  48. })
  49. }
  50. }).catch(err=>{
  51. app.showToptip(that,'error',err.data.msg);
  52. })
  53. },
  54. showModel(url){
  55. wx.showModal({
  56. title: '您还未认证,暂无权限',
  57. // content: '确定要删除该图片?',
  58. showCancel: true, //是否显示取消按钮
  59. cancelText: "取消", //默认是“取消”
  60. cancelColor: '#000', //取消文字的颜色
  61. confirmText: "去认证", //默认是“确定”
  62. confirmColor: '#2D59E6', //确定文字的颜色
  63. success: function (res) {
  64. if (res.cancel) {
  65. //点击取消,默认隐藏弹框
  66. } else {
  67. //点击去认证
  68. wx.navigateTo({
  69. url: url,
  70. })
  71. }
  72. },
  73. fail: function (res) {}, //接口调用失败的回调函数
  74. complete: function (res) {}, //接口调用结束的回调函数(调用成功、失败都会执行)
  75. })
  76. },
  77. /**
  78. * 生命周期函数--监听页面加载
  79. */
  80. onLoad: function (options) {
  81. },
  82. /**
  83. * 生命周期函数--监听页面初次渲染完成
  84. */
  85. onReady: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面显示
  89. */
  90. onShow: function () {
  91. },
  92. /**
  93. * 生命周期函数--监听页面隐藏
  94. */
  95. onHide: function () {
  96. },
  97. /**
  98. * 生命周期函数--监听页面卸载
  99. */
  100. onUnload: function () {
  101. },
  102. /**
  103. * 页面相关事件处理函数--监听用户下拉动作
  104. */
  105. onPullDownRefresh: function () {
  106. },
  107. /**
  108. * 页面上拉触底事件的处理函数
  109. */
  110. onReachBottom: function () {
  111. },
  112. /**
  113. * 用户点击右上角分享
  114. */
  115. onShareAppMessage: function () {
  116. }
  117. })