<template>
  <div>
    <div class="dialog-h-content scroll-h">

      <div v-if="view_real_data"
           class="div_tuomin">
        <el-button 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-4">姓名：</span>
            <span>{{ formData.name||'--'  }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-4">手机号：</span>
            <span>{{ formData.showMobile||'--' }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-4">证件号：</span>
            <span>{{ formData.showIdCard||'--' }}</span>
          </div>

          <div class="info-prop">
            <span class="info-title-4">现居地：</span>
            <span>{{ formData.presentAddress||'--'  }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-4">详细地址：</span>
            <span>{{ formData.detailAddress||'--'  }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-4">来自地区：</span>
            <span>{{ formData.sourceAddress||'--'  }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-4">来到本地时间：</span>
            <span>{{ formData.arriveDate||'--'  }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-4">离开本地时间：</span>
            <span>{{ formData.leaveDate||'--'  }}</span>
          </div>
          <div class="info-prop">
            <span class="info-title-4">备注：</span>
            <span>{{ formData.remark||'--'  }}</span>
          </div>

        </div>
      </div>

    </div>
    <div class="div-btn">
      <el-button size="small"
                 @click="handleCancle">关 闭</el-button>
      <!-- <el-button v-if="formType != 'detail'"
                 size="small"
                 type="primary"
                 :disabled="btnDisable"
                 @click="handleComfirm('ref_form')">确 定</el-button> -->
    </div>

  </div>
</template>

<script>

import { Loading } from 'element-ui' // 引入Loading服务
import { requestPost } from '@/js/dai/request'
import { dateFormats } from '@/utils/index'
import { isCard, isMobile } from '@/utils/validate'

let loading // 加载动画
export default {
  data () {

    return {

      initLoading: false,

      icNatId: '',
      formData: {},

    }
  },
  components: {},
  async mounted () {
    const { user } = this.$store.state
    this.agencyId = user.agencyId
    //获取网格下拉框数据
    // await this.loadGrid()
  },
  destroyed () {
    this.nowAllCode = []
  },
  props: {
    view_real_data: {//显示【显示脱敏信息】按钮
      type: Boolean,
      default: false,
    }
  },
  methods: {
    async handleTuomin () {
      const url = "/data/aggregator/epmetuser/detailByType";

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

      if (code === 0) {
        this.$set(this.formData, 'showMobile', data.mobile)
        this.$set(this.formData, 'showIdCard', data.idCard)
      } else {
        this.$message.error(msg);
      }

    },

    async initForm (row) {
      console.log('row----', row)

      this.formData.agencyId = this.agencyId
      this.icNatId = row.id
      await this.loadFormData(row.id)

      this.initLoading = true
      console.log('formtype', type)

    },


    async loadGrid () {
      const url = "/gov/org/customergrid/gridoption"

      let params = {
        agencyId: this.agencyId
      }

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

      if (code === 0) {
        this.gridList = data

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

    },
    async handleSelGrid (value) {

      const url = "/epmetuser/icresiuser/demandusers"

      let params = {
        agencyId: this.agencyId,
        gridId: value
      }

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

      if (code === 0) {
        this.personList = data

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

    },
    async getArea (node, resolve) {

      const url = "/commonservice/areacode/nextarea"
      let params = {
        parentLevel: node.data ? node.data.level : '',
        parentAreaCode: node.data ? node.data.code : ''
      }

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

      if (code === 0) {
        const nodes = data.map(item => ({
          value: item.areaCode, //
          label: item.areaName,
          code: item.areaCode,
          level: item.level,
          leaf: node.level >= 4 // 5层级
        }))
        resolve(nodes)

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

    },
    async handleSelAddress (value) {

      const url = "/gov/org/house/gethouseinfo/" + value

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

      if (code === 0) {
        this.formData.presentAddress = data.agencyPathName
        this.formData.presentAddressCode = data.areaCode
        this.formData.detailAddress = data.allName

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

    },


    async loadFormData (id) {

      const url = '/epmetuser/tripreport/detail'
      let params = {
        id,
      }
      const { data, code, msg } = await requestPost(url, params)
      if (code === 0) {
        console.log('deda-------', data)
        this.formData = { ...data, channel: [], content: '' }
        this.sourceAllCode = data.sourceAddressPathCode && data.sourceAddressPathCode.split(',')

        if (data.userType == 'icresi') this.isFromResi = true
        else this.nowAllCode = data.presentAddressPathCode && data.presentAddressPathCode.split(',')
      } else {
        this.$message.error(msg)
      }
    },

    handleCancle () {
      // this.resetData()
      this.$emit('dialogCancle')

    },

    resetData () {

    },
    // 开启加载动画
    startLoading () {
      loading = Loading.service({
        lock: true, // 是否锁定
        text: '正在加载……', // 加载中需要显示的文字
        background: 'rgba(0,0,0,.7)' // 背景颜色
      })
    },
    // 结束加载动画
    endLoading () {
      // clearTimeout(timer);
      if (loading) {
        loading.close()
      }
    }
  }
}
</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>


