<template>
  <div>
    <el-form :model="Form" :rules="rules"  ref="ruleForm" label-width="180px">
      <el-form-item label="单位类别" prop="dwType">
        <el-select v-model="Form.dwType" placeholder="请选择单位类别">
          <el-option v-for="item in DwTypelist"
          :key="item.dictKey"
          :label="item.dictValue"
          :value="item.dictKey">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="单位级别" prop="dwjb">
        <el-select v-model="Form.dwjb" placeholder="请选择单位类别">
          <el-option v-for="item in DwJblist"
          :key="item.dictKey"
          :label="item.dictValue"
          :value="item.dictKey">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="统一信用代码/登记证号" prop="orgCode">
        <el-input v-model="Form.orgCode" @input="changeorgCOde" maxlength="18"></el-input>
      </el-form-item>
      <el-form-item label="单位名称" prop="name">
        <el-input v-model="Form.name"></el-input>
      </el-form-item>
      <el-form-item label="登录用户名">
        <el-input v-model="Form.userName" disabled></el-input>
      </el-form-item>
      <el-form-item label="单位注册地址" prop="orgAddress">
        <el-input v-model="Form.orgAddress"></el-input>
      </el-form-item>
      <el-form-item label="法人代表/负责人" prop="contactMan">
        <el-input v-model="Form.contactMan"></el-input>
      </el-form-item>
      <el-form-item label="单位所属区域" prop="regionSid" class="demo-form-inline">
        <AreaPicker @areaPicker="areaPicker"></AreaPicker>
      </el-form-item>
      <el-form-item label="单位地理位置" prop="gisInfo">
        <el-input v-model="Form.gisInfo" readonly>
          <el-button slot="append" icon="el-icon-map-location" @click='mapDialog = true'></el-button>
        </el-input>
      </el-form-item>
      <el-form-item label="单位通讯地址" prop="postAddress">
        <el-input v-model="Form.postAddress"></el-input>
      </el-form-item>
      <el-form-item label="法人证书" prop="businessLicense">
        <UploadImg class="second" :FrontPhoto="Photourl" @imgUrl="FrontPhotoUrl"></UploadImg>
      </el-form-item>
    </el-form>

    <Position v-if="mapDialog" :address.sync="Form.postAddress" :maker-position.sync="Form.gisInfo" :dialog-visible.sync="mapDialog" />

  </div>
</template>

<script>
  // import AMap from 'AMap'
  import UploadImg from '@/components/uploadFile/index.vue'
  import AreaPicker from '@/components/AreaPicker/index.vue'
  import Position from './amap.vue'
  import { getDwType, getDwJb } from '@/api/system/dataDict/dataDict.js'
  export default {
    components:{UploadImg, AreaPicker, Position},
    props:{
      Form:{
        type: Object,
        default: function () {
          return {}
        }
      }
    },
    data() {
      return {
        DwTypelist: [],
        DwJblist: [],
        mapDialog: false,
        address: '',
        Photourl: require('@/assets/images/org/yyzz.png'),
        rules: {
          orgCode: [
            { required: true, message: '请输入统一信用代码', trigger: 'blur' },
            { min: 9, max: 18, message: '统一信用代码长度在 9位 或者 18 位', trigger: 'blur' }
          ],
          dwType: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
          dwjb: [{ required: true, message: '请选择活动区域', trigger: 'change' }],
          name: [{required: true, message: '请输入单位名称', trigger: 'blur'}],
          orgAddress: [{required: true, message: '请输入单位注册地址', trigger: 'blur'}],
          contactMan: [{required: true, message: '请输入法人代表/负责人', trigger: 'blur'}],
          regionSid: [{required: true, message: '请选择单位地区', trigger: ['blur', 'change']}],
          gisInfo: [{required: true, message: '请选择单位地理位置', trigger: 'blur'}],
          postAddress: [{required: true, message: '请输入单位通讯地址', trigger: 'blur'}],
          DwType: [{required: true, message: '请选择活动区域', trigger: 'change'}],
          businessLicense: [{required: true, message: '请上传应用执照', trigger: 'change'}],
        },
      }
    },
    async mounted() {
      getDwType().then((res) => {
        this.DwTypelist = res.data
      })
      getDwJb().then((res) => {
        this.DwJblist = res.data
      })
    },
    methods: {
      FrontPhotoUrl(url){
        this.$set(this.Form,'businessLicense',url.filePath)
        this.validateForm()
      },
      addressInput(){
        console.log('ssss')
        this.validateForm()
      },
      areaPicker(val){
        this.$set(this.Form,'regionSid',val)
      },
      changeorgCOde(){
        this.Form.userName = this.Form.orgCode
      },
      validateForm () {
        let flag = null
        this.$refs['ruleForm'].validate(valid => {
          if (valid) {
            flag = true
          } else {
            flag = false
          }
        })
        return flag
      }
    }
  }
</script>

<style>
  .avatar-uploader.second .avatar {
  	width: 350px;
  	height: 450px;
  }
  .map{
    width: 600px;
    height: 600px;
  }
  .amap-demo {
    height: 300px;
  }
</style>
