<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="style">
        <el-col :span="24" class="top">
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="main">
          <van-tabs>
            <van-tab title="平台登录">
              <el-col :span="24">
                <van-form>
                  <van-field v-model="webform.phone" name="手机/统一社会信用代码" label="手机/统一社会信用代码" placeholder="手机/统一社会信用代码" />
                  <van-field v-model="webform.passwd" type="password" name="密码" label="密码" placeholder="密码" />
                  <van-field name="radio" label="用户类别">
                    <template #input>
                      <van-radio-group v-model="webform.role" direction="horizontal">
                        <van-radio name="4">个人</van-radio>
                        <van-radio name="5">机构</van-radio>
                        <van-radio name="6">专家</van-radio>
                        <van-radio name="2">VIP用户</van-radio>
                      </van-radio-group>
                    </template>
                  </van-field>
                  <div style="margin: 16px;">
                    <van-button round block type="info" @click="onwebSubmit">
                      登录
                    </van-button>
                  </div>
                </van-form>
              </el-col>
            </van-tab>
            <van-tab title="管理登录">
              <el-col :span="24">
                <van-form>
                  <van-field v-model="form.phone" name="手机/机构代码" label="手机/机构代码" placeholder="手机/机构代码" />
                  <van-field v-model="form.passwd" type="password" name="密码" label="密码" placeholder="密码" />
                  <van-field name="radio" label="用户类别">
                    <template #input>
                      <van-radio-group v-model="form.role">
                        <van-radio name="1">合作机构/业务管理员</van-radio>
                      </van-radio-group>
                    </template>
                  </van-field>
                  <div style="margin: 16px;">
                    <van-button round block type="info" @click="onSubmit">
                      登录
                    </van-button>
                  </div>
                </van-form>
              </el-col>
            </van-tab>
          </van-tabs>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: login } = createNamespacedHelpers('login');
export default {
  name: 'index',
  props: {},
  components: {
    NavBar,
  },
  data: function() {
    return {
      // 头部标题
      title: '',
      // meta为true
      isleftarrow: '',
      // 返回
      navShow: true,
      // 平台登录
      webform: {},
      // 管理登录
      form: {},
    };
  },
  created() {},
  methods: {
    ...login({ toLogin: 'login' }),
    // 平台登录
    async onwebSubmit() {
      let data = this.webform;
      const res = await this.toLogin({ user: data });
      if (res.uid) {
        this.$router.push({ path: '/user/index' });
      }
    },
    // 管理登录
    async onSubmit() {
      let data = this.form;
      if (data.role == null) {
        data.role = '0';
        const res = await this.toLogin({ user: data });
        if (res.uid) {
          this.$router.push({ path: '/user/index' });
        }
      } else {
        const res = await this.toLogin({ user: data });
        if (res.uid) {
          this.$router.push({ path: '/user/index' });
        }
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  mounted() {
    this.title = this.$route.meta.title;
    this.isleftarrow = this.$route.meta.isleftarrow;
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
};
</script>

<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
}
.main {
  min-height: 570px;
}
/deep/.van-field__label {
  width: 7.2em;
}
/deep/.van-radio--horizontal {
  margin: 0 15px 10px 0;
}
/deep/.van-field__label {
  text-align: center;
}
</style>
