selectInputList.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <!--
  2. * @Description: 多列选择 用于选择并且需要输入的表单
  3. * @Author: kcz
  4. * @Date: 2020-03-27 18:36:56
  5. * @LastEditors: kcz
  6. * @LastEditTime: 2021-05-16 11:03:45
  7. -->
  8. <template>
  9. <a-form-model
  10. class="select-input-list-box"
  11. ref="dynamicValidateForm"
  12. layout="inline"
  13. :model="dynamicValidateForm"
  14. >
  15. <div v-for="(column, i) in record.columns" :key="i">
  16. <a-form-model-item>
  17. <a-checkbox
  18. v-if="record.options.multiple"
  19. @change="onCheckboxChange($event, i)"
  20. :checked="dynamicValidateForm.domains[i].checked"
  21. >
  22. {{ column.label }}
  23. </a-checkbox>
  24. <a-radio
  25. v-else
  26. @change="onRadioChange($event, i)"
  27. :checked="dynamicValidateForm.domains[i].checked"
  28. >{{ column.label }}</a-radio
  29. >
  30. </a-form-model-item>
  31. <span v-for="(item, index) in column.list" :key="index">
  32. <KFormModelItem
  33. :key="item.key + '1'"
  34. :record="item"
  35. :config="config"
  36. :parentDisabled="disabled"
  37. :domains="dynamicValidateForm.domains[i]"
  38. :dynamicData="dynamicData"
  39. v-model="dynamicValidateForm.domains[i][item.model]"
  40. @input="handleInput"
  41. />
  42. </span>
  43. </div>
  44. </a-form-model>
  45. </template>
  46. <script>
  47. import KFormModelItem from "./module/KFormModelItem";
  48. export default {
  49. name: "KBatch",
  50. props: ["record", "value", "dynamicData", "config", "parentDisabled"],
  51. components: {
  52. KFormModelItem
  53. },
  54. watch: {
  55. value: {
  56. // value 需要深度监听及默认先执行handler函数
  57. handler(val) {
  58. const initValue = val || [];
  59. if (!initValue.length) {
  60. this.record.columns.forEach(item => {
  61. const itemData = {};
  62. item.list.forEach(e => e.model && (itemData[e.model] = null));
  63. itemData.checked = false;
  64. itemData.value = item.value;
  65. itemData.label = item.label;
  66. initValue.push(itemData);
  67. });
  68. }
  69. this.dynamicValidateForm.domains = initValue;
  70. },
  71. immediate: true,
  72. deep: true
  73. }
  74. },
  75. data() {
  76. return {
  77. dynamicValidateForm: {
  78. domains: []
  79. }
  80. };
  81. },
  82. computed: {
  83. disabled() {
  84. return this.record.options.disabled || this.parentDisabled;
  85. }
  86. },
  87. methods: {
  88. validationSubform() {
  89. let verification;
  90. this.$refs.dynamicValidateForm.validate(valid => {
  91. verification = valid;
  92. });
  93. return verification;
  94. },
  95. resetForm() {
  96. this.$refs.dynamicValidateForm.resetFields();
  97. },
  98. onCheckboxChange(e, index) {
  99. this.dynamicValidateForm.domains[index].checked = e.target.checked;
  100. this.handleInput();
  101. },
  102. onRadioChange(e, index) {
  103. this.dynamicValidateForm.domains.forEach(item => (item.checked = false));
  104. this.dynamicValidateForm.domains[index].checked = e.target.checked;
  105. this.handleInput();
  106. },
  107. handleInput() {
  108. this.$emit("change", this.dynamicValidateForm.domains);
  109. }
  110. },
  111. mounted() {
  112. this.handleInput();
  113. }
  114. };
  115. </script>