main.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div :class="b()">
  3. <el-steps :active="formIndex"
  4. :space="option.space"
  5. :simple="option.simple"
  6. :process-status="option.processStatus"
  7. :align-center='vaildData(option.alignCenter,true)'
  8. :direction="option.direction"
  9. :class="b({'steps':option.direction})">
  10. <el-step :title="item.label"
  11. :icon="item.icon"
  12. :status="vaildData(item.status,status[index])"
  13. :description="item.description"
  14. v-for="(item,index) in columnOption"
  15. :key="index"
  16. @click.native="option.switchBtn?switchs(index):''"></el-step>
  17. </el-steps>
  18. <div :class="b('contail')">
  19. <slot name="before"></slot>
  20. <avue-form :option="formOption"
  21. :class="b('form')"
  22. :style="{width:vaildData(formOption.width,'40%')}"
  23. @submit="submit"
  24. v-model="text">
  25. <template slot-scope="scope"
  26. v-for="item in formOption.column"
  27. :slot="item.prop">
  28. <slot :value="scope.value"
  29. :column="scope.column"
  30. :dic="scope.dic"
  31. :name="item.prop"
  32. v-if="item.formsolt"></slot>
  33. </template>
  34. <template slot="menuForm">
  35. <el-button @click="breaks"
  36. v-if="formIndex!=1&&formIndex!=columnLen&&vaildData(option.breakBtn,true)">返回</el-button>
  37. <slot name="menuForm"></slot>
  38. </template>
  39. </avue-form>
  40. <slot name="after"></slot>
  41. </div>
  42. </div>
  43. </template>
  44. <script>
  45. import create from '../../utils/create';
  46. import { formInitVal } from '../../utils/util';
  47. export default create({
  48. name: 'form-steps',
  49. props: {
  50. value: {
  51. type: Object,
  52. default: () => { }
  53. },
  54. option: {
  55. type: Object,
  56. required: true
  57. }
  58. },
  59. computed: {
  60. columnOption () {
  61. return this.option.column || [];
  62. },
  63. columnLen () {
  64. return this.columnOption.length;
  65. },
  66. formOption () {
  67. return this.objectOption.option;
  68. },
  69. objectOption () {
  70. return this.columnOption[this.formIndex - 1];
  71. },
  72. status () {
  73. let status = [];
  74. const leng = this.step - 1;
  75. for (let i = 0; i < leng; i++) {
  76. status.push(this.vaildData(this.option.finishStatus, 'success'));
  77. }
  78. return status;
  79. }
  80. },
  81. watch: {
  82. formOption () {
  83. this.formInit();
  84. this.$emit('change', this.objectOption);
  85. },
  86. text: {
  87. handler () {
  88. for (let o in this.tableForm) {
  89. this.tableForm[o] = this.text[o];
  90. }
  91. },
  92. deep: true
  93. },
  94. value: {
  95. handler () {
  96. this.formVal();
  97. },
  98. deep: true
  99. }
  100. },
  101. data () {
  102. return {
  103. step: 1,
  104. tableForm: {},
  105. text: {},
  106. formIndex: 1
  107. };
  108. },
  109. created () {
  110. this.formInit();
  111. },
  112. methods: {
  113. reset () {
  114. this.formIndex = 1;
  115. this.step = 1;
  116. },
  117. switchs (index) {
  118. if (index < this.step) { this.formIndex = index + 1; }
  119. },
  120. next () {
  121. if (this.step <= this.formIndex) {
  122. this.step++;
  123. }
  124. this.formIndex++;
  125. },
  126. breaks () {
  127. this.formIndex--;
  128. },
  129. formInit () {
  130. const column = this.formOption.column;
  131. this.tableForm = formInitVal(column).tableForm;
  132. this.formVal();
  133. },
  134. formVal () {
  135. for (let o in this.value) {
  136. this.text[o] = this.value[o];
  137. }
  138. for (let o in this.tableForm) {
  139. this.tableForm[o] = this.text[o];
  140. }
  141. this.$emit('input', this.tableForm);
  142. },
  143. submit () {
  144. this.$emit('submit', this.tableForm, this.next);
  145. }
  146. }
  147. });
  148. </script>