
<template>
  <div>
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <project-view v-model="objId" />
      <a-form-model ref="form" :model="auditObj" :rules="rules" class="from-table">
        <audit-edit :auditObj.sync="auditObj" :disabledBtns.sync="disabledBtns" />
      </a-form-model>
    </a-spin>
  </div>
</template>
<script>
import { isEmptyParams } from "@/views/utils/common";
import { budgetList } from '@/views/report/project/config'
import ProjectView from '@/views/report/project/components/projectView'
import AuditList from '@/views/audit/components/auditInfo'
import AuditEdit from '@/views/audit/components/auditEdit'
export default {
  name: "Audit",
  components: {
    ProjectView, AuditList, AuditEdit
  },
  data () {
    return {
      projectInfo: {
        projName: '',
        startDate: '',
        endDate: '',
        applyMoney: '',
        projClassName: '',
        appPersonName: '',
        sex: '',
        titleName: '',
        degreeName: '',
        specName: '',
        jobUnit: '',
        mobile: '',
        address: '',
        appUnitName: '',
        linkName: '',
        linkEmail: '',
        linkTel: '',
        knowledgeName: '',
        projContent: '',
        projTarget: '',
        projKeywords: '',
        // 合作单位
        together: [{ unitName: '', unitAddress: '', projectWork: '' }, { unitName: '', unitAddress: '', projectWork: '' }],
        // 项目组成员
        members: [],
        // 经费
        budget: budgetList(),
        projDoc: null,
        fileList: [{ fileName: '', url: '', remarks: '', id: '' }],
        auditList: [{ result: '', unit: '', time: '' }],
      },
      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,
    };
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    },
    objId: {
      type: String,
      default () {
        return null
      }
    },
    disabledBtns: {
      type: Object,
      default () {
        return {
          btnPassed: false,
          btnReturn: true,
          btnUnpassed: false,
        }
      }
    }
  },
  created () {
    this.load()
  },
  methods: {
    load () {
      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
          }
          this.$emit('onDisabled', false)
        }).catch(() => { })
      }
    },
    cancel () {
      this.$emit('closeWindow', 'auditcel')
    },
    submit () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.$emit('onDisabled', true)
          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('closeWindow', 'audit')
              }
            }
            this.loading = false
            this.$emit('onDisabled', false)
          }).catch(() => {
            this.loading = false
            this.$emit('onDisabled', false)
          })
        } else {
          this.$emit('changeScroll')
          this.$message.error('请选择审核结果或填写审核意见！')
          return false
        }
      })
    },
  },
}
</script>
<style lang="less" scoped>
</style>

