main.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <div class="b()">
  3. <el-tabs v-model="formIndex"
  4. :type="option.type"
  5. :tab-position="option.tabPosition">
  6. <el-tab-pane v-for="(item,index) in columnOption"
  7. :key="index"
  8. :disabled="item.disabled"
  9. :name="index+''">
  10. <span slot="label">
  11. <i :class="item.icon"></i> {{item.label}}</span>
  12. </el-tab-pane>
  13. </el-tabs>
  14. <div>
  15. <slot name="before"></slot>
  16. <avue-form :option="formOption"
  17. @submit="submit"
  18. v-model="text">
  19. <template slot-scope="scope"
  20. v-for="item in formColumnOption"
  21. :slot="item.prop">
  22. <slot :value="scope.value"
  23. :column="scope.column"
  24. :dic="scope.dic"
  25. :name="item.prop"
  26. v-if="item.formsolt"></slot>
  27. </template>
  28. <template slot="menuForm">
  29. <slot name="menuForm"></slot>
  30. </template>
  31. </avue-form>
  32. <slot name="after"></slot>
  33. </div>
  34. </div>
  35. </template>
  36. <script>
  37. import create from '../../utils/create';
  38. import { formInitVal } from '../../utils/util';
  39. export default create({
  40. name: 'form-tabs',
  41. props: {
  42. value: {
  43. type: Object,
  44. default: () => { }
  45. },
  46. option: {
  47. type: Object,
  48. required: true
  49. }
  50. },
  51. computed: {
  52. columnOption () {
  53. return this.option.column || [];
  54. },
  55. columnLen () {
  56. return this.columnOption.length;
  57. },
  58. formOption () {
  59. return this.objectOption.option;
  60. },
  61. formColumnOption () {
  62. return this.formOption.column || [];
  63. },
  64. objectOption () {
  65. return this.columnOption[this.formIndex];
  66. }
  67. },
  68. watch: {
  69. formOption () {
  70. this.formInit();
  71. this.$emit('change', this.columnOption[this.formIndex]);
  72. },
  73. text: {
  74. handler () {
  75. for (let o in this.tableForm) {
  76. this.tableForm[o] = this.text[o];
  77. }
  78. },
  79. deep: true
  80. },
  81. value: {
  82. handler () {
  83. this.formVal();
  84. },
  85. deep: true
  86. }
  87. },
  88. data () {
  89. return {
  90. tableForm: {},
  91. text: {},
  92. formIndex: '0'
  93. };
  94. },
  95. created () {
  96. this.formInit();
  97. },
  98. methods: {
  99. formInit () {
  100. const column = this.formOption.column;
  101. this.tableForm = formInitVal(column).tableForm;
  102. this.formVal();
  103. },
  104. formVal () {
  105. for (let o in this.value) {
  106. this.text[o] = this.value[o];
  107. }
  108. for (let o in this.tableForm) {
  109. this.tableForm[o] = this.text[o];
  110. }
  111. this.$emit('input', this.tableForm);
  112. },
  113. submit () {
  114. this.$emit('submit', this.tableForm);
  115. }
  116. }
  117. });
  118. </script>