<template>
  <ai-detail>
    <template slot="title">
      <ai-title title="村民圈详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基础信息">
        <ai-wrapper slot="content">
          <ai-info-item label="话题" :value="dict.getLabel('villagerCircleTopic', info.topic)" isLine></ai-info-item>
          <ai-info-item label="发布人" :value="info.createUserName" isLine></ai-info-item>
          <ai-info-item label="发布时间" :value="info.createTime" isLine></ai-info-item>
          <ai-info-item label="所在位置" :value="info.gpsDesc" isLine></ai-info-item>
          <ai-info-item label="内容" :value="info.content" isLine></ai-info-item>
          <ai-info-item label="图片" isLine>
            <ai-uploader
              :instance="instance"
              disabled
              v-model="info.pictures"
              :limit="9">
            </ai-uploader>
          </ai-info-item>
        </ai-wrapper>
      </ai-card>
      <ai-card title="处理结果" v-if="info.status > 0">
        <div slot="content" style="margin-top: 16px">
          <ai-wrapper
            label-width="120px">
            <ai-info-item label="审核结果" :value="info.status === '1' ? '通过' : '拒绝'" isLine></ai-info-item>
            <ai-info-item label="审核意见" v-if="info.status === '2'" isLine :value="info.auditOpinion"></ai-info-item>
            <ai-info-item label="审核人" :value="info.auditUserName"></ai-info-item>
            <ai-info-item label="审核时间" :value="info.auditTime"></ai-info-item>
          </ai-wrapper>
        </div>
      </ai-card>
      <ai-dialog
        :visible.sync="isShow"
        width="800px"
        @close="onClose"
        title="审核"
        @onConfirm="onConfirm">
        <el-form class="ai-form" label-width="120px" :model="form" ref="form">
          <el-form-item label="是否通过审核" prop="pass" style="width: 100%;" :rules="[{ required: true, message: '请选择是否通过审核' }]">
            <el-radio-group v-model="form.pass">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="审核意见" v-if="form.pass === '0'" prop="opinion" style="width: 100%;" :rules="[{ required: true, message: '请输入审核意见' }]">
            <el-input type="textarea" :rows="5" :maxlength="500" v-model="form.opinion" clearable placeholder="请输入审核意见" show-word-limit></el-input>
          </el-form-item>
        </el-form>
      </ai-dialog>
    </template>
    <template #footer >
      <el-button @click="cancel">取消</el-button>
      <el-button type="primary" @click="isShow = true" v-if="info.status === '0'">审核</el-button>
    </template>
  </ai-detail>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name: 'Detail',

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

    data () {
      return {
        info: {},
        id: '',
        search: {
          current: 1,
          size: 10
        },
        form: {
          opinion: '',
          pass: ''
        },
        isShow: false,
        type: ''
      }
    },

    computed: {
      ...mapState(['user'])
    },

    created () {
      this.getInfo(this.params.id)
    },

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

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

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

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

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