wxLogin.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <el-dialog
  3. title="选择企业"
  4. :visible.sync="dialogVisible"
  5. width="30%">
  6. <el-select v-model="chooseCompanyId" placeholder="请选择">
  7. <el-option
  8. v-for="item in companyList"
  9. :key="item.scyId"
  10. :label="item.scyName"
  11. :value="item.scyId">
  12. </el-option>
  13. </el-select>
  14. <span slot="footer" class="dialog-footer">
  15. <el-button type="primary" @click="chooseLogin()">确 定</el-button>
  16. </span>
  17. </el-dialog>
  18. </template>
  19. <script>
  20. import {chooseCompanyLogin} from "@/api/login";
  21. export default {
  22. data() {
  23. return {
  24. companyList : [],
  25. chooseCompanyId : '',
  26. unionId : '',
  27. dialogVisible : false
  28. }
  29. },
  30. created() {
  31. const code = this.getUrlKey("code")
  32. if(code){
  33. let params = {}
  34. params.code = code
  35. this.$store.dispatch("WxLogin", params).then((response) => {
  36. var data = response.data;
  37. var unionId = data.unionId;
  38. if (data.code == "0") {
  39. this.$router.push({ path: "/certification" });
  40. // 认证单个企业
  41. } else if (data.code == "1") {
  42. // 认证通过
  43. if (data.loginUser.sysUser.companyStatus == "00") {
  44. this.$router.push({ path: this.redirect || "/" });
  45. // 认证未通过
  46. } else {
  47. console.log("未认证通过!")
  48. this.$router.push({ path: "/certification" });
  49. }
  50. // 多家企业
  51. } else if (data.code == "2") {
  52. this.companyList = data.companyList;
  53. this.chooseCompanyId = this.companyList[0].scyId;
  54. this.dialogVisible = true;
  55. // 未绑定用户
  56. } else {
  57. this.$router.push({ path: "/register?unionId="+ unionId});
  58. }
  59. }).catch((res) => {
  60. console.log(res)
  61. // console.log(code)
  62. //this.$router.push({ path: "/login" });
  63. // this.$router.push({ path: "/register" });
  64. });
  65. }else{
  66. this.$router.push({ path: "/login" });
  67. //this.$router.push({ path: "/register" });
  68. }
  69. },
  70. render: function(h) {
  71. return h() // avoid warning message
  72. },
  73. methods: {
  74. getUrlKey(name) {
  75. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
  76. },
  77. chooseLogin(){
  78. chooseCompanyLogin(this.chooseCompanyId).then(response => {
  79. if (response.code == "200") {
  80. // 认证通过
  81. if (response.data.sysUser.companyStatus == "00") {
  82. this.$store.dispatch('GetInfo').then(res => {
  83. this.$router.push({ path: this.redirect || "/" });
  84. })
  85. // 认证未通过
  86. } else {
  87. console.log("未认证通过!")
  88. this.$router.push({ path: "/certification" });
  89. }
  90. }
  91. }).catch((response)=>{
  92. });
  93. }
  94. }
  95. }
  96. </script>