<template>
  <div class="app-content" style="height: 76vh;overflow: auto;">
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <div class="page-content" ref="main">
        <div class="x_modal_content">
          <project-info v-model="projectInfo" v-if="projType" />
          <project-info-Key v-model="projectInfo" v-else />
          <a-form-model ref="form" :model="auditObj" :rules="rules" class="from-table font-line-space">
            <audit-edit :auditObj.sync="auditObj" />
          </a-form-model>
        </div>
      </div>
      <div class="page-footer">
        <a-button type="primary" @click="submit" style="margin-left:16px;">提交</a-button>
      </div>
    </a-spin>
  </div>
</template>
<script>
import { isEmptyParams } from "@/views/utils/common";
import { budgetList } from '@/views/report/project/config'
import { getType } from '@/views/utils/auth'
import projectInfo from '@/views/report/project/components/projectInfo'
import projectInfoKey from "@/views/report/project/components/keyProject/projectInfo"
import AuditList from '@/views/audit/components/auditInfo'
import AuditEdit from '@/views/audit/components/auditEdit'
export default {
  name: "Audit",
  components: {
    projectInfo, projectInfoKey, AuditList, AuditEdit
  },
  data () {
    return {
      projectInfo: {
        id: null,
        organizationCode: null,
        address: null,
        registeredAddress: null,
        postCode: null,
        legalPerson: null,
        workforce: null,
        specializedPersonnel: null,
        researchPersonnel: null,
        depositBank: null,
        bankAccount: null,
        depositBankAddress: null,
        interbankNumber: null,
        researchTotal: null,
        isResearchActive: null,
        researchCount: null,
        researchPersonCount: null,
        projName: null,
        leadUnit: null,
        recommendUnit: null,
        startDate: null,
        endDate: null,
        technologyInnovationBase: null,
        knowledgeId: null,
        totalFunding: null,
        govFunding: null,
        linkName: null,
        linkMobile: null,
        linkEmail: null,
        projAbstract: null,
        projKeywords: null,
        researchContent: null,
        memResume: null,
        researchProgress: null,
        researchContent: null,
        technologyTarget: null,
        economyTarget: null,
        achievementTarget: null,
        otherTarget: null,
        cooperativeUnits: [],
        members: [],
        budget: [],
        equipments: [],
        projectSubList: [],
        managementRuleList: [],
        fileList: [],
      },
      auditObj: { id: this.value, auditObjectId: this.objId, auditResult: null, auditType: 1, auditContent: '' },
      rules: {
        auditContent: { required: true, message: '请填写审核意见', trigger: 'blur' },
        auditResult: { required: true, message: '请选择审核结果', trigger: 'change' },
      },
      loading: false,
      projType: getType() == "1"
    };
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    },
    objId: {
      type: String,
      default () {
        return null
      }
    },
  },
  created () {
    this.loadProject()
  },
  methods: {
    loadProject () {
      let pars = { id: this.objId }
      if (this.objId != null) {
        this.loading = true
        this.$api.project.getProjectInfoById(pars).then(({ data = {} }) => {
          if (data) {
            this.projectInfo = data
            this.loading = false
          } else
            this.$emit('close', 'error')
        }).catch(() => { this.$emit('close', 'error') })
      }
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          let pars = isEmptyParams(this.auditObj)
          let par = { ...pars }
          this.$api.auditManager.projectAudit(par).then(({ data = {} }) => {
            if (data) {
              if (data === '项目上报已经到达上限!') {
                this.$message.info('项目上报已经到达上限!')
              } else {
                this.$message.success('审核成功!')
                this.$emit('close', 'audit')
              }
            }
            this.loading = false
          }).catch(() => { this.loading = false })
        } else {
          this.changeScroll()
          this.$message.error('请选择审核结果或填写审核意见!')
          return false
        }
      })
    },
    changeScroll () {
      this.$refs.main.scrollTop = document.getElementsByClassName('x_modal_content')[0].offsetHeight
    }
  },
}
</script>
<style scoped lang="less">
::v-deep .ant-spin-container {
  width: 100%;
  height: 100%;
}
::v-deep .page-content {
  width: 100%;
  height: calc(100% - 40px);
  overflow: auto;
}
::v-deep .page-footer {
  width: 100%;
  height: 40px;
  line-height: 40px;
  background: rgb(248, 248, 248);
  text-align: center;
}
textarea {
  height: 115px;
}
</style>