<template>
	<view class="rf-category informationData">
		<navbar-search
				:list="search.searchList"
				@selectedItem="getSelectedItem">
		</navbar-search>
		<u-tabs
				:list="tabs.tabsList"
				:is-scroll="false"
				bar-width="140"
				:current="tabs.current"
				@change="tabsChange">
		</u-tabs>
		<view class="viewContent">
			<indicatorDataQuery
					v-if="tabs.current===0"
					:searchItem="search.searchItem"
					@reset="ResetParent"
			></indicatorDataQuery>
			<indicatorDataRankings
					v-if="tabs.current===1"
					:searchItem="search.searchItem"
					@reset="ResetParent"
			></indicatorDataRankings>
			<dataExportTool
					v-if="tabs.current===2"
					@reset="ResetParent"
			></dataExportTool>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
import navbarSearch from "./dom/navbarSearch1";
import indicatorDataQuery from "./dom/indicatorDataQuery";
import indicatorDataRankings from "./dom/indicatorDataRankings";
import dataExportTool from "./dom/dataExportTool";

let _self;
export default {
	name:'informationData',
	components:{
		navbarSearch,
		indicatorDataQuery,
		indicatorDataRankings,
		dataExportTool
	},
	data(){
		return {
			/**
			 * 搜索栏
			 */
			search:{
				searchList: [],
				searchItem: {},
			},
			/**
			 * 标签栏
			 */
			tabs:{
				tabsList:[
					{
						name: this.$i18n.locale == 'zh' ? '指标数据查询' : 'Data Query'
					}, {
						name: this.$i18n.locale == 'zh' ? '指标数据排行' : 'Data Ranking'
					}, {
						name: this.$i18n.locale == 'zh' ? '数据导出工具' : 'Export Tool'
					}
				],
				current:0
			},
		}
	},
	onLoad(option) {
		_self = this;
		if([0,1,2].includes(Number(option.current))){
			this.tabs.current = Number(option.current)
		}
		this.init()
	},
	methods:{
		async init() {
			await this.getServerData()
		},
		i18n(data) {
			return this.$t('common.' + data);
		},
		/**
		 * 搜索栏
		 */
		async getServerData() {
			const res = await this.$myRequest({
				url: '/op/geiIntegratedDataMenus/getMenu',
				data: {}
			});
			this.setNodeId(res.data,'child')
			this.search.searchList = res.data;
		},
		setNodeId(data,childrenName='children',id=''){
			data.forEach((item,index)=>{
				let nodeId = id?`${id}_${index}`:`${index}`;
				this.$set(item,'nodeId',nodeId)
				if(item[childrenName] && item[childrenName].length > 0){
					this.setNodeId(item[childrenName],childrenName,nodeId)
				}
			})
		},
		getSelectedItem(e) {
			this.search.searchItem = e
		},
		/**
		 * 标签栏
		 */
		tabsChange(index) {
			this.tabs.current = index;
		},
		ResetParent(e){
			console.log(e)
			uni.redirectTo({
				url: '/pages/information/InformationData/InformationData?current='+ e
			});
		}
	}
}
</script>

<style scoped lang="scss">
uni-page-body {
	padding-top: 0;
}
page {
	background: #fff;
	width: 750upx;
	overflow-x: hidden;
	height: 100%;
	overflow: hidden;
}

.informationData{
	height: 100%;
	.viewContent{
		height: calc(100% - 88upx)
	}
}
</style>
