 <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.id)">详情</el-button>
                </div>
              </template>
            </el-table-column>
          </ai-table>
          <ai-dialog
            :visible.sync="isShow"
            width="890px"
            customFooter
            title="上报详情">
            <ai-bar title="健康状况"></ai-bar>
            <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>
            <ai-bar title="核酸检测信息"></ai-bar>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="检测日期">
                <span>{{ reportInfo.checkTime && reportInfo.checkTime.split(' ')[0] }}</span>
              </ai-info-item>
              <ai-info-item label="检测结果">
                <span :style="{color: reportInfo.checkResult === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicRecentTestResult', reportInfo.checkResult) }}</span>
              </ai-info-item>
              <ai-info-item label="健康码状态">
                <span :style="{color: (reportInfo.healthCode === '0' || reportInfo.healthCode === '1') ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicHealthCode', reportInfo.healthCode) }}</span>
              </ai-info-item>
              <ai-info-item label="已接种疫苗次数">
                <span>{{ $dict.getLabel('epidemicVaccineTime', reportInfo.vaccine) }}</span>
              </ai-info-item>
              <ai-info-item label="本人健康码截图" isLine>
                <ai-uploader
                  :instance="instance"
                  v-model="reportInfo.checkPhoto"
                  disabled
                  :limit="9">
                </ai-uploader>
              </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', formart: v => v === '0' ? '异常' : '正常' }
        ]
      }
    },

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

    methods: {
      toDetail (id) {
        this.instance.post(`/app/appepidemichealthreport/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.reportInfo = res.data
            this.reportInfo.checkPhoto = JSON.parse(res.data.checkPhoto)
            let healthName = ''
            this.reportInfo.isHealth = false
            res.data.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>
