<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">
          <person :form="form" @onSubmit="onSubmit"></person>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import NavBar from '@/layout/common/topInfo.vue';
import person from '@/layout/user/person.vue';
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions: market } = createNamespacedHelpers('market');
const { mapActions: expertsuser } = createNamespacedHelpers('expertsuser');
export default {
  name: 'index',
  props: {},
  components: {
    NavBar,
    person, //个人信息维护
  },
  data: () => ({
    // 头部标题
    title: '',
    // meta为true
    isleftarrow: '',
    // 返回
    navShow: true,
    // 个人信息
    form: {},
  }),
  created() {
    this.searchInfo();
  },
  computed: {
    ...mapState(['user']),
  },
  methods: {
    ...market(['fetch', 'update']),
    ...expertsuser({ expertsuserFetch: 'fetch', expertsuserUpdate: 'update', expertsuserUpgrade: 'upgrade' }),
    async searchInfo() {
      if (this.user.role == '2' || this.user.role == '3' || this.user.role == '7') {
        let res = await this.fetch(this.user.userid);
        if (res.errcode === 0) {
          console.log(res.data);

          this.$set(this, `form`, res.data);
        }
      } else if (this.user.role == '6') {
        let res = await this.expertsuserFetch(this.user.userid);
        if (res.errcode === 0) {
          this.$set(this, `form`, res.data);
        }
      }
    },
    async onSubmit({ data }) {
      if (data.role == '2' || data.role == '3' || data.role == '7') {
        let res;
        let msg;
        res = await this.update(data);
      } else if (data.role == '6') {
        let res;
        let msg;
        res = await this.expertsuserUpdate(data);
      }
      this.$message({
        message: '个人信息修改成功',
        type: 'success',
      });
      this.searchInfo();
    },
  },
  mounted() {
    this.title = this.$route.meta.title;
    this.isleftarrow = this.$route.meta.isleftarrow;
  },
};
</script>

<style lang="less" scoped>
.style {
  width: 100%;
  min-height: 667px;
  position: relative;
  background-color: #f9fafc;
}
.top {
  height: 46px;
  overflow: hidden;
  position: relative;
  z-index: 999;
}
.main {
  min-height: 570px;
}
.foot {
  position: absolute;
  bottom: 0;
}
</style>
