 <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>
            </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-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>
    </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,
        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.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
          }

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

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

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