<template>
  <ai-detail class="AppDynamicDetail">
    <template slot="title">
      <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
        <template #rightBtn>
          <div class="title-btns">
            <el-button type="primary" icon="iconfont iconRegister" @click="isShowExamine = true" v-if="info.status == 0">审核</el-button>
          </div>
        </template>
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper label-width="120px">
            <ai-info-item label="内容" isLine :value="info.content"></ai-info-item>
            <ai-info-item label="类型" isLine >{{dict.getLabel("wyGirdNewsType", info.type)}}</ai-info-item>
            <ai-info-item label="所属网格" isLine :value="info.girdName"></ai-info-item>
            <ai-info-item label="网格员姓名" isLine :value="info.name"></ai-info-item>
            <ai-info-item label="状态" isLine >{{dict.getLabel("auditStatus", info.status)}}</ai-info-item>
            <ai-info-item label="发布时间" isLine :value="info.createTime"></ai-info-item>
            <ai-info-item label="图片" isLine>
              <div class="files">
                <div class="file-item" v-for="(item, index) in info.files" :key="index">
                  <img :src="item.url" v-viewer="{movable: true}">
                </div>
              </div>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
       <ai-dialog
        :visible.sync="isShowExamine"
        width="800px"
        title="审核"
        @closed="isShowExamine=false"
        @onConfirm="handleEvent">
        <el-form class="ai-form" label-width="120px" :model="form" ref="form">
          <el-form-item label="是否通过" prop="status" style="width: 100%;" :rules="[{ required: true, message: '请选择是否通过' }]">
            <el-radio-group v-model="form.status">
              <el-radio label="1">是</el-radio>
              <el-radio label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <!-- <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-item label="图片" prop="files" style="width: 100%;">
            <ai-uploader
                :instance="instance"
                isShowTip
                v-model="form.files"
                :limit="9">
            </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,
      moduleId: String
    },

    data () {
      return {
        info: {},
        id: '',
        isShowExamine: false,
        form: {status: ''}
      }
    },

    created () {
      this.dict.load('wyGirdNewsType', 'auditStatus').then(() => {
        this.getDetail()
      })
    },

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

      handleEvent() {
        this.$refs.form.validate(v => {
          if (v) {
            this.instance.post(`/app/appgirdnews/examine?id=${this.params.id}&pass=${this.form.status}`).then(res => {
              if (res?.code == 0) {
                this.isShowExamine = false
                this.getDetail()
                this.$message.success('审核成功!')
              }
            })
          }
        })
      },

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

<style scoped lang="scss">
  .AppDynamicDetail {
    .files {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      .file-item {
        width: 240px;
        height: 240px;
        margin: 0 20px 20px 0;

        img, video {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
    }
  }
</style>
