<template>
  <div>
    <!-- :row-class-name="tableRowClassName" -->
    <el-table :data="doctorCheck.RegisterCheckList" border
      :height="(window.pageHeight < 600) ? 290 : (window.pageHeight - 350)" size="small" highlight-current-row
      ref="doctorCheck.RegisterCheckList" >
      <el-table-column prop="asbitemName" label="组合项目" min-width="120" />
      <el-table-column prop="completeFlag" label="状态" align="center" width="60">
        <template slot-scope="scope">
          <div :style="`color: ${setCheckStatusColor(scope.row.completeFlag)}`">
            {{ dddw(dict.checkCompleteFlag, 'id', scope.row.completeFlag, 'displayName') }}
            <!--
            <el-radio v-model="scope.row.checkCompleteFlag" label="0">未检</el-radio>
            <el-radio v-model="scope.row.checkCompleteFlag" label="1">已检</el-radio>
            <el-radio v-model="scope.row.checkCompleteFlag" label="2">弃检</el-radio>
            -->
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="checkDate" label="检查日期" min-width="90" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.checkDate">
            {{ moment(scope.row.checkDate).format("yyyy-MM-DD") }}
          </div>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>
<script>
import moment from "moment";
import { mapState } from "vuex";
import { getapi, postapi, putapi, deletapi } from "@/api/api";
import { dddw, setCheckStatusColor,listOrderBy } from "../../utlis/proFunc"

export default {
  components: {},
  props: ["patientRegisterId","brushTimes"],
  data() {
    return {};
  },

  created() { },

  //挂载完成
  mounted() {
    this.registerCheckList(this.patientRegisterId)
  },

  computed: {
    ...mapState(["window", "dict", "dataTransOpts", "doctorCheck"]),
  },
  methods: {
    moment, dddw,setCheckStatusColor,

    tableRowClassName({ row, rowIndex }) {
      //console.log(row)
      switch (row.completeFlag) {
        case '0':
          return 'danger'; //未检
        case '2':
          return 'info'; //未检
        default:
          return '';
      }
    },
  

    //获取检查组合项目
    registerCheckList(patientRegisterId) {
      this.doctorCheck.RegisterCheckList = []
      if (!patientRegisterId) return      
      postapi('/api/app/RegisterCheck/GetRegisterCheckAsbitemsByPatientRegisterId', { patientRegisterId })
        .then((res) => {
          // console.log("registerCheckList", res.data);
          if (res.code > -1) {
            this.doctorCheck.RegisterCheckList = listOrderBy(res.data,[{ colName: 'completeFlag', sortType: 'A' }])
          }
          // console.log("this.doctorCheck.RegisterCheckList", this.doctorCheck.RegisterCheckList);
        })
        .catch((err) => {
          this.$message.error({ showClose: true, message:  `操作失败，原因：${err}` });
        });
    },
  },

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