export default {
  id: 'education',
  title: '教育背景',
  showProgress: true,
  progress: 0,
  get: {
    action: '/zws/v1/enrollment/educations?project_id=1000',
    callback(data) {
      return data.map(item => {
        const { start_date: startDate, end_date: endDate } = item
        if (startDate) {
          item.dates = [startDate + '', endDate + '']
        }
        return item
      })
    }
  },
  update: {
    action: '/zws/v1/enrollment/educations/batch-upload',
    data: { project_id: 1000 },
    beforeRequest(data) {
      const records = data.map(item => {
        let [startDate, endDate] = item.dates
        item.start_date = startDate
        item.end_date = endDate
        return [
          'start_date',
          'end_date',
          'school_name_cn',
          'major_cn',
          'degree'
        ].reduce((result, key) => {
          result[key] = item[key]
          return result
        }, {})
      })
      return { records }
    }
  },
  form: {
    hasAdd: true,
    options: {
      labelWidth: '160px'
    },
    items: [
      /* 教育时间 */
      {
        type: 'date-picker-from-to-form',
        elemType: 'monthrange',
        label: '教育时间',
        labelWidth: '160px',
        model: 'dates',
        modelWidth: '300px',
        rangeSeparator: '至',
        startPlaceholder: '请选择开始时间',
        endPlaceholder: '请选择结束时间',
        attrs: { 'value-format': 'yyyyMM' },
        rules: [{ required: true, message: '请选择教育时间', trigger: 'blur' }]
      },
      /* 学校名称 */
      {
        type: 'input-form',
        label: '学校名称',
        model: 'school_name_cn',
        modelWidth: '300px',
        placeholder: '请输入学校名称',
        rules: [{ required: true, message: '请输入学校名称', trigger: 'blur' }]
      },
      /* 专业名称 */
      {
        type: 'input-form',
        label: '专业名称',
        model: 'major_cn',
        modelWidth: '300px',
        placeholder: '请输入专业名称',
        rules: [{ required: true, message: '请输入专业名称', trigger: 'blur' }]
      },
      /* 学历/学位 */
      {
        type: 'select-form',
        label: '学历/学位',
        model: 'degree',
        modelWidth: '300px',
        placeholder: '请选择',
        values: [
          { label: '专科', value: 1 },
          { label: '本科', value: 2 },
          { label: '本科/学士', value: 3 },
          { label: '硕士研究生', value: 4 },
          { label: '研究生/硕士', value: 5 },
          { label: '博士研究生', value: 6 },
          { label: '研究生/博士', value: 7 },
          { label: '其他', value: 9 }
        ],
        rules: [
          { required: true, message: '请选择学历/学位', trigger: 'change' }
        ]
      }
    ]
  }
}
