<template>
  <div class="app-container">
    <el-table
      v-loading="loading"
      :data="data"
      @sort-change="handleSortChange"
      style="width: 100%">
      <el-table-column
        type="index"
        label="序号"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('field')"
        prop="field"
        label="缺陷字段"
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('desc')"
        prop="desc"
        label="缺陷描述"
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('AAA28')"
        prop="AAA28"
        label="住院号码"
        width="100"
        align="center">
        <template slot-scope="scope">
          <span class="link" @click="toPage(scope.row.MED_REC_ID)">{{ scope.row.AAA28 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        v-if="codes.includes('AAA01')"
        prop="AAA01"
        label="姓名"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('time')"
        prop="AAC01"
        label="出院时间"
        sortable
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('AAC11N')"
        prop="AAC11N"
        label="出院科室"
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('AEE08')"
        prop="AEE08"
        label="编码员"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('AEE04')"
        prop="AEE04"
        label="住院医师"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('ICD10_NAME')"
        prop="ICD10_NAME"
        label="主要诊断名称"
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('ICD10_ID1')"
        prop="ICD10_ID1"
        label="主要诊断编码"
        width="160"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('ICD9_NAME')"
        prop="ICD9_NAME"
        label="主要手术名称"
        width="200"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('ICD9_ID1')"
        prop="ICD9_ID1"
        label="主要手术编码"
        width="120"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('level')"
        prop="level"
        label="缺陷分级"
        width="100"
        align="center">
      </el-table-column>
      <el-table-column
        v-if="codes.includes('type')"
        prop="type"
        label="缺陷归类"
        width="120"
        align="center">
      </el-table-column>
    </el-table>
  </div>
</template>

<script>

export default {
  props: {
    data: {
      type: Array,
      default() {
        return []
      }
    },
    loading: {
      type: Boolean,
      default() {
        return false
      }
    },
    codes: {
      type: Array,
      default() {
        return []
      }
    },
    type_name:{  // 'lc' 临床
      type: String,
      default() {
        return ''
      }
    },
    hospital_name:{
      type: String,
      default() {
        return ''
      }
    },
  },
  methods: {
    toPage(val) {
      this.storageSet('getData', val);
      const toPath = '/details'
      this.$router.push({ path: toPath, query: {type_name: this.type_name} });
    },
    
    handleSortChange(column) {
      const { prop, order } = column;
      let sort = []
      let str = '';
      if (order === 'descending') {
        str = 'desc';
      } else if (order === 'ascending') {
        str = 'asc';
      } else {
        str = null;
      }
      if (str) {
        sort = [prop, str]
      } else {
        sort = []
      }
      this.$emit('sort', sort)
    },
  }
}
</script>

<style lang="scss" scoped>
.btn-box {
  text-align: right;
  margin-bottom: 15px;
}
.link {
  cursor: pointer;
  color: #409EFF;
}
</style>
