<template>
  <div class="review-adjustment" v-loading="isLoading">
    <cy-up-down-drag>
      <div slot="top">
        <cy-steps :stepsData="stepList"></cy-steps>
        <el-collapse v-if="stepList.length" v-model="activeNames">
          <el-collapse-item v-for="(item, index) in stepList" :key="index" :name="index">
            <template slot="title">
              <cy-view-bar
                :view-bar-data="{ ...item.businessProcessingLogVo, formBusinessName: item.formBusinessName, index: index + 1 }">
              </cy-view-bar>
            </template>
            <template v-if="item.formBusinessName == '授信决议' || item.formBusinessName == '授信决议确认'">
              <cy-info-title>基础信息</cy-info-title>
              <basic-info :info="item.obj" />
              <cy-info-title>授信信息</cy-info-title>
              <credit-info :info="item.obj" :isView="true"></credit-info>
              <cy-info-title>放款条件</cy-info-title>
              <pay-condition :info="item.obj" :isView="true" />
              <cy-info-title>授信结论</cy-info-title>
              <resolution-result :info="item.obj" :isView="true" />
            </template>
            <template v-if="item.formBusinessName == '授信决议确认'">
              <cy-info-title>授信决议</cy-info-title>
              <confirm :info="item.obj" :isView="true" />
            </template>
            <template v-if="item.formBusinessName == '复议调整申请'">
              <cy-info-title>复议调整</cy-info-title>
              <update-info :info="item.obj" :isView="true" />
            </template>
            <template v-if="item.formBusinessName == '复议调整审批'">
              <cy-info-title>审批结论</cy-info-title>
              <audit-info :info="item.obj" :isView="true" />
            </template>
          </el-collapse-item>
        </el-collapse>
      </div>
      <cy-info-title slot="bar">复议调整</cy-info-title>
      <div slot="bottom">
        <update-info ref="updateInfo" :info="info"></update-info>
        <div class="submit-btn">
          <el-button @click="$router.go(-1)">取消</el-button>
          <el-button type="primary" @click="confirm">提交</el-button>
        </div>
      </div>
    </cy-up-down-drag>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  name: 'ReviewAdjustment',
  data() {
    return {
      stepList: [],
      stepDetail: {},
      activeNames: [],
      info: {
        projectInformation: {},
        coreEnterprise: {},
        supplierEnterprise: {}
      },
      isLoading: false
    }
  },
  components: {
    BasicInfo: () => import('./components/BasicInfo'),
    CreditInfo: () => import('./components/CreditInfo'),
    PayCondition: () => import('./components/PayCondition'),
    ResolutionResult: () => import('./components/ResolutionResult'),
    Confirm: () => import('./components/Confirm'),
    UpdateInfo: () => import('./components/UpdateInfo'),
    AuditInfo: () => import('./components/AuditInfo')
  },
  mounted() {
    this.getStepList()
    this.getDetail()
  },
  methods: {
    getDetail() {
      this.isLoading = true
      request({
        url: '/creditResolution/get',
        params: { id: this.$route.params.infoId },
        method: 'get'
      }).then(({ data }) => {
        this.info = data || {}
        this.isLoading = false
      }, () => {
        this.isLoading = false
      })
    },
    getStepList() {
      request({
        url: '/businessProcessingTask/doBusinessHistoryView',
        method: 'get',
        params: { businessKey: this.$route.params.infoId, businessType: 'CreditResolution' }
      }).then(({ data }) => {
        data.forEach(item => {
          item.obj.loanConditionsList = item.obj.loanConditionsHistoryList || []
          item.obj.randomId = Math.random()
        })
        this.stepList = data || []
      })
    },
    confirm() {
      this.$refs.updateInfo.confirm().then(res => {
        res.creditResolutionId = this.$route.params.infoId
        res.taskId = this.$route.params.taskId
        this.submit(res)
      })
    },
    submit(data) {
      this.isLoading = true
      request({
        url: '/creditResolution/reconsider/add',
        method: 'post',
        data
      }).then(() => {
        this.isLoading = false
        this.$message.success('提交成功')
        this.$router.go(-1)
      }, () => {
        this.isLoading = false
      })
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
