<template>
  <div id="applymmDetail">
    <el-row>
      <el-col :span="24" class="debt">
        <el-col :span="24" class="top">
          <topInfo :topTitle="topTitle" :display="display"></topInfo>
        </el-col>
        <el-col :span="24" class="main">
          <el-col :span="24" class="back">
            <detailTop @goBack="goBack"></detailTop>
          </el-col>
          <el-col :span="24" class="info">
            <applymmForm :ruleForm="mmForm" @fallow="fallow"></applymmForm>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import topInfo from '@/layout/common/topInfo.vue';
import detailTop from '@/layout/common/detailTop.vue';
import applymmForm from '@/layout/businessneed/applymmForm.vue';
import { createNamespacedHelpers, mapGetters, mapState } from 'vuex';
const { mapActions: applymmoney } = createNamespacedHelpers('applymmoney');
export default {
  name: 'applymmDetail',
  props: {},
  components: {
    topInfo, //头部导航
    detailTop, //头部返回
    applymmForm, //
  },
  data: () => ({
    display: 'none',
    topTitle: '申请理财产品详情',
    mmForm: {},
  }),
  created() {
    this.searchInfo();
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  methods: {
    ...applymmoney(['create', 'amlist', 'one', 'changefollow']),
    async searchInfo() {
      if (this.id) {
        const res = await this.one({ id: this.id });
        this.$set(this, `mmForm`, res.data);
      }
    },
    // 关注
    async fallow({ id, status }) {
      const res = await this.changefollow({ mid: id, status: status });
      if (res.errcode === 0) {
        this.$message({
          message: '操作成功',
          type: 'success',
        });
      } else {
        this.$message({
          message: '操作失败',
          type: 'error',
        });
      }
      this.searchInfo();
    },
    // 返回
    goBack() {
      this.$router.go(-1);
    },
  },
};
</script>

<style lang="less" scoped>
.debt {
  padding: 20px;
}
.top {
  border-bottom: 1px solid #ccc;
}
.main {
  border-radius: 10px;
  margin: 20px 0 0 0;
  box-shadow: 0 0 3px #666;
}
.main .back {
  padding: 10px 0 10px 15px;
}
</style>
