import {waitTime,REP_SUCCESS} from './utils.js';
import qs from 'qs';
import {GET_REQUEST} from './utils';
async function GET_USER(req,res){
  const query = qs.parse(req.url.split('?')[1]);
  const {name} = query;
  await waitTime();
  return {code:0,data:{name}}
}

async function SET_USER(req,res){
  const query = JSON.parse(req.body);
  const {name,age}= query;
  await waitTime();
  
  return {
    "code": 0,
    "data":{name,age}
  }
}

async function GET_USER_LIST(req,res){
  const {current,pageSize} = GET_REQUEST(req,res);
  const MAX_TOTAL=98;
  let data=[];
  let idx=(current-1)*pageSize;

  for(let i=0;i<pageSize;i++){
    if(idx>=MAX_TOTAL)break;
    data.push({
      name:`${idx++}小朋友`
    })
  }
  return {
    code:0,
    data:{
      list:data,
      page:{
        pageNum:current,
        pageSize:pageSize,
        total:MAX_TOTAL
      }
    }
  }
}

async function GET_USER_TYPE(req,res){
  let data=[];
  for(let i=0;i<10;i++){
    data.push({
      label:`标题${i}`,
      value:i,
      key:`title${i}`
    })
  }
  return {
    code:0,
    data:data
  }
}




export default {
  '/userType':{get:GET_USER_TYPE},
  '/userList':{get:GET_USER_LIST},
  '/user':{get:GET_USER,post:SET_USER},

}