<template>
  <div id="detail">
    <el-row>
      <el-col :span="24" class="debt">
        <el-col :span="24" class="top">
          <!-- <topInfo :topTitle="topTitle" :display="display"></topInfo> -->
          <detailTopInfo :topTitle="topTitle" :display="display"></detailTopInfo>
        </el-col>
        <el-col :span="24" class="main">
          <userInfoForm :ruleForm="ruleForm" :formTitle="formTitle" @submitForm="submitForm" @resetForm="resetForm"></userInfoForm>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import detailTopInfo from '@/layout/common/detailTopInfo.vue';
import userInfoForm from '@/layout/userInfo/userInfoForm.vue';
import { mapState, mapMutations, createNamespacedHelpers, mapGetters } from 'vuex';
const { mapActions: otheruser } = createNamespacedHelpers('otheruser');
export default {
  name: 'detail',
  props: {},
  components: {
    detailTopInfo, //头部导航
    userInfoForm, //头部返回
  },
  data: () => ({
    topTitle: '账号设置',
    display: 'none',

    formTitle: '个人信息管理',
    ruleForm: {},
  }),
  created() {
    this.searchInfo();
  },
  computed: {
    id() {
      return this.user.uid;
    },
    ...mapState(['user']),
  },
  methods: {
    ...otheruser(['query', 'fetch', 'update', 'create']),
    async searchInfo() {
      if (this.id) {
        const res = await this.fetch(this.id);
        this.$set(this, `ruleForm`, res.data);
      }
    },
    // 提交
    async submitForm({ data }) {
      let res;
      if (this.id) {
        res = await this.update(data);
        if (res.errcode === 0) {
          this.$router.push({ name: 'login' });
          this.$message({
            message: '信息修改成功',
            type: 'success',
          });
        }
      }
      console.log(res.data);
    },
    // 取消
    resetForm() {
      this.$router.push({ path: '/index' });
    },
    // 返回
    goBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  height: 50px;
  margin: 0 0 10px 0;
}
.main {
  min-height: 765px;
  background: #ffffff;
  padding: 20px;
}
</style>
