<template>
  <div style="height:75vh;overflow:auto" class="app-content">
    <a-spin :spinning="loading" style="width: 100%;height: 100%;">
      <div v-if="isShow" 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="指标说明" v-if="totalFunding > 50"></a-tab-pane>
          <a-tab-pane key="3" tab="项目信息"></a-tab-pane>
        </a-tabs>
        <div class="table-content">
          <div v-show="tabsActive==='1'" style="height:100%;">
            <div style="height:calc(100% - 40px);overflow: auto;">
              <a-form-model ref="form" :model="formData" :rules="rules" class="from-table font-line-space">
                <technology-evalucation v-if="totalFunding > 50" v-model="formData"></technology-evalucation>

                <div v-else>
                  <a-row type="flex" >
                    <a-col :span="4" class="bg-gray">
                      <div class="special-middle" style="text-align:center!important;">
                        <div>评审意见 </div>
                      </div>
                    </a-col>
                    <a-col :span="20">
                      <div>
                        <a-form-model-item prop="remark">
                          <a-textarea placeholder="评审意见" v-model="formData.remark" :maxLength="1000" style="width: 80%; height: 120px; margin-top: 6px" />
                        </a-form-model-item>
                      </div>
                    </a-col>
                  </a-row>
                  <a-row type="flex">
                    <a-col :span="4" class="bg-gray">
                      <div class="special-middle" style="text-align:center!important;">
                        <div>是否推荐立项支持 </div>
                      </div>
                    </a-col>
                    <a-col :span="20">
                      <a-form-model-item prop="supportState">
                        <a-radio-group v-model="formData.supportState">
                          <a-radio :value="1">是</a-radio>
                          <a-radio :value="0">否</a-radio>
                        </a-radio-group>
                      </a-form-model-item>
                    </a-col>
                  </a-row>
                </div>
              </a-form-model>
            </div>
            <div style="height:40px;width:100%;text-align:center;padding:4px 0px;background: #fafafa;border:1px solid #e8e8e8; border-width: 0px 1px 1px 1px;border-style: solid;border-color: #e8e8e8;">
              <a-button @click="save" style="margin-right:16px">保存</a-button>
              <a-button type="primary" @click="submit">提交</a-button>
            </div>
          </div>
          <div v-show="tabsActive==='2'" style="height:100%;overflow: auto;">
            <span style="line-height:2;">1. 意义及必要性</span><br />
            <span style="line-height:2;">（1）项目实施的意义及必要性：评价项目实施对相关科技创新工作提升的意义和必要性。</span><br />
            <span style="line-height:2;">2. 目标及考核指标</span><br />
            <span style="line-height:2;">（1）目标定位及可考核性：评价项目目标是否集中，定位是否准确合理；考核指标及预期提交的成果是否量化可考。</span><br />
            <span style="line-height:2;">（2）绩效目标设置合理性：评价项目绩效目标是否与研究内容及项目目标定位相匹配，分年度绩效目标设置是否合理。</span><br />
            <span style="line-height:2;">3. 主要内容</span><br />
            <span style="line-height:2;">（1）研发内容与目标实现关联度：评价项目提出的研发内容能否保障项目目标实现。</span><br />
            <span style="line-height:2;">（2）研究成果产业化成熟度：评价项目研究成果实现产业化的预期。</span><br />
            <span style="line-height:2;">（3）产业化市场竞争力及预期效益：评价项目产业化市场竞争力以及预期效益分析是否合理。</span><br />
            <span style="line-height:2;">4. 技术路线与实施方案</span><br />
            <span style="line-height:2;">（1）技术路线和实施方案设计：评价项目采用的技术路线和实施方案是否科学、合理、可行。</span><br />
            <span style="line-height:2;">（2）技术关键选择及创新性先进性：评价研究关键技术选择的准确性、创新性及先进性。</span><br />
            <span style="line-height:2;">（3）年度计划安排：评价研究内容及目标任务分解、阶段目标设置和时间安排的合理性。</span><br />
            <span style="line-height:2;">5. 工作基础及支撑条件</span><br />
            <span style="line-height:2;">（1）负责人及团队创新能力：评价项目负责人和团队创新能力是否满足项目要求。</span><br />
            <span style="line-height:2;">（2）研发平台及科研条件保障：评价是否具备项目顺利实施所需要的设备设施、场地、平台等基础设施科研条件保障。</span><br />
            <span style="line-height:2;">（3）前期工作基础：评价申报项目前期工作对支撑项目实施的能力。</span><br />
            <span style="line-height:2;">6. 组织运行与管理</span><br />
            <span style="line-height:2;">（1）经费预算合理性：评价项目经费总体预算及分配使用计划是否合理。</span><br />
            <span style="line-height:2;">（2）任务分工和权益分配：评价项目承担单位与参与单位之间以及团队人员之间是否有明确的分工，项目产生的权益分配是否明确合理。</span><br />
            <span style="line-height:2;">（3）项目组织协调及管理措施：评价是否具备为保障项目顺利实施所需要的组织协调及管理措施。</span><br />
            <span style="line-height:2;">7．项目风险分析</span><br />
            <span style="line-height:2;">（1）项目组织实施风险：评价项目组织实施是否存在风险。</span><br />
            <span style="line-height:2;">（2）目标实现风险：评价项目目标实现是否存在风险。</span>
          </div>
          <div v-show="tabsActive==='3'" style="height:100%;overflow: auto;">
            <project-view v-model="formData.projId" />
          </div>
        </div>
      </div>
      <div v-else style="width: 100%;height: 100%;">
        <div style="height:calc(100% - 40px);overflow: auto;">
          <div style="text-align:center;">
	          <!-- <span style="line-height:2;"><strong>内蒙古自治区卫生健康委首府地区公立医院高水平临床专科建设科技项目</strong></span> -->
          </div>
          <div style="text-align:center;">
	          <span style="line-height:2;"><strong>评审专家须知</strong></span>
          </div>
          <span style="line-height:2;">尊敬的专家：</span><br />
          <span style="line-height:2;">&nbsp; &nbsp; &nbsp; &nbsp;您好，感谢您参与此次云南省卫生健康委地区健康科技项目网上评审。为做好此次评审工作，现将相关事宜通知如下，请务必仔细阅读和严格执行。</span><br />
          <span style="line-height:2;">一、评审专家根据评价指标对本组所有申报项目（由于申报专业的不同，其中可能会有部分跨专业的项目，请专家一并评审打分，切勿遗漏）进行评阅打分，写出具体的评审意见及建议立项或不立项的主要原因。</span><br />
          <span style="line-height:2;">二、为调动广大医务工作者参与科研工作的积极性，请在评审过程中按照评分标准打分，确保项目质量。</span><br />
          <span style="line-height:2;">三、如申报项目涉及国家安全问题和其他可能造成不良舆论和后果的，或是存在境外机构或人员参与的，专家要从严审查审核。经评审确有不适宜公开的信息及数据或不适宜的观点及言论，可能危害国家安全或造成不良影响的项目，可评分为“0”并及时向我委具体负责同志反馈。</span><br />
          <span style="line-height:2;">四、为贯彻落实2024年国务院《政府工作报告》中关于“加强健康、养老等民生科技研发应用”的要求，请专家在确保质量的情况下，重点关注“可实现成果转化或临床应用”的申报项目。</span><br />
          <span style="line-height:2;">五、请严格遵守各项法律法规和评审纪律，评审工作做到实事求是、客观公正、科学规范、廉洁自律。</span><br />
          <span style="line-height:2;">六、此次专家评审时间为：{{exportTime.expertStart + '至' + exportTime.expertEnd}}，请务必于{{exportTime.expertEnd}}前提交评审结果。</span><br />
          <span style="line-height:2;">&nbsp; &nbsp; &nbsp; 再次感谢您对我们工作的大力支持，未尽事宜，另行通知。</span><br />
          <!-- <span style="line-height:2;">&nbsp; &nbsp; &nbsp; 联系电话：{{ unitInfo.linkTel }}</span><br /> -->
          <br />
        </div>
        <div style="height:40px;width:100%;text-align:center;padding:4px 0px;background: #fafafa;border:1px solid #e8e8e8; ">
          <a-button type="primary" @click="loadExpertInfo" :disabled="check.disabled">{{check.title}}</a-button>
        </div>
      </div>
    </a-spin>
  </div>
</template>

<script>
import { getType } from '@/views/utils/auth'
import { isEmptyParams } from "@/views/utils/common"
import { budgetList } from '@/views/report/project/config'
import moment from 'moment'
import projectView from '@/views/evaluation/components/projectView'
import technologyEvalucation from '@/views/evaluation/components/technologyEvalucation'

export default {
  name: "score",
  components: {
    projectView, technologyEvalucation
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null;
      },
    },
    exportTime: {
      expertStart: {
        type: String,
        default: () => {
          return null;
        },
      },
      expertEnd: {
        type: String,
        default: () => {
          return null;
        },
      }
    },
    totalFunding: {
      type: Number,
      default: () => {
        return 0.00;
      },
    }
  },
  data () {
    return {
      loading: false,
      isShow: false,
      isExpertInfoLoad: false,
      isProjectInfoLoad: false,
      tabsActive: '1',
      check: {
        time: 10, title: '我已阅读', count: 10, disabled: false,
      },
      formData: { id: null, projId: null, expertId: null, expertName: null, 
        score1: null, score2: null, score3: null, score4: null, score4: null, score5: null, score6: null, score7: null, score8: null, score9: null, 
        score10: null, score11: null, score12: null, score13: null, score14: null, score15: null, score16: null, score17: null, 
        totalScore: null, remark: null, supportState: null, projName: null, projNo: null, totalFunding: 0.00,
      },
      rules: {
        score1: { required: true, message: "*", trigger: "blur" },
        score2: { required: true, message: "*", trigger: "blur" },
        score3: { required: true, message: "*", trigger: "blur" },
        score4: { required: true, message: "*", trigger: "blur" },
        score5: { required: true, message: "*", trigger: "blur" },
        score6: { required: true, message: "*", trigger: "blur" },
        score7: { required: true, message: "*", trigger: "blur" },
        score8: { required: true, message: "*", trigger: "blur" },
        score9: { required: true, message: "*", trigger: "blur" },
        score10: { required: true, message: "*", trigger: "blur" },
        score11: { required: true, message: "*", trigger: "blur" },
        score12: { required: true, message: "*", trigger: "blur" },
        score13: { required: true, message: "*", trigger: "blur" },
        score14: { required: true, message: "*", trigger: "blur" },
        score15: { required: true, message: "*", trigger: "blur" },
        score16: { required: true, message: "*", trigger: "blur" },
        score17: { required: true, message: "*", trigger: "blur" },
        remark: [{ required: true, message: '请填写评审意见', trigger: 'blur' },],
        supportState: { required: true, message: "请选择是否支持立项", trigger: "blur" },
        evaluationType: { required: true, message: "*", trigger: "blur" },
      },
      projectInfo: {
        projName: '',
        startDate: '',
        endDate: '',
        applyMoney: '',
        projClassName: '',
        appPersonName: '',
        sex: '',
        titleName: '',
        degreeName: '',
        specName: '',
        jobUnit: '',
        mobile: '',
        address: '',
        appUnitName: '',
        linkName: '',
        linkEmail: '',
        linkTel: '',
        knowledgeName: '',
        projContent: '',
        projTarget: '',
        projKeywords: '',
        // 合作单位
        together: [],
        // 项目组成员
        members: [],
        // 经费
        budget: budgetList(),
        projDoc: null,
        fileList: [],
        auditList: [],
      },
      comBatch: { expertStart: '', expertEnd: '' },
      unitInfo: { linkTel: null },
    };
  },
  created () {
    this.getAssignExpertById()
    this.getYear()
    this.countStart()
    // this.getCurrentUnitInfo()
  },
  methods: {
    moment,
    getYear () {
      this.$api.batch.getCurrentYearBatch({ type: 5, projType: getType() }).then(({ data = {} }) => {
        if (data) {
          this.comBatch = data
        }
      }).catch(() => { this.loading = false })
    },
    countStart () {
      this.check.disabled = true
      this.check.title = '阅读中...(' + this.check.count + 's)'
      let time = setInterval(() => {
        if (this.check.count == 1) {
          clearInterval(time)
          this.check.title = '我已阅读'
          this.check.count = this.check.time
          this.check.disabled = false
        } else {
          this.check.count--
          this.check.title = '阅读中...(' + this.check.count + 's)'
        }
      }, 1000)
    },
    getCurrentUnitInfo() {
      this.$api.unit.getCurrentUnitInfo().then(({ data = {} }) => {
        if (data) {
          this.unitInfo = data
        }
      }).catch(() => { })
    },
    loadExpertInfo () {
      this.isShow = true
      if (!this.isExpertInfoLoad)
        this.loading = false
    },
    getAssignExpertById () {
      if (!!this.value) {
        this.loading = true
        this.$api.projectAssign.getAssignExpertById({ id: this.value }).then(({ data = {} }) => {
          if (data) {
            this.formData = data
            this.getProjectInfoById(data.projId)
            this.isExpertInfoLoad = true
            this.loading = false
          } else
            this.$emit('close', 'error')
        }).catch(() => {
          this.$message.warn('500 Internal Server Error！')
          this.$emit('close', 'error')
        })
      }
    },
    getProjectInfoById (id) {
      this.$api.project.getProjectInfoById({ id: id }).then(({ data = {} }) => {
        if (data) {
          let fileArr = []
          this.projectInfo = data
          for (let i = 0; i < this.projectInfo.fileList.length; i++) {
            if (this.projectInfo.fileList[i].fileExplain.indexOf("项目申报简要信息首页") == -1 && this.projectInfo.fileList[i].fileExplain.indexOf("项目组成员签字") == -1)
              fileArr.push(this.projectInfo.fileList[i])
          }
          this.projectInfo.fileList = fileArr
          this.isProjectInfoLoad = true
          this.loading = false
        } else
          this.$emit('close', 'error')
      }).catch(() => {
        this.$message.warn('500 Internal Server Error！')
        this.$emit('close', 'error')
      })
    },
    scoreCount () {
      let total = 0.0
      if (!!this.formData.projectBasis)
        total = (total * 100 + this.formData.projectBasis * 100) / 100
      if (!!this.formData.academicValue)
        total = (total * 100 + this.formData.academicValue * 100) / 100
      if (!!this.formData.innovation)
        total = (total * 100 + this.formData.innovation * 100) / 100
      if (!!this.formData.researchPlan)
        total = (total * 100 + this.formData.researchPlan * 100) / 100
      if (!!this.formData.expectedResults)
        total = (total * 100 + this.formData.expectedResults * 100) / 100
      this.formData.totalScore = total
      return total
    },
    callback (key) {
      this.tabsActive = key
    },
    save () {
      if (this.checkInfo()) {
        this.loading = true
        if (!this.formData.auditState || this.formData.auditState == 0)
          this.formData.auditState = 1
        let pars = isEmptyParams(this.formData)
        let par = { ...pars }
        this.$api.projectAssign.expertEvaluation(par).then(({ data = {} }) => {
          if (data) {
            this.$message.success('保存成功')
            this.$emit('close', 'save')
          }
          this.loading = false
        }).catch(() => { this.loading = false })
      } else {
        this.$message.warn('请填写信息后再保存！')
      }
    },
    checkInfo () {
      if (!!!this.formData.totalScore && !!!this.formData.remark) {
        return false
      } else {
        return true
      }
    },
    submit () {
      console.log(this.formData)
      this.$refs.form.validate(valid => {
        if (valid) {
          this.loading = true
          this.formData.auditState = 2
          let pars = isEmptyParams(this.formData)
          let par = { ...pars }
          this.$api.projectAssign.expertEvaluation(par).then(({ data = {} }) => {
            if (data) {
              this.$message.success('提交成功')
              this.$emit('close', 'submit')
            }
            this.loading = false
          }).catch(() => { this.loading = false })
        } else { this.tabsActive = '1' }
      })
    },
  },
};
</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: 1px solid #f0f0f0;
    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>
ant-tabs