<template>
  <div>
    <!-- :row-class-name="tableRowClassName" -->
    <el-table :data="doctorCheck.RegisterCheckList" style="width: 100%" 
      :height="window.pageHeight < 600 ? 400:window.pageHeight-200"  
      border highlight-current-row ref='doctorCheck_RegisterCheckList'
      @row-click="rowClick">
      <el-table-column prop="asbitemName" label="组合项目" width="198">
        <template slot-scope="scope">
            <div>
              <el-tooltip class="item" effect="dark" content="未检" placement="left">
                <i v-show="scope.row.completeFlag == '0'" class="el-icon-circle-plus" style="font-size: 18px;color: red;"></i>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="已检" placement="left">
                <i v-show="scope.row.completeFlag == '1'" class="el-icon-success" style="font-size: 18px;color: green;"></i>
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="弃检" placement="left">
                <i v-show="scope.row.completeFlag == '2'" class="el-icon-remove" style="font-size: 18px;"></i>
              </el-tooltip>
              {{scope.row.asbitemName}}
            </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import { mapState } from 'vuex';
import { getapi, postapi, putapi, deletapi } from "@/api/api";

export default {
  components: {},
  data() {
    return {
      
    };
  },

  created() {},

  //挂载完成
  mounted() {},

  computed:{
      ...mapState(['window','dataTransOpts','dict','doctorCheck']),
  },

  methods: {
    tableRowClassName({row, rowIndex}) {
      //console.log('tableRowClassName',rowIndex,row)
      if (row.completeFlag === '0') {
        return 'danger'; //未检
      } else if (row.completeFlag === '2') {
        return 'info'; //弃检
      }
      return '';
          
    },
    
    //选择组合项目
    rowClick(row){
      console.log('rowClick')
      this.doctorCheck.RegisterCheckId = row.id
      this.dataTransOpts.tableS.register_check.id = row.id
      setTimeout(() => { // 不管值是否改变，点击就强制刷新
        this.dataTransOpts.refresh.register_check.S++
        this.dataTransOpts.refresh.register_check_item.M++
      }, 10);
      // this.doctorCheck.RegisterCheckEdit = row
    },

    //获取检查组合项目
    registerCheckList(patientRegisterId){
      if(!patientRegisterId){
        this.doctorCheck.RegisterCheckList = []
        this.doctorCheck.RegisterCheckId = ''
        this.dataTransOpts.tableS.register_check.id = ''
        setTimeout(() => {
          this.dataTransOpts.refresh.register_check.S++
          this.dataTransOpts.refresh.register_check_item.M++
        }, 20);
        return
      }
      console.log(`/api/app/register-check/register-check-or-asbitem/${patientRegisterId}`)
      getapi(`/api/app/register-check/register-check-or-asbitem/${patientRegisterId}`)
      .then((res) => {
          console.log("registerCheckList", res.data);
          if (res.code != -1) {
            this.doctorCheck.RegisterCheckList = res.data;
            //查询出来 默认显示第1条记录明细、小结等
            if(res.data.length > 0) {
              this.doctorCheck.RegisterCheckId = res.data[0].id
              this.dataTransOpts.tableS.register_check.id = res.data[0].id              
              // this.doctorCheck.RegisterCheckEdit = res.data[0]

              this.$refs['doctorCheck_RegisterCheckList'].setCurrentRow(res.data[0])

            }else{
              this.dataTransOpts.tableS.register_check.id = ''
            }

            setTimeout(() => { // 不管值是否改变，点击就强制刷新
              this.dataTransOpts.refresh.register_check.S++   //刷新检查医生
              this.dataTransOpts.refresh.register_check_item.M++  //刷新检查明细
            }, 10);
          }
      })
      .catch((err) => {
          this.$message({type: "error",message: `操作失败，原因：${err}`});
      });
    },


  },

  
  //监听事件
  watch: {    
    //体检人员未切换时 也可以强制刷新数据
    "dataTransOpts.refresh.register_check.M":{
      immediate:true,
      handler(newVal, oldVal) {
        console.log(`watch 组合项目列表 newVal: ${newVal} oldVal: ${oldVal} patient_register.id: ${this.dataTransOpts.tableS.patient_register.id}`);        
        this.registerCheckList(this.dataTransOpts.tableS.patient_register.id)        
      }
    },
  }
};
</script>
<style scoped>

</style>
  