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.times = [(startDate + '').replace(/([\d]{4})([\d]{2})/gi, '$1-$2'), (endDate + '').replace(/([\d]{4})([\d]{2})/gi, '$1-$2')]
        }
        return item
      })
    }
  },
  update: {
    action: '/api/v1/enrollment/trainings',
    data: { project_id: 1000 },
    callback(data) {
      return data.map(item => {
        let [startDate, endDate] = item.times
        item.start_date = parseInt(startDate.replace(/-/gi, ''))
        item.end_date = parseInt(endDate.replace(/-/gi, ''))
        return item
      })
    }
  },
  form: {
    options: {
      labelWidth: '160px'
    },
    model: [
      {
        times: [],
        start_date: null,
        end_date: null,
        institute_cn: '',
        course_cn: ''
      }
    ],
    items: [
      /* 培训时间 */
      {
        'type': 'date-picker-from-to-form',
        'elemType': 'monthrange',
        'label': '培训时间',
        'required': false,
        'disabled': false,
        'label-width': '160px',
        'model': 'times',
        'model-width': '300px',
        'rangeSeparator': '至',
        'startPlaceholder': '请选择开始时间',
        'endPlaceholder': '请选择结束时间',
        'attrs': { 'value-format': 'yyyy-MM' }
      },
      /* 培训机构 */
      {
        'type': 'input-form',
        'label': '培训机构',
        'required': false,
        'model': 'institute_cn',
        'model-width': '300px',
        'placeholder': '请输入培训机构'
      },
      /* 课程名称 */
      {
        'type': 'input-form',
        'label': '课程名称',
        'required': false,
        'model': 'course_cn',
        'model-width': '300px',
        'placeholder': '请输入课程名称'
      }
    ]
  }
}
