cost.vue 50 KB

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