<template>
  <el-dialog
    :title="title"
    :visible.sync="modal"
    width="80%"
    :close-on-click-modal="false"
    @close="
      res => {
        $emit('cancel');
      }
    "
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
      <el-form-item label="幼儿园名称"> {{ form.name }} </el-form-item>
      <el-form-item label="幼儿园类型"> {{ form.type }} </el-form-item>
      <el-form-item label="所在地区">
        {{ form.area ? form.province + '/' + form.city + '/' + form.area : '' }}
      </el-form-item>
      <el-form-item label="详细地址"> {{ form.address }} </el-form-item>
      <el-form-item label="幼儿园logo">
        <img
          :src="form.logo"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.logo }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="幼儿园预览logo">
        <img
          :src="form.previewLogo"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.previewLogo }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="门店图片"
        ><img
          :src="form.cover"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.cover }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="办公电话"> {{ form.phonenumber }} </el-form-item>
      <el-form-item label="幼儿园介绍"> {{ form.brief }} </el-form-item>
      <el-form-item label="营业执照"
        ><img
          :src="form.businessLicense"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.businessLicense }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="申请人姓名"> {{ form.realName }} </el-form-item>
      <el-form-item label="手机号"> {{ form.personPhonenumber }} </el-form-item>
      <el-form-item label="邮箱"> {{ form.email }} </el-form-item>
      <el-form-item label="证照号码"> {{ form.idCardNumber }} </el-form-item>
      <el-form-item label="半身照"
        ><img
          :src="form.bodyPhoto"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.bodyPhoto }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="证件正面"
        ><img
          :src="form.idCardFront"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.idCardFront }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="证件背面"
        ><img
          :src="form.idCardBack"
          class="pre-img"
          @click="
            () =>
              this.$AdvanceViewImageModal({
                items: [{ src: form.idCardBack }]
              })
          "
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="auditStatus">
        <el-radio-group v-if="auditStatus !== 1" v-model="form.auditStatus">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="-1">不通过</el-radio>
        </el-radio-group>
        <span v-else>{{ form.auditStatus | auditStatusName }}</span>
      </el-form-item>
      <el-form-item label="审核备注">
        <el-input
          v-if="auditStatus !== 1"
          v-model="form.auditMsg"
          type="textarea"
          :rows="2"
          placeholder="请输入内容"
        >
        </el-input>
        <span v-else>{{ form.auditMsg }}</span>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="modal = false">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getItem, auditItem } from '@/api/scene';

export default {
  name: 'SceneVerifyItemModal',

  filters: {
    auditStatusName: function(num) {
      switch (num) {
        case 1:
          return '通过';
        case 0:
          return '待审核';
        case -1:
          return '拒绝';
        default:
          return '-';
      }
    }
  },

  props: {
    id: {
      type: String,
      default: ''
    },
    auditStatus: {
      type: Number,
      default: 0
    }
  },

  data() {
    return {
      title: '幼儿园详情',
      modal: true,
      form: {
        auditStatus: null,
        auditMsg: ''
      },
      rules: {
        auditStatus: [
          { required: true, message: '请选择是否通过', trigger: 'blur' }
        ]
      }
    };
  },

  watch: {
    id: {
      handler(id) {
        id && this.loadData();
      },
      immediate: true
    }
  },

  mounted() {},

  methods: {
    async loadData() {
      const { success, data, msg } = await getItem({
        id: this.id
      });
      if (success) {
        this.form = data;
      }
    },

    handleConfirm() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          const params = {
            auditStatus: this.form.auditStatus,
            auditMsg: this.form.auditMsg
          };
          if (this.id) params.id = this.form.infoId;
          const { success, msg } = await auditItem(params);
          if (success) {
            this.$success('保存成功！');
            this.modal = false;
            this.$g_emit('scene_reload');
          }
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.pre-img {
  height: 80px;
}
</style>
