ExpenseMessage.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. <template>
  2. <!--布局容器-->
  3. <div class="container" style="width: 99%; margin-top: 0px">
  4. <!-- 新增 -->
  5. <el-button
  6. class="operation"
  7. type="primary"
  8. plain
  9. size="medium"
  10. @click="addAmount"
  11. >新增科目</el-button
  12. >
  13. <el-button
  14. class="operation"
  15. type="primary"
  16. plain
  17. size="medium"
  18. @click="setexpandAll"
  19. >全部展开/折叠</el-button
  20. >
  21. <!-- 表格 -->
  22. <el-table
  23. v-if="refTable"
  24. class="expendtable"
  25. :stripe="true"
  26. :default-expand-all="expandStatus"
  27. :header-cell-style="{
  28. background: '#F2F7FC',
  29. fontWeight: '900',
  30. color: '#606266',
  31. }"
  32. :data="tableData"
  33. style="width: 100%; margin-bottom: 20px; margin-top: 30px"
  34. row-key="expensesId"
  35. border
  36. :tree-props="{ children: 'child', hasChildren: 'hasChildren' }"
  37. >
  38. <el-table-column prop="category" align="left" width="300" label="类目">
  39. </el-table-column>
  40. <el-table-column prop="remark" align="center" label="备注">
  41. </el-table-column>
  42. <el-table-column align="center" label="操作">
  43. <template slot-scope="scope">
  44. <el-button
  45. size="mini"
  46. @click="handleTableEdit(scope.$index, scope.row)"
  47. >编辑</el-button
  48. >
  49. <el-button
  50. size="mini"
  51. type="danger"
  52. @click="handleDelete(scope.$index, scope.row)"
  53. >删除</el-button
  54. >
  55. <el-button
  56. size="mini"
  57. type="success"
  58. @click="addHandeFn(scope.$index, scope.row)"
  59. >新增子类</el-button
  60. >
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <!-- 新增弹出框 -->
  65. <el-dialog
  66. class="dialog"
  67. :title="title"
  68. :close-on-click-modal="false"
  69. :before-close="handleClose"
  70. :visible.sync="dialogFormVisible"
  71. width="50%"
  72. >
  73. <el-form
  74. :model="formData"
  75. :rules="rules"
  76. ref="formData"
  77. label-width="120px"
  78. size="small"
  79. class="frame"
  80. >
  81. <el-row>
  82. <el-col :span="12">
  83. <el-form-item
  84. label="明细"
  85. :label-width="formLabelWidth"
  86. prop="category"
  87. >
  88. <el-input
  89. v-model="formData.category"
  90. autocomplete="off"
  91. ></el-input>
  92. </el-form-item>
  93. </el-col>
  94. <el-col :span="12">
  95. <el-form-item
  96. label="备注"
  97. :label-width="formLabelWidth"
  98. prop="remark"
  99. >
  100. <el-input v-model="formData.remark" autocomplete="off"></el-input>
  101. </el-form-item>
  102. </el-col>
  103. </el-row>
  104. </el-form>
  105. <div slot="footer" class="dialog-footer">
  106. <el-button @click="resetForm('formData')" size="small">取 消</el-button>
  107. <el-button type="primary" @click="submitForm('formData')" size="small"
  108. >确 定</el-button
  109. >
  110. </div>
  111. </el-dialog>
  112. </div>
  113. </template>
  114. <script>
  115. import KtCommonTable from "@/views/Core/KtCommonTable.vue"; //表格组件
  116. import KtButton from "@/views/Core/KtButton"; // 按钮权限组件
  117. export default {
  118. name: "ExpenseMessage",
  119. components: { KtCommonTable, KtButton },
  120. created() {
  121. },
  122. mounted() {
  123. this.findPage();
  124. },
  125. data() {
  126. return {
  127. refTable:true,//表格重新渲染
  128. expandStatus: false, //是否全部展开
  129. title: "新增明细",
  130. tableData: [], //表格数据
  131. button3Name: "删除",
  132. button3Background: "rgb(222, 80, 76)",
  133. button2Background: "rgb(14, 194, 22)",
  134. button2Name: "新建子类",
  135. dialogFormVisible: false, //弹出框状态
  136. formLabelWidth: "120px",
  137. formData: {
  138. category: "", //明细
  139. remark: "", //备注
  140. },
  141. rules: {
  142. category: [
  143. { required: true, message: "明细不能为空", trigger: "blur" },
  144. ],
  145. },
  146. formDataId: "", //编辑id
  147. parentId: "", //新建子类父id
  148. };
  149. },
  150. watch: {
  151. dialogFormVisible(n) {
  152. if (!n) {
  153. this.handleClose();
  154. }
  155. },
  156. },
  157. methods: {
  158. setexpandAll() {
  159. this.expandStatus = !this.expandStatus;
  160. this.refTable = false;
  161. this.$nextTick(() => {
  162. this.refTable = true;
  163. });
  164. },
  165. //删除
  166. handleDelete(index, row) {
  167. let id = row.expensesId;
  168. this.$confirm("确认删除该记录吗?", "提示", {
  169. type: "warning",
  170. })
  171. .then(() => {
  172. this.$api.expense.deleteAccountExpenses(id).then((res) => {
  173. if (res.code == 200) {
  174. this.$message.success("删除成功");
  175. this.findPage();
  176. } else {
  177. this.$message.error(res.msg);
  178. }
  179. });
  180. })
  181. .catch(() => {});
  182. },
  183. //新建子类
  184. addHandeFn(index, row) {
  185. this.parentId = row.expensesId;
  186. this.dialogFormVisible = true;
  187. },
  188. //获取列表数据
  189. findPage(data) {
  190. this.$api.expense
  191. .getAccountExpensesTreeList()
  192. .then((res) => {
  193. this.tableData = res.data;
  194. })
  195. .then(data != null ? data.callback : "");
  196. },
  197. //新增事件
  198. addAmount() {
  199. this.title = "新增明细";
  200. this.dialogFormVisible = true;
  201. },
  202. //弹框取消
  203. handleClose() {
  204. this.formDataId = ""; //编辑id
  205. this.parentId = ""; //新建子类父id
  206. this.dialogFormVisible = false;
  207. this.$refs.formData.resetFields();
  208. },
  209. //新增取消重置
  210. resetForm(formData) {
  211. this.dialogFormVisible = false;
  212. this.$refs[formData].resetFields();
  213. },
  214. //修改
  215. handleTableEdit(index, row) {
  216. this.title = "编辑明细";
  217. this.formDataId = row.expensesId;
  218. this.$api.expense
  219. .getAccountExpensesDetail(this.formDataId)
  220. .then((res) => {
  221. if (res.code == 200) {
  222. this.formData = JSON.parse(JSON.stringify(res.data));
  223. } else {
  224. this.$message.error(res.msg);
  225. }
  226. });
  227. this.dialogFormVisible = true;
  228. },
  229. //提交
  230. submitForm(formData) {
  231. let params = JSON.parse(JSON.stringify(this.formData));
  232. if (this.parentId) {
  233. params.parentId = this.parentId;
  234. }
  235. this.$refs[formData].validate((valid) => {
  236. if (valid) {
  237. if (this.formDataId) {
  238. //修改
  239. this.$api.expense.updateAccountExpenses(params).then((res) => {
  240. if (res.code == 200) {
  241. this.$message({
  242. message: "编辑成功",
  243. type: "success",
  244. });
  245. } else {
  246. this.$message({
  247. message: `编辑失败, ${res.msg}`,
  248. type: "error",
  249. });
  250. }
  251. this.dialogFormVisible = false;
  252. this.findPage();
  253. });
  254. } else {
  255. //新增
  256. this.$api.expense.insertAccountExpenses(params).then((res) => {
  257. if (res.code == 200) {
  258. this.$message({
  259. message: "添加成功",
  260. type: "success",
  261. });
  262. } else {
  263. this.$message({
  264. message: `添加失败, ${res.msg}`,
  265. type: "error",
  266. });
  267. }
  268. this.dialogFormVisible = false;
  269. this.findPage();
  270. });
  271. }
  272. } else {
  273. return false;
  274. }
  275. });
  276. },
  277. },
  278. };
  279. </script>
  280. <style scoped>
  281. .operation {
  282. margin-left: 14px !important;
  283. margin-top: 15px !important ;
  284. }
  285. .form {
  286. display: flex;
  287. margin-top: 14px;
  288. align-items: center;
  289. margin-left: -12px;
  290. margin-bottom: 20px;
  291. }
  292. .el-pagination {
  293. font-weight: normal;
  294. }
  295. .el-card__body {
  296. padding: 12px !important;
  297. }
  298. .footer .footerdiv {
  299. display: flex;
  300. align-items: center;
  301. }
  302. .container .el-form-item {
  303. margin-bottom: -14px !important;
  304. }
  305. .form .el-form-item__label {
  306. font-size: 15px !important;
  307. font-weight: 600 !important;
  308. }
  309. .ktTable {
  310. margin-top: 20px;
  311. }
  312. .el-row {
  313. margin-top: 18px;
  314. }
  315. .top {
  316. margin-top: 0px;
  317. }
  318. .el-date-editor--daterange.el-input__inner {
  319. width: 300px;
  320. }
  321. /deep/ .el-select--small {
  322. width: 100%;
  323. }
  324. .frame {
  325. width: 100%;
  326. background-color: #fff;
  327. padding: 20px;
  328. -webkit-box-sizing: border-box;
  329. box-sizing: border-box;
  330. margin-bottom: 15px;
  331. border-radius: 6px;
  332. border: 1px solid #ebeef5;
  333. -webkit-transition: all 0.2s ease-in-out;
  334. transition: all 0.2s ease-in-out;
  335. -webkit-box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  336. box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  337. }
  338. /deep/ .el-dialog__body {
  339. overflow-y: scroll;
  340. max-height: 500px;
  341. }
  342. .addremove-box {
  343. width: 100%;
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. font-size: 25px;
  348. margin-top: 10px;
  349. }
  350. .addremove-box > i {
  351. cursor: pointer;
  352. }
  353. .frame >>> .el-date-editor {
  354. width: 100%;
  355. }
  356. .expendtable >>> .el-table__body-wrapper {
  357. overflow-y: auto;
  358. height: 600px;
  359. }
  360. </style>