import React, { Component } from "react"; import st from "styled-components"; import { Input, Row, Col, Radio, Button, Form, DatePicker, Select, Table, message } from "antd"; import PSelect from '../../../../components/Pro/PSelect'; import PCascader from '../../../../components/Pro/PCascader'; import RegulatorCascader from '../../../../components/RegulatorCascader'; import bcx_utils from '../../../../common/bcx_utils'; import SelectContractModal from './SelectContractModal.jsx'; import AddShareTask from './AddShareTask'; import TaskInfoColumns1 from './TaskInfoColumns1'; import TaskInfoColumns2 from './TaskInfoColumns2'; import ActivityList from './ActivityList'; import moment from 'moment'; import { getTempTaskDetail, getActivityList } from '../../../../services/api'; import PMapMarker from '../../../../components/Pro/PMapMarker'; import './index.less'; const { RangePicker } = DatePicker; const { Option } = Select; const dateFormat = 'YYYY-MM-DD'; const formItemLayout = { labelCol: { span: 8 }, wrapperCol: { span: 16 }, labelAlign: 'right' }; const formItemLayout1 = { labelCol: { span: 4 }, wrapperCol: { span: 20 }, labelAlign: 'right' }; const formItemLayout2 = { labelCol: { span: 0 }, wrapperCol: { span: 24 }, labelAlign: 'right' }; const formItemLayout4 = { labelCol: { span: 10 }, wrapperCol: { span: 14 }, labelAlign: 'right' }; @Form.create() export default class TaskInfo extends Component { constructor(props) { super(props); this.state = { map: "",//地图 province: "",//省 place: "",//地点 searchResult: "",//地图搜索结果 showInitialMarker: false, param: { addressLongitude: null, addressLatitude: null }, contractModalVisble: false, comContractList: [],//关联的合同数据 shareTaskVisble: false, shareTaskList: [],//关联的共享任务 taskId: this.props.taskId || null, detailData: null,//详情数据(如果是编辑页面,需要先掉详情接口) activeDataList: [] } } componentWillReceiveProps(nextProps) { } componentDidMount() { console.log(this.props) this.__loadMapScript(); this.props.onGetForm && this.props.onGetForm(this.props.form); if (this.props.taskId) { this._getTempTaskDetail(this.props.taskId) } // 该接口存在问题,目前无法调用,先注释 // this._getActivityList() } __loadMapScript = () => { const script = document.createElement("script"); script.src = "http://webapi.amap.com/maps?v=1.4.4&key=9066916e054aa3083a6f081a2a9f9d7a"; document.body.appendChild(script); const script2 = document.createElement("script"); script2.src = "http://cache.amap.com/lbs/static/addToolbar.js"; if (!"AMap" in window) { document.body.appendChild(script2); } this._loading(); }; _loading = () => { let _this = this; function nextStep() { return new Promise((resolve) => { setTimeout(() => { resolve("AMap" in window); }, 500); }); } async function ajaxMap() { let ifComplete = false; for (var i = 0; i < 10; i++) { if (!ifComplete) { ifComplete = await nextStep(); } else { if (ifComplete) { // console.log("地图初始化中。。。"); (_this.state.param && _this.state.param.addressLongitude != '' && _this.state.param.addressLatitude != '') ? _this._initialMap(_this.state.param.addressLongitude, _this.state.param.addressLatitude) : _this._initialMap(); } else { message.error("网络超时") } } } } ajaxMap(); } _initialMap = (lng, lat) => { const that = this; const { AMap } = window; let config = { resizeEnable: true, zoom: 14, }; if (lng && lat) { config = { ...config, ...{ center: [lng, lat] } } } var map = new AMap.Map('temporary_map', config); this.setState({ map }); //是否显示初始化的标注 let showInitialMarker = that.state.showInitialMarker; if (showInitialMarker) { let marker = new AMap.Marker({ icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_r.png", position: [lng, lat] }); marker.setMap(map); } } _searchMap = () => { this.setState({ showInitialMarker: false }); const { AMap } = window; const that = this; let place = this.state.place; let province = this.state.province; let map = this.state.map; AMap.service('AMap.PlaceSearch', function () {//回调函数 //实例化PlaceSearch let placeSearch = new AMap.PlaceSearch(); //TODO: 使用placeSearch对象调用关键字搜索的功能 placeSearch.search(place, function (status, result) { if (status == 'no_data' || result.poiList.pois.length == 0) { bcx_utils.preventRepeatAsync((callback) => callback((resolve) => { message.warning(`当前搜索地址暂无记录`, 1.5, () => { window.setTimeout(() => { resolve(); }, 500); }); })) return; } let searchResult = result.poiList.pois; let searchResultTmp = searchResult; //查看是否有完全符合的结果 searchResult.map((item, index) => { if (place === item.name) { searchResult = []; searchResult.push(item) } }); let lng = searchResult[0].location.lng; let lat = searchResult[0].location.lat; //将第一个结果放在input里或者是完全匹配的结果 const { setFieldsValue } = that.props.form; let param = that.state.param; param.addressLongitude = searchResult[0].location.lng; param.addressLatitude = searchResult[0].location.lat; that.setState({ param }); that.setState({ markers: [] }) that.setState({ place: searchResult[0].name }); setFieldsValue({ taskAddress: province + searchResult[0].name }); that._initialMap(lng, lat); that.setState({ searchResult }); searchResult.map((item, index) => { let lng = item.location.lng; let lat = item.location.lat; that.addMarker(lng, lat, index); }); }); }) } handleKeyUp = (e) => { // e.preventDefault(); // if (!this.state.province) { // bcx_utils.preventRepeatAsync((callback) => callback((resolve) => { // message.warning(`请先选择省市区`, 1.5, () => { // window.setTimeout(() => { // resolve(); // }, 500); // }); // })) // } else { this.setState({ showInitialMarker: false }, () => { this._initialMap(); this._searchMap() }); // } } handleInputSearch = (e) => { const { value } = e.target; const province = this.state.province; this.setState({ place: value }); //不可删除 if (value.length < province.length) { e.target.value = province; } if (!value.includes(province)) { e.target.value = province; } } addMarker = (lng, lat, index) => { let searchResult = this.state.searchResult; let map = this.state.map; let markers = this.state.markers; let province = this.state.province; let that = this; let marker = new AMap.Marker({ icon: "http://webapi.amap.com/theme/v1.3/markers/n/mark_b.png", position: [lng, lat] }); markers.push(marker); marker.setMap(map); if (index) { marker.on('click', function () { // console.log('您点击了点', searchResult[index].name, searchResult[index].location.lng, searchResult[index].location.lat); let param = that.state.param; param.addressLongitude = searchResult[index].location.lng; param.addressLatitude = searchResult[index].location.lat; that.setState({ param, place: searchResult[index].name }); const { setFieldsValue } = that.props.form; setFieldsValue({ taskAddress: searchResult[index].name }); setFieldsValue({ longitudeAndLatitude: [searchResult[index].location.lng, searchResult[index].location.lat] }); }); } } _getTempTaskDetail(comTempTaskId) { getTempTaskDetail({ comTempTaskId }).then(res => { if (res.retType === '0') { this.setState({ detailData: res.data, shareTaskList: res.data.shareComList || [], comContractList: [res.data.comContractInfo], param: { addressLongitude: res.data.addressLongitude, addressLatitude: res.data.addressLatitude, }, place: res.data.taskAddress, showInitialMarker: true }) } }) } //必选框的标致 mustLabel() { return ( * ) } //关联合同中的移除合同 removeContract() { const { setFieldsValue } = this.props.form; this.setState({ comContractList: [] }); setFieldsValue({ comContractList: [] }); } //删除任务 removeTask(selectedTaskRows) { const { setFieldsValue } = this.props.form; const data = this.state.shareTaskList.filter(item => { if (!selectedTaskRows.includes(item)) { return item } }) this.setState({ shareTaskList: data }) if (data.length == 0) { setFieldsValue({ shareTaskList: [] }) } } //获取活动列表 _getActivityList() { getActivityList().then(res => { if (res.retType == '0') { this.setState({ activeDataList: res.data }) } }) } render() { const { detailData } = this.state; const { getFieldDecorator, getFieldValue, setFieldsValue } = this.props.form; const columns1 = TaskInfoColumns1.call(this); const columns2 = TaskInfoColumns2.call(this); return (