<template>
  <ai-detail class="detail">
    <template slot="title">
      <ai-title title="积分审核" isShowBack isShowBottomBorder @onBackClick="cancel(false)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #right>
          <el-button size="small" type="primary" @click="isShow = true" v-if="info.status === '0'">审核</el-button>
        </template>
        <template #content>
          <ai-wrapper>
            <ai-info-item label="事件类型" isLine :value="info.applyItemName"></ai-info-item>
            <ai-info-item label="申请人" :value="info.createUserName"></ai-info-item>
            <ai-info-item label="手机号" :value="info.detail"></ai-info-item>
            <ai-info-item label="所属地区" :value="info.areaName"></ai-info-item>
            <ai-info-item label="所属网格" :value="info.girdName"></ai-info-item>
            <ai-info-item label="审核时间" v-if="info.auditTime" :value="info.auditTime"></ai-info-item>
            <ai-info-item label="状态" :value="dict.getLabel('appIntegralApplyEventStatus', info.status)"></ai-info-item>
            <ai-info-item label="事件描述" isLine :value="info.content"></ai-info-item>
            <ai-info-item label="活动图片" isLine>
              <ai-uploader
                disabled
                :instance="instance"
                :value="info.files">
                </ai-uploader>
            </ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
      <ai-dialog
        :visible.sync="isShow"
        @onConfirm="onConfirm"
        @close="onClose"
        width="890px"
        title="审核">
        <el-form class="ai-form" :model="form" label-width="120px" ref="form">
          <el-form-item label="是否通过" prop="auditStatus" style="width: 100%;" :rules="[{required: true, message: '请选择是否通过', trigger: 'change'}]">
            <el-radio-group v-model="form.auditStatus">
              <el-radio label="0">否</el-radio>
              <el-radio label="1">是</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item prop="auditDesc" v-if="form.auditStatus === '0'" label="审批意见" style="width: 100%" :rules="[{required: true, message: '请输入审批意见', trigger: 'blur'}]">
            <el-input size="small" type="textarea" :rows="5" v-model="form.auditDesc" clearable placeholder="请输入审批意见"></el-input>
          </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: {},
        form: {
          auditDesc: '',
          auditStatus: ''
        },
        isShow: false
      }
    },

    created () {
      this.getInfo()
    },

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

      onClose () {
        this.id = ''
        this.form.auditDesc = ''
        this.form.auditStatus = ''
      },

      onConfirm () {
        this.$refs.form.validate((valid) => {
          if (valid) {
            this.instance.post(`/app/appintegraluserapply/auditById`, {
              ...this.form,
              id: this.params.id
            }).then(res => {
              if (res.code == 0) {
                this.$message.success('审核成功！')
                this.isShow = false
                this.getInfo()
              }
            })
          }
        })
      },

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

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