<template>
	<view id="warp">
		<view class="t_login_passList">
			<view class="input_icon">公司名称</view>
			<input
				class="input_css"
				v-model="companyInfo.companyName"
				border="none"
				placeholder="请输入公司名称"
			></input>
		</view>
		<view class="t_login_passList" @tap="onChooseLocation">
			<view class="input_icon">公司位置</view>
			<input
				class="input_css3"
				v-model="companyInfo.address"
				disabled
				border="none"
				placeholder="请选择公司位置"
			></input>
			<view class="code3">
				<uni-icons type="forward" size="20"></uni-icons>
			</view>
		</view>
		<view class="btn_css">
			<button class="btn" @tap="registerOk">保存</button>
		</view>
	</view>
</template>

<script>
	const {urlList,https} = require('@/static/api');
	export default {
		data() {
			return {
				companyInfo:uni.getStorageSync('userCompany'),
			};
		},
		onLoad() {
		},
		methods:{
			registerOk(){
				const that = this;
				if(that.companyInfo.companyName == ''){
					uni.showToast({
						title:'公司名称不能为空',
						icon:'none',
					})
					return
				}
				if(that.companyInfo.address == ''){
					uni.showToast({
						title:'公司位置不能为空',
						icon:'none',
					})
					return
				}
				https(urlList.getUserCompany,'PUT',that.companyInfo,'保存中...').then(data => {
					uni.showToast({
						title: data.message || '修改成功',
						icon: 'none',
						duration: 1000
					})
					uni.setStorage({
						key:"userCompany",
						data:that.companyInfo,
					});
					that.getUserInfo();
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			},
			// 选择公司位置
			onChooseLocation(){
				const _that = this;
				uni.chooseLocation({
					longitude: _that.companyInfo.longitude,
					latitude : _that.companyInfo.latitude,
				    success: function (res) {
						let {longitude,latitude} = res;
						https(urlList.getLocationName+'/'+longitude+'/'+latitude,'GET','','').then(data => {
							console.log('地址名称',data)
							_that.companyInfo.address = data.data;
							_that.companyInfo.longitude = longitude;
							_that.companyInfo.latitude = latitude;
						}).catch(err => {
							uni.showToast({
								title:err,
								icon:'none',
								duration:1500
							})
						})
				    }
				});
			},
			getUserInfo(){
				const _that = this;
				https(urlList.getUserInfo,'GET','','').then(data => {
					// console.log('个人中心',data)
					uni.setStorage({
						key:"userinfo",
						data:data.data,
					});
					setTimeout(e => {
						uni.navigateBack()
					},1000)
				}).catch(err => {
					uni.showToast({
						title:err,
						icon:'none',
						duration:1500
					})
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
#warp{
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	.t_login_passList{
		width:650rpx;
		padding: 20rpx 0rpx;
		border-bottom: 1rpx solid #e6e6e6;
		display: flex;
		flex-direction: row;
		align-items: center;
		.input_icon{
			width: 200rpx;
			display: flex;
			align-items: center;
			padding-left: 10rpx;
		}
		.input_css{
			width:400rpx;
			height: 70rpx;
		}
		.input_css3{
			width: 350rpx;
			height: 70rpx;
		}
		.code3{
			margin-left: 20rpx;
			width: 50rpx;
			display: flex;
			justify-content: flex-end;
		}
		
	}
	.btn_css{
		width: 650rpx;
		position: fixed;
		bottom:48rpx;
		display: block;
		.btn{
			background-color:#1B64F8FF;
			color: white;
		}
	}
}
</style>
