<template>
	<view class="p-root-address g_w_all g_bg_f_5">
		<view class="g_pl_10 g_pr_10" v-for="(item,index) in list" :key="index">
			<view class="g_flex_row_start g_pt_18 g_pb_10">
				<view class="g_pl_10 g_pr_4 g_flex_column_center">
					<image :src="item.icon" class="g_w_18 g_h_18"></image>
				</view>
				<view class="g_fs_16 g_c_3 g_flex_column_center">{{item.name}}</view>
			</view>
			<view class="g_pt_12 g_pb_12 g_pl_10 g_pr_10 g_bg_f g_radius_6 g_flex_row_start"
				  hover-class="thover"
				  @click="handleOpenAddress(item,index)"
			>
				<view class="g_flex_1">
					<view class="g_fs_16 g_c_3 g_fw_600 g_mb_4">{{item.title}}</view>
					<view class="g_fs_14 g_c_9 g_ell_1">{{item.address}}</view>
				</view>
				<view class="g_flex_none g_flex_column_center">
					<image :src="cdnBaseImg + 'jobmore.svg'" class="g_w_14 g_h_14"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default{
		onReady() {
			this.G.setNavStyle();
		},
		onShareAppMessage() {
			return this.G.shareFun();
		},
		data(){
			return {
				list:[],
				cdnBaseImg:this.G.store().cdnBaseImg
			}
		},
		onLoad(options) {
			let that = this,
				_data = {};
			that.G.Get(that.api.job_personDetail + "/" + options.uid, "", (res) => {
				_data = res.record;
				var reg = /.+?(省|市|自治区|自治州|县|区)/g; // 省市区的正则
				that.list = [
					{
						icon:that.G.store().cdnBaseImg + 'jobstore.svg',
						name:'企业地址',
						title:_data.storeName ? _data.storeName : '-',
						address:_data.storeAddr ? _data.storeAddr : '-',
						lat: _data.storeLat,
						lng: _data.storeLng
					},
					{
						icon:that.G.store().cdnBaseImg + 'jobinvite.svg',
						name:'面试地址',
						title:_data.interviewAddr ? _data.interviewAddr.match(reg).join('') : '-',
						address:_data.interviewAddr ? _data.interviewAddr : '-',
						lat: _data.interviewLat,
						lng: _data.interviewLng
					}
				]
			});
		},
		methods:{
			handleOpenAddress($item){
				console.log('地图经纬度：',$item)
				if($item.lat && $item.lng){
					uni.openLocation({
						name:$item.title,
						latitude: Number($item.lat),
						longitude: Number($item.lng),
						success: function () {
							console.log('success');
						},
						fail(err) {
							console.log('err',err)
						}
					});
				}else{
					if($item.name == '企业地址'){
						uni.showToast({
							icon:'none',
							title:'暂无企业地址'
						})
					}else{
						uni.showToast({
							icon:'none',
							title:'暂无面试地址'
						})
					}
				}
			}
		}
	}
</script>

<style lang="scss"> 
	.p-root-address{
		min-height: 100%;
		background-color: #f5f5f5;
	}
</style>