<template>
	<view>
		<view class="tit">请选择</view>
		<view class="list ddflex">
			<view :class="'li' + (currentTreeObj.id == item.id ? ' active':'')" v-for="(item,index) in category" :key="index" @click="switchType(item,index)">{{item.name}}</view>
		</view>
	</view>
</template>

<script>
const app = getApp();
const req = require('../../utils/request.js');
const api = require('../../utils/api.js');
const util = require('../../utils/util.js');
export default {
	data() {
		return {
			currentTreeObj: {},
			category: []
		};
	},

	onLoad() {
		var pages = getCurrentPages();
		var prevPage = pages[pages.length - 2];
		this.currentTreeObj = prevPage.$vm.treeObj
		this.getCategory()
	},


	methods: {
		getCategory(){
			req.getRequest('/api/v3/unified/tree/list',{type: 1},data=>{
				this.category = data;
			})
		},
		switchType(item,index){
			let pages = getCurrentPages(); //获取所有页面栈实例列表
			let nowPage = pages[pages.length - 1]; //当前页页面实例
			let prevPage = pages[pages.length - 2]; //上一页页面实例
			this.currentTreeObj = item
			prevPage.$vm.treeObj = item; //修改上一页data里面的tagIndex 参数值
			uni.navigateBack({ //uni.navigateTo跳转的返回，默认1为返回上一级
				delta: 1
			});
		}
	}
};
</script>

<style>
	@import "./index.css";
</style>