<template>
  <div id="info-1">
    <van-row>
      <van-col span="24" class="main">
        <van-form @submit="onSubmit" label-width="4em">
          <van-field v-model="form.id" name="id" label="数据id" style="display: none" />
          <van-field name="radio" label="用户类型" :rules="[{ required: true, message: '用户类型' }]">
            <template #input>
              <van-radio-group v-model="form.type" direction="horizontal">
                <van-radio name="1">咨询师</van-radio>
                <van-radio name="2">代理师</van-radio>
                <van-radio name="3">分析师</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <van-field v-model="form.phone" name="phone" label="账号" :rules="[{ required: true, message: '账号' }]" disabled />
          <van-field v-model="form.name" name="name" label="联系电话" :rules="[{ required: true, message: '联系电话' }]" />
          <van-field v-model="form.card" name="card" label="身份证号" :rules="[{ required: false, message: '身份证号' }]" />
          <van-field v-model="form.email" name="email" label="电子邮箱" :rules="[{ required: false, message: '电子邮箱' }]" />
          <van-field v-model="form.address" name="address" label="联系地址" :rules="[{ required: false, message: '联系地址' }]" />
          <van-field v-model="form.zwzc" name="zwzc" label="职务职称" :rules="[{ required: false, message: '职务职称' }]" />
          <van-field v-model="form.school" name="school" label="院校" :rules="[{ required: false, message: '院校' }]" />
          <van-field v-model="form.major" name="major" label="专业" :rules="[{ required: false, message: '专业' }]" />
          <van-field v-model="form.word_tel" name="word_tel" label="办公电话" :rules="[{ required: false, message: '办公电话' }]" />
          <div style="margin: 16px">
            <van-button round block type="info" native-type="submit">提交</van-button>
          </div>
        </van-form>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: answer_tea } = createNamespacedHelpers('answer_tea');
export default {
  name: 'info-1',
  props: {},
  components: {},
  data: function () {
    return {
      form: {},
    };
  },
  created() {
    this.search();
  },
  methods: {
    ...answer_tea(['fetch', 'update']),
    async search() {
      if (this.user.id) {
        let res = await this.fetch(this.user.id);
        if (this.$checkRes(res)) {
          this.$set(this, `form`, res.data);
        }
      }
    },
    async onSubmit(values) {
      let res = await this.update(values);
      if (this.$checkRes(res)) {
        this.$toast({ type: `success`, message: `操作完成` });
        this.search();
      }
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

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