<template>
  <el-dialog :visible.sync="visible" :title="dataForm.flag === '1' ? '查看' : '审核'" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="120px">
        <el-form-item label="姓名" prop="name">
            <el-input v-model="dataForm.name" placeholder="姓名" disabled></el-input>
        </el-form-item>
        <el-form-item label="身份证" prop="idCard">
            <el-input v-model="dataForm.idCard" placeholder="身份证" disabled></el-input>
        </el-form-item>
        <el-form-item label="手机号" prop="mobile">
            <el-input v-model="dataForm.mobile" placeholder="手机号" disabled></el-input>
        </el-form-item>
        <!--<el-form-item label="与房主关系" prop="yfzgx">-->
            <!--<el-input v-model="dataForm.yfzgx" placeholder="与房主关系" disabled></el-input>-->
        <!--</el-form-item>-->
        <el-form-item label="照片" prop="imgList">
            <template slot-scope="scope">
                <label v-for="(item,index) in dataForm.imgList" :key="index">
                    <img :src="item.fileUrl" @click="imgShow(item.fileUrl)" width="100" height="100" />
                </label>
            </template>
        </el-form-item>
        <el-form-item v-if="dataForm.flag === '2'" label="审核原因" prop="reason">
            <textarea v-model="dataForm.reason" placeholder="请输入审核原因" class="blacklist-reason"></textarea>
        </el-form-item>
      </el-form>
    <template slot="footer">
      <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
      <el-button v-if="dataForm.flag === '2'" type="danger" @click="dataFormSubmitHandle('2')">{{ $t('checkBTGBtn') }}</el-button>
      <el-button v-if="dataForm.flag === '2'" type="primary" @click="dataFormSubmitHandle('1')">{{ $t('checkTGBtn') }}</el-button>
    </template>
      <el-dialog :visible.sync="dialogVisible" :modal="false">
          <img width="100%" :src="dialogImageUrl" alt="">
      </el-dialog>
  </el-dialog>
</template>

<script>
import debounce from 'lodash/debounce'
export default {
  data () {
    return {
      visible: false,
      dataForm: {
        id: '',
          flag: '',
        contractId: '',
        name: '',
        idCard: '',
        mobile: '',
        yfzgx: '',
        imgList: [],
          reason: ''
      },
        dialogVisible: false,
        dialogImageUrl: ''
    }
  },
  computed: {
    dataRule () {
      return {
        contractId: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        name: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        idCard: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        mobile: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
        yfzgx: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ],
          imgList: [
          { required: true, message: this.$t('validate.required'), trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.getInfo()
        }
      })
    },
      // 查看大图
      imgShow(url){
          this.dialogImageUrl = url
          this.dialogVisible = true
      },
    // 获取信息
    getInfo () {
      this.$http.get(`/pli/power/rentTenantInfo/${this.dataForm.id}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = {
          ...this.dataForm,
          ...res.data
        }
      }).catch(() => {})
    },
    // 表单提交
    dataFormSubmitHandle: debounce(function (type) {
      this.$refs['dataForm'].validate((valid) => {
        if (!valid) {
          return false
        }
          this.dataForm.state = type
        this.$http.post('/pli/power/rentTenantInfo/landlord/review', this.dataForm).then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.$message({
            message: this.$t('prompt.success'),
            type: 'success',
            duration: 500,
            onClose: () => {
              this.visible = false
              this.$emit('refreshDataList')
            }
          })
        }).catch(() => {})
      })
    }, 1000, { 'leading': true, 'trailing': false })
  }
}
</script>
<style lang="scss" scoped>
    .blacklist-reason {
        width: 100%;
        height: 80px;
        border: 1px solid #e4e4e4;
        border-radius: 4px;
        resize: none;
        padding: 8px;
        box-sizing: border-box;
    }
</style>
