<template>
  <div>
    <el-card>
      <div slot="header" class="clearfix">
        <span style="font-weight:bold">绩效考核表</span>-{{form.name}}
        <dict-tag :options="dict.type.ehr_pm_status" :value="form.status" style="display:inline-block;margin-right:5px;" />
        <el-tag v-if="form.isTwoEvaluation">双向评估</el-tag>
        <div style="float: right; padding: 3px 0; display:flex;justify-content:space-between" type="text">
          <el-button size="mini" plain @click="btnBack">返回</el-button>
          <el-button type="primary" size="mini" @click="btnSubmit" :loading="loading" v-if="this.$store.state.user.name == form.staff && (form.status == '0' || form.status == '3')">提交</el-button>
          <CopyItemDialog style="margin: 0 10px" @setItems="setItems" v-if="this.$store.state.user.name == form.staff && form.status == '0'" :id="rowId"></CopyItemDialog>
          <ApproveLogDialog style="margin: 0 10px" :pmId="form.id"></ApproveLogDialog>
          <AdjustlogDialog style="margin: 0 10px" :pmId="form.id"></AdjustlogDialog>
          <el-button size="mini" plain @click="btnPreviou" v-if="ids">上一个</el-button>
          <el-button size="mini" plain @click="btnNext" v-if="ids">下一个</el-button>
        </div>
      </div>
      <div v-loading="loading">
        <el-form size="mini" ref="dataForm" :model="form" :rules="rules">
          <el-descriptions :column="6">
            <el-descriptions-item label="员工编号">{{form.staff}}</el-descriptions-item>
            <el-descriptions-item label="员工姓名">{{form.staffName}}</el-descriptions-item>
            <el-descriptions-item label="入职日期">{{form.dateJoin}}</el-descriptions-item>
            <el-descriptions-item label="转正日期">{{form.probationComplete}}</el-descriptions-item>
            <el-descriptions-item label="部门" span="2">{{form.deptName}}</el-descriptions-item>
            <el-descriptions-item label="职位">{{form.jobName}}</el-descriptions-item>
            <el-descriptions-item label="评估周期">{{form.name}}</el-descriptions-item>
            <el-descriptions-item label="评估人">{{form.evaluatorName}}</el-descriptions-item>
            <el-descriptions-item label="所属分组">
              <div v-for="dict in dict.type.ehr_pm_group" v-if="form.staffDivide == dict.value">
                <div>{{ dict.label }}</div>
              </div>
            </el-descriptions-item>
          </el-descriptions>
          <el-descriptions :column="6 ">
            <el-descriptions-item label="自评分" v-if="form.status > 3">{{form.saMark}}</el-descriptions-item>
            <el-descriptions-item label="上级评分" v-if="form.status > 4">{{form.ldMark}}</el-descriptions-item>
            <el-descriptions-item label="综合得分" v-if="form.status > 4">{{form.mark}}</el-descriptions-item>
          </el-descriptions>
          <el-row style="color: #606266;font-size: 14px;" v-if="form.status > 3">
            <el-col :span="2">
              个人总结：
            </el-col>
            <el-col :span="22">
              <div style="white-space: pre-wrap;text-align: left">{{form.summary}}</div>
            </el-col>
          </el-row>
          <el-row style="margin-top:10px;color: #606266;font-size: 14px;" v-if="form.status > 4">
            <el-col :span="2">
              总评语:
            </el-col>
            <el-col :span="22">
              <div v-for="(item,index) in comment" :key="index">{{item[0]}}:{{item[1]}}</div>
            </el-col>
          </el-row>
          
          <el-table size="mini"  :data="form.performanceItem" show-summary :summary-method="getSummaries" border>
            <el-table-column type="index" width="50" label="序号"/>
            <el-table-column width="100" label="评估方面" align="center" prop="aspect">
              <template slot-scope="scope">
                <dict-tag :options="dict.type.ehr_pm_aspect" :value="scope.row.aspect"/>
              </template>
            </el-table-column>
            <el-table-column width="100" label="评估指标" align="center" prop="target" />
            <el-table-column width="80" label="权重(%)" align="center" prop="weight">
              <template slot-scope="scope">
                {{scope.row.asItem ? "+/-" : scope.row.weight}}
              </template>
            </el-table-column>
            <el-table-column label="指标说明" align="center" prop="instructions">
              <template slot-scope="scope">
                <div style="white-space: pre-wrap;text-align: left">{{scope.row.instructions}}</div>
              </template>
            </el-table-column>
            <el-table-column label="评分标准" align="center" prop="standard">
              <template slot-scope="scope">
                <div style="white-space: pre-wrap;text-align: left">{{scope.row.standard}}</div>
              </template>
            </el-table-column>
            <el-table-column width="100" label="数据来源" align="center" prop="source" />
            <el-table-column width="80" label="自评分" align="center" prop="selfScoring" v-if="form.status > 3"/>
              <el-table-column label="自评语" align="center" prop="selfComment" v-if="form.status > 3">
              <template slot-scope="scope">
                <div style="white-space: pre-wrap;text-align: left">{{scope.row.selfComment}}</div>
              </template>
            </el-table-column>
            <el-table-column width="80" label="评估人" align="center" prop="evaluatorName" v-if="form.status > 4 && form.isTwoEvaluation"/>
            <el-table-column width="80" label="上级评分" align="center" prop="leaderScoring" v-if="form.status > 4"/>
            <el-table-column label="评分说明" align="center" prop="leaderComment" v-if="form.status > 4">
              <template slot-scope="scope">
                <div style="white-space: pre-wrap;text-align: left">{{scope.row.leaderComment}}</div>
              </template>
            </el-table-column>
          </el-table>
        </el-form>
      </div>
    </el-card>
  </div>
</template>

<script>
import ApproveLogDialog from './btnApproveLog.vue'
import AdjustlogDialog from './btnAjMarkLog.vue'
import CopyItemDialog from './btnCopyItem.vue'
import { getPerformance} from "@/api/business/ehr/pm/performance";

export default {
  name: 'detail',
  dicts: ['ehr_pm_aspect','ehr_pm_role','ehr_pm_group','ehr_pm_status'],
  props: ['pageStu','rowId',"ids"],
  model: {
    prop: 'isList',
    event: 'jugislist'
  },
  components: {ApproveLogDialog,AdjustlogDialog,CopyItemDialog},
  data() {
    return {
      //id
      id:null,
      //表单
      form:{},
      //遮罩
      loading: false,
      //明细权重合计值
      weightSum: 0,
    }
  },
  computed: {
    comment() {
      if(this.form.comment){
        let obj = JSON.parse(this.form.comment);
        let arr = Object.entries(obj)
        return arr;
      }else{
        return [];
      }
    }
	},
  async created() {
    this.id = this.rowId;
    this.fetchPerformance(this.id);
    if(this.pageStu == 'add'){
    }
    if(this.pageStu == 'edit' || this.pageStu == 'see') {
    }
  },
  methods: {
    //返回
    btnBack(){
      this.$emit('jugislist', true)
      this.$emit('refresh')
    },
    //查询详情
    async fetchPerformance(id){
      this.loading = true;
      await getPerformance(id).then(res => {
        if (res.code === 200) {
          this.form = res.data;
          this.id = res.data.id;
         }
         this.loading = false;
      })
    },
    //上一个
    btnPreviou(){
      let i = this.ids.indexOf(this.id) - 1;
      if(i > -1){
        let id = this.ids[i];
        this.fetchPerformance(id);
      }else{
        this.$modal.msgSuccess("已经是当前页第一条了！");
      }
    },
    //下一个
    btnNext(){
      let i = this.ids.indexOf(this.id) + 1;
      if(i < this.ids.length){
        let id = this.ids[i];
        this.fetchPerformance(id);
      }else{
        this.$modal.msgSuccess("已经是当前页最后一条了！");
      }
      
    },
    //合计
    getSummaries(param){
      if(this.form.isTwoEvaluation){
        return ['合计','','',this.form.weight,'','','',this.form.saMark,'','',this.form.ldMark];
      }else{
        return ['合计','','',this.form.weight,'','','',this.form.saMark,'',this.form.ldMark];
      }
    },
  }
}
</script>

<style lang="scss" scoped>

.btn_group {
  z-index: 500;
  position: fixed;
  bottom: 0;
  width: 100%;
  line-height: var(--footer-height);
  color: #fff;
}
</style>
