<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>
            <a-button type="danger" style="float: right;" @click="recentAppearance">近期面貌</a-button>
            <a-button type="danger" style="float: right; margin-right: 10px;" @click="imageClick">影像</a-button>
          </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 autocomplete="off" style="width:90%;" allow-clear readonly value="面上水利工程已开工项目"></a-input>
          </a-form-item>
          <a-form-item label="项目类型">
            <a-input v-model:value="formObj.srfcType" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="中央投资计划">
            <a-input v-model:value="formObj.cntrIntSrfc" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="地方投资计划">
            <a-input v-model:value="formObj.cntrIntSrfc" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="已完成中央投资">
            <a-input v-model:value="formObj.locIntSrfc" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="已完成地方配套">
            <a-input v-model:value="formObj.flocIntSrfc" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="完成比例">
            <a-input v-model:value="formObj.fsoccIntSrfc" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="经度">
            <a-input v-model:value="formObj.centerX" autocomplete="off" style="width:90%;" allow-clear></a-input>
          </a-form-item>
          <a-form-item label="纬度">
            <a-input v-model:value="formObj.centerY" autocomplete="off" style="width:90%;" allow-clear></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>
    <theRecentAppearance
      v-if="xcztShow"
      @jqmmDialogClose="jqmmDialog"
      :jqmmShow="xcztShow"
      :openType="openType"
      :jqmmEngId="currentObjectRgstrId"
      :dialogTitle="currentObjectName + '近期面貌'"
      style="z-index: 9999;">
    </theRecentAppearance>
    <a-modal :title="currentObjectName + '影像'" :open="imageShow" @cancel="imageShow = false" width="60%">
      <div style="height: 60vh;">
        <mapLocation ref="mapRef" v-if="imageShow" :gdX="centerX" :gdY="centerY"></mapLocation>
      </div>
    </a-modal>
  </div>
</template>

<script>
import { getrgstrIdObject_sltsn } from '../../../api/duChaTianBao';
import request from '../../../utils/gw_ajax_request';
import { dateFormat } from '../../../utils/gw_date';
import unlimitDatePicker from '../../../widgets/baseWidget/unLimitdatePicker.vue';
import inputWith from '../../../widgets/inuptWith.vue';
import theRecentAppearance from '../../duChaDuiXiang/theRecentAppearance';
import mapLocation from '../mapLocation';

export default {
  components: {
    inputWith: inputWith,
    unlimitDatePicker: unlimitDatePicker,
    theRecentAppearance,
    mapLocation,
  },
  props: [
    'id',
    'currentObjectRgstrId',
    'currentResCode',
    'currentObjectId',
    'currentObjectName',
    'openType',
  ],
  data() {
    return {
      options: [
        {
          label: '水土保持监督执法',
          value: '1',
        },
        {
          label: '水资源监督执法',
          value: '2',
        },
        {
          label: '河道清障、涉河建设项目及水利工程保护监督执法',
          value: '3',
        },
      ],
      formObj: {
        prjName: '',
        adName: '',
        srfcType: '',
        cntrIntSrfc: '',
        intSrfc: '',
        locIntSrfc: '',
        flocIntSrfc: '',
        fsoccIntSrfc: '',
        centerX: '',
        centerY: '',
      },
      dialogFormVisible: false,
      formLabelWidth: '160px',
      loading: true,
      operationType1: '',
      currentResCode1: '',
      currentObjectId1: '',
      value1: '',
      provList: [],
      cityList: [],
      countryList: [],
      provName: '',
      cityName: '',
      countryName: '',
      provNames: '',
      cityNames: '',
      countryNames: '',
      curSelectItem: 0,
      showLocSelect: false,
      locat: {
        location: '',
        admDiv: '',
      },
      xcztShow: false,
      imageShow: false,
      xcztEngId: '',
      centerX: 0,
      centerY: 0,
    };
  },
  computed: {
    recPersId() {
      return localStorage.getItem('persId')
        ? localStorage.getItem('persId')
        : '';
    },
  },
  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 = '';
      }
    },
  },
  mounted() {
    this.currentResCode1 = this.currentResCode;
    this.currentObjectId1 = this.currentObjectId;
    this.getRgstridObj();
    this.getAreaList();
  },
  methods: {
    getRgstridObj() {
      getrgstrIdObject_sltsn(this.currentObjectId, '3').then(
        (res) => {
          if (res.data) {
            this.formObj = res.data;
          } else {
            this.formObj = {};
          }
        },
        (err) => {},
      );
    },
    addHandler() {
      // _self.formObj.compDate = _self.value1;
      // _self.formObj['compDateStr'] = dateFormat(_self.value1, 'yyyy-MM-dd');
      this.formObj['persId'] = this.recPersId;
      this.formObj.objId = this.currentObjectId1;
      // _self.formObj.compDateDesc = _self.formObj.compDateStr==''?null:_self.formObj.compDateStr;
      console.log(this.formObj);
      // 基础信息纠错，经纬度修改粗略校验经度纬度整数部分的范围
      try {
        this.$confirm({
          title: '提示',
          content: '确认保存基础信息？',
          okType: 'warning',
          onOk: () => {
            request
              .post('/att/acclrt/base/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');
    },
    formatRadio(val) {
      if (val == '1') {
        return '是';
      } else if (val == '0') {
        return '否';
      } else {
        return val;
      }
    },
    getAreaList(val) {
      const areaParams = {
        adName: '',
        id: this.dczId,
        pageNum: 1,
        pageSize: 10000,
      };
      let adCode = '';
      if (!val) {
        adCode = '000000000000';
      } 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);
    },
    RsvrTypeChange(val) {},
    cityChange(val) {
      this.curSelectItem = 2;
      if (val && val != '') {
        this.formObj.admDiv = val;
        this.countryName = '';
        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;
      }
    },
    //  近期面貌
    recentAppearance() {
      this.xcztShow = true;
    },
    jqmmDialog() {
      this.xcztShow = false;
    },
    // 影像
    imageClick() {
      if (!this.centerX && !this.centerY) {
        this.$message.warning('暂无经纬度信息！');
        return false;
      }
      this.imageShow = true;
    },
  },
};
</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>
