comp-subject-setting.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <basic-container>
  3. <avue-crud
  4. v-bind="bindVal"
  5. v-on="onEvent"
  6. v-model="form"
  7. :page.sync="page"
  8. @on-load="getList"
  9. >
  10. <template slot="menuLeft">
  11. <!-- <el-button
  12. v-if="!isSelAnnual"
  13. type="danger"
  14. size="small"
  15. icon="el-icon-delete"
  16. plain
  17. @click="handleDelete"
  18. >
  19. 删 除
  20. </el-button> -->
  21. <el-button
  22. v-if="!isSelAnnual"
  23. type="success"
  24. size="small"
  25. plain
  26. icon="el-icon-upload2"
  27. @click="handleImport"
  28. >
  29. 导入
  30. </el-button>
  31. <el-button
  32. type="warning"
  33. size="small"
  34. plain
  35. icon="el-icon-download"
  36. @click="handleExport"
  37. >
  38. 导出
  39. </el-button>
  40. <print-table-btn @click="printTable" />
  41. </template>
  42. <template slot="body">
  43. <h3 class="page-title">{{ pageTitle }}</h3>
  44. </template>
  45. </avue-crud>
  46. <upload-excel-dialog ref="uploadExcelDialog" templateKey="企业会计科目设置" :uploadAfter="uploadAfter"/>
  47. <WideTablePrinter
  48. ref="printWideTable"
  49. :columns="wideTableColumns"
  50. :data="data"
  51. :print-title="pageTitle"
  52. :rows-per-page="30"
  53. :default-landscape="true"
  54. :zoom="80"
  55. />
  56. </basic-container>
  57. </template>
  58. <script>
  59. import { getList as getSubjectTreeList } from "@/api/basicResource/subjectSetting";
  60. import {exportBlob} from "@/api/common";
  61. import UploadExcelDialog from "@/components/upload-excel-dialog";
  62. import {getToken} from "@/util/auth";
  63. import {downloadXls} from "@/util/util";
  64. import { mapGetters } from "vuex";
  65. export default window.$crudCommon({
  66. components: {
  67. UploadExcelDialog,
  68. },
  69. data() {
  70. return {
  71. treeData: [],
  72. wideTableColumns: [],
  73. };
  74. },
  75. activated() {
  76. this.getMenuData();
  77. },
  78. computed: {
  79. ...mapGetters(['tag']),
  80. pageTitle() {
  81. return this.tag.label;
  82. }
  83. },
  84. methods: {
  85. loopData(data, level) {
  86. level++;
  87. return data.map(item => {
  88. item.level = level;
  89. item.disabled = level === 4 ? false : true;
  90. if (item.children && item.children.length) {
  91. this.loopData(item.children, level);
  92. }
  93. return item;
  94. });
  95. },
  96. getMenuData() {
  97. getSubjectTreeList().then(res => {
  98. this.loading = false;
  99. if (res.data.code == 200) {
  100. const column = this.findObject(this.option.column, "subjectId");
  101. column.dicData = this.loopData(JSON.parse(JSON.stringify(res.data.data)), 0);
  102. this.treeData = column.dicData;
  103. }
  104. })
  105. },
  106. handleImport() {
  107. this.$refs.uploadExcelDialog.open('/api/kd-scientific/subject/enterprise/import');
  108. },
  109. uploadAfter() {
  110. this.page.currentPage = 1;
  111. this.getList(this.page);
  112. },
  113. handleExport() {
  114. exportBlob(`/api/kd-scientific/subject/enterprise/export?${this.website.tokenHeader}=${getToken()}`, this.params).then(res => {
  115. downloadXls(res.data, `${this.pageTitle}.xlsx`);
  116. });
  117. },
  118. /**
  119. * 打印表格
  120. * @param isLandscape 是否横向打印
  121. */
  122. printTable(isLandscape) {
  123. this.wideTableColumns = this.printOption.column;
  124. this.$nextTick(() => {
  125. this.$refs.printWideTable.printTable(isLandscape);
  126. })
  127. },
  128. findParentNames(categories, childId, parentNames = []) {
  129. const child = categories.find(cat => cat.id == childId);
  130. if (!child || !child.parentId) {
  131. return parentNames;
  132. }
  133. const parent = categories.find(cat => cat.id == child.parentId);
  134. if (parent) {
  135. parentNames.unshift(parent.name); // 添加到数组开头保持顺序
  136. return this.findParentNames(categories, parent.id, parentNames);
  137. }
  138. return parentNames;
  139. },
  140. getFormData() {
  141. let newList = [];
  142. const getAllList = data => {
  143. data.forEach(element => {
  144. newList.push(element);
  145. if (element.children && element.children.length) {
  146. getAllList(element.children)
  147. }
  148. });
  149. }
  150. getAllList(this.treeData);
  151. let parentNames = this.findParentNames(newList, this.form.subjectId);
  152. return { ...this.form, subjectName: `${parentNames.join('\\')}\\${this.form.$subjectId}` };
  153. },
  154. },
  155. }, {
  156. // 模块路径
  157. name: 'basicResource/compSubjectSetting',
  158. res: ({ data }) => {
  159. data.records = data.records.map(item => {
  160. item.rdSubject = item.rdSubjectEnable === 1 ? item.subjectName : '';
  161. item.adSubject = item.adSubjectEnable === 1 ? item.subjectName : '';
  162. return item;
  163. });
  164. return data;
  165. },
  166. });
  167. </script>