index.js 1.7 KB

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