| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367 |
- <template>
- <basic-container>
- <avue-crud
- v-model="form"
- :option="option"
- :data="data"
- :table-loading="loading"
- ref="crud"
- @search-change="searchChange"
- @search-reset="searchReset"
- @row-save="rowSave"
- @row-update="rowUpdate"
- >
- <template slot="menuLeft">
- <el-button
- type="warning"
- size="small"
- plain
- icon="el-icon-download"
- @click="handleExport"
- >
- 导出
- </el-button>
- </template>
- <template slot="icon" slot-scope="scope">
- <i :class="scope.row.icon" style="font-size: 24px"></i>
- </template>
- <template slot="menu" slot-scope="{ row, size, type }">
- <el-button v-if="row.level === 3" :size="size" :type="type" icon="el-icon-plus" @click="handleAdd(row)">
- 新增子级
- </el-button>
- <el-button v-if="row.type === 0" :size="size" :type="type" icon="el-icon-edit" @click="handleEdit(row)">
- 编辑
- </el-button>
- <el-button v-if="row.type === 0" :size="size" :type="type" icon="el-icon-delete" @click="rowDel(row)">
- 删除
- </el-button>
- </template>
- <template slot="body">
- <h3 class="page-title">{{ tag.label }}</h3>
- </template>
- </avue-crud>
- </basic-container>
- </template>
- <script>
- import { getList, add, update, remove } from "@/api/basicResource/subjectSetting";
- import {exportBloByPost} from "@/api/common";
- import {getToken} from "@/util/auth";
- import {downloadXls} from "@/util/util";
- import { mapGetters } from "vuex";
- export default {
- data() {
- return {
- loading: false,
- parentId: undefined,
- form: {},
- data: [],
- query: {},
- option: {
- height: "auto",
- calcHeight: 30,
- tip: false,
- searchShow: true,
- searchMenuSpan: 6,
- index: true,
- border: true,
- searchLabelWidth: 140,
- labelWidth: 160,
- menuWidth: 130,
- dialogClickModal: false,
- dialogWidth: 500,
- dialogType: "drawer",
- rowKey: "id",
- rowParentKey: "parentId",
- defaultExpandAll: true,
- tree: true,
- addBtn: false,
- editBtn: false,
- delBtn: false,
- refreshBtn: false,
- gridBtn: false,
- columnBtn: false,
- searchShowBtn: false,
- column: [
- {
- label: "上级科目",
- prop: "parentId",
- type: "tree",
- dicData: [],
- span: 24,
- hide: true,
- disabled: true,
- props: {
- value: "id",
- label: "name"
- },
- rules: [
- {
- required: false,
- message: "请选择上级菜单",
- trigger: "click"
- }
- ]
- },
- {
- label: "科目名称",
- prop: "name",
- type: "input",
- span: 24,
- minWidth: 160,
- search: true,
- showOverflowTooltip: true,
- rules: [
- {
- required: true,
- message: "请输入科目名称",
- trigger: "blur",
- },
- ],
- },
- {
- label: "科目代码",
- prop: "code",
- type: "input",
- span: 24,
- search: true,
- width: 120,
- align: 'center',
- display: false,
- showOverflowTooltip: true,
- rules: [
- {
- required: true,
- message: "请输入科目代码",
- trigger: "blur",
- },
- ],
- },
- {
- label: "会计科目",
- prop: "accSubject",
- type: "textarea",
- span: 24,
- minWidth: 160,
- display: false,
- showOverflowTooltip: true,
- },
- {
- label: "高新研发费用科目",
- prop: "rdSubject",
- type: "textarea",
- span: 24,
- minWidth: 160,
- display: false,
- showOverflowTooltip: true,
- },
- {
- label: "高新研发费用科目",
- prop: "rdSubjectEnable",
- type: "radio",
- dicData:[{
- label: '是',
- value: 1
- },{
- label: '否',
- value: 0
- }],
- hide: true,
- span: 24,
- showOverflowTooltip: true,
- },
- {
- label: "加计扣除研发费用科目",
- prop: "adSubjectEnable",
- type: "radio",
- dicData:[{
- label: '是',
- value: 1
- },{
- label: '否',
- value: 0
- }],
- hide: true,
- span: 24,
- showOverflowTooltip: true,
- },
- {
- label: "加计扣除研发费用科目",
- prop: "adSubject",
- type: "textarea",
- span: 24,
- minWidth: 160,
- display: false,
- showOverflowTooltip: true,
- },
- {
- label: "辅助核算",
- prop: "fzhs",
- span: 24,
- width: 100,
- display: false,
- showOverflowTooltip: true,
- },
- ],
- },
- };
- },
- computed: {
- ...mapGetters(['tag'])
- },
- mounted() {
- this.loadData();
- this.getMenuData();
- },
- methods: {
- handleExport() {
- exportBloByPost(`/api/kd-scientific/subject/export?${this.website.tokenHeader}=${getToken()}`, this.query).then(res => {
- downloadXls(res.data, `${this.tag.label}.xlsx`);
- });
- },
- loopData(data, level, maxLevel) {
- level++;
- return data.map(item => {
- item.level = level;
- item.disabled = level === 4 ? true : false;
- item.hasChildren = item.children && item.children.length ? false : true;
- if (item.level === 4) {
- item.rdSubject = item.rdSubjectEnable === 1 ? item.accSubject : '';
- item.adSubject = item.adSubjectEnable === 1 ? item.accSubject : '';
- }
- if (maxLevel) {
- if (level >= maxLevel) {
- delete item.children;
- } else {
- this.loopData(item.children || [], level, maxLevel);
- }
- } else {
- this.loopData(item.children || [], level);
- }
- return item;
- });
- },
- getMenuData() {
- getList().then(res => {
- this.loading = false;
- if (res.data.code == 200) {
- const column = this.findObject(this.option.column, "parentId");
- column.dicData = this.loopData(JSON.parse(JSON.stringify(res.data.data)), 0, 3);
- }
- })
- },
- loadData(params) {
- this.loading = true;
- getList(params).then(res => {
- this.loading = false;
- if (res.data.code == 200) {
- this.data = this.loopData(res.data.data, 0);
- }
- })
- },
- searchReset() {
- this.query = {};
- this.parentId = 0;
- this.loadData();
- },
- searchChange(params, done) {
- this.query = params;
- this.parentId = '';
- this.loadData(params);
- done();
- },
- rowDel(row) {
- this.$confirm('确定将选择数据删除?', '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- remove(row.id).then(({ data }) => {
- if (data.code == 200) {
- this.$message.success("删除成功!");
- this.loadData();
- }
- });
- })
- },
- findParentNames(categories, childId, parentNames = []) {
- const child = categories.find(cat => cat.id == childId);
-
- if (!child || !child.parentId) {
- return parentNames;
- }
-
- const parent = categories.find(cat => cat.id == child.parentId);
- if (parent) {
- parentNames.unshift(parent.name); // 添加到数组开头保持顺序
- return this.findParentNames(categories, parent.id, parentNames);
- }
-
- return parentNames;
- },
- getFormData(row) {
- const params = { ...row };
- let parentNames = [];
- if (params.parentId) {
- let newList = [];
- const getAllList = data => {
- data.forEach(element => {
- newList.push(element);
- if (element.children && element.children.length) {
- getAllList(element.children)
- }
- });
- }
- getAllList(this.data);
- parentNames = this.findParentNames(newList, params.parentId);
- let currParent = newList.find(item => item.id == params.parentId);
- if (!!currParent) {
- parentNames.push(currParent.name);
- }
- }
-
- return { ...params, accSubject: parentNames.length ? `${parentNames.join('\\')}\\${params.name}` : params.name }
- },
- rowSave(row, done) {
- const params = this.getFormData(row);
- add(params).then(({ data }) => {
- done();
- if (data.code == 200) {
- this.$message.success("新增成功!");
- this.loadData();
- }
- }).catch(() => {
- done();
- })
- },
- handleEdit(row) {
- this.$refs.crud.rowEdit(row);
- },
- rowUpdate(row, index, done) {
- const params = this.getFormData(row);
- update(params).then(({ data }) => {
- done();
- if (data.code == 200) {
- this.$message.success("修改成功!");
- this.loadData();
- }
- }).catch(() => {
- done();
- })
- },
- handleAdd(row) {
- this.parentId = row.id;
- const column = this.findObject(this.option.column, "parentId");
- column.value = row.id;
- this.form.parentId = row.id;
- column.addDisabled = true;
- this.$refs.crud.rowAdd();
- },
- },
- };
- </script>
|