<template>
  <ai-detail>
    <template slot="title">
      <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
        <template #rightBtn>
          <el-button
            size="small"
            type="primary"
            @click="isShow = true"
            v-if="(checkType === '1' || checkType === '2') && info.status !== '3' && info.status !== '2'">
            {{ checkType === '1' ? '走访核实' : '处理结果' }}
          </el-button>
        </template>
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper>
            <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="dict.getLabel('fpRiskType', info.riskType)"></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="备注说明" isLine :value="info.remarks"></ai-info-item>
            <ai-info-item label="操作人" :value="info.createUserName"></ai-info-item>
            <ai-info-item label="归口部门" :value="info.departmentName"></ai-info-item>
            <ai-info-item label="操作时间" isLine :value="info.createTime"></ai-info-item>
            <ai-info-item label="状态" isLine :value="dict.getLabel('fpRiskPersonStatus', info.status)"></ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-card title="走访核实" v-if="info.visitTime">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="处理意见" :value="info.visitOpinion"></ai-info-item>
            <ai-info-item label="处理时间" :value="info.visitTime"></ai-info-item>
            <ai-info-item label="业务员" :value="info.visitUserName"></ai-info-item>
            <ai-info-item label="照片" isLine>
              <ai-uploader
                disabled
                :instance="instance"
                v-model="info.visitFiles"
                :limit="9">
              </ai-uploader>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-card title="处理结果" v-if="info.auditTime">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="处理意见" :value="info.auditOpinion"></ai-info-item>
            <ai-info-item label="处理时间" :value="info.auditTime"></ai-info-item>
            <ai-info-item label="业务员" :value="info.auditUserName"></ai-info-item>
            <ai-info-item label="照片" isLine>
              <ai-uploader
                disabled
                :instance="instance"
                v-model="info.auditFiles"
                :limit="9">
              </ai-uploader>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-dialog
        :visible.sync="isShow"
        width="800px"
        @close="onClose"
        title="审核"
        @onConfirm="onConfirm">
        <el-form class="ai-form" label-width="110px" :model="form" ref="form">
          <el-form-item label="处理意见" prop="operation" style="width: 100%;" :rules="[{ required: true, message: '请选择处理意见' }]">
            <el-radio-group v-model="form.operation">
              <el-radio label="0" v-if="checkType === '1'">疑似风险</el-radio>
              <el-radio label="1" v-if="checkType === '2'">纳入监测</el-radio>
              <el-radio label="2">解除风险</el-radio>
            </el-radio-group>
            <!-- <span v-if="info.status != '2'">解除风险</span>
            <span v-if="info.status === '0' && checkType === '1'">疑似风险</span>
            <span v-if="info.status !== '2' && checkType === '2'">纳入监测</span> -->
          </el-form-item>
          <el-form-item label="备注说明" prop="opinion" style="width: 100%;" :rules="[{ required: true, message: '请输入备注说明' }]">
            <el-input type="textarea" :rows="5" :maxlength="200" v-model="form.opinion" clearable placeholder="请输入备注说明" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="照片" prop="files" style="width: 100%;">
            <ai-uploader
              :instance="instance"
              v-model="form.files"
              :limit="9">
              <template slot="tips">
                <p>最多上传9张图片,单个文件最大10MB，支持jpg、jpeg、png格式</p>
              </template>
            </ai-uploader>
          </el-form-item>
        </el-form>
      </ai-dialog>
    </template>
  </ai-detail>
</template>

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

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

    data () {
      return {
        info: {},
        id: '',
        checkType: '',
        form: {
          opinion: '',
          operation: '',
          ids: ''
        },
        isShow: false
      }
    },

    created () {
      if (this.params && this.params.id) {
        this.id = this.params.id
        this.getInfo(this.params.id)
      }
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/apppreventionreturntopovertyriskperson/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
          }
        })
        this.instance.post('/app/appgirdmemberinfo/checkLogOnUser').then((res) => {
          if (res.code == 0) {
            this.checkType = res.data.checkType
          }
        })
      },

      onClose () {
        this.form.opinion = ''
        this.form.operation = ''
      },

      onConfirm () {
        this.$refs.form.validate(v => {
          if (v) {
            this.instance.post(`/app/apppreventionreturntopovertyriskperson/monitor`, {
              ...this.form,
              ids: [this.params.id]
            }).then(res => {
              if (res.code == 0) {
                this.$message.success('操作成功！')
                this.isShow = false
                this.getInfo(this.params.id)
              }
            })
          }
        })
      },

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

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