/**
 * 学生管理Mock数据
 * @author pangu
 */
import Mock from 'mockjs'

// 学生列表数据
const studentList = []
for (let i = 1; i <= 50; i++) {
  studentList.push({
    studentId: i,
    studentName: Mock.Random.cname(),
    studentNo: `STU202600${String(i).padStart(2, '0')}`,
    gender: Mock.Random.pick(['1', '2']),
    genderName: Mock.Random.pick(['男', '女']),
    birthday: Mock.Random.date('yyyy-MM'),
    regionId: 111,
    regionPath: '湖北省-武汉市-武昌区',
    schoolId: Mock.Random.pick([1, 2, 3]),
    schoolName: Mock.Random.pick(['武汉市第一中学', '武汉市第二中学', '武汉市第三中学']),
    schoolGradeId: Mock.Random.pick([1, 2, 3]),
    gradeName: Mock.Random.pick(['七年级', '八年级', '九年级']),
    schoolClassId: Mock.Random.pick([1, 2, 3, 4]),
    className: Mock.Random.pick(['1班', '2班', '3班', '4班']),
    subjectId: Mock.Random.pick([1, 2, 3, null]),
    subjectName: Mock.Random.pick(['语文', '数学', '英语', null]),
    memberId: Mock.Random.pick([1, 2]),
    memberNickname: Mock.Random.cname() + '家长',
    memberPhone: '138****' + Mock.Random.string('number', 4),
    status: '0',
    createTime: Mock.Random.datetime('yyyy-MM-dd HH:mm:ss'),
    remark: null
  })
}

// 查询学生列表
Mock.mock(/\/api\/student\/list/, 'get', (options) => {
  const { pageNum = 1, pageSize = 10 } = options.body ? JSON.parse(options.body) : {}
  const start = (pageNum - 1) * pageSize
  const end = start + pageSize
  
  return {
    code: 200,
    msg: '查询成功',
    rows: studentList.slice(start, end),
    total: studentList.length
  }
})

// 获取学生详情
Mock.mock(/\/api\/student\/\d+$/, 'get', (options) => {
  const id = parseInt(options.url.match(/\/api\/student\/(\d+)$/)[1])
  const student = studentList.find(s => s.studentId === id)
  
  return {
    code: 200,
    msg: '查询成功',
    data: student
  }
})

// 新增学生
Mock.mock('/api/student', 'post', () => {
  return {
    code: 200,
    msg: '新增成功'
  }
})

// 修改学生
Mock.mock('/api/student', 'put', () => {
  return {
    code: 200,
    msg: '修改成功'
  }
})

// 删除学生
Mock.mock(/\/api\/student\/\d+$/, 'delete', () => {
  return {
    code: 200,
    msg: '删除成功'
  }
})

// 批量导入学生
Mock.mock('/api/student/import', 'post', () => {
  return {
    code: 200,
    msg: '导入成功',
    data: {
      total: 100,
      successCount: 95,
      failCount: 5,
      errorList: [
        { rowNum: 3, studentName: '张三', studentNo: 'STU001', errorMsg: '学号已存在' },
        { rowNum: 15, studentName: '李四', studentNo: 'STU015', errorMsg: '手机号格式错误' },
        { rowNum: 28, studentName: '王五', studentNo: 'STU028', errorMsg: '学校不存在' },
        { rowNum: 45, studentName: '赵六', studentNo: 'STU045', errorMsg: '年级不存在' },
        { rowNum: 67, studentName: '孙七', studentNo: 'STU067', errorMsg: '班级不存在' }
      ]
    }
  }
})

// 下载导入模板
Mock.mock('/api/student/template', 'get', () => {
  return {
    code: 200,
    msg: '下载成功'
  }
})

// 检查学号唯一性
Mock.mock(/\/api\/student\/checkStudentNo/, 'get', () => {
  return {
    code: 200,
    msg: '查询成功',
    data: true
  }
})
