 <template>
  <ai-detail>
    <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.createTime"></ai-info-item>
              <ai-info-item label="身份证号" :value="info.idNumber"></ai-info-item>
              <ai-info-item label="手机号码" :value="info.phone"></ai-info-item>
              <ai-info-item label="人员类别" isLine :value="dict.getLabel('epidemicMemberType', info.type)"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="行程信息">
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="出发时间" :value="info.startTime"></ai-info-item>
              <ai-info-item label="出发地区" :value="info.startAreaName"></ai-info-item>
              <ai-info-item label="出发地址" isLine :value="info.startAddress"></ai-info-item>
              <ai-info-item label="出行方式" :value="dict.getLabel('epidemicRecentTravel', info.travelType)"></ai-info-item>
              <ai-info-item label="行程描述" isLine :value="info.description"></ai-info-item>
              <ai-info-item label="到达时间" :value="info.arriveTime"></ai-info-item>
              <ai-info-item label="到达地区" :value="info.arriveAreaName"></ai-info-item>
              <ai-info-item label="返乡地址" isLine :value="info.arriveAddress"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="健康状况">
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="当前体温" :value="info.temperature + '℃'"></ai-info-item>
              <ai-info-item label="14天内是否接触新冠确诊或疑似患者">
                <span>{{ dict.getLabel('epidemicTouchInFourteen', info.touchInFourteen) }}</span>
              </ai-info-item>
              <ai-info-item label="当前健康状况" :value="info.status === '0' ? '异常' : '正常'">
                <span>{{ info.healthName }}</span>
              </ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="核酸检测">
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="检测日期" :value="info.checkTime && info.checkTime.split(' ')[0]"></ai-info-item>
              <ai-info-item label="检测结果" :value="dict.getLabel('epidemicRecentTestResult', info.checkResult)"></ai-info-item>
              <ai-info-item label="本人健康码截图" isLine>
                <ai-uploader
                  :instance="instance"
                  v-model="info.checkPhoto"
                  disabled
                  :limit="9">
                </ai-uploader>
              </ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
      </div>
      <div v-show="currIndex === 1">
        <ai-card title="异常处理">
          <template #right>
            <el-button type="primary" v-if="info.status === '0'" @click="release">解除异常</el-button>
          </template>
          <template #content>
            <ai-wrapper
              label-width="120px">
              <ai-info-item label="姓名" :value="info.name"></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.phone"></ai-info-item>
              <ai-info-item label="人员类别" isLine :value="dict.getLabel('epidemicMemberType', info.type)"></ai-info-item>
              <ai-info-item label="异常状况" isLine>
                <span :style="{color: info.unusual ? 'red' : '#333'}">{{ info.unusual || '-' }}</span>
              </ai-info-item>
              <ai-info-item label="异常解除人" v-if="info.releaseName && info.status === '1'" :value="info.releaseName"></ai-info-item>
              <ai-info-item label="异常解除时间" v-if="info.releaseTime && info.status === '1'" :value="info.releaseTime"></ai-info-item>
            </ai-wrapper>
          </template>
        </ai-card>
        <ai-card title="异常情况记录">
          <template #right>
            <el-button type="primary" v-if="info.status === '0'" @click="isShow = true">添加记录</el-button>
          </template>
          <template #content>
            <ai-table
              :tableData="tableData"
              :col-configs="colConfigs"
              :total="total"
              :current.sync="search.current"
              :size.sync="search.size"
              @getList="getList">
              <el-table-column slot="options" width="120px" fixed="right" label="操作" align="center">
                <template slot-scope="{ row }">
                  <div class="table-options">
                    <el-button type="text" @click="remove(row.id)">删除</el-button>
                  </div>
                </template>
              </el-table-column>
            </ai-table>
          </template>
        </ai-card>
        <ai-dialog
          :visible.sync="isShow"
          width="800px"
          @close="form.content = ''"
          title="添加异常记录"
          @onConfirm="onConfirm">
          <el-form class="ai-form" label-width="120px" :model="form" ref="form">
            <el-form-item label="异常记录" prop="content" style="width: 100%;" :rules="[{ required: true, message: '请输入异常记录' }]">
              <el-input type="textarea" :rows="5" :maxlength="500" v-model="form.content" clearable placeholder="请输入异常记录" show-word-limit></el-input>
            </el-form-item>
          </el-form>
        </ai-dialog>
      </div>
    </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
        },
        form: {
          content: ''
        },
        isShow: false,
        currIndex: 0,
        tableData: [],
        colConfigs: [
          {prop: 'content', label: '异常记录', align: 'center' },
          {prop: 'createTime', label: '创建时间', align: 'center'},
          {prop: 'createUserName', label: '记录人', align: 'center' }
        ],
        tabList: ['基本信息', '异常处理']
      }
    },

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

        this.getList()
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appepidemicbackhomerecord/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.checkPhoto = res.data.checkPhoto ? JSON.parse(res.data.checkPhoto) : []
            let healthName = ''
            this.info.isHealth = false
            res.data.health.split(',').forEach(v => {
              if (v > 0) {
                this.info.isHealth = true
              }
              healthName = healthName + this.$dict.getLabel('epidemicRecentHealth', v)
            })
            this.info.healthName = healthName
          }
        })
      },

      release () {
        this.$confirm('确定解除异常？').then(() => {
          this.instance.post(`/app/appepidemicbackhomerecord/release?recordId=${this.params.id}`, {
            id: this.params.id
          }).then(res => {
            if (res.code == 0) {
              this.$message.success('解除异常成功！')
              this.currIndex = 0
              this.getInfo(this.params.id)
            }
          })
        })
      },

      remove(id) {
        this.$confirm('确定删除该数据？').then(() => {
          this.instance.post(`/app/appepidemicunusuallog/delete?ids=${id}`).then(res => {
            if (res.code == 0) {
              this.$message.success('删除成功！')
              this.getList()
            }
          })
        })
      },

      onConfirm() {
        this.$refs.form.validate(v => {
          if (v) {
            this.instance.post('/app/appepidemicunusuallog/addOrUpdate', {
              ...this.form,
              recordId: this.params.id
            }).then(res => {
              if (res?.code == 0) {
                this.isShow = false
                this.getList()
                this.$message.success('添加成功!')
              }
            })
          }
        })
      },

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

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

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