<template>
	<view class="content">
		<!-- 自定义导航 -->
		<view class="navbar-box">
			<u-navbar title="机构信息" :safeAreaInsetTop="true" @leftClick="leftClick"></u-navbar>
		</view>
		<u-cell-group>
			<u-cell-item  
				v-for="item in infoList" :key="item.title" 
				:title="item.title" 
				:value="item.filter?filterOrganiType(infoData[item.valueKey]):infoData[item.valueKey]" 
				:arrow="false">
			</u-cell-item>
		</u-cell-group>
	</view>
</template>

<script>
	import {otherApiUrl} from '@/common/apiurl.js';
	export default {
		data() {
			return {
				infoList:[
					{title:'机构类型',valueKey:'organType',filter:true},
					{title:'机构名称',valueKey:'organName'},
					{title:'负责人',valueKey:'person'},
					{title:'联系电话',valueKey:'phone'},
				],
				infoData:{},
				organiTypeList:[],
			}
		},
		onLoad() {
			this.getInfo();
			this.organiTypeDict();
		},
		computed:{
			filterOrganiType(){
				return function(value){
					let v = '';
					for (let i = 0; i < this.organiTypeList.length; i++){
						// console.log('value',value);
						// console.log('value',this.organiTypeList[i]);
						let item = this.organiTypeList[i];
						if (value == item.value) {
						  v = item.label;
						  break;
						}
					}
					return v
				}
			}
		},
		methods: {
			leftClick() {
			   let canNavBack = getCurrentPages();
			     if(canNavBack && canNavBack.length>1) {  
			       uni.navigateBack({  
			         delta: 1  
			       });  
			     } else {  
			       history.back();  
			     }
			},
			async getInfo(){
				let {code,data,msg} = await	this.$u.api.loginInfo();
				this.infoData = data;
			},
			async organiTypeDict() {
				let { code, data, msg} = await this.$u.get(otherApiUrl.getDict + 'organizational_type')
				if(code === 200) {
					this.organiTypeList = data.map(item => {
						return {
							label: item.dictLabel,
							value: item.dictValue
						}
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>

</style>