<template>
  <div id="bind">
    <el-row>
      <el-col :span="24" class="info">
        <el-col :span="24" class="top">
          <NavBar v-show="navShow" :title="title" :isleftarrow="isleftarrow"> </NavBar>
        </el-col>
        <el-col :span="24" class="mess" style="padding-top:10vh;">
          <writeStu :form="form" @onSubmit="onSubmit"></writeStu>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import writeStu from '@/layout/common/writeStu.vue';
import Vue from 'vue';
import _ from 'lodash';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('login');
export default {
  metaInfo: { title: '学生注册' },
  name: 'bind',
  props: {},
  components: {
    NavBar, //底部信息
    writeStu, //填写学生绑定信息
  },
  data: () => ({
    form: {},
    title: '填写信息',
    isleftarrow: '',
    transitionName: 'fade',
    navShow: true,
  }),
  created() {},
  computed: {
    openid() {
      return this.$route.query.openid;
    },
  },
  methods: {
    ...mapActions(['login', 'bind']),
    async onSubmit(form) {
      form.openid = this.openid;
      let res = await this.bind(form);
      if (res.errcode === 0) {
        this.$notify({
          message: '绑定成功',
          type: 'success',
        });
        sessionStorage.setItem('user', JSON.stringify(res.data));
        window.history.replaceState({}, '首页', `${Vue.config.weixin.baseUrl}/api/train/auth?redirect_uri=${Vue.config.weixin.target}/login&type=0`);
      } else {
        this.$notify({
          message: res.errmsg,
          type: 'danger',
        });
      }
    },
  },
};
</script>

<style lang="less" scoped></style>
