<template>
  <div id="">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;">
        <p style="font-weight:bolder;background-color:#d5d5ff;padding:3px;">信息填报</p>
        <a-form :model="formObj" :label-col="{ span: 4 }" :wrapper-col="{ span: 14 }">
          <p style="margin-top:10px;margin-bottom: 10px;overflow: hidden;">
            <a-icon type="caret-right" />
            <span style="width:120px;padding-left: 10px">基本信息</span>
            <span class="hrs"></span>
          </p>
          <a-form-item label="项目名称">
            <a-input v-model:value="formObj.prjName" autocomplete="off" style="width:90%;"></a-input>
          </a-form-item>
          <a-form-item label="行政区划">
            <div v-if="showLocSelect">
              <!-- <a-select v-model:value="provName" @change="provChange" placeholder="选择省" style="margin-right: 10px;">
                <a-select-option v-for="item in provList" :key="item.adCode" :value="item.adCode">{{ item.adName }}
                </a-select-option>
              </a-select> -->
              <a-select v-model:value="cityName" @change="cityChange" placeholder="选择市" style="margin-right: 10px;">
                <a-select-option v-for="item in cityList" :key="item.adCode" :value="item.adCode">{{ item.adName }}
                </a-select-option>
              </a-select>
              <a-select v-model:value="countryName" @change="countryChange" placeholder="选择县">
                <a-select-option v-for="item in countryList" :key="item.adCode" :value="item.adCode">{{ item.adName }}
                </a-select-option>
              </a-select>
              &#x3000;
              <span
                v-if="showLocSelect"
                @click="showLocSelect = false"
                style="color: #009fff;font-size:12px;cursor:pointer">取消</span>
            </div>
            <div v-else>
              <a-input v-model:value="formObj.adName" autocomplete="off" style="width:90%;" />
              &#x3000;
              <span @click="showLocSelect = true" style="color: #009fff;font-size:12px;cursor:pointer">更改</span>
            </div>
          </a-form-item>
          <a-form-item label="工程类型">
            <a-input allow-clear v-model:value="formObj.prjType" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="初步设计批复工期">
            <a-input allow-clear v-model:value="formObj.prjPtm" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="开工时间">
            <a-input allow-clear v-model:value="formObj.prjStm" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="建设进度">
            <a-input allow-clear v-model:value="formObj.schedule" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="水行政主管部门联系人">
            <a-input allow-clear v-model:value="formObj.wrPers" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="管理人员联系电话">
            <a-input allow-clear v-model:value="formObj.wrPresTel" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="现场负责人名称">
            <a-input allow-clear v-model:value="formObj.sitePres" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="现场负责人电话">
            <a-input allow-clear v-model:value="formObj.sitePresTle" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="经度">
            <a-input allow-clear v-model:value="formObj.centerX" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item label="纬度">
            <a-input allow-clear v-model:value="formObj.centerY" autocomplete="off"></a-input>
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 14, offset: 4 }">
            <a-button type="primary" @click="addHandler" v-if="openType">保 存</a-button>
          </a-form-item>
        </a-form>
      </a-layout-content>
    </a-layout>
  </div>
</template>

<script>
import { getrgstrIdObject_keyjx } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { dateFormat } from '../../../utils/gw_date.js';
import inputWith from '../../../widgets/inuptWith.vue';
import unlimitDatePicker from '../../../widgets/unLimitdatePicker.vue';

export default {
  components: {
    inputWith: inputWith,
    unlimitDatePicker: unlimitDatePicker,
  },
  props: [
    'id',
    'currentObjectRgstrId',
    'currentResCode',
    'currentObjectId',
    'currentObjectName',
    'openType',
  ],
  data() {
    return {
      formObj: {},
      dialogFormVisible: false,
      formLabelWidth: '160px',
      currentResCode1: '',
      currentObjectId1: '',
      value1: '',
      provList: [],
      cityList: [],
      countryList: [],
      townList: [],
      villageList: [],
      provName: '',
      cityName: '',
      countryName: '',
      townName: '',
      villageName: '',
      provNames: '',
      cityNames: '',
      countryNames: '',
      townNames: '',
      villageNames: '',
      curSelectItem: 1,
      showLocSelect: false,
      locat: {
        location: '',
        admDiv: '',
      },
      xcztShow: false,
      imageShow: false,
      xcztEngId: '',
      centerX: 0,
      centerY: 0,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  mounted() {
    this.currentResCode1 = this.currentResCode;
    this.currentObjectId1 = this.currentObjectId;
    this.getRgstridObj();
    this.getAreaList();
  },
  watch: {
    id(n, o) {
      this.getRgstridObj();
    },
    showLocSelect(val) {
      if (!val) {
        this.formObj.rvLoc = this.locat.location;
        this.formObj.admDiv = this.locat.admDiv;
        this.provName = '';
        this.cityName = '';
        this.countryName = '';
      }
    },
  },
  methods: {
    getRgstridObj() {
      getrgstrIdObject_keyjx(this.currentObjectId).then((res) => {
        if (res.data) {
          this.formObj = res.data;
        } else {
          this.formObj = {};
        }
      });
    },
    addHandler() {
      this.formObj.id = this.currentObjectRgstrId;
      this.formObj.rgstrId = this.currentObjectRgstrId;
      console.log(this.formObj);
      // 基础信息纠错，经纬度修改粗略校验经度纬度整数部分的范围
      if (this.formObj.centerYGd < 4 || this.formObj.centerYGd > 54) {
        this.$message.error('纬度的整数范围应在4-54之间，请重新填写！');
        this.formObj.centerYGd = '';
        return;
      }
      if (this.formObj.centerXGd < 74 || this.formObj.centerXGd > 136) {
        this.$message.error('经度的整数范围应在74-136之间，请重新填写！');
        this.formObj.centerXGd = '';
        return;
      }
      try {
        this.$confirm('确认保存基础信息？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          request.post('/bis/insp/keyjx/update', this.formObj).then((res) => {
            if (res.success) {
              this.$emit('addShuiKuSuccess');
              this.showLocSelect = false;
              this.getRgstridObj();
              this.$message.success('修改成功');
            } else {
              this.$emit('cancelHandler');
            }
          });
        });
      } catch (e) {}
    },
    cancelHandler() {
      this.$emit('cancelHandler');
    },
    getAreaList(val) {
      const areaParams = {
        adName: '',
        id: this.dczId,
        pageNum: 1,
        pageSize: 10000,
      };
      let adCode = '';
      if (!val) {
        adCode = '360000000000';
      } else {
        adCode = val;
      }
      request
        .get('/dc/ad/base/getAdData', { params: { adCode: adCode } })
        .then((res) => {
          if (res.success) {
            if (this.curSelectItem == 1) {
              this.cityList = res.data;
            } else if (this.curSelectItem == 2) {
              this.countryList = res.data;
            } else {
              this.provList = res.data;
            }
          }
        });
    },
    provChange(val) {
      this.curSelectItem = 1;
      this.cityName = '';
      this.countryName = '';
      this.formObj.admDiv = val;
      this.provList.forEach((ele) => {
        if (ele.adCode == this.provName) {
          this.provNames = ele.adName;
        }
      });
      this.formObj.adName = this.provNames;
      this.getAreaList(val);
    },
    cityChange(val) {
      this.curSelectItem = 2;
      if (val && val != '') {
        this.formObj.admDiv = val;
        this.countryName = '';
        this.townName = '';
        this.villageName = '';
        this.cityList.forEach((ele) => {
          if (ele.adCode == this.cityName) {
            this.cityNames = ele.adName;
          }
        });
        this.formObj.adName = this.provNames + this.cityNames;
        this.getAreaList(val);
      }
    },
    countryChange(val) {
      if (val && val != '') {
        this.formObj.admDiv = val;
        this.countryList.forEach((ele) => {
          if (ele.adCode == this.countryName) {
            this.countryNames = ele.adName;
          }
        });
        this.formObj.adName =
          this.provNames + this.cityNames + this.countryNames;
      }
    },
  },
};
</script>

<style lang="less" scoped>
#dcdxHeader {
  padding: 15px 20px;
}

#dxdcFooter {
  text-align: center;
}

#dxdcAside {
  border: 1px solid #d5d5ff;
}

:deep(form .ant-select) {
  width: 20%;
}
</style>
