 <template>
  <ai-detail isHasSidebar>
    <template slot="title">
      <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(true)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-table
            class="detail-table__table"
            :tableData="tableData"
            :col-configs="colConfigs"
            :total="total"
            :current.sync="search.current"
            :size.sync="search.size"
            @getList="getList">
            <el-table-column slot="options" width="140px" fixed="right" label="操作" align="center">
              <template slot-scope="{ row }">
                <div class="table-options">
                  <el-button type="text" @click="toDetail(row)">详情</el-button>
                </div>
              </template>
            </el-table-column>
          </ai-table>
          <ai-dialog
            :visible.sync="isShow"
            width="890px"
            customFooter
            title="上报详情">
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="当前体温">
                <span :style="{color: reportInfo.temperature > 37.3 ? '#FF4466' : '#42D784'}">{{ reportInfo.temperature }}℃</span>
              </ai-info-item>
              <ai-info-item label="14天内是否接触新冠确诊或疑似患者">
                <span :style="{color: reportInfo.touchInFourteen === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicTouchInFourteen', reportInfo.touchInFourteen) }}</span>
              </ai-info-item>
              <ai-info-item label="当前健康状况" isLine>
                <span :style="{color: !reportInfo.isHealth ? '#42D784' : '#FF4466'}">{{ reportInfo.healthName }}</span>
              </ai-info-item>
            </ai-wrapper>
            <div class="dialog-footer" slot="footer">
              <el-button @click="isShow = false">关闭</el-button>
            </div>
          </ai-dialog>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  export default {
    name: 'Detail',

    props: {
      instance: Function,
      dict: Object,
      params: Object
    },

    data () {
      return {
        total: 0,
        info: {},
        id: '',
        search: {
          current: 1,
          size: 10
        },
        reportInfo: {},
        isShow: false,
        currIndex: 0,
        tableData: [],
        colConfigs: [
          {prop: 'createTime', label: '上报日期', align: 'center', dateFormart: 'YYYY-MM-DD'},
          {
            prop: 'status',
            label: '健康状态',
            align: 'center',
            render (h, {row}) {
              return h('span',{
                style: {
                  color: row.status === '0' ? '#F46' : '#2EA222'
                }
              }, row.status === '0' ? '异常' : '正常')
            }
          }
        ]
      }
    },

    created () {
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.dict.load(['epidemicRecentHealth', 'epidemicRecentTravel', 'epidemicTouchInFourteen', 'epidemicMemberType', 'epidemicRecentTestResult']).then(() => {
          this.getList()
        })
      }
    },

    methods: {
      toDetail (e) {
        this.reportInfo = e
        let healthName = ''
        e.health.split(',').forEach(v => {
          if (v > 0) {
            this.reportInfo.isHealth = true
          }
          healthName = healthName + this.dict.getLabel('epidemicRecentHealth', v)
        })
        this.reportInfo.healthName = healthName
        this.isShow = true
      },

      getList () {
        this.instance.post(`/app/appepidemichealthreport/list`, null, {
          params: {
            ...this.search,
            memberId: this.params.id
          }
        }).then(res => {
          if (res.code == 0) {
            this.tableData = res.data.records
            this.total = res.data.total
          }
        })
      },

      cancel (isRefresh) {
        this.$emit('change', {
          type: 'list',
          isRefresh: !!isRefresh
        })
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
