| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- <template>
- <!--布局容器-->
- <div class="container" style="width: 99%; margin-top: 0px">
- <!-- 新增 -->
- <el-button
- class="operation"
- type="primary"
- plain
- size="medium"
- @click="addAmount"
- >新增科目</el-button
- >
- <el-button
- class="operation"
- type="primary"
- plain
- size="medium"
- @click="setexpandAll"
- >全部展开/折叠</el-button
- >
- <!-- 表格 -->
- <el-table
- v-if="refTable"
- class="expendtable"
- :stripe="true"
- :default-expand-all="expandStatus"
- :header-cell-style="{
- background: '#F2F7FC',
- fontWeight: '900',
- color: '#606266',
- }"
- :data="tableData"
- style="width: 100%; margin-bottom: 20px; margin-top: 30px"
- row-key="expensesId"
- border
- :tree-props="{ children: 'child', hasChildren: 'hasChildren' }"
- >
- <el-table-column prop="category" align="left" width="300" label="类目">
- </el-table-column>
- <el-table-column prop="remark" align="center" label="备注">
- </el-table-column>
- <el-table-column align="center" label="操作">
- <template slot-scope="scope">
- <el-button
- size="mini"
- @click="handleTableEdit(scope.$index, scope.row)"
- >编辑</el-button
- >
- <el-button
- size="mini"
- type="danger"
- @click="handleDelete(scope.$index, scope.row)"
- >删除</el-button
- >
- <el-button
- size="mini"
- type="success"
- @click="addHandeFn(scope.$index, scope.row)"
- >新增子类</el-button
- >
- </template>
- </el-table-column>
- </el-table>
- <!-- 新增弹出框 -->
- <el-dialog
- class="dialog"
- :title="title"
- :close-on-click-modal="false"
- :before-close="handleClose"
- :visible.sync="dialogFormVisible"
- width="50%"
- >
- <el-form
- :model="formData"
- :rules="rules"
- ref="formData"
- label-width="120px"
- size="small"
- class="frame"
- >
- <el-row>
- <el-col :span="12">
- <el-form-item
- label="明细"
- :label-width="formLabelWidth"
- prop="category"
- >
- <el-input
- v-model="formData.category"
- autocomplete="off"
- ></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item
- label="备注"
- :label-width="formLabelWidth"
- prop="remark"
- >
- <el-input v-model="formData.remark" autocomplete="off"></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click="resetForm('formData')" size="small">取 消</el-button>
- <el-button type="primary" @click="submitForm('formData')" size="small"
- >确 定</el-button
- >
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import KtCommonTable from "@/views/Core/KtCommonTable.vue"; //表格组件
- import KtButton from "@/views/Core/KtButton"; // 按钮权限组件
- export default {
- name: "ExpenseMessage",
- components: { KtCommonTable, KtButton },
- created() {
- },
- mounted() {
- this.findPage();
- },
- data() {
- return {
- refTable:true,//表格重新渲染
- expandStatus: false, //是否全部展开
- title: "新增明细",
- tableData: [], //表格数据
- button3Name: "删除",
- button3Background: "rgb(222, 80, 76)",
- button2Background: "rgb(14, 194, 22)",
- button2Name: "新建子类",
- dialogFormVisible: false, //弹出框状态
- formLabelWidth: "120px",
- formData: {
- category: "", //明细
- remark: "", //备注
- },
- rules: {
- category: [
- { required: true, message: "明细不能为空", trigger: "blur" },
- ],
- },
- formDataId: "", //编辑id
- parentId: "", //新建子类父id
- };
- },
- watch: {
- dialogFormVisible(n) {
- if (!n) {
- this.handleClose();
- }
- },
- },
- methods: {
- setexpandAll() {
- this.expandStatus = !this.expandStatus;
- this.refTable = false;
- this.$nextTick(() => {
- this.refTable = true;
- });
- },
- //删除
- handleDelete(index, row) {
- let id = row.expensesId;
- this.$confirm("确认删除该记录吗?", "提示", {
- type: "warning",
- })
- .then(() => {
- this.$api.expense.deleteAccountExpenses(id).then((res) => {
- if (res.code == 200) {
- this.$message.success("删除成功");
- this.findPage();
- } else {
- this.$message.error(res.msg);
- }
- });
- })
- .catch(() => {});
- },
- //新建子类
- addHandeFn(index, row) {
- this.parentId = row.expensesId;
- this.dialogFormVisible = true;
- },
- //获取列表数据
- findPage(data) {
- this.$api.expense
- .getAccountExpensesTreeList()
- .then((res) => {
- this.tableData = res.data;
- })
- .then(data != null ? data.callback : "");
- },
- //新增事件
- addAmount() {
- this.title = "新增明细";
- this.dialogFormVisible = true;
- },
- //弹框取消
- handleClose() {
- this.formDataId = ""; //编辑id
- this.parentId = ""; //新建子类父id
- this.dialogFormVisible = false;
- this.$refs.formData.resetFields();
- },
- //新增取消重置
- resetForm(formData) {
- this.dialogFormVisible = false;
- this.$refs[formData].resetFields();
- },
- //修改
- handleTableEdit(index, row) {
- this.title = "编辑明细";
- this.formDataId = row.expensesId;
- this.$api.expense
- .getAccountExpensesDetail(this.formDataId)
- .then((res) => {
- if (res.code == 200) {
- this.formData = JSON.parse(JSON.stringify(res.data));
- } else {
- this.$message.error(res.msg);
- }
- });
- this.dialogFormVisible = true;
- },
- //提交
- submitForm(formData) {
- let params = JSON.parse(JSON.stringify(this.formData));
- if (this.parentId) {
- params.parentId = this.parentId;
- }
- this.$refs[formData].validate((valid) => {
- if (valid) {
- if (this.formDataId) {
- //修改
- this.$api.expense.updateAccountExpenses(params).then((res) => {
- if (res.code == 200) {
- this.$message({
- message: "编辑成功",
- type: "success",
- });
- } else {
- this.$message({
- message: `编辑失败, ${res.msg}`,
- type: "error",
- });
- }
- this.dialogFormVisible = false;
- this.findPage();
- });
- } else {
- //新增
- this.$api.expense.insertAccountExpenses(params).then((res) => {
- if (res.code == 200) {
- this.$message({
- message: "添加成功",
- type: "success",
- });
- } else {
- this.$message({
- message: `添加失败, ${res.msg}`,
- type: "error",
- });
- }
- this.dialogFormVisible = false;
- this.findPage();
- });
- }
- } else {
- return false;
- }
- });
- },
- },
- };
- </script>
-
- <style scoped>
- .operation {
- margin-left: 14px !important;
- margin-top: 15px !important ;
- }
- .form {
- display: flex;
- margin-top: 14px;
- align-items: center;
- margin-left: -12px;
- margin-bottom: 20px;
- }
- .el-pagination {
- font-weight: normal;
- }
- .el-card__body {
- padding: 12px !important;
- }
- .footer .footerdiv {
- display: flex;
- align-items: center;
- }
- .container .el-form-item {
- margin-bottom: -14px !important;
- }
- .form .el-form-item__label {
- font-size: 15px !important;
- font-weight: 600 !important;
- }
- .ktTable {
- margin-top: 20px;
- }
- .el-row {
- margin-top: 18px;
- }
- .top {
- margin-top: 0px;
- }
- .el-date-editor--daterange.el-input__inner {
- width: 300px;
- }
- /deep/ .el-select--small {
- width: 100%;
- }
- .frame {
- width: 100%;
- background-color: #fff;
- padding: 20px;
- -webkit-box-sizing: border-box;
- box-sizing: border-box;
- margin-bottom: 15px;
- border-radius: 6px;
- border: 1px solid #ebeef5;
- -webkit-transition: all 0.2s ease-in-out;
- transition: all 0.2s ease-in-out;
- -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
- box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
- }
- /deep/ .el-dialog__body {
- overflow-y: scroll;
- max-height: 500px;
- }
- .addremove-box {
- width: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- font-size: 25px;
- margin-top: 10px;
- }
- .addremove-box > i {
- cursor: pointer;
- }
- .frame >>> .el-date-editor {
- width: 100%;
- }
- .expendtable >>> .el-table__body-wrapper {
- overflow-y: auto;
- height: 600px;
- }
- </style>
-
|