/**
 * 荣誉奖励
 */

export default function(_this) {
  return {
    id: 'application_info_honor',
    title: '荣誉奖励',
    visible() {
      return _this.visible
    },
    get: {
      action: `/api/enrollment/v1.0/application-materials/${webConf.others.projectId}`,
      callback(data) {
        const { honors: list = [], submission_stage: submissionStage = 'FILLING' } = data.data.material
        this.form.options.disabled = submissionStage !== 'FILLING'
        return list.length ? list : [{}]
      }
    },
    update: {
      action: `/api/enrollment/v1.0/application-materials/${webConf.others.projectId}/put`,
      beforeRequest(data) {
        const honors = data.map(item => {
          return ['time', 'title', 'institution_cn'].reduce((result, key) => {
            result[key] = item[key]
            return result
          }, {})
        })
        return { honors }
      }
    },
    form: {
      prev: { to: { query: { active: 'application_info', tab: 'application_info_training' } }, isSubmit: true },
      next: { to: { query: { active: 'application_declare' } }, isSubmit: true },
      hasAdd: true,
      options: { labelWidth: '140px' },
      items: [
        {
          type: 'v-datepicker',
          label: '获取时间',
          model: 'time',
          attrs: { type: 'date', valueFormat: 'yyyy-MM-dd', placeholder: '请选择获取时间' },
          rules: [{ required: true, message: '请选择获取时间', trigger: 'blur' }]
        },
        {
          type: 'v-input',
          label: '荣誉奖励',
          model: 'title',
          attrs: { placeholder: '请输入荣誉奖励' },
          rules: [{ required: true, message: '请输入荣誉奖励', trigger: 'blur' }]
        },
        {
          type: 'v-input',
          label: '证书颁发机构',
          model: 'institution_cn',
          attrs: { placeholder: '请输入证书颁发机构' },
          rules: [{ required: true, message: '请输入证书颁发机构', trigger: 'blur' }]
        }
      ]
    }
  }
}
