<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">处理结果</el-button>
        </template>
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper>
            <ai-info-item label="姓名" :value="info.title"></ai-info-item>
            <ai-info-item label="联系方式" :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="风险类型" :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="身份证号" :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="所属区域" isLine :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="联系地址" isLine :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="备注说明" isLine :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="处理时间" :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="处理人" :value="info.publishUnitName"></ai-info-item>
            <ai-info-item label="状态" isLine :value="info.publishUnitName"></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="pass" style="width: 100%;" :rules="[{ required: true, message: '请选择处理意见' }]">
            <el-radio-group v-model="form.pass" @change="onStatusChange">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </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: '',
        form: {
          opinion: '',
          pass: '',
          files: []
        },
        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/appmininotice/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.images = res.data.images ? JSON.parse(res.data.images) : []
          }
        })
      },

      onStatusChange () {
        this.form.opinion = ''
        this.$refs.form.clearValidate()
      },

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

      onConfirm () {
        this.$refs.form.validate(v => {
          if (v) {
            this.instance.post('/app/appcontentinfo/examine', null, {
              params: {
                ...this.form,
                id: this.id
              }
            }).then(res => {
              if (res?.code == 0) {
                this.isShow = false
                this.getList()
                this.$message.success('审核成功!')
              }
            })
          }
        })
      },

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

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