 <template>
  <ai-detail isHasSidebar v-loading="isLoading">
    <template slot="title">
      <ai-title title="健康上报详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <AiSidebar :tabTitle="tabList" v-model="currIndex"></AiSidebar>
      <div v-show="currIndex === 0">
        <ai-card title="基本信息" v-show="currIndex === 0">
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="姓名" :value="info.name"></ai-info-item>
              <ai-info-item label="手机号" :value="info.phone"></ai-info-item>
              <ai-info-item label="上报时间" :value="info.createTime"></ai-info-item>
              <ai-info-item label="身份证号" :value="info.idNumber"></ai-info-item>
              <ai-info-item label="所属地区" :value="info.areaName"></ai-info-item>
              <ai-info-item label="详细地址" isLine :value="info.address"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
      </div>
      <div v-show="currIndex === 1">
        <ai-card title="每日上报">
          <template #content>
            <ai-table
              :isShowPagination="false"
              tableSize="small"
              border
              :tableData="info.reportInfos"
              :col-configs="colConfigs1"
              @getList="() => {}">
              <el-table-column slot="nucleicAcidUrl" label="核酸截图" align="center">
                <template slot-scope="{ row }">
                  <ai-uploader
                    :instance="instance"
                    :value="[{url: row.nucleicAcidUrl}]"
                    disabled
                    :limit="9">
                  </ai-uploader>
                </template>
              </el-table-column>
              <el-table-column slot="options" width="100px" 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>
          </template>
        </ai-card>
      </div>
      <div v-show="currIndex === 2">
        <ai-card title="风险处置">
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="姓名" :value="info.name"></ai-info-item>
              <ai-info-item label="手机号" :value="info.phone"></ai-info-item>
              <ai-info-item label="上报时间" :value="info.createTime"></ai-info-item>
              <ai-info-item label="身份证号" :value="info.idNumber"></ai-info-item>
              <ai-info-item label="所属地区" :value="info.areaName"></ai-info-item>
              <ai-info-item label="详细地址" isLine :value="info.address"></ai-info-item>
              <ai-info-item label="风险解除人" v-if="riskDisposalInfo.createUserName" :value="riskDisposalInfo.createUserName"></ai-info-item>
              <ai-info-item label="风险解除时间" v-if="riskDisposalInfo.createTime" :value="riskDisposalInfo.createTime"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="风险情况记录">
          <template #content>
            <ai-table
              :isShowPagination="false"
              tableSize="small"
              border
              :tableData="info.handleLogs"
              :col-configs="colConfigs2"
              @getList="() => {}">
            </ai-table>
          </template>
        </ai-card>
      </div>
      <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.contactPatients === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('epidemicTouchInFourteen', reportInfo.contactPatients) }}</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.nucleicAcidDate && reportInfo.nucleicAcidDate.split(' ')[0] }}</span>
          </ai-info-item>
          <ai-info-item label="检测结果">
            <span :style="{color: reportInfo.nucleicAcidResult === '0' ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('EP_nucleicAcidResult', reportInfo.nucleicAcidResult) }}</span>
          </ai-info-item>
          <ai-info-item label="健康码状态">
            <span :style="{color: (reportInfo.jkmType === '0' || reportInfo.jkmType === '1') ? '#42D784' : '#FF4466'}">{{ $dict.getLabel('EP_jkmType', reportInfo.jkmType) }}</span>
          </ai-info-item>
          <ai-info-item label="已接种疫苗次数">
            <span>{{ $dict.getLabel('EP_vaccinationCount', reportInfo.vaccinationCount) }}</span>
          </ai-info-item>
          <ai-info-item label="本人健康码截图" isLine>
            <ai-uploader
              :instance="instance"
              :value="[{url: reportInfo.jkmUrl}]"
              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-detail>
</template>

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

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

    data () {
      return {
        info: {},
        isShow: false,
        currIndex: 0,
        isLoading: false,
        riskDisposalInfo: {},
        reportInfo: {},
        tableData: [],
        colConfigs1: [
          {prop: 'createTime', label: '上报日期', align: 'center' },
          {prop: 'phone', label: '上报位置', align: 'center'},
          { prop: 'status',
            label: '健康状态',
            align: 'center',
            render: (h, params) => {
              return h(
                'span', {
                  style: {
                    color: params.row.status === '1' ? 'red' : ''
                  }
                }, params.row.status === '0' ? '正常' : '异常'
              )
            }
          },
          {slot: 'nucleicAcidUrl', label: '核酸截图', align: 'center'}
        ],
        colConfigs2: [
          {prop: 'content', label: '风险记录', align: 'center' },
          {prop: 'createTime', label: '创建时间', align: 'center'},
          {prop: 'createUserName', label: '记录人', align: 'center' }
        ],
        tabList: ['基本信息', '每日上报', '风险处置']
      }
    },

    created () {
      this.isLoading = true
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.dict.load(['EP_vaccinationCount', 'EP_jkmType', 'epidemicTouchInFourteen', 'EP_healthType']).then(() => {
          this.getInfo(this.params.id)
        })
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appepidemicpreventionhealthreportinfo/userDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data

            if (res.data.handleLogs && res.data.handleLogs.length) {
              this.riskDisposalInfo = res.data.handleLogs.filter(v => v.riskRelief).length ? res.data.handleLogs.filter(v => v.riskRelief)[0] : {}

              this.info.handleLogs = res.data.handleLogs.filter(v => !v.riskRelief)
            }
          }

          this.isLoading = false
        }).catch(() => {
          this.isLoading = false
        })
      },

      toDetail (row) {
        this.reportInfo = row
        let healthName = ''
        this.reportInfo.isHealth = false
        row.health.split(',').forEach(v => {
          if (v > 0) {
            this.reportInfo.isHealth = true
          }
          healthName = healthName + this.dict.getLabel('EP_healthType', v)
        })
        this.reportInfo.healthName = healthName
        this.isShow = true
      },

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

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