<template>
  <div style="height:75vh;overflow:auto" class="app-content">
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <a-tabs type="card" @change="callback" :activeKey='tabsActive'>
        <a-tab-pane key="1" tab="结题信息"></a-tab-pane>
        <a-tab-pane key="2" tab="结题评审"></a-tab-pane>
      </a-tabs>
      <div class="table-content">
        <div v-show="tabsActive==='1'" style="height:100%;overflow: auto;" class="from-table ">
          <conclusion-info v-model="conclusionData" />
        </div>
        <div v-show="tabsActive==='2'" style="height:100%;overflow: auto;">
          <a-form-model ref="form" :model="formData" :rules="rules" style="border-top: 0px" class="from-table font-line-space">
            <a-row>
              <a-col :span="24" style="border-top: 0px">
                <div style="text-align: center; font-size: 18pt; margin-top: 8px;">
                  <span>{{province}}卫生健康委科研项目结题材料要求</span>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2" class="bg-gray">
                <div class="special-middle">
                  <div>纸质编号：</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle">
                  <div>
                    <a-form-model-item prop="paperNumber">
                      <a-input placeholder="纸质编号" v-model="formData.paperNumber" :maxLength="50" style="width: 90%" />
                    </a-form-model-item>
                  </div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle">
                  <div>项目合同编号：</div>
                </div>
              </a-col>
              <a-col :span="6">
                <div class="special-middle">
                  <div>
                    <a-form-model-item prop="contractNo">
                      <a-input placeholder="项目合同编号" v-model="formData.contractNo" :maxLength="50" style="width: 90%" />
                    </a-form-model-item>
                  </div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle">
                  <div>项目负责人：</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle">
                  <div>{{ formData.appPersonName }}</div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2" class="bg-gray">
                <div class="special-middle">
                  <div>立项年份：</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle">
                  <div>{{ formData.reportYear }}</div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle">
                  <div>项目名称：</div>
                </div>
              </a-col>
              <a-col :span="14">
                <div class="special-middle">
                  <div>{{ formData.projName }}</div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="4" class="bg-gray">
                <div class="special-middle">
                  <div>结题审核人：</div>
                </div>
              </a-col>
              <a-col :span="8">
                <div class="special-middle">
                  <div>
                    <a-form-model-item prop="auditPersonName">
                      <a-input placeholder="结题审核人" v-model="formData.auditPersonName" :maxLength="20" style="width: 90%" />
                    </a-form-model-item>
                  </div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle">
                  <div>结题日期：</div>
                </div>
              </a-col>
              <a-col :span="8">
                <div class="special-middle">
                  <div>
                    <a-form-model-item prop="conclusionDate" style="width:200px;">
                      <a-date-picker format="YYYY-MM-DD" valueFormat="YYYY-MM-DD HH:mm:ss" v-model="formData.conclusionDate" style="width: 180px" @change="dateChange" />
                    </a-form-model-item>
                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2" class="bg-gray">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>序号</div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>结题材料</div>
                </div>
              </a-col>
              <a-col :span="8" class="bg-gray">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>检查要求</div>
                </div>
              </a-col>
              <a-col :span="4" class="bg-gray">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>是否符合要求</div>
                </div>
              </a-col>
              <a-col :span="6" class="bg-gray">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>备注</div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2">
                <div class="special-middle" style="text-align: center;">
                  <div>1</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle" style="text-align: center;">
                  <div>{{province}}卫生健康委科研项目结题报告书</div>
                </div>
              </a-col>
              <a-col :span="12">
                <div class="special-middle">
                  <div>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[0].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[0].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[1].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[1].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[2].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[2].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[3].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[3].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                  </div>
                </div>
              </a-col>
              <a-col :span="6">
                <div class="special-middle" style="text-align: center;">
                  <div>

                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2">
                <div class="special-middle" style="text-align: center;">
                  <div>2</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle" style="text-align: center;">
                  <div>项目研究报告</div>
                </div>
              </a-col>
              <a-col :span="12">
                <div class="special-middle">
                  <div>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[4].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[4].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                  </div>
                </div>
              </a-col>
              <a-col :span="6">
                <div class="special-middle" style="text-align: center;">
                  <div>

                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2">
                <div class="special-middle" style="text-align: center;">
                  <div>3</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle" style="text-align: center;">
                  <div>立项文件和申报（合同书）复印件</div>
                </div>
              </a-col>
              <a-col :span="12">
                <div class="special-middle">
                  <div>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[5].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 60px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[5].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                  </div>
                </div>
              </a-col>
              <a-col :span="6">
                <div class="special-middle" style="text-align: center;">
                  <div>
                    检查要求任一项不符合要求均不予以结题
                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="2">
                <div class="special-middle" style="text-align: center;">
                  <div>4</div>
                </div>
              </a-col>
              <a-col :span="4">
                <div class="special-middle" style="text-align: center;">
                  <div>附件（支撑材料：项目实施中取得的相关成果及证明材料,包括学术论文、专著、软件、专利、获奖证书、推广证明等）</div>
                </div>
              </a-col>
              <a-col :span="12">
                <div class="special-middle">
                  <div>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[6].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[6].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[7].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 20px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[7].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[8].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[8].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                    <a-row type="flex">
                      <a-col :span="16" v-if="formData">{{formData.conclusionMaterialList[9].materialName}}</a-col>
                      <a-col :span="8" style="text-align: center; padding-top: 10px;">
                        <a-radio-group v-model="formData.conclusionMaterialList[9].materialValue" :options="plainOptions" @change="onChange" />
                      </a-col>
                    </a-row>
                  </div>
                </div>
              </a-col>
              <a-col :span="6">
                <div class="special-middle" style="text-align: center;">
                  <div>
                  </div>
                </div>
              </a-col>
            </a-row>
            <a-row type="flex">
              <a-col :span="14">
                <div class="special-middle" style="text-align: center; font-weight: bold;">
                  <div>是否予以结题盖委科教处章</div>
                </div>
              </a-col>
              <a-col :span="10">
                <div class="special-middle" style="text-align: center;">
                  <div>
                    <a-radio-group v-model="formData.isStamp" :options="plainOptions" @change="onChange" />
                  </div>
                </div>                
              </a-col>
            </a-row>
            <a-form-model ref="auditForm" :model="formData.comProjectAudit" :rules="rules">
              <audit-edit :auditObj.sync="formData.comProjectAudit" :disabledBtns="disabledBtns" />
            </a-form-model>
          </a-form-model>
        </div>
      </div>
    </a-spin>
  </div>
</template>

<script>
import { isEmptyParams } from '@/views/utils/common'
import AuditEdit from '@/views/audit/components/auditEdit'
import conclusionInfo from '@/views/conclusion/components/conclusionInfo'

export default {
  name: "conclusionMaterialAudit",
  components: { conclusionInfo, AuditEdit },
  props: {
    value: {
      type: String,
      default: () => {
        return null;
      },
    },
    auditId: {
      type: String,
      default () {
        return null
      },
    },
    objId: {
      type: String,
      default () {
        return null
      },
    },
  },
  data () {
    return {
      tabsActive: '1',
      conclusionData: {
        projNo: null,
        projName: null,
        appPersonName: null,
        appUnitName: null,
        telephone: null,
        planCategory: null,
        startDate: null,
        endDate: null,
        promotionContent: null,
        promotionTarget: null,
        selfEvaluation: null,
        achievingResults: null,
        thesisList: [],
        researchersList: [],
        //拔款
        grant: [],
        //其它途径筹资
        finance: [],
        //主要支出项目
        spending: [],
        balance: null,
        researchContent: null,
        workPlan: null,
        extensionReport: null,
        fileList: [],
        catalogList: [],
        auditList: [],
        province: process.env.VUE_APP_SYSTEM_PROVINCE,
      },
      formData: {
        paperNumber: '',
        contractNo: '',
        auditPersonName: '',
        conclusionDate: null,
        conclusionMaterialList: [
          { materialName: '1.1.学术委员会盖章（或单位盖章）', materialValue: 0 },
          { materialName: '1.2.伦理委员会盖章：（不涉及伦理委员会的项目请注明“本项目不涉及伦理审查”）', materialValue: 0 },
          { materialName: '1.3.实施单位公章', materialValue: 0 },
          { materialName: '1.4.市州卫健局公章（省直单位不做要求）', materialValue: 0 },
          { materialName: '2.1.研究报告填报要求全面地反映项目工作进展与成果、经费使用情况等，确保内容真实、数据准确。', materialValue: 0 },
          { materialName: '3.1立项文件复印件可主要附通知页、附件项目负责人编号页；3.2申报（合同书）可只复印封面页、项目申报简要信息页（预期研究成果页）、经费预算页、申请者所在单位（包括合作单位）的审查与保证页、所在单位伦理委员会审查意见页、市（州）卫健局、省卫健委审批意见、签订协议页。', materialValue: 0 },
          { materialName: '4.1.自身课题目标是否满足（若没完成不予已结题）', materialValue: 0 },
          { materialName: '4.2.委里成果最低要求：一篇以上以第一作者或通讯作者公开发表的学术论文复印件（中文要求：期刊封面、项目人所在目录页及文章全文；英文要求将题目翻译成中文）。', materialValue: 0 },
          { materialName: '4.3.学术论文是否有项目编号', materialValue: 0 },
          { materialName: '4.4.学术论文内容是否与课题内容相关', materialValue: 0 },
        ],
        isStamp: 0,
        comProjectAudit: {
          id: this.auditId,
          auditObjectId: this.objId,
          auditResult: null,
          auditType: 4,
          auditContent: '',
        },
      },
      loading: false,
      plainOptions: [{ label: '是', value: 1 }, { label: '否', value: 0 }],
      disabledBtns: {
        btnPassed: false,
        btnReturn: false,
        btnUnpassed: false
      },
      rules: {
        paperNumber: { required: true, message: '请填写纸质编号：', trigger: 'blur' },
        contractNo: { required: true, message: '请填写项目合同编号：', trigger: 'blur' },
        auditPersonName: { required: true, message: '请填写结题审核人：', trigger: 'blur' },
        conclusionDate: { required: true, message: '请选择结题日期', trigger: 'change' },
        auditContent: { required: true, message: '请填写审核意见', trigger: 'blur' },
        auditResult: { required: true, message: '请选择审核结果', trigger: 'change' },
      },
    };
  },
  created () {
    this.getConclusionByProjId()
    this.getConclusionMaterialList()
  },
  methods: {
    callback (key) {
      this.tabsActive = key
    },
    getConclusionByProjId () {
      if (!!this.value) {
        this.$api.conclusion.getConclusionByProjId({ id: this.value }).then(({ data = {} }) => {
          if (data) {
            this.conclusionData = data
            this.loading = false
          } else {
            this.$emit('close', 'error')
          }
        }).catch(() => {
          this.$message.error('500 Internal Server Error！');
          this.$emit('close', 'error')
        })
      } else {
        this.$message.error('500 Internal Server Error！');
        this.$emit('close', 'error')
      }
    },
    getConclusionMaterialList () {
      this.loading = true
      this.$api.conclusion.getConclusionMaterialList({ ProjectID: this.value }).then(({ data = {} }) => {
        if (data) {
          data.comProjectAudit.id = this.auditId
          data.comProjectAudit.auditObjectId = this.objId
          data.comProjectAudit.auditContent = ''
          this.formData = data

          this.loading = false
        }
      }).catch(() => { this.loading = false })
    },
    onChange () {

    },
    dateChange () {

    },
    submit () {
      this.$refs.form.validate((valid1) => {
        if (valid1) {
          this.$refs.auditForm.validate((valid) => {
            if (valid) {
              let pars = isEmptyParams(this.formData)
              let par = { ...pars }
              this.$api.conclusion.SaveConclusionMaterial(par).then(({ data = {} }) => {
                if (data) {
                  if (data === "审核成功！") {
                    this.$message.success('审核成功！')
                    this.$emit('closeWindow')
                  }
                  else
                    this.$message.error('审核失败，请稍后重试！')
                }
              }).catch(() => { this.loading = false })
            }
          })
        }
      })

    }
  }
};
</script>
<style scoped lang="less">
.app-content {
  ::v-deep.ant-spin-nested-loading .ant-spin-container {
    height: 100%;
  }
  .table-content {
    height: calc(100% - 40px);
    border-width: 0px 1px 1px 1px;
    border-style: solid;
    border-color: #e8e8e8;

    // border:1px solid #e8e8e8;

    padding: 6px 6px;
  }
  padding: 0;
  ::v-deep.ant-tabs .ant-tabs-bar {
    margin: 0 !important;
  }
  ::v-deep
    .ant-tabs
    .ant-tabs-bar
    .ant-tabs-nav-container
    .ant-tabs-nav-wrap
    .ant-tabs-nav-scroll
    .ant-tabs-nav
    .ant-tabs-tab {
    min-width: 160px !important;
    text-align: center;
  }
}
</style>