@wg-npm/survey-creator 0.3.7725 → 0.3.7738

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3180,19 +3180,19 @@ var script$d = Vue.extend({
3180
3180
  data() {
3181
3181
  return {
3182
3182
  operators: ["<=", "<"],
3183
+ leftScores: [],
3184
+ rightScores: []
3183
3185
  };
3184
3186
  },
3185
3187
  created() {
3186
3188
  this.value.leftOperator = _.unescape(this.value.leftOperator);
3187
3189
  this.value.rightOperator = _.unescape(this.value.rightOperator);
3190
+ this.createInitScoresOption();
3188
3191
  },
3189
3192
  computed: {
3190
3193
  totalScore() {
3191
3194
  return this.$rootComponent.currentSurvey.statistics.maxScore;
3192
3195
  },
3193
- scores() {
3194
- return _.range(1, this.totalScore + 1, 1);
3195
- },
3196
3196
  otherConditions() {
3197
3197
  let otherEvaluationItems = _.filter(_.map(this.evaluationItems, (item, index) => {
3198
3198
  return _.extend({}, item, { index: index });
@@ -3202,95 +3202,48 @@ var script$d = Vue.extend({
3202
3202
  },
3203
3203
  },
3204
3204
  methods: {
3205
- getSelectedRangeByValue(value, ranges) {
3206
- let otherRange = _.map(ranges, (item) => {
3205
+ createInitScoresOption() {
3206
+ this.leftScores = _.map(_.range(1, this.totalScore + 1, 1), function (num) {
3207
3207
  return {
3208
- min: _.get(item, "payload.minScore"),
3209
- max: _.get(item, "payload.maxScore"),
3208
+ value: num,
3209
+ label: num,
3210
+ disabled: false
3210
3211
  };
3211
3212
  });
3212
- return _.head(_.filter(otherRange, function (o) {
3213
- return value > o.min && value < o.max;
3214
- }));
3215
- },
3216
- getUsableRanges() {
3217
- let usedRange = _.map(this.otherConditions, (item) => {
3218
- return [item.payload.minScore, item.payload.maxScore];
3213
+ this.rightScores = _.map(_.range(1, this.totalScore + 1, 1), function (num) {
3214
+ return {
3215
+ value: num,
3216
+ label: num,
3217
+ disabled: false
3218
+ };
3219
3219
  });
3220
- let globalMin = 0;
3221
- let globalMax = this.totalScore;
3222
- let usableRange = new Array();
3223
- if (usedRange.length == 1) {
3224
- let first = usedRange[0][0] - 1;
3225
- if (usedRange[0][0] !== 0) {
3226
- let item = [0, first];
3227
- usableRange.push(item);
3228
- }
3229
- if (usedRange[length - 1][1] != globalMax) {
3230
- usableRange.push([usedRange[length - 1][1], globalMax]);
3231
- }
3232
- return usableRange;
3233
- }
3234
- else {
3235
- let other = usedRange.reduce((a, v) => {
3236
- if (typeof a[0] == "number") {
3237
- if (a[0] != globalMin) {
3238
- return [
3239
- [0, a[0]],
3240
- [a[1], v[0]],
3241
- [v[1], v[1]],
3242
- ];
3243
- }
3244
- else {
3245
- return [
3246
- [a[1], v[0]],
3247
- [v[1], v[1]],
3248
- ];
3249
- }
3250
- }
3251
- else {
3252
- a[a.length - 1][1] = v[0];
3253
- if (a.length != usedRange.length)
3254
- a.push([v[1], v[1]]);
3255
- }
3256
- return a;
3257
- });
3258
- if (usedRange[length - 1][1] != globalMax) {
3259
- other.push([usedRange[length - 1][1], globalMax]);
3260
- }
3261
- return other;
3262
- }
3263
3220
  },
3264
- disabledScoreOption(value, type) {
3221
+ resetScoreOptions(options, type) {
3265
3222
  debugger;
3266
- if (this.checkValueInOtherRange(value)) {
3267
- return true;
3268
- }
3269
- let leftScore = _.get(this.value, "minScore", 0);
3270
- let rightScore = _.get(this.value, "maxScore", this.totalScore);
3271
- if (leftScore != null && type == "left" && value >= rightScore) {
3272
- return true;
3273
- }
3274
- if (rightScore != null && type == "right" && value <= leftScore) {
3275
- return true;
3223
+ if (this.otherConditions.length == 0) {
3224
+ return;
3276
3225
  }
3277
- },
3278
- checkValueInOtherRange(value) {
3279
3226
  let otherRange = _.map(this.otherConditions, (item) => {
3280
3227
  return {
3281
3228
  min: _.get(item, "payload.minScore", 0),
3282
3229
  max: _.get(item, "payload.maxScore", 0),
3283
3230
  };
3284
3231
  });
3285
- return _.some(otherRange, function (o) {
3286
- return value >= o.min && value <= o.max;
3232
+ let currentValue = this.value;
3233
+ let currentTotalScore = this.totalScore;
3234
+ _.map(options, function (o) {
3235
+ let disabled = _.some(otherRange, function (or) {
3236
+ let condition_a = o >= or.min && o <= or.max;
3237
+ let condition_b = type == "left" ? o.value >= _.get(currentValue, "minScore", 0) : o.value <= _.get(currentValue, "maxScore", currentTotalScore);
3238
+ return condition_a && condition_b;
3239
+ });
3240
+ return {
3241
+ value: o.value,
3242
+ label: o.label,
3243
+ disabled: disabled
3244
+ };
3287
3245
  });
3288
3246
  },
3289
- generateExpr() {
3290
- let minScore = this.value.minScore;
3291
- let maxScore = this.value.maxScore;
3292
- return `${minScore} ${this.value.leftOperator} score and score ${this.value.rightOperator} ${maxScore}`;
3293
- },
3294
3247
  },
3295
3248
  });
3296
3249
 
@@ -3298,35 +3251,35 @@ var script$d = Vue.extend({
3298
3251
  const __vue_script__$d = script$d;
3299
3252
 
3300
3253
  /* template */
3301
- var __vue_render__$d = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('Row',{attrs:{"type":"flex","justify":"start","gutter":6,"align":"middle"}},[_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.evaluation.condition.score_condition_title"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":4}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.minScore"),"rules":{
3302
- required: true,
3303
- type: 'number',
3304
- trigger: 'change',
3305
- message: _vm.t('survey_creator.question.scoreRequiredTip'),
3306
- }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},model:{value:(_vm.value.minScore),callback:function ($$v) {_vm.$set(_vm.value, "minScore", $$v);},expression:"value.minScore"}},_vm._l((_vm.scores),function(score){return _c('Option',{key:score,attrs:{"value":score,"disabled":_vm.disabledScoreOption(score, 'left')}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.leftOperator"),"rules":{
3307
- required: true,
3308
- trigger: 'change',
3309
- message: _vm.t('survey_creator.question.notEmpty'),
3310
- }}},[_c('Select',{staticClass:"operator",attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.leftOperator),callback:function ($$v) {_vm.$set(_vm.value, "leftOperator", $$v);},expression:"value.leftOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.totalScores"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.rightOperator"),"rules":{
3311
- required: true,
3312
- trigger: 'change',
3313
- message: _vm.t('survey_creator.question.notEmpty'),
3314
- }}},[_c('Select',{staticClass:"operator",attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.rightOperator),callback:function ($$v) {_vm.$set(_vm.value, "rightOperator", $$v);},expression:"value.rightOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":4}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.maxScore"),"rules":{
3315
- required: true,
3316
- type: 'number',
3317
- trigger: 'change',
3318
- message: _vm.t('survey_creator.question.scoreRequiredTip'),
3319
- }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},model:{value:(_vm.value.maxScore),callback:function ($$v) {_vm.$set(_vm.value, "maxScore", $$v);},expression:"value.maxScore"}},_vm._l((_vm.scores),function(score){return _c('Option',{key:score,attrs:{"value":score,"disabled":_vm.disabledScoreOption(score, 'right')}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1)],1)};
3254
+ var __vue_render__$d = function () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('Row',{attrs:{"type":"flex","justify":"start","gutter":6,"align":"middle"}},[_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.evaluation.condition.score_condition_title"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":4}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.minScore"),"rules":{
3255
+ required: true,
3256
+ type: 'number',
3257
+ trigger: 'change',
3258
+ message: _vm.t('survey_creator.question.scoreRequiredTip'),
3259
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},on:{"on-change":function($event){return _vm.resetScoreOptions(_vm.leftScores,'left')}},model:{value:(_vm.value.minScore),callback:function ($$v) {_vm.$set(_vm.value, "minScore", $$v);},expression:"value.minScore"}},_vm._l((_vm.leftScores),function(score){return _c('Option',{key:score.value,attrs:{"value":score.value,"disabled":score.disabled}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.leftOperator"),"rules":{
3260
+ required: true,
3261
+ trigger: 'change',
3262
+ message: _vm.t('survey_creator.question.notEmpty'),
3263
+ }}},[_c('Select',{staticClass:"operator",attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.leftOperator),callback:function ($$v) {_vm.$set(_vm.value, "leftOperator", $$v);},expression:"value.leftOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{staticClass:"label"},[_vm._v("\n "+_vm._s(_vm.t("survey_creator.question.totalScores"))+"\n ")]),_vm._v(" "),_c('Col',{attrs:{"span":3}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.rightOperator"),"rules":{
3264
+ required: true,
3265
+ trigger: 'change',
3266
+ message: _vm.t('survey_creator.question.notEmpty'),
3267
+ }}},[_c('Select',{staticClass:"operator",attrs:{"placeholder":_vm.t('survey_creator.question.evaluation.condition.operator')},model:{value:(_vm.value.rightOperator),callback:function ($$v) {_vm.$set(_vm.value, "rightOperator", $$v);},expression:"value.rightOperator"}},_vm._l((_vm.operators),function(operator,index){return _c('Option',{key:index,attrs:{"value":operator}},[_vm._v("\n "+_vm._s(operator)+"\n ")])}),1)],1)],1),_vm._v(" "),_c('Col',{attrs:{"span":4}},[_c('FormItem',{attrs:{"prop":("evaluationItems[" + _vm.itemIndex + "].conditions[" + _vm.index + "].payload.maxScore"),"rules":{
3268
+ required: true,
3269
+ type: 'number',
3270
+ trigger: 'change',
3271
+ message: _vm.t('survey_creator.question.scoreRequiredTip'),
3272
+ }}},[_c('Select',{attrs:{"placeholder":_vm.t('survey_creator.question.selectScore')},on:{"on-change":function($event){return _vm.resetScoreOptions(_vm.rightScores,'right')}},model:{value:(_vm.value.maxScore),callback:function ($$v) {_vm.$set(_vm.value, "maxScore", $$v);},expression:"value.maxScore"}},_vm._l((_vm.rightScores),function(score){return _c('Option',{key:score.value,attrs:{"value":score.value,"disabled":score.disabled}},[_vm._v("\n "+_vm._s(score)+"\n ")])}),1)],1)],1)],1)};
3320
3273
  var __vue_staticRenderFns__$d = [];
3321
3274
 
3322
3275
  /* style */
3323
3276
  const __vue_inject_styles__$d = function (inject) {
3324
3277
  if (!inject) return
3325
- inject("data-v-1411052e_0", { source: ".label[data-v-1411052e]{text-align:right;margin-bottom:24px}[data-v-1411052e] .operator .ivu-select-selected-value{height:28px;line-height:28px}", map: undefined, media: undefined });
3278
+ inject("data-v-29fedcdf_0", { source: ".label[data-v-29fedcdf]{text-align:right;margin-bottom:24px}[data-v-29fedcdf] .operator .ivu-select-selected-value{height:28px;line-height:28px}", map: undefined, media: undefined });
3326
3279
 
3327
3280
  };
3328
3281
  /* scoped */
3329
- const __vue_scope_id__$d = "data-v-1411052e";
3282
+ const __vue_scope_id__$d = "data-v-29fedcdf";
3330
3283
  /* module identifier */
3331
3284
  const __vue_module_identifier__$d = undefined;
3332
3285
  /* functional template */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wg-npm/survey-creator",
3
- "version": "0.3.7725",
3
+ "version": "0.3.7738",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "scripts": {
@@ -12,8 +12,8 @@
12
12
  "lint-fix": "eslint \"**/*.ts\" \"**/*.vue\" --fix --no-error-on-unmatched-pattern"
13
13
  },
14
14
  "peerDependencies": {
15
- "@wg-npm/survey-core": "0.3.7725",
16
- "@wg-npm/survey-service-api": "0.3.7725",
15
+ "@wg-npm/survey-core": "0.3.7738",
16
+ "@wg-npm/survey-service-api": "0.3.7738",
17
17
  "axios": "^0.19.2",
18
18
  "camelcase": "^6.0.0",
19
19
  "deepmerge": "^4.2.2",
@@ -38,8 +38,8 @@
38
38
  "@typescript-eslint/eslint-plugin": "^3.6.0",
39
39
  "@typescript-eslint/parser": "^3.6.0",
40
40
  "@vue/eslint-config-prettier": "^6.0.0",
41
- "@wg-npm/survey-core": "0.3.7725",
42
- "@wg-npm/survey-service-api": "0.3.7725",
41
+ "@wg-npm/survey-core": "0.3.7738",
42
+ "@wg-npm/survey-service-api": "0.3.7738",
43
43
  "acorn": "^7.3.1",
44
44
  "axios": "^0.19.2",
45
45
  "babelrc-rollup": "^3.0.0",
@@ -1,277 +1,235 @@
1
1
  <template>
2
- <Row type="flex" justify="start" :gutter="6" align="middle">
3
- <Col class="label">
4
- {{
5
- t("survey_creator.question.evaluation.condition.score_condition_title")
6
- }}
7
- </Col>
8
- <Col :span="4">
9
- <FormItem
10
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.minScore`"
11
- :rules="{
2
+ <Row type="flex" justify="start" :gutter="6" align="middle">
3
+ <Col class="label">
4
+ {{
5
+ t("survey_creator.question.evaluation.condition.score_condition_title")
6
+ }}
7
+ </Col>
8
+ <Col :span="4">
9
+ <FormItem
10
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.minScore`"
11
+ :rules="{
12
12
  required: true,
13
13
  type: 'number',
14
14
  trigger: 'change',
15
15
  message: t('survey_creator.question.scoreRequiredTip'),
16
16
  }"
17
- >
18
- <Select
19
- v-model="value.minScore"
20
- :placeholder="t('survey_creator.question.selectScore')"
21
- >
22
- <Option
23
- v-for="score in scores"
24
- :value="score"
25
- :key="score"
26
- :disabled="disabledScoreOption(score, 'left')"
27
- >
28
- {{ score }}
29
- </Option>
30
- </Select>
31
- </FormItem>
32
- </Col>
33
- <Col :span="3">
34
- <FormItem
35
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.leftOperator`"
36
- :rules="{
17
+ >
18
+ <Select
19
+ v-model="value.minScore"
20
+ :placeholder="t('survey_creator.question.selectScore')"
21
+ @on-change="resetScoreOptions(leftScores,'left')"
22
+ >
23
+ <Option
24
+ v-for="score in leftScores"
25
+ :value="score.value"
26
+ :key="score.value"
27
+ :disabled="score.disabled"
28
+ >
29
+ {{ score }}
30
+ </Option>
31
+ </Select>
32
+ </FormItem>
33
+ </Col>
34
+ <Col :span="3">
35
+ <FormItem
36
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.leftOperator`"
37
+ :rules="{
37
38
  required: true,
38
39
  trigger: 'change',
39
40
  message: t('survey_creator.question.notEmpty'),
40
41
  }"
41
- >
42
- <Select
43
- class="operator"
44
- v-model="value.leftOperator"
45
- :placeholder="
42
+ >
43
+ <Select
44
+ class="operator"
45
+ v-model="value.leftOperator"
46
+ :placeholder="
46
47
  t('survey_creator.question.evaluation.condition.operator')
47
48
  "
48
- >
49
- <Option
50
- v-for="(operator, index) in operators"
51
- :value="operator"
52
- :key="index"
53
- >
54
- {{ operator }}
55
- </Option>
56
- </Select>
57
- </FormItem>
58
- </Col>
59
- <Col class="label">
60
- {{ t("survey_creator.question.totalScores") }}
61
- </Col>
62
- <Col :span="3">
63
- <FormItem
64
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.rightOperator`"
65
- :rules="{
49
+ >
50
+ <Option
51
+ v-for="(operator, index) in operators"
52
+ :value="operator"
53
+ :key="index"
54
+ >
55
+ {{ operator }}
56
+ </Option>
57
+ </Select>
58
+ </FormItem>
59
+ </Col>
60
+ <Col class="label">
61
+ {{ t("survey_creator.question.totalScores") }}
62
+ </Col>
63
+ <Col :span="3">
64
+ <FormItem
65
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.rightOperator`"
66
+ :rules="{
66
67
  required: true,
67
68
  trigger: 'change',
68
69
  message: t('survey_creator.question.notEmpty'),
69
70
  }"
70
- >
71
- <Select
72
- class="operator"
73
- v-model="value.rightOperator"
74
- :placeholder="
71
+ >
72
+ <Select
73
+ class="operator"
74
+ v-model="value.rightOperator"
75
+ :placeholder="
75
76
  t('survey_creator.question.evaluation.condition.operator')
76
77
  "
77
- >
78
- <Option
79
- v-for="(operator, index) in operators"
80
- :value="operator"
81
- :key="index"
82
- >
83
- {{ operator }}
84
- </Option>
85
- </Select>
86
- </FormItem>
87
- </Col>
88
- <Col :span="4">
89
- <FormItem
90
- :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.maxScore`"
91
- :rules="{
78
+ >
79
+ <Option
80
+ v-for="(operator, index) in operators"
81
+ :value="operator"
82
+ :key="index"
83
+ >
84
+ {{ operator }}
85
+ </Option>
86
+ </Select>
87
+ </FormItem>
88
+ </Col>
89
+ <Col :span="4">
90
+ <FormItem
91
+ :prop="`evaluationItems[${itemIndex}].conditions[${index}].payload.maxScore`"
92
+ :rules="{
92
93
  required: true,
93
94
  type: 'number',
94
95
  trigger: 'change',
95
96
  message: t('survey_creator.question.scoreRequiredTip'),
96
97
  }"
97
- >
98
- <Select
99
- v-model="value.maxScore"
100
- :placeholder="t('survey_creator.question.selectScore')"
101
- >
102
- <Option
103
- v-for="score in scores"
104
- :value="score"
105
- :key="score"
106
- :disabled="disabledScoreOption(score, 'right')"
107
- >
108
- {{ score }}
109
- </Option>
110
- </Select>
111
- </FormItem>
112
- </Col>
113
- </Row>
98
+ >
99
+ <Select
100
+ v-model="value.maxScore"
101
+ :placeholder="t('survey_creator.question.selectScore')"
102
+ @on-change="resetScoreOptions(rightScores,'right')"
103
+ >
104
+ <Option
105
+ v-for="score in rightScores"
106
+ :value="score.value"
107
+ :key="score.value"
108
+ :disabled="score.disabled"
109
+ >
110
+ {{ score }}
111
+ </Option>
112
+ </Select>
113
+ </FormItem>
114
+ </Col>
115
+ </Row>
114
116
  </template>
115
117
  <script lang="ts">
116
- import Vue from "vue";
117
- import {
118
- Col,
119
- FormItem,
120
- InputNumber,
121
- Message,
122
- Option,
123
- Row,
124
- Select,
125
- } from "view-design";
126
- import _ from "lodash";
127
- import ExprMixin from "./expr-mixin";
128
- import LocaleMixin from "../../../../../mixins/locale-mixin";
129
- import { ExprConditionType } from "@wg-npm/survey-core/src/models";
118
+ import Vue from "vue";
119
+ import {
120
+ Col,
121
+ FormItem,
122
+ InputNumber,
123
+ Message,
124
+ Option,
125
+ Row,
126
+ Select,
127
+ } from "view-design";
128
+ import _ from "lodash";
129
+ import ExprMixin from "./expr-mixin";
130
+ import LocaleMixin from "../../../../../mixins/locale-mixin";
131
+ import {ExprConditionType} from "@wg-npm/survey-core/src/models";
130
132
 
131
- Vue.prototype.$Message = Message;
133
+ Vue.prototype.$Message = Message;
132
134
 
133
- export default Vue.extend({
134
- name: "score",
135
- mixins: [ExprMixin, LocaleMixin],
136
- components: {
137
- Row,
138
- Col,
139
- Select,
140
- Option,
141
- FormItem,
142
- InputNumber,
143
- },
144
- data() {
145
- return {
146
- operators: ["<=", "<"],
147
- };
148
- },
149
- created() {
150
- this.value.leftOperator = _.unescape(this.value.leftOperator);
151
- this.value.rightOperator = _.unescape(this.value.rightOperator);
152
- },
153
- computed: {
154
- totalScore() {
155
- return this.$rootComponent.currentSurvey.statistics.maxScore;
156
- },
157
- scores() {
158
- return _.range(1, this.totalScore + 1, 1);
159
- },
160
- otherConditions() {
161
- let otherEvaluationItems = _.filter(
162
- _.map(this.evaluationItems, (item, index) => {
163
- return _.extend({}, item, { index: index });
164
- }),
165
- (item) => item.index != this.itemIndex
166
- );
167
- const conditions = _.flatMap(otherEvaluationItems, item=>_.get(item,"conditions",[]));
168
- return _.filter(conditions,
169
- (item) => _.get(item,"type") == ExprConditionType.SCORE
170
- );
171
- },
172
- },
173
- methods: {
174
- getSelectedRangeByValue(value, ranges) {
175
- let otherRange = _.map(ranges, (item) => {
176
- return {
177
- min: _.get(item, "payload.minScore"),
178
- max: _.get(item, "payload.maxScore"),
179
- };
180
- });
181
- return _.head(
182
- _.filter(otherRange, function (o) {
183
- return value > o.min && value < o.max;
184
- })
185
- );
186
- },
187
- //todo 此功能暂未启用
188
- getUsableRanges() {
189
- let usedRange = _.map(this.otherConditions, (item) => {
190
- return [item.payload.minScore, item.payload.maxScore];
191
- });
192
- let globalMin = 0;
193
- let globalMax = this.totalScore;
194
- // arr must sorted asc
195
- let usableRange = new Array();
196
- if (usedRange.length == 1) {
197
- let first = usedRange[0][0] - 1;
198
- if (usedRange[0][0] !== 0) {
199
- let item = [0, first];
200
- usableRange.push(item);
201
- }
202
- if (usedRange[length - 1][1] != globalMax) {
203
- usableRange.push([usedRange[length - 1][1], globalMax]);
204
- }
205
- return usableRange;
206
- } else {
207
- let other = usedRange.reduce((a, v) => {
208
- if (typeof a[0] == "number") {
209
- if (a[0] != globalMin) {
210
- return [
211
- [0, a[0]],
212
- [a[1], v[0]],
213
- [v[1], v[1]],
214
- ];
215
- } else {
216
- return [
217
- [a[1], v[0]],
218
- [v[1], v[1]],
219
- ];
220
- }
221
- } else {
222
- a[a.length - 1][1] = v[0];
223
- if (a.length != usedRange.length) a.push([v[1], v[1]]);
224
- }
225
- return a;
226
- });
227
- if (usedRange[length - 1][1] != globalMax) {
228
- other.push([usedRange[length - 1][1], globalMax]);
229
- }
230
- return other;
231
- }
232
- },
233
- disabledScoreOption(value, type) {
234
- debugger
235
- if (this.checkValueInOtherRange(value)) {
236
- return true;
237
- }
238
- let leftScore = _.get(this.value, "minScore", 0);
239
- let rightScore = _.get(this.value, "maxScore", this.totalScore);
240
- if (leftScore != null && type == "left" && value >= rightScore) {
241
- return true;
242
- }
243
- if (rightScore != null && type == "right" && value <= leftScore) {
244
- return true;
245
- }
246
- },
247
- checkValueInOtherRange(value) {
248
- let otherRange = _.map(this.otherConditions, (item) => {
249
- return {
250
- min: _.get(item, "payload.minScore", 0),
251
- max: _.get(item, "payload.maxScore", 0),
252
- };
253
- });
254
- return _.some(otherRange, function (o) {
255
- return value >= o.min && value <= o.max;
256
- });
257
- },
258
- generateExpr() {
259
- let minScore = this.value.minScore;
260
- let maxScore = this.value.maxScore;
261
- return `${minScore} ${this.value.leftOperator} score and score ${this.value.rightOperator} ${maxScore}`;
262
- },
263
- },
264
- });
135
+ export default Vue.extend({
136
+ name: "score",
137
+ mixins: [ExprMixin, LocaleMixin],
138
+ components: {
139
+ Row,
140
+ Col,
141
+ Select,
142
+ Option,
143
+ FormItem,
144
+ InputNumber,
145
+ },
146
+ data() {
147
+ return {
148
+ operators: ["<=", "<"],
149
+ leftScores: [],
150
+ rightScores: []
151
+ };
152
+ },
153
+ created() {
154
+ this.value.leftOperator = _.unescape(this.value.leftOperator);
155
+ this.value.rightOperator = _.unescape(this.value.rightOperator);
156
+ this.createInitScoresOption()
157
+ },
158
+ computed: {
159
+ totalScore() {
160
+ return this.$rootComponent.currentSurvey.statistics.maxScore;
161
+ },
162
+ otherConditions() {
163
+ let otherEvaluationItems = _.filter(
164
+ _.map(this.evaluationItems, (item, index) => {
165
+ return _.extend({}, item, {index: index});
166
+ }),
167
+ (item) => item.index != this.itemIndex
168
+ );
169
+ const conditions = _.flatMap(otherEvaluationItems, item => _.get(item, "conditions", []));
170
+ return _.filter(conditions,
171
+ (item) => _.get(item, "type") == ExprConditionType.SCORE
172
+ );
173
+ },
174
+ },
175
+ methods: {
176
+ createInitScoresOption() {
177
+ this.leftScores = _.map(_.range(1, this.totalScore + 1, 1), function (num) {
178
+ return {
179
+ value: num,
180
+ label: num,
181
+ disabled: false
182
+ }
183
+ })
184
+ this.rightScores = _.map(_.range(1, this.totalScore + 1, 1), function (num) {
185
+ return {
186
+ value: num,
187
+ label: num,
188
+ disabled: false
189
+ }
190
+ })
191
+ },
192
+ resetScoreOptions(options, type) {
193
+ debugger
194
+ if (this.otherConditions.length == 0) {
195
+ return
196
+ }
197
+ let otherRange = _.map(this.otherConditions, (item) => {
198
+ return {
199
+ min: _.get(item, "payload.minScore", 0),
200
+ max: _.get(item, "payload.maxScore", 0),
201
+ };
202
+ });
203
+
204
+ let currentValue = this.value;
205
+ let currentTotalScore = this.totalScore;
206
+
207
+ _.map(options, function (o) {
208
+ let disabled = _.some(otherRange, function (or) {
209
+ let condition_a = o >= or.min && o <= or.max;
210
+ let condition_b = type == "left" ? o.value >= _.get(currentValue, "minScore", 0) : o.value <= _.get(currentValue, "maxScore", currentTotalScore)
211
+ return condition_a && condition_b;
212
+ })
213
+ return {
214
+ value: o.value,
215
+ label: o.label,
216
+ disabled: disabled
217
+ }
218
+ })
219
+ },
220
+ },
221
+ });
265
222
  </script>
266
223
  <style scoped lang="less">
267
- .label {
268
- text-align: right;
269
- margin-bottom: 24px;
270
- }
271
- /deep/ .operator {
272
- .ivu-select-selected-value {
273
- height: 28px;
274
- line-height: 28px;
275
- }
276
- }
224
+ .label {
225
+ text-align: right;
226
+ margin-bottom: 24px;
227
+ }
228
+
229
+ /deep/ .operator {
230
+ .ivu-select-selected-value {
231
+ height: 28px;
232
+ line-height: 28px;
233
+ }
234
+ }
277
235
  </style>