<template>
  <div class="acceptance-legal-review">
    <cy-up-down-drag>
      <div slot="top">
        <history-view></history-view>
      </div>
      <div slot="bar">
        <div>
          法务终审
        </div>
      </div>
      <div slot="bottom">
        <div class="tempalte-content" style="min-height: auto; padding: 0px 20px ">
          <contract-files :details="contractInfo"></contract-files>
          <up-acceptance-sheet :details="upFilesObj"></up-acceptance-sheet>
          <down-acceptance-sheet v-show="downFilesObj.file.length" :details="downFilesObj"></down-acceptance-sheet>
          <acceptance-conclusion ref="conclusion" :sign-confirm="signConfirm"></acceptance-conclusion>
          <div class="submit-btn">
            <el-button style="width: 150px;" @click="() => { $router.go(-1) }">取消</el-button>
            <el-button style="width: 150px;" type="primary" @click="onSubmit">提交</el-button>
          </div>
        </div>
      </div>
    </cy-up-down-drag>
  </div>
</template>

<script >
import AcceptanceConclusion from './components/AcceptanceConclusion.vue'
import ContractFiles from './components/ContractFiles.vue'
import DownAcceptanceSheet from './components/DownAcceptanceSheet.vue'
import UpAcceptanceSheet from './components/UpAcceptanceSheet.vue'
import HistoryView from './components/HistoryView.vue'
import { getReviewDetail, legalReview, Loadings } from '@/api/acceptanceManagement/index'
export default {
  name: 'AcceptanceLegalReview',
  components: {
    ContractFiles,
    UpAcceptanceSheet,
    DownAcceptanceSheet,
    AcceptanceConclusion,
    HistoryView
  },
  data() {
    return {
      loadingInstance: null,
      submitDisable: false,
      contractInfo: {},
      upFilesObj: {},
      downFilesObj: {
        file: []
      },
      signConfirm: {}
    }
  },
  created() {
    this.getDetail()
  },
  methods: {
    async onSubmit() {
      const conclusionResult = await this.$refs.conclusion.getSubmit()
      const { taskId, id } = this.$route.query
      const { approvalConclusion, approvalComment } = conclusionResult
      const postData = new FormData()
      postData.append('Loading', true)
      postData.append('taskId', taskId)
      postData.append('acceptanceBasicInfoId', id)
      postData.append('approvalConclusion', approvalConclusion)
      postData.append('approvalComment', approvalComment)
      this.loadingInstance = Loadings()
      legalReview(postData).then(res => {
        if (res.success) {
          this.loadingInstance && this.loadingInstance.close()
          this.$message.success('提交成功。')
          this.$router.push({
            name: 'AcceptanceManagement'
          })
        } else {
          this.$message.warning(res.msg)
          this.loadingInstance && this.loadingInstance.close()
        }
      }).catch(res => {
        this.loadingInstance && this.loadingInstance.close()
      })
    },
    getDetail() {
      const { id } = this.$route.query
      getReviewDetail({ id: id }).then(res => {
        if (res.success) {
          this.detailInfos = res.data
          this.upFilesObj = { file: res.data.acceptanceUpstreamFiles }
          this.downFilesObj = { file: res.data.signConfirmFiles ? res.data.signConfirmFiles : [] }
          this.contractInfo = {
            purchContract: res.data.procureContractFile,
            salesContract: res.data.saleContractFiles
          }

          this.signConfirm = { show: res.data.signConfirm === 1 }
          console.log(this.downFilesObj, this.signConfirm)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  /* .template-examine .submit-btn {
    position: absolute;
    bottom: 40px;
    right: 40px;
  } */
</style>
