<template>
  <div id="detail">
    <el-row>
      <el-col :span="24">
        <el-col :span="24" class="top">
          <detailTopInfo :topTitle="topTitle" :display="display" @goBack="goBack"></detailTopInfo>
        </el-col>
        <el-col :span="24" class="main">
          <detailInfo
            :ruleForm="ruleForm"
            :rzlc="rzlc"
            :sshy="sshy"
            @submitForm="submitForm"
            @resetForm="resetForm"
            @shenheForm="shenheForm"
            :formTitle="formTitle"
          ></detailInfo>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import detailTopInfo from '@/layout/custom/detailTopInfo.vue';
import detailInfo from '@/layout/institution/detailInfo.vue';

import { createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('institution');
const { mapActions: Mapdictionary } = createNamespacedHelpers('dictionary');
export default {
  name: 'detail',
  props: {},
  components: {
    detailTopInfo, //表单头部按钮
    detailInfo, //表单内容
  },
  data: () => ({
    topTitle: '金融机构',
    display: 'block',
    formTitle: '信息管理',
    ruleForm: {},
    sshy: [],
    rzlc: [],
  }),
  created() {
    this.search();
    this.searchinfo();
  },
  computed: {
    id() {
      return this.$route.query.id;
    },
  },
  methods: {
    ...mapActions(['query', 'delete', 'fetch', 'update']),
    ...Mapdictionary({ list: 'query' }),
    async search() {
      const res = await this.fetch(this.id);
      console.log(res.data);
      this.$set(this, `ruleForm`, res.data);
    },

    async searchinfo() {
      const sshy = await this.list({ type: 'sshy' });
      const rzlc = await this.list({ type: 'rzlc' });
      // var options = res.data.filter(item => item.type === '0');
      // var rzlc = res.data.filter(item => item.type === '1');
      this.$set(this, `sshy`, sshy.data);
      this.$set(this, `rzlc`, rzlc.data);
    },
    // 提交
    submitForm(ruleForm) {
      console.log(ruleForm);
      let res = this.update(this.ruleForm);
      this.$checkRes(res, '修改成功', '修改失败');
      this.$router.push({ path: '/institution/index/0' });
    },
    async shenheForm({ data }) {
      data.status = '2';
      let res = this.update(data);
      this.$checkRes(res, '审核成功', '审核失败');
      this.$router.push({ path: '/institution/index/0' });
    },
    // 取消
    resetForm() {
      this.$router.push({ path: '/financial/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>
