perillScore.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function selectedScore(methods, assessmentMethod) {
  2. const method = (methods || []).find(item => String(item.assessmentMethod) === assessmentMethod)
  3. const option = method && (method.questionOption || []).find(item => item.questionOption === method.answer)
  4. return option && Number.isFinite(Number(option.number)) ? Number(option.number) : null
  5. }
  6. function validateFutureExpectation(methods) {
  7. const currentScore = selectedScore(methods, '1')
  8. const futureScore = selectedScore(methods, '2')
  9. if (currentScore === null || futureScore === null || futureScore < currentScore) {
  10. return '一年后期待分不得低于现状评分,请注意!'
  11. }
  12. return ''
  13. }
  14. const AGREEMENT_OPTIONS = {
  15. 1: '1-强烈不同意(Strongly disagree)',
  16. 2: '2-不同意(Disagree)',
  17. 3: '3-中立(Neutral)',
  18. 4: '4-同意(Agree)',
  19. 5: '5-完全同意(Totally agree)'
  20. }
  21. function normalizeFutureExpectationOptions(methods) {
  22. return (methods || []).map(method => {
  23. if (String(method.assessmentMethod) !== '2') return method
  24. return Object.assign({}, method, {
  25. questionOption: (method.questionOption || []).map(option => {
  26. const text = AGREEMENT_OPTIONS[option.number]
  27. return text ? Object.assign({}, option, { questionOption: text }) : option
  28. })
  29. })
  30. })
  31. }
  32. module.exports = { validateFutureExpectation, normalizeFutureExpectationOptions }