index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. "use strict";
  2. var _component = require("../common/component");
  3. function emit(target, value) {
  4. target.$emit("input", value);
  5. target.$emit("change", value);
  6. }
  7. (0, _component.VantComponent)({
  8. field: true,
  9. relation: {
  10. name: "checkbox-group",
  11. type: "ancestor",
  12. current: "checkbox"
  13. },
  14. classes: ["icon-class", "label-class"],
  15. props: {
  16. value: Boolean,
  17. disabled: Boolean,
  18. useIconSlot: Boolean,
  19. checkedColor: String,
  20. labelPosition: String,
  21. labelDisabled: Boolean,
  22. shape: {
  23. type: String,
  24. value: "round"
  25. },
  26. iconSize: {
  27. type: null,
  28. value: 20
  29. }
  30. },
  31. data: {
  32. parentDisabled: false
  33. },
  34. methods: {
  35. emitChange: function emitChange(value) {
  36. if (this.parent) {
  37. this.setParentValue(this.parent, value);
  38. } else {
  39. emit(this, value);
  40. }
  41. },
  42. toggle: function toggle() {
  43. var _this$data = this.data,
  44. parentDisabled = _this$data.parentDisabled,
  45. disabled = _this$data.disabled,
  46. value = _this$data.value;
  47. if (!disabled && !parentDisabled) {
  48. this.emitChange(!value);
  49. }
  50. },
  51. onClickLabel: function onClickLabel() {
  52. var _this$data2 = this.data,
  53. labelDisabled = _this$data2.labelDisabled,
  54. parentDisabled = _this$data2.parentDisabled,
  55. disabled = _this$data2.disabled,
  56. value = _this$data2.value;
  57. if (!disabled && !labelDisabled && !parentDisabled) {
  58. this.emitChange(!value);
  59. }
  60. },
  61. setParentValue: function setParentValue(parent, value) {
  62. var parentValue = parent.data.value.slice();
  63. var name = this.data.name;
  64. var max = parent.data.max;
  65. if (value) {
  66. if (max && parentValue.length >= max) {
  67. return;
  68. }
  69. if (parentValue.indexOf(name) === -1) {
  70. parentValue.push(name);
  71. emit(parent, parentValue);
  72. }
  73. } else {
  74. var index = parentValue.indexOf(name);
  75. if (index !== -1) {
  76. parentValue.splice(index, 1);
  77. emit(parent, parentValue);
  78. }
  79. }
  80. }
  81. }
  82. });