index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { __spreadArray } from "tslib";
  2. import { Component, triggerEventValues, getValueFromProps, } from '../_util/simply';
  3. import { ChecklistDefaultProps } from './props';
  4. import mixinValue from '../mixins/value';
  5. Component(ChecklistDefaultProps, {
  6. onChange: function (item) {
  7. var _a = getValueFromProps(this, [
  8. 'multiple',
  9. 'options',
  10. ]), multiple = _a[0], options = _a[1];
  11. var value;
  12. value = item.value;
  13. if (multiple) {
  14. var currentValue_1 = this.getValue();
  15. if (currentValue_1.indexOf(value) > -1) {
  16. currentValue_1 = currentValue_1.filter(function (v) { return v !== value; });
  17. }
  18. else {
  19. currentValue_1 = __spreadArray(__spreadArray([], currentValue_1, true), [value], false);
  20. }
  21. if (!this.isControlled()) {
  22. this.update(currentValue_1);
  23. }
  24. triggerEventValues(this, 'change', [
  25. currentValue_1,
  26. options.filter(function (v) { return currentValue_1.indexOf(v.value) > -1; }),
  27. ]);
  28. }
  29. else {
  30. if (!this.isControlled()) {
  31. this.update(value);
  32. }
  33. triggerEventValues(this, 'change', [
  34. value,
  35. options.find(function (v) { return v.value === value; }),
  36. ]);
  37. }
  38. },
  39. }, null, [
  40. mixinValue({
  41. transformValue: function (val) {
  42. var value = val || [];
  43. return {
  44. needUpdate: true,
  45. value: value,
  46. };
  47. },
  48. }),
  49. ]);