<template>
  <div>
    <div class="dialog-h-content scroll-h">
      <div class="div_tuomin">
        <el-button v-if="view_real_data"
                   size="mini"
                   class="diy-button--search"
                   @click="handleTuomin">显示脱敏信息</el-button>
      </div>
      <div v-if="initLoading"
           class="m-row">
        <div class="m-info">
          <div class="info-prop">
            <span class="info-title-2">所属楼栋：</span>
            <span>{{ agencyObj.neighborHoodName }}-{{agencyObj.label}}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-2">单元号：</span>
            <span>{{ dataForm.unitName?dataForm.unitName:'--' }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-2">门牌号：</span>
            <span>{{ dataForm.doorName}}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-2">房屋编码：</span>
            <span>{{ dataForm.coding?dataForm.coding:'--'}}</span>
          </div>
          <div v-if="dataForm.houseQrcodeUrl"
               style="display: flex;flex-direction: column;">
            <img style="margin-left: 70px;width: 200px;"
                 :src="dataForm.houseQrcodeUrl">
            <a style="margin-left: 80px"
               :href="dataForm.houseQrcodeUrl"
               target="_blank">下载</a>
          </div>

          <div class="info-prop">
            <span class="info-title-2">房屋类型：</span>
            <span>{{dataForm.houseTypeName?dataForm.houseTypeName:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">房屋用途：</span>
            <span>{{dataForm.purposeName?dataForm.purposeName:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">房屋状态：</span>
            <span>{{dataForm.rentName?dataForm.rentName:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">房主姓名：</span>
            <span>{{dataForm.ownerName?dataForm.ownerName:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">联系方式：</span>
            <span>{{dataForm.showOwnerPhone?dataForm.showOwnerPhone:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">房主身份证：</span>
            <span>{{dataForm.showOwnerIdCard?dataForm.showOwnerIdCard:'--' }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-2">备注：</span>
            <span>{{dataForm.remark?dataForm.remark:'--' }}</span>
          </div>

        </div>
      </div>

    </div>
    <div class="div-btn">
      <el-button size="small"
                 @click="handleCancle">关 闭</el-button>

    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost, requestGet } from '@/js/dai/request'


let loading // 加载动画
export default {
  data () {
    return {
      formType: 'add', //表单操作类型 add新增，edit编辑，detail详情
      btnDisable: false,
      initLoading: false,
      unitList: [],

      houseId: '', //房屋ID
      houseType: '1',
      purpose: '1',
      rentFlag: 0,
      dataForm: {
        neighborHoodId: '', // 所属小区ID
        buildingId: '',//所属楼栋ID
        buildingUnitId: '',//所属单元ID
        doorName: '',//门牌号
        houseType: '',//房屋类型【楼房，平房，别墅】
        purpose: '',//房屋用途【住宅，商业，办公，工业，仓储，商住混用，其他】
        rentFlag: 0,//房屋状态【是：1，否：0】	出租1、闲置2、自住	0
        ownerPhone: '', //联系方式
        ownerName: '', //房主名字
        ownerIdCard: '', //房主身份证
        remark: '',
        // realPerson: 0,
        coding: '',
        sysCoding: ''
      },

      keyWords: '',
      agencyObj: {},

    }
  },
  components: {},
  mounted () {

  },

  methods: {
    handleCancle () {
      // this.diaDestroy()
      this.$emit('diaDetailClose')

    },
    diaDestroy () {
      if (map) {
        map.destroy()
      }
    },
    async initForm (row, agencyObj) {


      //  this.dataForm = JSON.parse(JSON.stringify(row))
      this.agencyObj = agencyObj
      this.houseId = row.houseId
      await this.loadHouseInfo()
      this.initLoading = true




      // this.$refs.ref_form.resetFields();
      // this.agencyObj = agencyObj
      // this.formType = type
      // console.log('agencyObj-----', agencyObj)
      // if (row) {

      //   this.houseId = row.houseId
      //   await this.loadHouseInfo()


      // } else {

      //   this.dataForm.neighborHoodId = this.agencyObj.neighborHoodId
      //   this.dataForm.buildingId = this.agencyObj.id
      // }


      // await this.loadUnitList()

    },

    async handleTuomin () {
      const url = "/data/aggregator/epmetuser/detailByType";

      const { data, code, msg } = await requestPost(url, {
        id: this.houseId,
        type: "checkHouse",
      });

      if (code === 0) {
        this.$set(this.dataForm, 'showOwnerPhone', data.mobile)
        this.$set(this.dataForm, 'showOwnerIdCard', data.idCard)
      } else {
        this.$message.error(msg);
      }

    },

    async loadHouseInfo () {

      const url = "/gov/org/ichouse/" + this.houseId

      const { data, code, msg } = await requestGet(url)

      if (code === 0) {
        // debugger
        this.dataForm = { ...data }

        this.houseType = this.dataForm.houseType
        this.purpose = this.dataForm.purpose
        this.rentFlag = parseInt(this.dataForm.rentFlag)


      } else {
        this.$message.error(msg)
      }

    },


    resetData () {
      this.houseId = '' //房屋ID
      this.houseType = '1'
      this.purpose = '1'
      this.rentFlag = 0
      this.dataForm = {
        neighborHoodId: '', // 所属小区ID
        buildingId: '',//所属楼栋ID
        buildingUnitId: '',//所属单元ID
        doorName: '',//门牌号
        houseType: '1',//房屋类型【楼房，平房，别墅】
        purpose: '1',//房屋用途【住宅，商业，办公，工业，仓储，商住混用，其他】
        rentFlag: 0,//是否出租【是：1，否：0】
        ownerPhone: '', //联系方式
        ownerName: '', //房主名字
        ownerIdCard: '', //房主身份证
        remark: '', // 备注
        coding: '',
        sysCoding: ''
      }

    },
    // 开启加载动画
    startLoading () {
      loading = Loading.service({
        lock: true, // 是否锁定
        text: '正在加载……', // 加载中需要显示的文字
        background: 'rgba(0,0,0,.7)' // 背景颜色
      })
    },
    // 结束加载动画
    endLoading () {
      // clearTimeout(timer);
      if (loading) {
        loading.close()
      }
    }
  },
  computed: {
    dataRule () {
      return {
        buildingUnitId: [
          { required: true, message: '所属单元不能为空', trigger: 'blur' },
        ],
        doorName: [
          { required: true, message: '门牌号不能为空', trigger: 'blur' }
        ],
        coding: [
          { required: true, message: '房屋编码不能为空', trigger: 'blur' }
        ],
        houseType: [
          { required: true, message: '房屋类型不能为空', trigger: 'blur' }
        ],
        purpose: [
          { required: true, message: '房屋用途不能为空', trigger: 'blur' }
        ],
        rentFlag: [
          { required: true, message: '是否出租不能为空', trigger: 'blur' }
        ],
        ownerPhone: [
          { required: false }
        ],
        ownerName: [
          { required: false }
        ],
        ownerIdCard: [
          { required: false }
        ],
        remark: [
          { required: false }
        ],
      }
    },

  },
  props: {
    view_real_data: {//显示【显示脱敏信息】按钮
      type: Boolean,
      default: false,
    }
  }
}
</script>
<style lang="scss" scoped >
@import "@/assets/scss/modules/management/detail-main.scss";

.div_tuomin {
  position: absolute;
  top: 0;
  right: 40px;
  z-index: 1000;
}
</style>
