cost.vue 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. <template>
  2. <div class="laborCostStatistics">
  3. <div class="laborCostStatistics-head">
  4. <el-row>
  5. <el-col :span="4">
  6. <span class="mr-10" style="color: #999;">图表Y轴{{ parentDeptId }}</span>
  7. <el-radio-group v-model="chartYAxis" size="small" @change="subtypeSwitching">
  8. <el-radio-button label="workingHours" v-if="permissions.countHours">显示工时</el-radio-button>
  9. <el-radio-button label="cost" v-if="permissions.countCost">显示成本</el-radio-button>
  10. </el-radio-group>
  11. </el-col>
  12. <el-col :span="18">
  13. <template v-if="user.timeType.fixMonthcost == 0">
  14. <el-date-picker size="small" v-model="chartDate" class="mr-10" style="width: 260px;"
  15. :editable="false" @change="filterConditionSwitching" format="yyyy-MM-dd"
  16. value-format="yyyy-MM-dd" :clearable="false" :range-separator="$t('other.to')"
  17. type="daterange" :start-placeholder="$t('time.startDate')"
  18. :end-placeholder="$t('time.endDate')"></el-date-picker>
  19. </template>
  20. <template v-if="user.timeType.fixMonthcost == 1">
  21. <el-date-picker v-model="chartDate" class="mr-10" style="width: 260px;" :editable="false"
  22. size="small" format="yyyy-MM" value-format="yyyy-MM" :clearable="false" type="month"
  23. @change="filterConditionSwitching"></el-date-picker>
  24. </template>
  25. <el-radio-group v-model="singleChoiceType" size="small" :disabled="radioLoading"
  26. @change="filterConditionSwitching" style="margin-right: 10px;">
  27. <el-radio-button :label="$t('other.project')"></el-radio-button>
  28. <el-radio-button :label="$t('zhu-xiang-mu')"
  29. v-if="user.timeType.mainProjectState"></el-radio-button>
  30. <el-radio-button :label="$t('projectclassification')"
  31. v-if="user.companyId != '1071'"></el-radio-button>
  32. <el-radio-button :label="'设备'" v-if="devicePermissions"></el-radio-button>
  33. <el-radio-button :label="$t('lable.department')"
  34. v-if="(permissions.viewAllSummary || permissions.viewMagDeptSummary)"></el-radio-button>
  35. <el-radio-button :label="$t('ren-yuan')" v-if="permissions.countPersonnel"></el-radio-button>
  36. <el-radio-button :label="namess"
  37. v-if="jichu.customDegreeActive == 1 && !jichu.customDegreeMultiple"></el-radio-button>
  38. <el-radio-button v-for="item in theCustomList" :key="item.id"
  39. :label="item.name"></el-radio-button>
  40. </el-radio-group>
  41. <div v-show="singleChoiceType == '部门' && parentDeptId">
  42. <el-button @click="backToParentDept" size="small">返回上级</el-button>
  43. </div>
  44. <el-select v-model="projectStatus" placeholder="请选择项目状态" clearable @change="filterConditionSwitching" v-if="singleChoiceType == '项目'" size="small" style="margin-right: 10px">
  45. <el-option label="进行中" value="1"></el-option>
  46. <el-option label="已完成" value="2"></el-option>
  47. <el-option label="已撤销" value="3"></el-option>
  48. <el-option label="暂停" value="4"></el-option>
  49. </el-select>
  50. <select-project v-model="chartProjectId" :size="'small'" :placeholder="'请选择项目'" clearable
  51. v-if="singleChoiceType == '项目' || singleChoiceType == '设备' || singleChoiceType == namess"
  52. @change="filterConditionSwitching"></select-project>
  53. <select-personnel v-model="chartUserId" v-if="singleChoiceType == '人员'"
  54. @change="filterPersonnel"></select-personnel>
  55. </el-col>
  56. <el-col :span="2" style="display: flex;justify-content: flex-end;">
  57. <el-button @click="exportTheCustomListFlg" size="small" :loading="theCustomListFlgBtnLoading"
  58. v-if="theCustomListFlg">报表导</el-button>
  59. <el-button @click="showExportDialog" size="small" v-else>报表导出</el-button>
  60. </el-col>
  61. </el-row>
  62. </div>
  63. <div class="laborCostStatistics-con">
  64. <div ref="echartsRef" id="echartsRef" :style="`width: 100%; height: 100%; overflow-x: auto;`"
  65. v-loading="echartsLoading">
  66. <EchartsEchar :options="echartsEcharData" :widthHtval="widthHtval" clickOnTheEvent
  67. @chartClickEvents="chartClickEvents"></EchartsEchar>
  68. </div>
  69. </div>
  70. <div class="laborCostStatistics-end">
  71. <div>
  72. <template v-if="singleChoiceType == '项目'">
  73. <el-radio-group v-model="nameNumber" size="small" @change="subtypeSwitching">
  74. <el-radio-button label="1">{{ $t('headerTop.projectName') }}</el-radio-button>
  75. <el-radio-button label="2">{{ user.companyId == '7030' ? '项目令号' : '项目编号' }}</el-radio-button>
  76. </el-radio-group>
  77. </template>
  78. <template v-if="singleChoiceType == '部门' && this.parentDeptId">
  79. <el-radio-group v-model="departmentPersonnel" @change="departmentPersonnelSwitch" size="small">
  80. <el-radio-button label="1">{{ $t('lable.department') }}</el-radio-button>
  81. <el-radio-button label="2">{{ $t('ren-yuan') }}</el-radio-button>
  82. </el-radio-group>
  83. </template>
  84. </div>
  85. <el-pagination :current-page="pageIndex" :page-sizes="[50]" :page-size="50"
  86. @current-change="echartsCurrentChange" layout="total, sizes, prev, pager, next" :total="pageTotal">
  87. </el-pagination>
  88. </div>
  89. <!-- 报表导出 -->
  90. <cost-report-export v-model="reportExportVisable" ref="reportExportDisRef" :singleChoiceType="singleChoiceType"
  91. :hasReportUserList="hasReportUserList" :chartDate="chartDate" :theCustomListId="theCustomListId"
  92. :theCustomListPlant="theCustomListPlant"></cost-report-export>
  93. </div>
  94. </template>
  95. <script>
  96. import selectProject from "../../components/selectProject.vue";
  97. import selectPersonnel from "../../components/selectPersonnel.vue";
  98. import EchartsEchar from "../../components/echartsEchar.vue"
  99. import costReportExport from "./costReportExport.vue";
  100. import { barChartOptions } from "./project";
  101. export default {
  102. components: {
  103. selectProject,
  104. selectPersonnel,
  105. EchartsEchar,
  106. costReportExport
  107. },
  108. data() {
  109. return {
  110. user: JSON.parse(sessionStorage.getItem("user")),
  111. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  112. chartYAxis: 'workingHours',
  113. chartDate: [],
  114. singleChoiceType: sessionStorage.radio != null ? sessionStorage.radio : this.$t('other.project'),
  115. chartProjectId: '',
  116. chartUserId: '',
  117. chartDeptId: '',
  118. radioLoading: false,
  119. jichu: [],
  120. chartYAxisVal: { workingHours: '1', cost: '0' },
  121. theCustomList: [], // 自定义数据来源
  122. theCustomListFlg: false, // 判断是否点击的是自定义配置的数据来源
  123. theCustomListId: '',
  124. theCustomListPlantLIst: [],
  125. theCustomListPlant: '',
  126. pageIndex: 1,
  127. pageTotal: 0,
  128. nameNumber: 1, // 项目, 编号
  129. departmentPersonnel: 1, // 部门, 人员
  130. parentDeptId: '', // 部门详情的部门和人员切换显示
  131. echartsLoading: false,
  132. echartsEcharData: {}, // 图表数据源
  133. totalHours: 0, // 总小时
  134. allListData: [],
  135. personnelAll: [],
  136. personnelAllPlly: [],
  137. widthHtval: document.body.clientWidth - 230, // 图表宽度
  138. params: null,
  139. jichu: '',
  140. namess: '',
  141. devicePermissions: false,
  142. chartDataSource: [], // 图表数据源
  143. parentDeptStack: [],
  144. reportExportVisable: false,
  145. hasReportUserList: [],
  146. theCustomListFlgBtnLoading: false,
  147. projectStatus: '',
  148. }
  149. },
  150. methods: {
  151. filterPersonnel(id, name) {
  152. this.pageIndex = 1
  153. if(!id) {
  154. this.filterConditionSwitching()
  155. }
  156. if (this.chartUserId) {
  157. let arrList = JSON.parse(JSON.stringify(this.personnelAllPlly))
  158. const arr = arrList.list.filter(item => item.name == name)
  159. arrList.list = arr
  160. this.allListData = arrList
  161. if (this.user.userNameNeedTranslate === 1) {
  162. const dealWithList = arr.map(item => ({
  163. type: item.type,
  164. id: item.name
  165. }));
  166. this.dealWithTranslationPlone(dealWithList);
  167. } else {
  168. this.initialChartData();
  169. }
  170. }
  171. },
  172. async exportTheCustomListFlg() {
  173. this.theCustomListFlgBtnLoading = true;
  174. try {
  175. await this.$refs['reportExportDisRef'].exportProjectData();
  176. } catch (error) {
  177. console.error("错误信息", error);
  178. } finally {
  179. this.theCustomListFlgBtnLoading = false;
  180. }
  181. },
  182. getEchart() { // 获取图表数据
  183. const { timeType: { fixMonthcost } } = this.user;
  184. sessionStorage.radio = this.singleChoiceType;
  185. this.radioLoading = true;
  186. const param = this.chartDate ? {
  187. startDate: fixMonthcost === 0 ? this.chartDate[0] : this.chartDate,
  188. endDate: fixMonthcost === 0 ? this.chartDate[1] : this.chartDate
  189. } : {};
  190. const urlMap = {
  191. ['项目']: {
  192. url: this.port.project.listCost,
  193. extraParams: { projectId: this.chartProjectId, type: this.chartYAxisVal[this.chartYAxis], status: this.projectStatus ? this.projectStatus : '0' }
  194. },
  195. ['主项目']: { url: '/project/getTimeCostByMainProject' },
  196. ['项目分类']: { url: '/project/getTimeCostByCategory' },
  197. ['部门']: {
  198. url: this.port.project.depCost,
  199. extraParams: { parentDeptId: this.parentDeptId },
  200. callback: () => { this.departmentadio = '1'; }
  201. },
  202. ['人员']: {
  203. callback: () => {
  204. this.getUserCostList();
  205. return true;
  206. }
  207. },
  208. ['设备']: {
  209. url: '/device-log/getDeviceTimeCost',
  210. extraParams: { projectId: this.chartProjectId }
  211. },
  212. [this.namess]: {
  213. url: '/project/getDegreeCost',
  214. extraParams: { projectId: this.chartProjectId }
  215. }
  216. };
  217. const customConfig = {
  218. url: '/project/getTimeCostByUserCustom',
  219. extraParams: { customId: this.theCustomListId, fieldName: this.theCustomListPlant }
  220. };
  221. const config = this.theCustomListFlg ? customConfig : urlMap[this.singleChoiceType];
  222. if (config) {
  223. if (config.callback && config.callback()) {
  224. return;
  225. }
  226. Object.assign(param, config.extraParams);
  227. const url = config.url;
  228. // 这里可以继续处理 url 和 param,例如发送请求等
  229. this.postData(url, param).then((res) => {
  230. this.processingRequestData(res.data)
  231. }).finally(() => {
  232. this.radioLoading = false
  233. })
  234. }
  235. },
  236. processingRequestData(data) { // 处理请求数据
  237. const { userNameNeedTranslate } = this.user
  238. // let accumulateNumbers = 0
  239. // if (this.singleChoiceType == '项目' || this.singleChoiceType == '主项目' || this.singleChoiceType == '项目分类') {
  240. // for (let i in data.costList) {
  241. // accumulateNumbers += parseFloat(data.costList[i].cost)
  242. // }
  243. // } else if (this.singleChoiceType == '部门') {
  244. // for (let i in data.costList) {
  245. // accumulateNumbers += parseFloat(data.costList[i].costTime)
  246. // }
  247. // } else if (this.singleChoiceType == this.namess) {
  248. // for (let i in data) {
  249. // accumulateNumbers += parseFloat(data[i].cost)
  250. // }
  251. // } else if (this.theCustomListFlg) {
  252. // for (let i in data.list) {
  253. // accumulateNumbers += parseFloat(data.list[i].cost)
  254. // }
  255. // }
  256. // this.totalHours = accumulateNumbers
  257. let accumulateNumbers = 0;
  258. const costList = data.costList || data.list || data;
  259. const costKey = this.singleChoiceType === '部门' ? 'costTime' : 'cost';
  260. if (Array.isArray(costList)) {
  261. accumulateNumbers = costList.reduce((sum, item) => sum + parseFloat(item[costKey] || 0), 0);
  262. } else if (typeof costList === 'object') {
  263. accumulateNumbers = Object.values(costList).reduce((sum, item) => sum + parseFloat(item[costKey] || 0), 0);
  264. }
  265. // additionName // 未转译的数据另外存储一份,用作 DOM 上渲染
  266. if (userNameNeedTranslate == 1) {
  267. for (var i in costList) {
  268. costList[i].additionName = data.costList[i].departmentName
  269. }
  270. }
  271. this.totalHours = accumulateNumbers;
  272. this.allListData = data
  273. if (userNameNeedTranslate == 1 && this.singleChoiceType == '部门') {
  274. const arr = this.allListData.costList.map(item => ({
  275. type: item.type,
  276. id: item.departmentName
  277. }));
  278. this.dealWithTranslation(arr)
  279. } else {
  280. this.initialChartData()
  281. }
  282. },
  283. subtypeSwitching() {
  284. this.initialChartData()
  285. },
  286. departmentPersonnelSwitch() { // 部门人员切换显示
  287. const typeIndex = this.departmentPersonnel
  288. if (typeIndex == '1') {
  289. this.getEchart()
  290. } else {
  291. this.getUserCostList(this.parentDeptId)
  292. }
  293. },
  294. initialChartData() { // 初始图表数据
  295. let list = []
  296. let totalMoneyCost = ((this.singleChoiceType == '项目' || this.singleChoiceType == '项目分类') ? this.allListData.totalMoneyCost : this.allListData.totalCostMoney);
  297. let newBarChartOptions = { ...barChartOptions }
  298. // 先将数据置空,防止数据残留
  299. this.echartsEcharData = [{ data: [] }]
  300. // 分页数据
  301. if (this.singleChoiceType != '人员' && this.departmentPersonnel != 2) {
  302. this.pageTotal = this.allListData.costList ? this.allListData.costList.length : 0
  303. list = this.allListData.costList && this.allListData.costList.slice(0 + 10 * (this.pageIndex - 1), 49 + 50 * (this.pageIndex - 1))
  304. if (list && list.length > 20) {
  305. this.widthHtval += Math.max(0, list.length - 20) * 40;
  306. } else {
  307. this.widthHtval = document.body.clientWidth - 230
  308. }
  309. }
  310. if (this.singleChoiceType == '项目') {
  311. newBarChartOptions = this.processProjectChartData(list, totalMoneyCost, newBarChartOptions)
  312. } else if (this.singleChoiceType == '主项目') {
  313. newBarChartOptions = this.processingMainProjectChartData(list, totalMoneyCost, newBarChartOptions)
  314. } else if (this.singleChoiceType == '项目分类') {
  315. newBarChartOptions = this.projectClassificationChartData(list, totalMoneyCost, newBarChartOptions)
  316. } else if (this.singleChoiceType == '设备') {
  317. newBarChartOptions = this.equipmentChartData(list, totalMoneyCost, newBarChartOptions)
  318. } else if (this.singleChoiceType == '部门' && this.departmentPersonnel != 2) {
  319. newBarChartOptions = this.processDepartmentalChartData(list, totalMoneyCost, newBarChartOptions)
  320. } else if (this.singleChoiceType == '人员' || this.departmentPersonnel == 2) {
  321. newBarChartOptions = this.personnelChartData(totalMoneyCost)
  322. } else if (this.theCustomListFlg) {
  323. this.pageTotal = this.allListData.list ? this.allListData.list.length : 0
  324. list = this.pageTotal ? this.allListData.list.slice(0 + 50 * (this.pageIndex - 1), 49 + 50 * (this.pageIndex - 1)) : []
  325. newBarChartOptions = this.theCustomListFlgChartData(list, totalMoneyCost, newBarChartOptions)
  326. } else if (this.singleChoiceType == this.namess) {
  327. this.pageTotal = this.allListData ? this.allListData.length : 0
  328. list = this.allListData.slice(0 + 10 * (this.pageIndex - 1), 49 + 50 * (this.pageIndex - 1))
  329. newBarChartOptions = this.namessChartData(list, totalMoneyCost, newBarChartOptions)
  330. }
  331. console.log({ ...newBarChartOptions }, '<==== 图表数据')
  332. this.echartsEcharData = { ...newBarChartOptions }
  333. },
  334. equipmentChartData(list, totalMoneyCost = 0, chartData) { // 设备图表数据
  335. let xList = [], yList = [], totalHours = 0;
  336. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  337. const { countCost, countHours } = this.permissions
  338. for (let i in list) {
  339. xList.push(list[i].projectName);
  340. let item = {
  341. "value": yAxisValue == 0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney : (list[i].cost ? list[i].cost.toFixed(1) : 0),
  342. "id": list[i].id || i,
  343. }
  344. if (countCost) {
  345. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  346. }
  347. if (countHours) {
  348. item.cost = list[i].cost
  349. totalHours += parseFloat(list[i].cost);
  350. }
  351. yList.push(item);
  352. }
  353. totalHours = this.totalHours.toFixed(1);
  354. totalMoneyCost = totalMoneyCost.toFixed(2)
  355. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  356. },
  357. theCustomListFlgChartData(list, totalMoneyCost = 0, chartData) { // 不知道啥东西
  358. let xList = [], yList = [], totalHours = 0;
  359. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  360. const { countCost, countHours } = this.permissions
  361. for (var i in list) {
  362. xList.push(list[i].name);
  363. let item = {
  364. "value": yAxisValue == 0 ? list[i].costMoney : list[i].cost,
  365. "id": list[i].id || i,
  366. }
  367. if (countCost) {
  368. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  369. totalMoneyCost += parseFloat(list[i].costMoney);
  370. }
  371. if (countHours) {
  372. item.cost = list[i].cost
  373. totalHours += parseFloat(list[i].cost);
  374. }
  375. yList.push(item);
  376. }
  377. totalHours = this.totalHours.toFixed(1);
  378. totalMoneyCost = totalMoneyCost.toFixed(2);
  379. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  380. },
  381. namessChartData(list, totalMoneyCost = 0, chartData) { // namess 图表数据
  382. let xList = [], yList = [], totalHours = 0;
  383. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  384. const { countCost, countHours } = this.permissions
  385. for (var i in list) {
  386. xList.push(list[i].name);
  387. let item = {
  388. "value": yAxisValue == 0 ? list[i].costMoney : list[i].cost,
  389. "id": list[i].id || i,
  390. }
  391. if (countCost) {
  392. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  393. totalMoneyCost += parseFloat(list[i].costMoney);
  394. }
  395. if (countHours) {
  396. item.cost = list[i].cost
  397. totalHours += parseFloat(list[i].cost);
  398. }
  399. yList.push(item);
  400. }
  401. totalHours = this.totalHours.toFixed(1);
  402. totalMoneyCost = totalMoneyCost.toFixed(2);
  403. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  404. },
  405. personnelChartData() { // 人员图表数据
  406. const { countCost, countHours } = this.permissions
  407. const { list, userList, totalCostMoney } = this.allListData;
  408. const startIndex = 50 * (this.pageIndex - 1);
  409. const endIndex = startIndex + 49;
  410. // 数量数据
  411. // list = [...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list, ...list]
  412. const _this = this;
  413. const xList = [];
  414. const yList = [];
  415. const array = [];
  416. const series = [];
  417. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  418. const paginatedList = list.slice(startIndex, endIndex);
  419. let totalHours = this.totalHours.toFixed(1);
  420. let totalMoneyCost = totalCostMoney;
  421. this.hasReportUserList = userList;
  422. this.pageTotal = list ? list.length : 0;
  423. if (list && list.length > 20) {
  424. this.widthHtval += Math.max(0, list.length - 20) * 40;
  425. } else {
  426. this.widthHtval = document.body.clientWidth - 230
  427. }
  428. if (paginatedList.length > 0) {
  429. let num = paginatedList.length == 0 ? 0 : paginatedList[0].project.length;
  430. for (var i in paginatedList) {
  431. xList.push(paginatedList[i].name);
  432. var pro = paginatedList[i].project;
  433. for (var j in pro) {
  434. if (array.indexOf(pro[j].project) == -1) {
  435. array.push(pro[j].project)
  436. }
  437. }
  438. }
  439. for (var i in array) {
  440. yList.push(array[i]);
  441. let dataList = [];
  442. let nameObj = {}
  443. list.forEach(item => {
  444. let moneyTol = 0;
  445. let timeTol = 0;
  446. item.project.forEach((project, index) => {
  447. moneyTol += +project.money;
  448. timeTol += +project.time;
  449. });
  450. // 假设每个 item.project 都至少有一个元素
  451. if (item.project.length > 0) {
  452. const lastProject = item.project[item.project.length - 1];
  453. nameObj[item.name] = { moneyTol: moneyTol, timeTol: timeTol }
  454. lastProject.moneyTol = moneyTol;
  455. lastProject.timeTol = timeTol;
  456. }
  457. });
  458. for (var j in paginatedList) {
  459. let project = paginatedList[j].project, num = 0;
  460. if (project.length != 0) {
  461. for (var k in project) {
  462. if (project[k].project == array[i]) {
  463. let item = {
  464. "value": yAxisValue == 0 ? project[k].money : project[k].time,
  465. }
  466. if (countCost) {
  467. item.money = project[k].money
  468. }
  469. if (countHours) {
  470. item.cost = project[k].time
  471. }
  472. if (project[k].moneyTol) {
  473. item.moneyTol = project[k].moneyTol
  474. item.timeTol = project[k].timeTol
  475. }
  476. dataList.push(item)
  477. } else {
  478. num++;
  479. }
  480. if (k == project.length - 1 && num != project.length - 1) {
  481. dataList.push({
  482. "value": 0,
  483. "cost": 0,
  484. "money": 0,
  485. })
  486. }
  487. }
  488. } else {
  489. dataList.push({
  490. "value": 0,
  491. "cost": 0,
  492. "money": 0,
  493. })
  494. }
  495. }
  496. let cerName = array[array.length - 1] // 最后一个项目
  497. series.push({
  498. name: array[i],
  499. type: 'bar',
  500. stack: '1',
  501. barMaxWidth: 30,
  502. data: dataList,
  503. label: {
  504. normal: {
  505. show: true,
  506. position: 'top',
  507. formatter: function (params) {
  508. const { seriesName, data, name } = params
  509. if (!name) {
  510. return ''
  511. }
  512. const unit = yAxisValue == 0 ? _this.$t('yuan') : 'h';
  513. const totalValue = yAxisValue == 0 ? nameObj[name] && nameObj[name].moneyTol : nameObj[name] && nameObj[name].timeTol;
  514. const dayValue = yAxisValue == 0 ? 0 : nameObj[name] && (nameObj[name].timeTol/_this.user.timeType.allday).toFixed(1);
  515. return seriesName === cerName ? `${totalValue ? totalValue.toFixed(1) : 0} ${unit}${yAxisValue == 0?'':('/'+dayValue+'人天')}` : '';
  516. }
  517. }
  518. }
  519. });
  520. }
  521. }
  522. let chartData = { ...barChartOptions }
  523. totalMoneyCost = totalMoneyCost.toFixed(2)
  524. chartData.title = {
  525. ...chartData.title,
  526. text: `工时成本总计:${countCost ? `成本 ${totalMoneyCost},` : ''} ${countHours ? `时长 ${totalHours} 小时` : ''}`
  527. }
  528. chartData.legend = {
  529. x: 80,
  530. y: 10,
  531. data: yList,
  532. show: true,
  533. top: "5%",
  534. }
  535. chartData.toolbox = {
  536. show: true,
  537. feature: {
  538. saveAsImage: {
  539. show: this.user.userNameNeedTranslate == 1 ? false : true
  540. },
  541. restore: {
  542. show: true
  543. },
  544. magicType: {
  545. type: ['line', 'bar']
  546. }
  547. }
  548. }
  549. chartData.tooltip = {
  550. trigger: 'axis',
  551. formatter: function (params, ticket, callback) {
  552. var totalTime = 0;
  553. var totalCost = 0;
  554. var res = "";
  555. for (var i in params) {
  556. if (params[i].data.value > 0) {
  557. res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>" + _this.$t('headerTop.projectName') + ":" + params[i].seriesName
  558. + "</font><br/>" +
  559. ((_this.permissions.countCost) ? _this.$t('workcost') + ":" + params[i].data.money + _this.$t('yuan') + "</br>" : '') +
  560. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + ":" + params[i].data.cost + _this.$t('time.hour') + "</br>" : '') + "</div>";
  561. totalTime += Number(params[i].data.cost);
  562. totalCost += Number(params[i].data.money);
  563. }
  564. }
  565. if (_this.user.userNameNeedTranslate != 1) {
  566. res = res + '<br/>' + params[0].name + '<br/>' + _this.$t('zong-ji') + ':' +
  567. ((_this.permissions.countHours) ? totalTime.toFixed(1) + _this.$t('time.hour') : '') +
  568. ((_this.permissions.countCost) ? totalCost.toFixed(2) + _this.$t('yuan') : '') +
  569. "<br/>";
  570. } else {
  571. res = res + '<br/>' + '' + '<br/>' + _this.$t('zong-ji') + ':' +
  572. ((_this.permissions.countHours) ? totalTime.toFixed(1) + _this.$t('time.hour') : '') +
  573. ((_this.permissions.countCost) ? totalCost.toFixed(2) + _this.$t('yuan') : '') +
  574. "<br/>";
  575. }
  576. return res;
  577. }
  578. }
  579. chartData.xAxis = {
  580. data: xList,
  581. axisLabel: {
  582. interval: 0, rotate: 20
  583. }
  584. }
  585. chartData.yAxis = {
  586. type: 'value',
  587. axisLabel: {
  588. formatter: yAxisValue == 0 ? '{value} (' + this.$t('yuan') + ')' : '{value} (' + this.$t('time.hour') + ')'
  589. }
  590. }
  591. chartData.series = series;
  592. return { ...chartData }
  593. // return this.processingPersonnelChartData(totalHours, totalMoneyCost)
  594. },
  595. processDepartmentalChartData(list, totalMoneyCost = 0, chartData) { // 处理部门图表数据
  596. let xList = [], yList = [], totalHours = 0;
  597. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  598. const { countCost, countHours } = this.permissions
  599. for (let i in list) {
  600. xList.push(list[i].departmentName);
  601. let item = {
  602. "value": yAxisValue == 0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney : (list[i].costTime ? list[i].costTime.toFixed(1) : 0),
  603. "id": list[i].departmentId,
  604. "hasSubDept": list[i].hasSubDept,
  605. "type": list[i].type
  606. }
  607. if (countCost) {
  608. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  609. }
  610. if (countHours) {
  611. item.cost = list[i].costTime
  612. totalHours += parseFloat(list[i].costTime);
  613. }
  614. yList.push(item);
  615. }
  616. totalHours = this.totalHours.toFixed(1);
  617. totalMoneyCost = totalMoneyCost.toFixed(2)
  618. console.log(xList, yList, list, '<==== xList, yList,')
  619. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  620. },
  621. projectClassificationChartData(list, totalMoneyCost = 0, chartData) { // 处理项目分类图表数据
  622. let xList = [], yList = [], totalHours = 0;
  623. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  624. const { countCost, countHours } = this.permissions
  625. for (let i in list) {
  626. xList.push(list[i].categoryName);
  627. let item = {
  628. "value": yAxisValue == 0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney : (list[i].cost ? list[i].cost.toFixed(1) : 0),
  629. "id": list[i].id || i,
  630. }
  631. if (countCost) {
  632. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  633. }
  634. if (countHours) {
  635. item.cost = list[i].cost
  636. totalHours += parseFloat(list[i].cost);
  637. }
  638. yList.push(item);
  639. }
  640. totalHours = this.totalHours.toFixed(1);
  641. totalMoneyCost = totalMoneyCost.toFixed(2)
  642. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  643. },
  644. processingMainProjectChartData(list, totalMoneyCost = 0, chartData) { // 处理主项目图表数据
  645. let xList = [], yList = [], totalHours = 0;
  646. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  647. const { countCost, countHours } = this.permissions
  648. for (let i in list) {
  649. xList.push(list[i].mainProjectName);
  650. let item = {
  651. "value": yAxisValue == 0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney : (list[i].cost ? list[i].cost.toFixed(1) : 0),
  652. "id": list[i].id || i,
  653. }
  654. if (countCost) {
  655. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  656. }
  657. if (countHours) {
  658. item.cost = list[i].cost
  659. totalHours += parseFloat(list[i].cost);
  660. }
  661. yList.push(item);
  662. }
  663. totalHours = this.totalHours.toFixed(1);
  664. totalMoneyCost = totalMoneyCost.toFixed(2)
  665. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  666. },
  667. processProjectChartData(list, totalMoneyCost = 0, chartData) { // 处理项目图表数据
  668. let xList = [], yList = [], totalHours = 0;
  669. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  670. const { countCost, countHours } = this.permissions
  671. for (let i in list) {
  672. xList.push(this.nameNumber == '1' ? list[i].project : list[i].projectCode);
  673. let item = {
  674. "value": yAxisValue == 0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney : (list[i].cost ? list[i].cost.toFixed(1) : 0),
  675. "id": list[i].id || i,
  676. }
  677. if (countCost) {
  678. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  679. }
  680. if (countHours) {
  681. item.cost = list[i].cost
  682. totalHours += parseFloat(list[i].cost);
  683. }
  684. yList.push(item);
  685. }
  686. totalHours = this.totalHours.toFixed(1);
  687. totalMoneyCost = totalMoneyCost.toFixed(2)
  688. return { ...this.sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) }
  689. },
  690. sameChartProcessing(xList, yList, totalHours, totalMoneyCost, chartData) { // 项目,主项目,人员,项目分类,部门 等相同处理
  691. const _this = this
  692. const yAxisValue = this.chartYAxisVal[this.chartYAxis]
  693. const { countCost, countHours } = this.permissions
  694. const { userNameNeedTranslate } = this.user
  695. chartData.title = {
  696. text: `工时成本总计:${countCost ? `成本 ${totalMoneyCost},` : ''} ${countHours ? `时长 ${totalHours} 小时/${(totalHours/_this.user.timeType.allday).toFixed(1)}人天` : ''}`,
  697. left: 'left',
  698. }
  699. chartData.toolbox = {
  700. show: true,
  701. feature: {
  702. saveAsImage: { show: userNameNeedTranslate == 1 ? false : true }, restore: { show: true }, magicType: { type: ['line', 'bar'] },
  703. }
  704. }
  705. chartData.tooltip = {
  706. trigger: 'axis',
  707. formatter: function (params, ticket, callback) {
  708. _this.params = params;
  709. var res
  710. if (_this.user.userNameNeedTranslate != '1') {
  711. var res = params[0].name + "<br/>" +
  712. ((_this.permissions.countCost) ? _this.$t('workcost') + " : " + params[0].data.money
  713. + _this.$t('yuan') + "<br/>" : '') +
  714. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + " : " + params[0].data.cost + _this.$t('time.hour') : '');
  715. } else {
  716. var res = "<TranslationOpenDataText type='departmentName' :openid='" + _this.allListData.costList[params[0].dataIndex].additionName + "'></TranslationOpenDataText>" + "<br/>" +
  717. ((_this.permissions.countCost) ? _this.$t('workcost') + " : " + params[0].data.money
  718. + _this.$t('yuan') + "<br/>" : '') +
  719. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + " : " + params[0].data.cost + _this.$t('time.hour') : '');
  720. }
  721. return res;
  722. }
  723. }
  724. chartData.xAxis = {
  725. data: xList,
  726. axisLabel: {
  727. interval: 0, rotate: 20
  728. }
  729. }
  730. chartData.yAxis = {
  731. type: 'value',
  732. axisLabel: {
  733. formatter: yAxisValue == 0 ? '{value} (' + '元' + ')' : ('{value}' + '小时')
  734. }
  735. }
  736. chartData.series = [{
  737. name: yAxisValue == 0 ? this.$t('workcost') + '(' + this.$t('yuan') + ')' : this.$t('screening.workTime') + '(' + this.$t('time.hour') + ')',
  738. type: 'bar',
  739. barMaxWidth: 30,
  740. data: yList,
  741. label: {
  742. normal: {
  743. show: true,
  744. position: 'top',
  745. // formatter: ` ${yAxisValue == 0 ? '{c}元' : '{c}小时/{{c}/8}人天'}`,
  746. formatter: function(params) {
  747. var dayValue = yAxisValue == 0?0:(params.value/_this.user.timeType.allday).toFixed(1);
  748. return ` ${yAxisValue == 0 ? (params.value + '元') : (params.value + 'h/'+dayValue+'人天')}`; // params.value 等价于 {c}
  749. }
  750. }
  751. }
  752. }]
  753. return { ...chartData }
  754. },
  755. getUserCostList(departmentId) { // 获取人员成本列表
  756. const { timeType: { fixMonthcost } } = this.user;
  757. const urls = this.port.project.userCost;
  758. const params = {};
  759. if (this.chartDate) {
  760. const [start, end] = fixMonthcost === 0 ? this.chartDate : [this.chartDate, this.chartDate];
  761. params.startDate = start;
  762. params.endDate = end;
  763. }
  764. if (departmentId) {
  765. params.departmentId = departmentId;
  766. }
  767. this.postData(urls, params).then(res => {
  768. const { list = [] } = res.data;
  769. const alltime = list.reduce((total, item) =>
  770. total + item.project.reduce((sum, proj) => sum + parseFloat(proj.time), 0), 0);
  771. this.totalHours = alltime;
  772. this.personnelAll = res.data;
  773. this.allListData = res.data;
  774. this.personnelAllPlly = JSON.parse(JSON.stringify(res.data));
  775. if (this.user.userNameNeedTranslate === 1) {
  776. const dealWithList = list.map(item => ({
  777. type: item.type,
  778. id: item.name
  779. }));
  780. this.dealWithTranslationPlone(dealWithList, res.data.list);
  781. } else {
  782. this.initialChartData();
  783. }
  784. }).finally(() => {
  785. this.radioLoading = false;
  786. })
  787. },
  788. dealWithTranslation(items) { // 部门译处理
  789. if (WWOpenData.initCanvas) {
  790. WWOpenData.initCanvas()
  791. }
  792. const myFunOne = async () => {
  793. const result = await new Promise((resolve, reject) => {
  794. if (WWOpenData.prefetch) {
  795. WWOpenData.prefetch({ items }, (err, data) => {
  796. if (err) { return reject(err) }
  797. resolve(data)
  798. })
  799. }
  800. })
  801. for (var i in this.allListData.costList) {
  802. this.allListData.costList[i].departmentName = result.items[i].data
  803. }
  804. this.initialChartData()
  805. }
  806. myFunOne()
  807. },
  808. dealWithTranslationPlone(items) { // 人员转译处理
  809. if (WWOpenData.initCanvas) {
  810. WWOpenData.initCanvas()
  811. }
  812. const myFunOne = async () => {
  813. const result = await new Promise((resolve, reject) => {
  814. if (WWOpenData.prefetch) {
  815. WWOpenData.prefetch({ items }, (err, data) => {
  816. if (err) { return reject(err) }
  817. resolve(data)
  818. })
  819. }
  820. })
  821. for (var i in this.allListData.list) {
  822. if (result.items[i]) {
  823. this.allListData.list[i].name = result.items[i].data
  824. }
  825. }
  826. this.initialChartData()
  827. }
  828. myFunOne()
  829. },
  830. filterConditionSwitching() { // 切换筛选条件
  831. this.theCustomListFlg = false
  832. let ints = null
  833. for (var i in this.theCustomList) {
  834. if (this.singleChoiceType == this.theCustomList[i].name) {
  835. this.theCustomListId = this.theCustomList[i].id
  836. this.theCustomListPlant = this.theCustomListPlantLIst[i]
  837. this.theCustomListFlg = true
  838. ints = i
  839. }
  840. }
  841. if (this.theCustomListFlg) {
  842. this.customList = this.theCustomList[ints].subUserCustomList
  843. this.customName = this.theCustomList[ints].subUserCustomList[0].name
  844. }
  845. this.getEchart()
  846. },
  847. // 图表点击事件
  848. chartClickEvents(data) {
  849. const { params, myChart } = data
  850. const { timeType: { fixMonthcost } } = this.user
  851. if (this.singleChoiceType == '部门' || this.singleChoiceType == '项目') {
  852. const pointInPixel = [params.offsetX, params.offsetY];
  853. if (myChart.containPixel('grid', pointInPixel)) {
  854. if (this.singleChoiceType == '项目') {
  855. if (this.chartDate != null) {
  856. if (fixMonthcost == 0) {
  857. this.$router.push("/cost/" + this.params[0].data.id + "/" + this.params[0].name
  858. + "?startDate=" + this.chartDate[0] + "&endDate=" + this.chartDate[1]);
  859. } else {
  860. this.$router.push("/cost/" + this.params[0].data.id + "/" + this.params[0].name
  861. + "?startDate=" + this.chartDate + "&endDate=" + this.chartDate);
  862. }
  863. } else {
  864. this.$router.push("/cost/" + this.params[0].data.id + "/" + this.params[0].name);
  865. }
  866. }
  867. if (this.singleChoiceType == '部门') {
  868. if (this.params[0].data.type == 'departmentName') {
  869. if (this.params[0].data.hasSubDept) {
  870. if (this.parentDeptId != this.params[0].data.id) {
  871. this.parentDeptId = this.params[0].data.id;
  872. this.parentDeptStack.push(this.parentDeptId);
  873. this.getEchart()
  874. }
  875. } else {
  876. if (this.departmentPersonnel == '2') {
  877. return
  878. }
  879. if (this.chartDate != null) {
  880. this.$router.push("/costDep/" + this.params[0].data.id + "/" + this.params[0].name
  881. + "?startDate=" + this.chartDate[0] + "&endDate=" + this.chartDate[1]);
  882. } else {
  883. this.$router.push("/costDep/" + this.params[0].data.id + "/" + this.params[0].name);
  884. }
  885. }
  886. }
  887. }
  888. }
  889. }
  890. },
  891. backToParentDept() { // 返回上级
  892. if (this.singleChoiceType == '部门') {
  893. if (this.parentDeptStack.length > 0) {
  894. this.parentDeptStack.pop();
  895. if (this.parentDeptStack.length > 0) {
  896. this.parentDeptId = this.parentDeptStack[this.parentDeptStack.length - 1];
  897. } else {
  898. this.parentDeptId = null;
  899. }
  900. this.getEchart();
  901. }
  902. }
  903. },
  904. // 获取自定义数据
  905. getCustomData() {
  906. this.postData(`/user-custom/getUserCustomTitle`, {}).then((res) => {
  907. this.theCustomList = res.data.result
  908. this.theCustomListPlantLIst = res.data.field
  909. })
  910. },
  911. jutishez() {
  912. this.postData(`/time-type/getCompanyTimeSetting`, { companyId: this.user.companyId }).then((res) => {
  913. this.jichu = res.data
  914. if (res.data.customDegreeActive == 1) {
  915. this.namess = res.data.customDegreeName
  916. }
  917. })
  918. },
  919. processingInitialData() { // 处理初始数据
  920. const { countCost, countHours } = this.permissions;
  921. const { timeType: { fixMonthcost }, moduleList } = this.user;
  922. this.devicePermissions = moduleList.filter(item => item.name === '设备管理').length > 0;
  923. this.chartYAxis = countCost && !countHours ? 'cost' : 'workingHours';
  924. const { query } = this.$route;
  925. const today = this.dayjs();
  926. if (fixMonthcost === 0) {
  927. this.chartDate = query.startDate
  928. ? [query.startDate, query.endDate]
  929. : [today.startOf('month').format('YYYY-MM-DD'), today.format('YYYY-MM-DD')];
  930. } else if (fixMonthcost === 1) {
  931. this.chartDate = query.startDate || today.format('YYYY-MM');
  932. }
  933. // this.exportParam.dateRange = this.chartDate;
  934. if (query.endDate && query.startDate && query.financeAudit) {
  935. const lastDay = this.dayjs(`${query.endDate}-01`).endOf('month').format('YYYY-MM-DD');
  936. this.chartDate = [`${query.startDate}-01`, lastDay];
  937. }
  938. this.chartYAxis = 'workingHours'
  939. },
  940. echartsCurrentChange(val) {
  941. this.pageIndex = val
  942. this.processingRequestData(this.allListData)
  943. },
  944. // 左右滚动
  945. scrollFunction() {
  946. this.domObj = document.getElementById('echartsRef') // 通过id获取要设置的div
  947. if (this.domObj.attachEvent) { // IE
  948. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  949. } else if (this.domObj.addEventListener) {
  950. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  951. }
  952. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  953. },
  954. mouseScroll(event) { // google 浏览器下
  955. let detail = event.wheelDelta || event.detail
  956. let moveForwardStep = -1
  957. let moveBackStep = 1
  958. let step = 0
  959. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  960. event.preventDefault() // 阻止浏览器默认事件
  961. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  962. },
  963. showExportDialog() { // 显示报表导出
  964. this.reportExportVisable = true
  965. },
  966. // 单独封装请求
  967. async postData(urls, param) {
  968. return new Promise((resolve, reject) => {
  969. this.http.post(urls, { ...param },
  970. res => {
  971. if (res.code == 'ok') {
  972. resolve(res)
  973. } else {
  974. this.$message({
  975. message: res.msg,
  976. type: 'error'
  977. })
  978. reject(res)
  979. }
  980. resolve(res)
  981. },
  982. error => {
  983. this.$message({
  984. message: error,
  985. type: "error"
  986. });
  987. reject(error)
  988. }
  989. )
  990. });
  991. },
  992. },
  993. created() { },
  994. mounted() {
  995. const { timeType: { userCustomStatic } } = this.user;
  996. userCustomStatic && this.getCustomData(); // 获取自定义数据
  997. this.processingInitialData()
  998. this.jutishez()
  999. setTimeout(() => {
  1000. this.getEchart()
  1001. this.scrollFunction()
  1002. }, 300)
  1003. }
  1004. }
  1005. </script>
  1006. <style lang="scss" scoped>
  1007. * {
  1008. box-sizing: border-box;
  1009. }
  1010. .laborCostStatistics {
  1011. width: 100%;
  1012. height: 100%;
  1013. padding: 15px;
  1014. display: flex;
  1015. flex-direction: column;
  1016. .laborCostStatistics-con {
  1017. margin: 10px 0;
  1018. }
  1019. .laborCostStatistics-end {
  1020. display: flex;
  1021. justify-content: space-between;
  1022. }
  1023. .laborCostStatistics-con {
  1024. flex: 1;
  1025. }
  1026. .el-col {
  1027. display: flex;
  1028. align-items: center;
  1029. }
  1030. .mr-10 {
  1031. margin-right: 10px;
  1032. }
  1033. }
  1034. </style>