<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="info.content" isLine></ai-info-item>
          <ai-info-item label="发布地区" :value="info.areaName" isLine></ai-info-item>
          <ai-info-item label="议事截止时间" :value="info.discussDeadline"></ai-info-item>
          <ai-info-item label="公示截止时间" :value="info.publicityDeadline"></ai-info-item>
          <ai-info-item label="议事类型" :value="dict.getLabel('discussType', info.type)" isLine></ai-info-item>
          <ai-info-item label="是否匿名投票" v-if="info.type === '1'" :value="info.anonymous === '1' ? '是' : '否'"></ai-info-item>
          <ai-info-item label="投票方式" v-if="info.type === '1'" :value="info.voteType === '0' ? '单选' : '多选'"></ai-info-item>
          <ai-info-item label="图片" isLine>
            <ai-uploader
              :instance="instance"
              disabled
              v-model="info.images"
              :limit="9">
            </ai-uploader>
          </ai-info-item>
        </ai-wrapper>
      </ai-card>
      <ai-dialog
        :visible.sync="isShowAdd"
        width="680px"
        height="580px"
        title="发表意见"
        @close="onClose"
        @onConfirm="onConfirm">
        <el-form ref="form" class="ai-form" :model="form" label-width="110px" label-position="right">
          <el-form-item label="发表意见" prop="content" style="width: 100%;" :rules="[{ required: true, message: '请发表你的观点和意见', trigger: 'blur' }]">
            <el-input size="small" type="textarea" :rows="5" show-word-limit :maxlength="140" placeholder="请发表你的观点和意见" v-model="form.content"></el-input>
          </el-form-item>
        </el-form>
      </ai-dialog>
    </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
        },
        isShowAdd: false,
        form: {
          content: ''
        },
        type: ''
      }
    },

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

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

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appvillagediscuss/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.images = res.data.images ? JSON.parse(res.data.images) : []
            this.type = res.data.type
          }
        })
      },

      onClose () {
        this.form.content = ''
      },

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

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