Ant Design Vue 樹形表格計算盈收金額

樹形表格計算

    • 一、盈收金額計算
      • 1、根據需要輸入的子級位置,修改數據
      • 2、獲取兄弟節點數據,并計算兄弟節點的金額合計
      • 3、金額合計,遍歷給所有的父級

一、盈收金額計算

1、根據需要輸入的子級位置,修改數據

2、獲取兄弟節點數據,并計算兄弟節點的金額合計

3、金額合計,遍歷給所有的父級

<template><a-modal :title="titleMap[mode]" :visible="visible" :destroyOnClose="true" :maskClosable="false" @cancel="handleCancel"width="95%"><a-spin :spinning="spinning" tip="加載中..."><a-table :columns="columns" bordered :data-source="newSource" :scroll="{ x: 800, y: 500 }" :pagination="false":rowKey="(record, index) => { return record.projectId }" :defaultExpandAllRows="true"v-if="newSource.length"><template slot="promote" slot-scope="text,record"><span>{{ rateCompute(record.preActual, record.budget) }}</span></template><template slot="budget" slot-scope="text,record"><div class="editable-cell"><div v-if="editable" class="editable-cell-input-wrapper"><div v-if="editableData[record.projectId]"><a-input v-model="editableData[record.projectId]['budget']"@pressEnter="save(editableData[record.projectId])" type="number"@change="e => e.target.value = e.target.value.replace(/^0+(\d)|[^\d]+/g, '')" /><a-icon type="check" @click="save(editableData[record.projectId])"style="margin-right: 20px;" /><a-popconfirm title="確定取消?" @confirm="cancel(record.projectId)"><a-icon type="close" /></a-popconfirm></div><div v-else>{{ text }}</div></div><div v-else class="editable-cell-text-wrapper"><div v-if="record.children == null">{{ text || ' ' }}<a-icon type="edit" @click="edit(record)" /></div><div v-else>{{ text || ' ' }}</div></div></div></template></a-table></a-spin><template slot="footer"><a-button key="back" @click="handleCancel">關閉</a-button><a-button type="primary" :visible="visibleBtn" :loading="loadingBtn" @click="handleSubmit">保存</a-button></template></a-modal>
</template>

JS

import { cloneDeep } from 'lodash-es';
export default {data() {return {visible: false,dataSource: [],newSource: [], //變化的源數據spinning: true,columns: [],//頭部表單editableData: {},// 修改的位置數據editable: false, //是否編輯visibleBtn: false,loadingBtn: false,mode: "add",titleMap: {add: '新增',edit: '修改'},}},methods: {//計算比率// 本月比上月情況=(本月數字-上月數字)/上月數字,如果本月大于上月,結果就是正數,即上升,反之為下降rateCompute(a, b) {if (a > 0 && b > 0) {if (a < b) return ((((b - a) / a) * 100).toFixed(2)) + '%'else if (b < a) '-' + ((((b - a) / a) * 100).toFixed(2)) + '%'else return '0%'} else {if (a == 0 && b > a) return '100%'else return '0%'}},edit(row) {this.editable = truethis.editableData[row.projectId] = cloneDeep(row)},save(row) {this.editable = falsethis.calculate(row)},// 計算calculate(row) {//計算時,需要同步執行	this.fun1(row)delete this.editableData[row.projectId];},fun1(row) {if (row.inOrOut == 2) {if(Number(row.budget) > 0){this.getObj(this.newSource, row.projectId, Number('-' + row.budget), row, callback)}else{this.getObj(this.newSource, row.projectId, Number(row.budget), row, callback)}} else {this.getObj(this.newSource, row.projectId, Number(row.budget), row, callback)}// 使用回調,同步執行下面的方法function callback(isFind, _this, row) {if (isFind) {_this.fun2(row)}}},fun2(row) {// 獲取兄弟節點的父級idlet brotherParentId = row.parentProjectId// 獲取兄弟節點數據let brotherParentArr = this.getBrotherParentId(this.newSource, brotherParentId)console.log(brotherParentArr)if (brotherParentArr.length > 0) {// 兄弟數組的和  相差值let ParentVal = brotherParentArr.reduce((accumulator, currentValue) => Number(accumulator) + Number(currentValue));if (ParentVal) {this.fun3(row, ParentVal)}}},fun3(row, ParentVal) {// 相關連的數據包括原來未改變的初始值let joinedArr = this.get_level_all(this.dataSource, row.projectId).filter(item => item.projectId != row.projectId)let _this = this// 相差值if (joinedArr.length > 0) {joinedArr.forEach((item) => {_this.getParentId(_this.newSource, item.projectId, Number(ParentVal))});}},// 根據id ,找到當前元素的對象,并進行賦值getObj(data, id, val, row, callback) {let isFind = falsedata.find((item) => {if (item.projectId === id) {if (val == 0) item.budget = '0'else item.budget = Number(val)item.promote = this.rateCompute(Number(item.preActual), Number(item.budget))isFind = true} else if (item.children != null && item.children.length > 0) {this.getObj(item.children, id, val, row, callback);}});if (isFind) {callback(isFind, this, row)return isFind}},// 根據id,找到所有的上級idget_level_all(data, id, arr = []) {data.find((item) => {if (item.projectId === id) {arr.push(item);return true;} else if (item.children != null && item.children.length > 0) {arr = this.get_level_all(item.children, id, arr);if (arr.length) {arr.push(item);return true;} else {return false;}}return false;});return arr;},// 根據id,找到所有的同級數據getBrotherParentId(data, id, arr = []) {data.find((item) => {if (item.parentProjectId == id) {// 收支類型,1:收入,2:支出,3:其它// 支出:減if(item.inOrOut == '2'){if(Number(item.budget)>0){arr.push((item.inOrOut == '2' ? Number(('-' + item.budget)) : Number(item.budget)));}else{arr.push(Number(item.budget));}}else{arr.push(Number(item.budget));}} else if (item.children != null && item.children.length > 0) {this.getBrotherParentId(item.children, id, arr);}});return arr;},// 根據相差值遍歷相關的父級或祖級getParentId(arr, id, numDiffer) {arr.forEach(item => {if (item.projectId == id) {item.budget = Number(this.sumChildren(item.children))item.promote = this.rateCompute(item.preActual, item.budget)}if (item.children != null && item.children.length > 0) {this.getParentId(item.children, id, numDiffer)}})},// 獲取子集得計算和sumChildren(children) {let sum = 0children.map(item => {if (item.inOrOut == '2' && Number(item.budget) < 0) {sum += Number(item.budget)} else {sum += item.inOrOut == '2' ? Number(('-' + item.budget)) : Number(item.budget)}})return sum},// 取消cancel(key) {this.editable = falsedelete this.editableData[key];},//顯示open(mode = 'add', par) {this.mode = mode;this.visible = true;//接口數據,在下面let headers = res.data.headers//去除不需要顯示的列headers.map(item => {if (item.hidden == false) this.operator(item)})this.columns.push({title: '提升比率',dataIndex: 'promote',key: 'promote',align: 'left',width: 120,scopedSlots: { customRender: 'promote' }})let row = res.data.rows//樹形表格,children沒有數據需要為空this.handNull(row)this.dataSource = rowthis.spinning = falsethis.newSource = row},// 子集沒數據,賦值為空 nullhandNull(data) {data.forEach((item) => {//計算提升比率item.promote = this.rateCompute(item.preActual, item.budget)if (item.children.length == 0) {item.children = null} else {this.handNull(item.children);}});},// columns 表頭賦值operator(item) {let obj = {}if (item.columnId == 'projectName') {obj['title'] = item.nameobj.dataIndex = 'name'obj.key = 'name'obj.align = 'left'}else if (item.columnId == 'preActual') {obj['title'] = item.nameobj.dataIndex = 'preActual'obj.key = 'preActual'obj.align = 'left'obj.width = 200}else if (item.columnId == 'budget') {obj['title'] = item.nameobj.dataIndex = 'budget'obj.key = 'budget'obj.align = 'left'obj.width = 200obj.scopedSlots = { customRender: 'budget' }}else return;this.columns.push(obj)},//關閉handleCancel() {this.visible = false;this.editable = falsethis.$emit("close");},// 確認handleSubmit() {this.loadingBtn = true;this.visibleBtn = true;//新增或修改let Api = this.mode == 'add' ? add : editApi(par).then(res => {if (res.code === 200) {this.$notification['success']({message: '提示',description: '保存成功!',duration: 8})this.visible = falsethis.$emit("success");} else {this.$notification['error']({message: '提示',description: res.message,duration: 8})}this.visibleBtn = falsethis.loadingBtn = false})},}

json


{"code": 200,"message": "操作成功","data": {"title": "月度預算","tabulatorId": "146","storeId": "159","storeName": "麓谷公園店","tabulator": "李生","headers": [{"columnId": "projectId","name": "項目ID","hidden": true,"primary": false},{"columnId": "projectName","name": "項目名稱","hidden": false,"primary": false},{"columnId": "isLeaf","name": "是否葉子","hidden": true,"primary": false},{"columnId": "inOrOut","name": "收支類型","hidden": true,"primary": false},{"columnId": "parentProjectId","name": "上級預算項目ID","hidden": true,"primary": false},{"columnId": "preActual","name": "10月","hidden": false,"primary": false},{"columnId": "budget","name": "11月預算","hidden": false,"primary": true}],"rows": [{"projectId": "165","name": "利潤","parentProjectId": null,"inOrOut": 1,"children": [{"projectId": "174","name": "成本","parentProjectId": "165","inOrOut": 2,"children": [{"projectId": "175","name": "原材料成本","parentProjectId": "174","inOrOut": 2,"children": [],"budget": "0","preBudget": "","preActual": "0","leaf": true}],"preBudget": "","preActual": "0","budget": "0","leaf": false},{"projectId": "173","name": "稅額","parentProjectId": "165","inOrOut": 2,"children": [],"preBudget": "","preActual": "0","budget": "0","leaf": true},{"projectId": "166","name": "營業收入","parentProjectId": "165","inOrOut": 1,"children": [{"projectId": "170","name": "外賣折后營收","parentProjectId": "166","inOrOut": 1,"children": [{"projectId": "172","name": "外賣優免","parentProjectId": "170","inOrOut": 2,"children": [],"preBudget": "","preActual": "0","budget": "0","leaf": true},{"projectId": "171","name": "外賣折前營收","parentProjectId": "170","inOrOut": 1,"children": [],"preBudget": "","preActual": "0","budget": "0","leaf": true}],"preBudget": "","preActual": "0","budget": "0","leaf": false}],"preBudget": "","preActual": "0","budget": "0","leaf": false}],"preBudget": "","preActual": "0","budget": "0","leaf": false}]}
}
折后盈收=折前盈收-優免

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/166967.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/166967.shtml
英文地址,請注明出處:http://en.pswp.cn/news/166967.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

銷售管理系統的實用性怎么樣?

銷售管理系統好用嗎&#xff1f;好用&#xff0c;銷售管理系統可以管理銷售流程、自動化大量重復性工作&#xff0c;讓銷售人員從瑣碎的任務中掙脫出來&#xff0c;投入到客戶跟進和維護客戶關系之中。那么&#xff0c;CRM系統的好用體現在哪些方面&#xff1f; 1.加速銷售流程…

react中的state

沒想到hooks中也有state這一說法 看下面的兩個案例 1、無state變化不會執行父子函數 2、有state更改執行父子函數

CDN加速在網站搭建中的必要性與優勢分析

隨著互聯網的快速發展&#xff0c;網站已經成為企業展示和用戶交互的主要平臺。在構建一個高性能、用戶體驗良好的網站時&#xff0c;CDN&#xff08;內容分發網絡&#xff09;的應用變得愈發重要。本文將從網站搭建的角度出發&#xff0c;深入分析CDN加速的必要性以及在提升網…

深度學習之六(自編碼器--Autoencoder)

概念 自編碼器(Autoencoder)是一種神經網絡架構,用于無監督學習和數據的降維表示。它由兩部分組成:編碼器(Encoder)和解碼器(Decoder)。 結構: 編碼器(Encoder): 接收輸入數據并將其壓縮為潛在表示(latent representation),通常比輸入數據的維度要低。編碼器的…

最詳細的軟件測試面試題整理與分析

前言 時光荏苒&#xff0c;一轉眼到了2023年末尾&#xff0c;2024年也快要來了&#xff0c;人員就業市場以往的寒冬也貌似有了轉暖的跡象&#xff0c;身邊大批的就業人員也開始了緊張的備戰之中。 近幾周也和多家合作公司的HR進行了溝通&#xff0c;發現雖然崗位就業情況較去年…

vue3中引入svg矢量圖

vue3中引入svg矢量圖 1、前言2、安裝SVG依賴插件3、在vite.config.ts 中配置插件4、main.ts入口文件導入5、使用svg5.1 在src/assets/icons文件夾下引入svg矢量圖5.2 在src/components目錄下創建一個SvgIcon組件5.3 封裝成全局組件&#xff0c;在src文件夾下創建plugin/index.t…

SQLserver 數據庫導入MySQL的方法

原文&#xff1a; https://blog.csdn.net/lht631935612/article/details/132086172#httpspanbaiducoms1TlLiRI9stxqTcwBJ5p6UAE993BEE68EA5EFBC9Ahttpspanbaiducoms1TlLiRI9stxqTcwBJ5p6UA2020E68F90E58F96E7A081EFBC9Av6d5_font_colordd0000v6d5font_8 下載鏈接&#xff1a;…

使用openfeign調用下載流的文件不完整的替代方案

OpenFeign是一種聲明式的Web服務客戶端&#xff0c;它使得編寫HTTP客戶端變得更加簡單和直觀。它使用了注解方式來描述HTTP API&#xff0c;使得開發者可以使用Java接口來調用遠程HTTP服務。 OpenFeign的核心特點包括&#xff1a; 聲明式API: 您可以使用注解聲明要調用的遠程AP…

一鍵創新 | 拓世法寶AI智能直播一體機激發房產自媒體創造力

在數字化時代&#xff0c;房產銷售已然不再是傳統的模式。隨著社交媒體和自媒體的興起&#xff0c;短視頻直播成為房產自媒體營銷的新風口。然而&#xff0c;行業也面臨著諸多挑戰&#xff0c;如何更好地利用新媒體拓展市場&#xff0c;提升自媒體效果成為擺在業內人士面前的難…

JMeter測試報錯422 Unprocessable Entity

添加HTTP信息頭&#xff1a; ? HTTP請求-》添加-〉配置元件-》HTTP信息頭管理器 ? 如果需要送json&#xff0c;需要添加Content-Type:application/json&#xff0c;否則會報【422 Unprocessable Entity】

好用的CRM系統到底有多重要?怎么選?

我們都知道&#xff0c;CRM軟件可以讓企業效率加倍。但如果選錯了CRM&#xff0c;企業損失點錢是小&#xff0c;客戶轉化率下降才是大。下面我們就來說說&#xff0c;市面上有哪些好用的CRM&#xff1f;以及好用的CRM軟件的重要性。 好用的CRM軟件的重要性&#xff1a; 客戶管…

Qt 軟件調試(一) Log日志調試

終于這段時間閑下來了&#xff0c;可以系統的編寫Qt軟件調試的整個系列。前面零零星星的也有部分輸出&#xff0c;但終究沒有形成體系。借此機會&#xff0c;做一下系統的總結。慎獨、精進~ 日志是有效幫助我們快速定位&#xff0c;找到程序異常點的實用方法。但是好的日志才能…

百度 文心一言 sdk 試用

JMaven Central: com.baidu.aip:java-sdk (sonatype.com) Java sdk地址如上&#xff1a; 文心一言開發者 文心一言 (baidu.com) ERNIE Bot SDK https://yiyan.baidu.com/developer/doc#Fllzznonw ERNIE Bot SDK提供便捷易用的接口&#xff0c;可以調用文心一言的能力&#…

口袋參謀:如何避免寶貝被降權?這招屢試屢爽!

?至少99.99999%的店鋪在今年都被降權過&#xff01;各家店鋪被降權的原因&#xff0c;無非就一個原因&#xff0c;那就是s單&#xff01; s單的風險也就兩種&#xff0c;一是操作問題&#xff0c;二是賬號問題。 操作問題被降權&#xff0c;這個大家都心知肚明&#xff0c;s…

5大原因,設備校準為什么是實驗室搬遷后的首要任務?

實驗室搬遷是一個復雜而緊張的過程。要考慮的事情太多&#xff0c;很容易忽視您最重要的任務之一——檢查設備在新環境中的性能。 校準對于確保設備安全運行和遵守監管標準至關重要。 1.保持合規性并遵守法律要求 生物技術和制藥等行業有特定的校準要求&#xff0c;實驗室必…

Java詳解之I/O[BIO、NIO、AIO使用方法和示范代碼]

前言&#xff1a; 小弟能力不足&#xff0c;認知有限&#xff0c;難免考慮不全面&#xff0c;希望大佬能給出更好的建議&#xff0c;指出存在的問題和不足&#xff0c;在此跪謝。 IO發展史 Java中對于I/O能力的支持主要分為三個比較關鍵的階段&#xff1a; BIO 第一個階段…

淺談安科瑞直流電表在印尼某基站的應用

摘要&#xff1a;本文介紹了安科瑞直流電表在印尼的應用。主要用于印尼某基站的電流電壓電能的計量&#xff0c;配合霍爾傳感器對基站進行計量。 Abstract: This article introduces the application of Acrel DC meters in base station in Indonesia.The device is measuri…

【此時不應有 \anaconda3\envs\ blenderproc \Library\ssl\cacert.pem】問題已解決

conda 創建新環境后&#xff0c;使用conda activate blenderproc命令激活環境時出現以下錯誤&#xff1a; 此時不應有 \anaconda3\envs\ blenderproc \Library\ssl\cacert.pem 其他博客里面https://blog.csdn.net/weixin_46599926/article/details/132576960解釋這個是因為co…

前端 HTML 和 JavaScript 的基礎知識有哪些?

前端開發是Web開發的一個重要領域&#xff0c;涉及到HTML&#xff08;Hypertext Markup Language&#xff09;和JavaScript兩個主要的技術。HTML用于定義網頁的結構和內容&#xff0c;而JavaScript用于實現網頁的交互和動態效果。以下是前端HTML和JavaScript的基礎知識&#xf…

如何做好測試管理崗?深度分析職業規劃

在給學生做職業規劃的時候&#xff0c;經常就有同學說&#xff1a;我以后要做管理崗&#xff01;其實對于很多剛入行的同學&#xff0c;可能說這句話的時候并沒有真正理解管理崗需要做什么事&#xff0c;以及需要具備什么樣的技能。所以&#xff0c;作為資深測試經理&#xff0…