cost.vue 53 KB

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