package com.fjs.scenic.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.fjs.scenic.entity.user.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fjs.scenic.entity.Type;
import com.fjs.scenic.utils.TablePage;

@Controller
@RequestMapping("/type")
public class TypeController {
	
	@GetMapping("/list")
	public String index(ModelMap model){
		List<Type> types = new ArrayList<>();
		Type type1 = new Type();
		type1.setId(1);
		type1.setPid(0);
		type1.setParent(true);
		type1.setName("系统管理");
		types.add(type1);
		Type type11 = new Type();
		type11.setId(10);
		type11.setPid(1);
		type11.setParent(false);
		type11.setName("用户管理");
		types.add(type11);
		Type type12 = new Type();
		type12.setId(11);
		type12.setPid(1);
		type12.setParent(false);
		type12.setName("角色管理");
		types.add(type12);
		Type type2 = new Type();
		type2.setId(2);
		type2.setPid(0);
		type2.setParent(true);
		type2.setName("商品管理");
		types.add(type2);
		Type type21 = new Type();
		type21.setId(12);
		type21.setPid(2);
		type21.setParent(false);
		type21.setName("商品添加");
		types.add(type21);
		/*for(int i =1;i<=10;i++){
			Type type = new Type();
			type.setId(i);
			type.setPid(1);
			type.setParent(true);
			type.setName("yangya"+i);
			types.add(type);
		}*/
		model.put("types", types);
		return "type_list";
//		return "treeTable";
	}

	@GetMapping("/list1")
	public String index1(ModelMap model){
		List<Type> types = new ArrayList<>();
		Type type1 = new Type();
		type1.setId(1);
		type1.setPid(0);
		type1.setParent(true);
		type1.setName("系统管理");
		types.add(type1);
		Type type11 = new Type();
		type11.setId(10);
		type11.setPid(1);
		type11.setParent(false);
		type11.setName("用户管理");
		types.add(type11);
		Type type12 = new Type();
		type12.setId(11);
		type12.setPid(1);
		type12.setParent(false);
		type12.setName("角色管理");
		types.add(type12);
		Type type2 = new Type();
		type2.setId(2);
		type2.setPid(0);
		type2.setParent(true);
		type2.setName("商品管理");
		types.add(type2);
		Type type21 = new Type();
		type21.setId(12);
		type21.setPid(2);
		type21.setParent(false);
		type21.setName("商品添加");
		types.add(type21);
		/*for(int i =1;i<=10;i++){
			Type type = new Type();
			type.setId(i);
			type.setPid(1);
			type.setParent(true);
			type.setName("yangya"+i);
			types.add(type);
		}*/
		model.put("types", types);
//		return "type_list";
		return "treeTable";
	}
	
	@PostMapping("/page")
	@ResponseBody
	public TablePage<User> page(HttpServletRequest request){
		String strdraw = request.getParameter("draw");
		String strstart = request.getParameter("start");
		String strlength = request.getParameter("length");
		String name = request.getParameter("name");
		int draw = strdraw == null?0:Integer.parseInt(strdraw);
		int start = strstart == null?0:Integer.parseInt(strstart);
		int length = strlength == null?0:Integer.parseInt(strlength);
		
		Type type = new Type();
		
		
		TablePage<User> data = new TablePage<>();
		data.setDraw(draw);
		data.setRecordsTotal(length);
		data.setRecordsFiltered(length);
		List<User> users = new ArrayList<>();
		for(int i =1;i<=length;i++){
			User user =new User();
			user.setId(i);
//			user.setName("yangya"+i);
			users.add(user);
		}
		data.setData(users);
		return data;
	}

}
