<template>
	<view>
		<uni-list  >
			<uni-list-item v-for="(item,index) in projectList" :title="item.unitCode" :key="index" :rightText="item.unitName" @click="onClick(index,item)" clickable style="cursor: pointer;"/>			
		</uni-list>
	</view>
</template>

<script>
	import {selectProject} from "@/common/api/commonApi.js";
	export default {
		data() {
			return {
				projectList:[]
			}
		},
		onLoad:function(){
			this.$util.persistLogin(this);
		},
		created:function(){
			this.getProjectList();
		},
		methods: {
			getProjectList:function(){
				var that=this;
				selectProject().then((res)=>{
					console.info('getProjectList',res);
					if(!res.isSuccess){
						uni.showToast({
							title:res.errMsg,
							duration:3000,
							icon:"none"
							 
						});
					}
					res.data.forEach(function(item,index,array){
						that.$set(that.projectList,index,item);
					});
					//console.info(that.projectList);
				});
			},
			onClick:function(index,item) {
				//console.info(index);
				//console.info(item);
				let unitCode=item.unitCode;                      //获取项目编码
				this.$store.commit('setProjectCode',unitCode);  //赋值
				uni.setStorage({
					key:'storage_state',
					data:this.$store.state,
					success:function(){
						console.info("setProjectCode选择项目后状态缓存成功");
					},
					fail: () => {
						console.error("setProjectCode选择项目后状态缓存失败");
					}
				});
				//导向到首页
				uni.navigateTo({
					url: "/pages/index/index"
				});
				// uni.showToast({
				// 	title: '点击反馈'
				// });
			}
		}
	}
</script>

<style>

</style>
