提交 118fa6c0 authored 作者: 钟是志's avatar 钟是志

定位组件修改

上级 f977297f
...@@ -13,130 +13,114 @@ import { getPopconfirm } from '@/webPublic/one_stop_public/utils/utils'; ...@@ -13,130 +13,114 @@ import { getPopconfirm } from '@/webPublic/one_stop_public/utils/utils';
const Popconfirm = getPopconfirm(); const Popconfirm = getPopconfirm();
export default class location extends Component { export default class location extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
locationMsg: {}, locationMsg: {},
btn: true, btn: true,
style: { display: 'none' }, style: { display: 'none' },
}; };
} }
// 该方法在首次渲染之前调用(数据初始化) // 该方法在首次渲染之前调用(数据初始化)
componentWillMount() {} componentWillMount() {}
//已经生成对应的dom结构 //已经生成对应的dom结构
componentDidMount = () => {}; componentDidMount = () => {};
//在组件从 DOM 中移除的时候立刻被调用。 //在组件从 DOM 中移除的时候立刻被调用。
componentWillUnmount = () => {}; componentWillUnmount = () => {};
getLocationMsg = (locationMsg) => { getLocationMsg = locationMsg => {
console.log(locationMsg); console.log(locationMsg);
//如果不为空的话显示提示 //如果不为空的话显示提示
this.setState({ loading: true }, () => { this.setState({ loading: true }, () => {
if (Object.keys(locationMsg).length !== 0) { if (Object.keys(locationMsg).length !== 0) {
this.setState({ this.setState({
locationMsg: locationMsg, locationMsg: locationMsg,
loading: false, loading: false,
style: { display: 'block' }, style: { display: 'block' },
btn: false, btn: false,
}); });
} else { } else {
this.setState({ this.setState({
loading: false, loading: false,
}); });
} }
}); });
}; };
submitLocation = () => { submitLocation = () => {
const { showLocation } = this.props; const { showLocation } = this.props;
if (!showLocation) return; if (!showLocation) return;
if (isEmpty(this.state.locationMsg) && window.lat && window.lng) { if (isEmpty(this.state.locationMsg) && window.lat && window.lng) {
let obj = { let obj = {
lat: window.lat, lat: window.lat,
lng: window.lng, lng: window.lng,
}; };
this.props.onChange(obj); this.props.onChange(obj);
if (this.props.get === 'web') { if (this.props.get === 'web') {
openToast('success', '成功', '已添加定位地址'); openToast('success', '成功', '已添加定位地址');
} else { } else {
successToast('已添加定位地址'); successToast('已添加定位地址');
} }
} else if (!isEmpty(this.state.locationMsg)) { } else if (!isEmpty(this.state.locationMsg)) {
this.props.onChange(this.state.locationMsg); this.props.onChange(this.state.locationMsg);
if (this.props.get === 'web') { if (this.props.get === 'web') {
openToast('success', '成功', '已添加定位地址'); openToast('success', '成功', '已添加定位地址');
} else { } else {
successToast('已添加定位地址'); successToast('已添加定位地址');
} }
} else { } else {
if (this.props.get === 'web') { if (this.props.get === 'web') {
openToast('error', '错误', '定位失败,请稍后重试'); openToast('error', '错误', '定位失败,请稍后重试');
} else { } else {
successToast('定位失败,请稍后重试'); successToast('定位失败,请稍后重试');
} }
} }
}; };
// 点击确定提交定位 // 点击确定提交定位
confirm = (e) => { confirm = e => {
console.log(e); console.log(e);
if (this.state.btn) { if (this.state.btn) {
if (this.props.get === 'web') { if (this.props.get === 'web') {
openToast('error', '错误', '正在定位,请稍后重试'); openToast('error', '错误', '正在定位,请稍后重试');
} else { } else {
failToast('正在定位,请稍后重试'); failToast('正在定位,请稍后重试');
} }
return; return;
} }
this.submitLocation(); this.submitLocation();
}; };
render() { render() {
let { locationMsg, btn } = this.state; let { locationMsg, btn } = this.state;
let { lat, lng, address, params, json, showLocation } = this.props; let { lat, lng, address, params, json, showLocation } = this.props;
return ( return (
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
<Location <Location
lat={lat} lat={lat}
json={json} json={json}
lng={lng} lng={lng}
getLocationMsg={this.getLocationMsg.bind(this)} getLocationMsg={this.getLocationMsg.bind(this)}
showMap={this.props.showMap} showMap={this.props.showMap}
params={params} params={params}
/> />
<div style={{ display: showLocation ? 'block' : 'none' }}> <div style={{ display: showLocation ? 'block' : 'none' }}>
{' '} {' '}
<Popconfirm <Popconfirm
title={btn ? '正在定位中' : locationMsg.address} title={btn ? '正在定位中' : locationMsg.address}
onConfirm={this.confirm} onConfirm={this.confirm}
okText="提交" okText="提交"
cancelText="取消"> cancelText="取消"
<Button >
disabled={btn} <Button
style={{ margin: 'auto', width: this.props.width }} disabled={btn}
loading={this.state.loading} style={{ margin: 'auto', width: this.props.width }}
className={styles.btn} loading={this.state.loading}
type="primary"> className={styles.btn}
{this.props.btnName} type="primary"
</Button> >
</Popconfirm> {this.props.btnName}
</div> </Button>
</div> </Popconfirm>
); </div>
// return ( </div>
// <div style={{ paddingBottom: 49, paddingTop: 44 }}> );
// <Nav name="签到" link/> }
// <div id="EditAddress" className={styles.EditAddress}>
// <Location getLocationMsg={this.getLocationMsg.bind(this)}/>
// <Button onClick={this.submitLocation} className={styles.btn} type='primary'>签到</Button>
// <div style={this.state.style} className={styles.div}>
// <p><i>经纬度:</i><span>{this.state.locationMsg.lng},{this.state.locationMsg.lat}</span></p>
// <p><i>详细地址:</i><span>{this.state.locationMsg.address}</span></p>
// <p><i>最近的路口:</i><span>{this.state.locationMsg.nearestJunction}</span></p>
// <p><i>最近的路:</i><span>{this.state.locationMsg.nearestRoad}</span></p>
// <p><i>最近的POI:</i><span>{this.state.locationMsg.nearestPOI}</span></p>
// <Button onClick={this.submitLocation} className={styles.btn} type='primary'>签到</Button>
// </div>
// </div>
// </div>
// )
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论