<template>
  <div id="">
    <a-layout>
      <a-layout-content style="border:1px solid #d5d5ff;margin-left:5px;padding:0px;">
        <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.cwsName" autocomplete="off" style="width:90%;"></a-input>
          </a-form-item>
          <a-form-item label="供水方式">
            <a-input v-model:value="formObj.waterSupply" autocomplete="off" style="width:90%;"></a-input>
          </a-form-item>
          <a-form-item label="供水人数" required>
            <a-input v-model:value="formObj.supplyCount" autocomplete="off" style="width:90%;"></a-input>
          </a-form-item>
          <a-form-item label="供水人数" required>
            <a-select v-model:value="formObj.supplyType" placeholder="请选择">
              <a-select-option value="">请选择</a-select-option>
              <a-select-option value="1">万人以下供水工程</a-select-option>
              <a-select-option value="2">万人以上供水工程</a-select-option>
            </a-select>
          </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.loc" 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>
    <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" width="60%">
      <div style="height: 60vh;">
        <mapLocation ref="mapRef" v-if="imageShow" :gdX="formObj.gdX" :gdY="formObj.gdY"></mapLocation>
      </div>
    </a-modal>
  </div>
</template>

<script>
import {
  getrgstrIdObjectById_ncgsgc,
  getrgstrIdObjectById_sxzzf,
} 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';
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 {
      objTypeList: [
        { label: '县（市、区）水利局', value: '1' },
        { label: '地市水利局', value: '2' },
        { label: '在建水利工程', value: '3' },
        { label: '运管工程督导检查情况表', value: '4' },
      ],
      formObj: {
        cwsCode: '',
        cwsName: '',
        waterSupply: '',
        adCode: '',
        adName: '',
        loc: '',
        gdX: '',
        gdY: '',
        supplyCount: '',
        supplyType: '',
      },
      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')
        : '';
    },
  },
  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() {
      getrgstrIdObjectById_ncgsgc(this.currentObjectRgstrId).then(
        (res) => {
          if (res.data) {
            this.formObj = res.data;
          } else {
            this.formObj = {};
          }
        },
        (err) => {},
      );
    },
    addHandler() {
      // if(!this.formObj.cwsCode){
      //     this.$message.warning('请输入工程编码')
      //     return
      // }
      if (!this.formObj.cwsName) {
        this.$message.warning('请输入工程名称');
        return;
      }
      // if(!this.formObj.waterSupply){
      //     this.$message.warning('请输入供水方式')
      //     return
      // }
      if (!this.formObj.supplyType) {
        this.$message.warning('请选择供水工程类型');
        return;
      }
      this.formObj['persId'] = this.recPersId;
      this.formObj.objId = this.currentObjectId1;
      this.formObj.rgstrId = this.currentObjectRgstrId;
      try {
        this.$confirm('确认保存基础信息？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        }).then(() => {
          request.post('/bis/insp/cwsjx/', this.formObj).then((res) => {
            if (res.success) {
              this.showLocSelect = false;
              this.getRgstridObj();
              this.$message.success('修改成功');
              this.$emit('cancelHandler1', this.formObj.supplyType);
            } 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.provList.forEach((ele) => {
        if (ele.adCode == this.provName) {
          this.provNames = ele.adName;
        }
      });
      this.formObj.adName = this.provNames;
      this.formObj.adCode = val;
      this.getAreaList(val);
    },
    RsvrTypeChange(val) {},
    cityChange(val) {
      this.curSelectItem = 2;
      if (val && val != '') {
        this.countryName = '';
        this.cityList.forEach((ele) => {
          if (ele.adCode == this.cityName) {
            this.cityNames = ele.adName;
          }
        });
        this.formObj.adName = this.provNames + this.cityNames;
        this.formObj.adCode = val;
        this.getAreaList(val);
      }
    },
    countryChange(val) {
      if (val && val != '') {
        this.countryList.forEach((ele) => {
          if (ele.adCode == this.countryName) {
            this.countryNames = ele.adName;
          }
        });
        this.formObj.adName =
          this.provNames + this.cityNames + this.countryNames;
        this.formObj.adCode = val;
      }
    },
    //  近期面貌
    recentAppearance() {
      this.xcztShow = true;
    },
    jqmmDialog() {
      this.xcztShow = false;
    },
    // 影像
    imageClick() {
      if (!this.formObj.gdX && !this.formObj.gdY) {
        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>
