export default {
  id: 'training',
  title: '所受培训（可选）',
  showProgress: true,
  progress: 0,
  get: {
    action: '/zws/v1/enrollment/trainings?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/trainings/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', 'institute_cn', 'course_cn'].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: 'institute_cn',
        modelWidth: '300px',
        placeholder: '请输入培训机构',
        rules: [{ required: true, message: '请输入培训机构', trigger: 'blur' }]
      },
      /* 课程名称 */
      {
        type: 'input-form',
        label: '课程名称',
        model: 'course_cn',
        modelWidth: '300px',
        placeholder: '请输入课程名称',
        rules: [
          {
            required: true,
            message: '请输入课程名称',
            trigger: 'blur'
          }
        ]
      }
    ]
  }
}
