subject-setting.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. v-model="form"
  5. :option="option"
  6. :data="data"
  7. ref="crud"
  8. @row-save="rowSave"
  9. @row-update="rowUpdate"
  10. @row-del="rowDel"
  11. >
  12. <template slot="icon" slot-scope="scope">
  13. <i :class="scope.row.icon" style="font-size: 24px"></i>
  14. </template>
  15. <template slot="menu" slot-scope="{ row, size, type }">
  16. <el-button :size="size" :type="type" @click="handleAdd(row)">
  17. 新增子级
  18. </el-button>
  19. </template>
  20. </avue-crud>
  21. </basic-container>
  22. </template>
  23. <script>
  24. import { getList } from "@/api/basicResource/subjectSetting";
  25. export default {
  26. data() {
  27. return {
  28. parentId: undefined,
  29. form: {},
  30. data: [],
  31. option: {
  32. height: "auto",
  33. calcHeight: 30,
  34. tip: false,
  35. searchShow: true,
  36. searchMenuSpan: 6,
  37. border: true,
  38. searchLabelWidth: 140,
  39. labelWidth: 140,
  40. menuWidth: 290,
  41. dialogClickModal: false,
  42. dialogWidth: 500,
  43. dialogType: "drawer",
  44. rowKey: "id",
  45. rowParentKey: "parentId",
  46. defaultExpandAll: true,
  47. tree: true,
  48. column: [
  49. {
  50. label: "科目代码",
  51. prop: "code",
  52. type: "input",
  53. span: 24,
  54. search: true,
  55. width: 200,
  56. showOverflowTooltip: true,
  57. rules: [
  58. {
  59. required: true,
  60. message: "请输入科目代码",
  61. trigger: "blur",
  62. },
  63. ],
  64. },
  65. {
  66. label: "科目名称",
  67. prop: "name",
  68. type: "input",
  69. span: 24,
  70. minWidth: 160,
  71. search: true,
  72. showOverflowTooltip: true,
  73. rules: [
  74. {
  75. required: true,
  76. message: "请输入科目名称",
  77. trigger: "blur",
  78. },
  79. ],
  80. },
  81. {
  82. label: "会计科目",
  83. prop: "accSubject",
  84. type: "input",
  85. span: 24,
  86. minWidth: 160,
  87. search: true,
  88. showOverflowTooltip: true,
  89. },
  90. {
  91. label: "高新研发费用科目",
  92. prop: "rdSubject",
  93. type: "input",
  94. span: 24,
  95. minWidth: 160,
  96. search: true,
  97. showOverflowTooltip: true,
  98. },
  99. {
  100. label: "加计扣除研发费用科目",
  101. prop: "adSubject",
  102. type: "input",
  103. span: 24,
  104. minWidth: 160,
  105. search: true,
  106. showOverflowTooltip: true,
  107. },
  108. ],
  109. },
  110. };
  111. },
  112. mounted() {
  113. this.loadData();
  114. },
  115. methods: {
  116. loadData() {
  117. getList().then(res => {
  118. console.log(res)
  119. if (res.data.code == 200) {
  120. const loopData = data => {
  121. return data.map(item => {
  122. item.hasChildren = item.children && item.children.length ? false : true;
  123. if (item.children && item.children.length) {
  124. loopData(item.children);
  125. }
  126. return item;
  127. });
  128. }
  129. this.data = loopData(res.data.data);
  130. console.log(this.data)
  131. // this.data = res.data.data.map(item => {
  132. // item.children = item.children || [];
  133. // delete item.hasChildren;
  134. // return item;
  135. // });
  136. // console.log(this.data)
  137. }
  138. })
  139. },
  140. rowDel(row, index, done) {
  141. done(row);
  142. },
  143. rowSave(row, done) {
  144. row.parentId = this.parentId;
  145. row.id = new Date().getTime();
  146. this.parentId = undefined;
  147. done(row);
  148. },
  149. rowUpdate(row, index, done) {
  150. done(row);
  151. },
  152. handleAdd(row) {
  153. this.parentId = row.id;
  154. this.$refs.crud.rowAdd();
  155. },
  156. },
  157. };
  158. </script>