export default {
  id: 'training',
  title: '所受培训',
  showProgress: true,
  progress: 0,
  required: false,
  get: {
    action: '/zws/v1/enrollment/trainings?project_id=1001',
    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: 1001 },
    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: '80px'
    },
    items: [
      {
        type: 'date-picker-from-to-form',
        elemType: 'monthrange',
        label: '培训时间',
        model: 'dates',
        rangeSeparator: '至',
        startPlaceholder: '请选择开始时间',
        endPlaceholder: '请选择结束时间',
        attrs: { 'value-format': 'yyyyMM' },
        rules: [{ required: true, message: '请选择培训时间', trigger: 'blur' }]
      },
      {
        type: 'input-form',
        label: '培训机构',
        model: 'institute_cn',
        rules: [{ required: true, message: '请输入培训机构', trigger: 'blur' }]
      },
      {
        type: 'input-form',
        label: '课程名称',
        model: 'course_cn',
        rules: [
          {
            required: true,
            message: '请输入课程名称',
            trigger: 'blur'
          }
        ]
      }
    ]
  }
}
