cost.vue 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510
  1. <template>
  2. <section>
  3. <el-row style="padding-bottom: 0px;text-align:center;margin-top:20px;z-index: 999;">
  4. <el-col :span="6" >
  5. <div ><span style="color:#999;">{{ $t('chartY') }} </span>
  6. <el-radio-group v-model="yAxisValue" @change="onYAxisChange" size="small">
  7. <el-radio-button label="0" v-if="permissions.countCost">{{ $t('accordingtothecost') }}</el-radio-button>
  8. <el-radio-button label="1" v-if="permissions.countHours">{{ $t('accordingtoworkinghours') }}</el-radio-button>
  9. </el-radio-group></div>
  10. </el-col>
  11. <el-col :span="14" style="display: flex;flex-wrap: wrap;justify-content: flex-end;">
  12. <el-date-picker v-show="user.timeType.fixMonthcost==0" size="small"
  13. v-model="dateRange" :editable="false"
  14. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  15. @change="getEchart"
  16. :clearable="true"
  17. :range-separator="$t('other.to')"
  18. type="daterange"
  19. :start-placeholder="$t('time.startDate')"
  20. :end-placeholder="$t('time.endDate')"
  21. ></el-date-picker>
  22. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  23. v-model="dateRange" :editable="false" size="small"
  24. format="yyyy-MM" value-format="yyyy-MM"
  25. @change="getEchart"
  26. :clearable="false"
  27. type="month"
  28. ></el-date-picker>
  29. <el-radio-group v-model="radio" @change="getEchart" style="margin-left:10px;" size="small" :disabled="radioLoading">
  30. <el-radio-button :label="$t('other.project')"></el-radio-button>
  31. <el-radio-button :label="$t('zhu-xiang-mu')" v-if="user.timeType.mainProjectState"></el-radio-button>
  32. <el-radio-button :label="$t('projectclassification')" v-if="user.companyId != '1071'"></el-radio-button>
  33. <el-radio-button :label="$t('lable.department')" v-if="permissions.viewAllSummary || permissions.viewMagDeptSummary"></el-radio-button>
  34. <el-radio-button :label="$t('ren-yuan')" v-if="permissions.countPersonnel"></el-radio-button>
  35. <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button>
  36. <el-radio-button v-for="item in theCustomList" :key="item.id" :label="item.name"></el-radio-button>
  37. </el-radio-group>
  38. <el-select v-if="radio == $t('other.project')||radio == namess " v-model="proJuctId" :placeholder="$t('defaultText.pleaseSelectSnItem')" clearable filterable size="small" @change="getEchart" style="margin-left:10px">
  39. <el-option v-for="(item) in projectList" :key="item.id" :label="item.projectName + (item.projectCode ? item.projectCode : '')" :value="item.id">
  40. <span style="float: left;color: #8492a6;">{{ item.projectCode }}</span>
  41. <span style="float: right;font-size: 13px;margin-left: 20px">{{ item.projectName }}</span>
  42. </el-option>
  43. </el-select>
  44. <!--
  45. <el-select v-model="customName" filterable placeholder="请选择" style="margin-top: 10px;width: 350px" v-if="theCustomListFlg" @change="jieliu()">
  46. <el-option v-for="item in customList" :key="item.id" :label="item.name" :value="item.name"></el-option>
  47. </el-select> -->
  48. <el-select v-model="personnelValue" filterable clearable :placeholder="hasReportUserList.length == 0 ? $t('nodata') : $t('pleaseselectpersonnel')" size="small" style="margin-top: 10px;width: 350px" v-if="(radio == $t('ren-yuan'))&& user.userNameNeedTranslate != '1'" @change="personnel()"
  49. :disabled="hasReportUserList.length == 0 ? true : false">
  50. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.name">
  51. <span style="float: left">{{ item.name }}</span>
  52. <span style="float: right; color: #8492a6; font-size: 13px;margin-left: 20px" v-if="item.jobNumber">{{ item.jobNumber }}</span>
  53. </el-option>
  54. </el-select>
  55. <span style="text-align: left">
  56. <selectCat v-if="radio == $t('ren-yuan') && user.userNameNeedTranslate == '1'" :size="'small'" :widthStr="'350'" :distinction="'2'" :subject="hasReportUserList" :clearable="true" @selectCal="selectCal" :disabled="hasReportUserList.length == 0 ? true : false"></selectCat>
  57. </span>
  58. </el-col>
  59. <el-col :span="4">
  60. <el-button @click="exportProjectData" v-if="theCustomListFlg" size="small">{{ $t('reporderived') }}</el-button>
  61. <el-button @click="showExportDialog" v-else size="small">{{ $t('reporderived') }}</el-button>
  62. </el-col>
  63. </el-row>
  64. <!-- <div id="clearfix" :style="'width:'+widthHtval+'px;position: relative; height:'+containerHeight+'px;'">
  65. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  66. </div> -->
  67. <div id="clearfix" :class="radio == $t('ren-yuan') ? 'ryuans' : ''" :style="'overflow-x: auto;width:100%;padding-bottom: 100px; position: relative; height:'+containerHeight+'px;'" v-loading="radioLoading">
  68. <div id="container" :style="'height:'+(containerHeight - 20)+'px;width:100%'"></div>
  69. <div class="poss">
  70. <el-pagination
  71. @size-change="echartsSizeChange"
  72. @current-change="echartsCurrentChange"
  73. :current-page="page"
  74. :page-sizes="[50]"
  75. :page-size="50"
  76. layout="total, sizes, prev, pager, next"
  77. :total="total">
  78. </el-pagination>
  79. </div>
  80. </div>
  81. <!-- <div>
  82. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  83. </div> -->
  84. <div style="position:fixed;top:170px;left:600px;" v-show="radio==$t('lable.department') && parentDeptId != null">
  85. <el-button @click="backToParentDept">{{ $t('returnsuperior') }}</el-button>
  86. </div>
  87. <!--导出报表条件选择 -->
  88. <el-dialog :title="$t('timeReportExport')" v-if="exportDialog" :visible.sync="exportDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  89. <el-form ref="form3" :model="exportParam" >
  90. <el-form-item prop="projectId" :label="$t('defaultText.selectProject')" v-if="radio != $t('ren-yuan') && radio != $t('projectclassification') && radio != $t('lable.department')">
  91. <el-select v-model="exportParam.projectId" :placeholder="$t('other.allProject')" clearable style="width:350px;" filterable="true" popper-class="projectSelectPopperClass">
  92. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName + item.projectCode" :value="item.id">
  93. <span style="float: left;color: #8492a6;">{{ item.projectCode }}</span>
  94. <span style="float: right;font-size: 13px;">{{ item.projectName }}</span>
  95. </el-option>
  96. </el-select>
  97. </el-form-item>
  98. <el-form-item prop="exportContent" label="导出内容" v-if="permissions.countCost && permissions.countHours && (radio == $t('other.project') || radio == $t('projectclassification'))">
  99. <el-select v-model="exportParam.exportContent" style="width:350px;" filterable="true" popper-class="projectSelectPopperClass">
  100. <el-option label="工时和成本" value="hoursAndCost"></el-option>
  101. <el-option label="仅工时" value="hours"></el-option>
  102. <el-option label="仅成本" value="cost"></el-option>
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item :label="$t('departmentchoice')" v-if="radio == $t('other.project')">
  106. <el-cascader v-if="user.userNameNeedTranslate != 1" v-model="exportParam.deptId" :options="departmentList" :placeholder="$t('defaultText.pleaseChoose')"
  107. :props="{ checkStrictly: true, expandTrigger: 'hover' }" clearable filterable style="width:350px;"
  108. ></el-cascader>
  109. <vueCascader :size="'medium'" :widthStr="'350'" :clearable="true" :subject="departmentList" :radios="true" :distinction="'1'" @vueCasader="vueCasader" v-if="user.userNameNeedTranslate == 1"></vueCascader>
  110. </el-form-item>
  111. <el-form-item prop="projectCategoryId" :label="$t('projectclassification')" v-if="radio == $t('projectclassification')">
  112. <el-select v-model="exportParam.projectCategoryId" :placeholder="$t('classificationitems')" clearable style="width:350px;" filterable="true">
  113. <el-option v-for="item in categoryList" :key="item.id" :label="item.name" :value="item.id">
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item prop="userIds" :label="$t('screening.selectPeople')" v-if="radio == $t('ren-yuan')">
  118. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userIds" :placeholder="$t('lable.allStaff')" multiple="true" clearable style="width:350px;" filterable="true">
  119. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  120. </el-select>
  121. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :widthStr="'350'" :filterable="true" :subject="hasReportUserList" :clearable="true" :multiSelect="true" @selectCal="selectCal" :distinction="'1'"></selectCat>
  122. </el-form-item>
  123. <el-form-item prop="userIds" :label="$t('screening.selectPeople')" v-if="radio == $t('other.project') || radio == $t('projectclassification')">
  124. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userIds" :placeholder="$t('lable.allStaff')" multiple="true" clearable style="width:350px;" filterable="true">
  125. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  126. </el-select>
  127. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :widthStr="'350'" :filterable="true" :subject="users" :clearable="true" :multiSelect="true" @selectCal="selectCal" :distinction="'1'"></selectCat>
  128. </el-form-item>
  129. <el-form-item prop="projectId" :label="user.timeType.fixMonthcost==0?$t('time.dateRange'):$t('Selectmonth')">
  130. <el-date-picker v-show="user.timeType.fixMonthcost==0"
  131. v-model="exportParam.dateRange" :editable="false"
  132. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  133. :clearable="false"
  134. :range-separator="$t('other.to')"
  135. type="daterange"
  136. :start-placeholder="$t('time.startDate')"
  137. :end-placeholder="$t('time.endDate')"
  138. ></el-date-picker>
  139. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  140. v-model="dateRange" :editable="false"
  141. format="yyyy-MM" value-format="yyyy-MM"
  142. @change="getEchart"
  143. :clearable="true"
  144. type="month"
  145. ></el-date-picker>
  146. </el-form-item>
  147. <el-form-item :label="$t('screening.selectPeople')" v-if="false">
  148. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userId" :placeholder="$t('lable.allStaff')" style="width: 350px" filterable="true" clearable="true">
  149. <span v-for="(item, index) in users" :key="index">
  150. <el-option :label="item.name" :value="item.id"></el-option>
  151. </span>
  152. </el-select>
  153. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :distinction="'4'" :widthStr="'350'" :subject="users" :clearable="true" @selectCal="selectCal"></selectCat>
  154. </el-form-item>
  155. <el-form-item prop="type" :label="$t('choosethestyle')" v-if="radio == $t('other.project') || radio == $t('projectclassification')">
  156. <el-select v-model="exportParam.type" :placeholder="$t('choosethestyle')" style="width:350px;" >
  157. <el-option :label="radio == $t('projectclassification') ? $t('classifiedontheline') : $t('Itemontheline')" value="0"></el-option>
  158. <el-option :label="radio == $t('projectclassification') ? $t('classifiedcolumns') : $t('itemisonthecolumn')" value="1"></el-option>
  159. </el-select>
  160. <div class="prompt">
  161. <el-popover placement="top" width="1200" trigger="hover">
  162. <img src="../../assets/image/hanglie.png" alt="" width="100%" v-if="this.radio != $t('projectclassification')">
  163. <img src="../../assets/image/hanglie_corp.png" alt="" width="100%" v-else>
  164. <i class="el-icon-question" slot="reference" />
  165. </el-popover>
  166. </div>
  167. </el-form-item>
  168. <el-form-item v-if="exportParam.type == 1 && permissions.countHours && (radio == $t('other.project'))">
  169. <el-checkbox v-model="exportParam.withPercent" >含项目工时占比</el-checkbox>
  170. </el-form-item>
  171. <el-form-item v-if="(radio == $t('other.project') || radio == $t('projectclassification')) && exportParam.type == '0'">
  172. <el-checkbox v-model="exportParam.projectSum" >{{ $t('individualprojectdata') }}</el-checkbox>
  173. </el-form-item>
  174. </el-form>
  175. <div slot="footer" class="dialog-footer">
  176. <el-button type="primary" @click="exportProjectData" style="width:100%;" >{{ $t('export.export') }}</el-button>
  177. </div>
  178. </el-dialog>
  179. </section>
  180. </template>
  181. <script>
  182. // 引入自定义组件
  183. import selectCat from "@/components/select.vue"
  184. //引入自定义级联组件
  185. import vueCascader from "@/components/cascader.vue"
  186. import util from "../../common/js/util";
  187. export default {
  188. components: {
  189. selectCat,
  190. vueCascader
  191. },
  192. data() {
  193. return {
  194. totalTime111: 0,
  195. allListData: [],
  196. page: 1,
  197. size: 50,
  198. total: 0,
  199. personnelValue: '',
  200. personnelAll: [],
  201. personnelAllPlly: [],
  202. yAxisValue: localStorage.yAxisValue?localStorage.yAxisValue:0,
  203. parentDeptStack:[],
  204. parentDeptId:null,
  205. hasReportUserList:[],
  206. projectList:[],
  207. categoryList: [],
  208. exportParam:{projectId:null,dateRange:[],userId: null,type: '0', withPercent: false},
  209. exportDialog:false,
  210. dateRange:[],
  211. user: JSON.parse(sessionStorage.getItem("user")),
  212. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  213. radio: sessionStorage.radio!=null?sessionStorage.radio:this.$t('other.project'),
  214. containerHeight: 0,
  215. // myChart: null,
  216. params: null,
  217. widthHtval: document.body.clientWidth - 230,
  218. users: [],
  219. jichu: [],
  220. namess: '',
  221. timers: null, // 点击的时间
  222. zhishin: 0,
  223. theCustomList: [], // 自定义数据来源
  224. theCustomListFlg: false, // 判断是否点击的是自定义配置的数据来源
  225. theCustomListId: '',
  226. theCustomListPlantLIst: [],
  227. theCustomListPlant: '',
  228. customId: '',
  229. customName: '',
  230. customList: [],
  231. departmentList: [],
  232. radioLoading: false,
  233. proJuctId:'',
  234. };
  235. },
  236. methods: {
  237. echartsCurrentChange(val){
  238. this.page = val
  239. if(this.radio == this.$t('ren-yuan')){
  240. this.gtff()
  241. }else{
  242. this.jieliu_echarts()
  243. }
  244. },
  245. //Y轴点击改变显示的数据
  246. onYAxisChange() {
  247. localStorage.yAxisValue = this.yAxisValue;
  248. this.jieliu();
  249. },
  250. jutishez() {
  251. this.http.post('/time-type/getCompanyTimeSetting', {
  252. companyId: this.user.companyId,
  253. },
  254. res => {
  255. if (res.code == "ok") {
  256. this.jichu = res.data
  257. if(res.data.customDegreeActive == 1) {
  258. this.namess = res.data.customDegreeName
  259. }
  260. } else {
  261. this.$message({
  262. message: res.msg,
  263. type: "error"
  264. });
  265. }
  266. },
  267. error => {
  268. this.$message({
  269. message: error,
  270. type: "error"
  271. });
  272. });
  273. },
  274. getUsers() {
  275. this.http.post('/user/getSimpleActiveUserList', {},
  276. res => {
  277. if (res.code == "ok") {
  278. this.users = res.data;
  279. } else {
  280. this.$message({
  281. message: res.msg,
  282. type: "error"
  283. });
  284. }
  285. },
  286. error => {
  287. this.$message({
  288. message: error,
  289. type: "error"
  290. });
  291. });
  292. },
  293. showExportDialog() {
  294. // console.log(12345)
  295. // 清空选择的人
  296. if(this.radio == this.$t('ren-yuan')) {
  297. this.exportParam.userIds = new Array()
  298. }
  299. console.log(this.exportParam)
  300. this.exportDialog = true;
  301. this.exportParam.dateRange = this.dateRange;
  302. // console.log(this.hasReportUserList)
  303. if (this.radio == this.$t('ren-yuan')) {
  304. // this.exportParam.userIds = [];
  305. }
  306. if (this.radio == this.$t('other.project')) {
  307. this.exportParam.deptId = []
  308. }
  309. if(this.permissions.countCost && this.permissions.countHours && (this.radio == this.$t('other.project') || this.radio == this.$t('projectclassification'))){
  310. this.$set(this.exportParam, 'exportContent', 'hoursAndCost')
  311. }
  312. },
  313. //获取我的项目列表
  314. getMyProjectList() {
  315. this.http.post('/project/getProjectList', {
  316. },
  317. res => {
  318. if (res.code == "ok") {
  319. this.projectList = res.data;
  320. } else {
  321. this.$message({
  322. message: res.msg,
  323. type: "error"
  324. });
  325. }
  326. },
  327. error => {
  328. this.$message({
  329. message: error,
  330. type: "error"
  331. });
  332. });
  333. },
  334. exportProjectData() {
  335. var param = {stateKey: 1};
  336. if (this.exportParam.dateRange != null) {
  337. param = {startDate:this.exportParam.dateRange[0], endDate: this.exportParam.dateRange[1],stateKey: 1};
  338. }
  339. var url = "/project/exportTimeCost";
  340. var fileName = this.$t('projectmanhourcoststatistics')+ '.xlsx';
  341. if(this.radio == this.$t('other.project')){
  342. if (this.exportParam.userIds != null && this.exportParam.userIds.length > 0) {
  343. var ids = '';
  344. this.exportParam.userIds.forEach(u=>{
  345. ids += u+',';
  346. })
  347. param.userIds = ids.substring(0,ids.length-1);
  348. }
  349. //是否含工时占比显示
  350. if (this.exportParam.withPercent) {
  351. param.withPercent = 1;
  352. }
  353. }
  354. if (this.radio == this.$t('ren-yuan') ) {
  355. // console.log(this.exportParam.userIds);
  356. fileName = this.$t('labortimecoststatistics')+ '.xlsx';
  357. url = '/department/exportUserStatistic';
  358. if (this.exportParam.userIds != null && this.exportParam.userIds.length > 0) {
  359. var ids = '';
  360. this.exportParam.userIds.forEach(u=>{
  361. ids += u+',';
  362. })
  363. param.userIds = ids.substring(0,ids.length-1);
  364. }
  365. }
  366. if(this.radio == this.$t('projectclassification')){
  367. fileName = this.$t('projectclassificationlaborosttatistics')+ '.xlsx';
  368. url = '/project/exportTimeCostByCategory'
  369. if(this.exportParam.projectCategoryId){
  370. param.projectCategoryId = this.exportParam.projectCategoryId
  371. }
  372. if (this.exportParam.userIds != null && this.exportParam.userIds.length > 0) {
  373. var ids = '';
  374. this.exportParam.userIds.forEach(u=>{
  375. ids += u+',';
  376. })
  377. param.userIds = ids.substring(0,ids.length-1);
  378. }
  379. }
  380. if(this.radio == this.$t('lable.department')){
  381. fileName = this.$t('departmenthourscoststatistics')+ '.xlsx'
  382. url = '/department/exportDeptStatistic'
  383. }
  384. if (this.exportParam.projectId && this.radio != this.$t('ren-yuan') && this.radio != this.$t('projectclassification')) {
  385. param.projectId = this.exportParam.projectId;
  386. }
  387. if (this.exportParam.userId) {
  388. if(this.radio == this.$t('lable.department') || this.radio == this.$t('ren-yuan')){
  389. param.userId = this.exportParam.userId;
  390. }
  391. }
  392. if (this.exportParam.type == 1) {
  393. this.exportParam.projectSum = null
  394. }
  395. if (this.exportParam.projectSum != null) {
  396. if(this.radio == this.$t('other.project') || this.radio == this.$t('lable.department') || this.radio == this.$t('projectclassification')){
  397. param.projectSum = this.exportParam.projectSum;
  398. }
  399. }
  400. if(!this.theCustomListFlg) {
  401. param.type = this.exportParam.type*1
  402. }
  403. console.log(this.radio)
  404. if(this.theCustomListFlg) {
  405. url = '/project/exportTimeCostByUserCustom'
  406. fileName = this.radio + this.$t('statistical') + '.xlsx'
  407. // param.subCustomName = this.customName
  408. param.customId = this.theCustomListId
  409. param.fieldName = this.theCustomListPlant
  410. }
  411. if(this.exportParam.deptId) {
  412. if(this.exportParam.deptId.length > 0) {
  413. param.deptId = this.exportParam.deptId[this.exportParam.deptId.length - 1]
  414. }
  415. }
  416. if(this.permissions.countCost && this.permissions.countHours && (this.radio == this.$t('other.project') || this.radio == this.$t('projectclassification'))){
  417. param.exportContent = this.exportParam.exportContent
  418. }
  419. if(this.radio == this.namess) {
  420. url = '/project/exportDegreeCost'
  421. param = {
  422. startDate:this.exportParam.dateRange[0],
  423. endDate: this.exportParam.dateRange[1],
  424. projectId: this.exportParam.projectId,
  425. }
  426. fileName = this.radio + '成本统计' + '.xlsx'
  427. }
  428. this.http.post(url, param,
  429. res => {
  430. if (res.code == "ok") {
  431. this.exportDialog = false;
  432. var aTag = document.createElement('a');
  433. aTag.download = fileName;
  434. aTag.href = res.data;
  435. aTag.click();
  436. } else {
  437. this.$message({
  438. message: res.msg,
  439. type: "error"
  440. });
  441. }
  442. },
  443. error => {
  444. this.$message({
  445. message: error,
  446. type: "error"
  447. });
  448. });
  449. },
  450. // 人员筛选
  451. personnel() {
  452. this.page = 1
  453. if(this.personnelValue) {
  454. var arrlist = JSON.parse(JSON.stringify(this.personnelAllPlly))
  455. var arr = []
  456. for(var i in arrlist.list) {
  457. // console.log(arrlist.list[i].name, this.personnelValue)
  458. if(arrlist.list[i].name == this.personnelValue) {
  459. arr.push(arrlist.list[i])
  460. }
  461. }
  462. arrlist.list = arr
  463. this.allListData = arrlist
  464. // this.gtff()
  465. if(this.user.userNameNeedTranslate == '1') {
  466. if(arrlist.list.length > 0) {
  467. let list = arrlist.list
  468. let dealWithList = []
  469. for(var i in list) {
  470. let obj = {}
  471. obj.type = list[i].type
  472. obj.id = list[i].name
  473. dealWithList.push(obj)
  474. }
  475. this.dealWithTranslationPlone(dealWithList)
  476. } else {
  477. this.getUserCostList()
  478. }
  479. } else {
  480. this.allListData = arrlist
  481. this.gtff()
  482. }
  483. } else {
  484. this.allListData = this.personnelAllPlly
  485. this.gtff()
  486. }
  487. },
  488. //获取人员成本统计列表
  489. getUserCostList() {
  490. // console.log(this.port.project.userCost, '获取人员成本统计列表')
  491. // console.log(this.user.timeType.fixMonthcost)
  492. // console.log(Boolean(this.dateRange))
  493. let startDateNum = ''
  494. let endDateNum = ''
  495. if(this.dateRange) {
  496. startDateNum = this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange
  497. endDateNum = this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
  498. }
  499. // return
  500. this.http.post(this.port.project.userCost, {
  501. // startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
  502. // endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
  503. startDate: startDateNum,
  504. endDate: endDateNum
  505. },
  506. res => {
  507. this.radioLoading = false
  508. var _this = this;
  509. this.hasReportUserList = [];
  510. if (res.code == "ok") {
  511. let alltime = 0
  512. for(let i in res.data.list){
  513. for(let m in res.data.list[i].project){
  514. alltime += parseFloat(res.data.list[i].project[m].time)
  515. }
  516. }
  517. this.totalTime111 = alltime
  518. //
  519. //
  520. this.personnelAll = res.data
  521. this.allListData = res.data
  522. this.personnelAllPlly = JSON.parse(JSON.stringify(res.data))
  523. if(this.user.userNameNeedTranslate == '1') {
  524. let list = res.data.list
  525. let dealWithList = []
  526. for(var i in list) {
  527. let obj = {}
  528. obj.type = list[i].type
  529. obj.id = list[i].name
  530. dealWithList.push(obj)
  531. }
  532. this.dealWithTranslationPlone(dealWithList, res.data.list)
  533. } else {
  534. this.personnelAll = res.data
  535. this.allListData = res.data
  536. // console.log('人员返回', this.allListData);
  537. this.gtff()
  538. }
  539. } else {
  540. this.$message({
  541. message: res.msg + '里面',
  542. type: "error"
  543. });
  544. }
  545. },
  546. error => {
  547. this.radioLoading = false
  548. this.$message({
  549. message: error + '外面',
  550. type: "error"
  551. });
  552. });
  553. },
  554. // 共同方法
  555. gtff() {
  556. let data = this.allListData
  557. var _this = this;
  558. this.hasReportUserList = data.userList;
  559. this.total = data.list ? data.list.length : 0
  560. var totalHours = 0.0;
  561. var xList = [] , yList = [] , list = data.list.slice(0+50*(this.page-1),49+50*(this.page-1)), array = [] , series = [];
  562. var totalMoneyCost = data.totalCostMoney;
  563. for(var i in list) {
  564. if(i>20) {
  565. this.widthHtval = +this.widthHtval + 60
  566. } else {
  567. this.widthHtval = document.body.clientWidth - 230
  568. }
  569. }
  570. if (list.length > 0) {
  571. var num = list.length==0?0:list[0].project.length;
  572. // console.log('for 1');
  573. for(var i in list) {
  574. xList.push(list[i].name);
  575. var pro = list[i].project;
  576. for(var j in pro) {
  577. if(array.indexOf(pro[j].project) == -1) {
  578. array.push(pro[j].project)
  579. }
  580. }
  581. }
  582. // console.log('for 2');
  583. for(var i in array) {
  584. yList.push(array[i]);
  585. var dataList = [];
  586. let nameObj = {}
  587. list.forEach(item => {
  588. let moneyTol = 0;
  589. let timeTol = 0;
  590. item.project.forEach((project, index) => {
  591. moneyTol += +project.money;
  592. timeTol += +project.time;
  593. });
  594. // 假设每个 item.project 都至少有一个元素
  595. if (item.project.length > 0) {
  596. const lastProject = item.project[item.project.length - 1];
  597. nameObj[item.name] = {moneyTol: moneyTol, timeTol: timeTol}
  598. lastProject.moneyTol = moneyTol;
  599. lastProject.timeTol = timeTol;
  600. }
  601. });
  602. // console.log('==================>', list, nameObj);
  603. for(var j in list) {
  604. var project = list[j].project , num = 0;
  605. if(project.length != 0) {
  606. // console.log('for 2 1 1');
  607. for(var k in project) {
  608. if(project[k].project == array[i]) {
  609. let item = {
  610. "value": this.yAxisValue==0?project[k].money:project[k].time,
  611. }
  612. if(this.permissions.countCost){
  613. item.money = project[k].money
  614. }
  615. if(this.permissions.countHours){
  616. item.cost = project[k].time
  617. // totalHours += parseFloat(project[k].time);
  618. }
  619. if(project[k].moneyTol) {
  620. item.moneyTol = project[k].moneyTol
  621. item.timeTol = project[k].timeTol
  622. }
  623. dataList.push(item)
  624. } else {
  625. num++;
  626. }
  627. if(k == project.length-1 && num != project.length-1) {
  628. dataList.push({
  629. "value": 0,
  630. "cost": 0,
  631. "money":0,
  632. })
  633. }
  634. }
  635. } else {
  636. dataList.push({
  637. "value": 0,
  638. "cost": 0,
  639. "money":0,
  640. })
  641. }
  642. }
  643. // console.log(array[i], dataList, array, '《==============看看数据')
  644. let cerName = array[array.length - 1] // 最后一个项目
  645. let yAxisValue = this.yAxisValue
  646. series.push({
  647. name: array[i],
  648. type: 'bar',
  649. stack: '1',
  650. barMaxWidth: 30,
  651. data: dataList,
  652. label: {
  653. normal: {
  654. show: true,
  655. position: 'top',
  656. formatter: function(params) {
  657. const { seriesName, data, name} = params
  658. if(!name) {
  659. return ''
  660. }
  661. const unit = yAxisValue == 0 ? '元' : '小时';
  662. console.log(nameObj, name, nameObj[name], params)
  663. const totalValue = yAxisValue == 0 ? nameObj[name].moneyTol : nameObj[name].timeTol;
  664. return seriesName === cerName ? `${totalValue ? totalValue.toFixed(0) : 0} ${unit}` : '';
  665. }
  666. }
  667. }
  668. });
  669. }
  670. }
  671. var myChart = echarts.init(document.getElementById("container"));
  672. totalHours = this.totalTime111.toFixed(1);
  673. // 设置宽度
  674. myChart.resize({
  675. width: this.widthHtval
  676. })
  677. // console.log('设置宽度');
  678. // 设置宽度
  679. _this.myChart = myChart;
  680. var option = {
  681. //总成本
  682. title: {
  683. // text: '工时成本总计' + totalMoneyCost.toFixed(2) + '元, 时长'+totalHours+'小时',
  684. text: this.$t('otalhourscost')+ ':' +
  685. ((this.permissions.countCost) ? this.$t('costof') + ' ' + totalMoneyCost.toFixed(2) + ' ' + this.$t('yuan') + ',' : '') +
  686. ((this.permissions.countHours) ? this.$t('time.duration') + ' ' +totalHours + ' ' + this.$t('time.hour') : ''),
  687. left:'left',
  688. },
  689. // 工具箱
  690. legend: {
  691. x: 80,
  692. y: 10,
  693. data: yList,
  694. show: true,
  695.       top:"5%",//与上方的距离 可百分比% 可像素px
  696. },
  697. grid : {
  698. top : 80, //距离容器上边界40像素
  699. // bottom: 100, //距离容器下边界30像素
  700. bottom: 35, //距离容器下边界30像素
  701. left: 150,
  702. right: 150
  703. },
  704. toolbox: {
  705. show: true,
  706. feature:{
  707. saveAsImage:{
  708. show: this.user.userNameNeedTranslate == 1 ? false : true
  709. },
  710. restore:{
  711. show:true
  712. },
  713. magicType:{
  714. type:['line','bar']
  715. }
  716. }
  717. },
  718. tooltip:{
  719. trigger:'axis',
  720. formatter: function (params,ticket,callback) {
  721. var totalTime = 0;
  722. var totalCost = 0;
  723. var res = "";
  724. for(var i in params) {
  725. if (params[i].data.value > 0) {
  726. res += "<div style='margin-top:3px;font-size:12px;'><font color='#ddd'>" + _this.$t('headerTop.projectName') + ":" + params[i].seriesName
  727. + "</font><br/>" +
  728. ((_this.permissions.countCost) ? _this.$t('workcost')+ ":" + params[i].data.money + _this.$t('yuan') + "</br>" : '') +
  729. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + ":" + params[i].data.cost + _this.$t('time.hour') + "</br>" : '') + "</div>";
  730. totalTime += Number(params[i].data.cost);
  731. totalCost += Number(params[i].data.money);
  732. }
  733. }
  734. if(_this.user.userNameNeedTranslate != 1) {
  735. res = res +'<br/>'+ params[0].name+ '<br/>' + _this.$t('zong-ji') + ':' +
  736. ((_this.permissions.countHours) ? totalTime.toFixed(1) + _this.$t('time.hour') : '') +
  737. ((_this.permissions.countCost) ? totalCost.toFixed(2) + _this.$t('yuan') : '') +
  738. "<br/>";
  739. } else {
  740. res = res +'<br/>'+ '' + '<br/>' + _this.$t('zong-ji') + ':' +
  741. ((_this.permissions.countHours) ? totalTime.toFixed(1) + _this.$t('time.hour') : '') +
  742. ((_this.permissions.countCost) ? totalCost.toFixed(2) + _this.$t('yuan') : '') +
  743. "<br/>";
  744. }
  745. return res;
  746. }
  747. },
  748. xAxis: {
  749. data: xList,
  750. axisLabel: {
  751. interval:0,rotate:20
  752. }
  753. },
  754. yAxis: [{
  755. type : 'value',
  756. axisLabel: {
  757. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value} ('+this.$t('time.hour')+')'
  758. // formatter:this.yAxisValue==0?'{value} (元)':'{value} (小时)'
  759. }
  760. }],
  761. series: series,
  762. };
  763. console.log('人员=======>', series)
  764. // console.log('setoption');
  765. myChart.setOption(option,{notMerge:true});
  766. },
  767. yanjiu() {
  768. // console.log('触发')
  769. },
  770. getEchart(e){
  771. var that = this
  772. // 更具选中的名字筛选出对应的自定义id
  773. that.theCustomListFlg = false
  774. let ints = null
  775. for(var i in that.theCustomList) {
  776. if(that.radio == that.theCustomList[i].name) {
  777. that.theCustomListId = that.theCustomList[i].id
  778. that.theCustomListPlant = that.theCustomListPlantLIst[i]
  779. that.theCustomListFlg = true
  780. ints = i
  781. }
  782. }
  783. if(that.theCustomListFlg) {
  784. that.customList = that.theCustomList[ints].subUserCustomList
  785. that.customName = that.theCustomList[ints].subUserCustomList[0].name
  786. // that.getCusTom()
  787. }
  788. that.jieliu()
  789. },
  790. getCusTom() {
  791. this.http.post('/sub-user-custom/list',{
  792. userCustomId: this.theCustomListId
  793. },res => {
  794. if(res.code == 'ok'){
  795. this.customList = res.data
  796. this.customName = res.data[0].name
  797. }else {
  798. this.$message({
  799. message: res.msg,
  800. type: 'error'
  801. })
  802. }
  803. },error => {
  804. this.$message({
  805. message: error,
  806. type: 'error'
  807. })
  808. })
  809. },
  810. getCategoryList(){
  811. this.http.post('/project-category/list',{},
  812. res => {
  813. if(res.code == 'ok'){
  814. this.categoryList = res.data
  815. }else {
  816. this.$message({
  817. message: res.msg,
  818. type: 'error'
  819. })
  820. }
  821. },err => {
  822. this.$message({
  823. message: err,
  824. type: 'error'
  825. })
  826. })
  827. },
  828. backToParentDept() {
  829. if (this.radio == this.$t('lable.department')) {
  830. if (this.parentDeptStack.length > 0) {
  831. this.parentDeptStack.pop();
  832. if (this.parentDeptStack.length > 0) {
  833. this.parentDeptId = this.parentDeptStack[this.parentDeptStack.length -1];
  834. } else {
  835. this.parentDeptId = null;
  836. }
  837. this.jieliu();
  838. }
  839. }
  840. },
  841. // 脱离出来的方法
  842. jieliu() {
  843. sessionStorage.radio = this.radio;
  844. this.radioLoading = true
  845. var param = {};
  846. if (this.dateRange != null) {
  847. param = {
  848. startDate:this.user.timeType.fixMonthcost==0?this.dateRange[0]:this.dateRange,
  849. endDate: this.user.timeType.fixMonthcost==0?this.dateRange[1]:this.dateRange
  850. };
  851. // console.log(param);
  852. }
  853. var url = '';
  854. if (this.radio==this.$t('other.project')) {
  855. url = this.port.project.listCost;
  856. param.projectId=this.proJuctId
  857. param.type=this.yAxisValue
  858. }else if(this.radio == this.$t('zhu-xiang-mu')){
  859. url = '/project/getTimeCostByMainProject'
  860. // param.userId = this.user.id
  861. }else if (this.radio==this.$t('projectclassification')) {
  862. url = '/project/getTimeCostByCategory';
  863. // param.parentDeptId = this.parentDeptId;
  864. // param.userId = this.user.id
  865. } else if (this.radio==this.$t('lable.department')) {
  866. url = this.port.project.depCost;
  867. param.parentDeptId = this.parentDeptId;
  868. } else if (this.radio==this.$t('ren-yuan')) {
  869. this.getUserCostList();
  870. return;
  871. } else if (this.radio == this.namess) {
  872. url = '/project/getDegreeCost'
  873. param.projectId=this.proJuctId
  874. } else if (this.theCustomListFlg) {
  875. url = '/project/getTimeCostByUserCustom'
  876. // param.subCustomName = this.customName
  877. param.customId = this.theCustomListId
  878. param.fieldName = this.theCustomListPlant
  879. // console.log(param, '要传的数据')
  880. }
  881. this.http.post(url, param,
  882. res => {
  883. if (res.code == "ok") {
  884. this.radioLoading = false
  885. let alltime = 0
  886. if(this.radio==this.$t('other.project') || this.radio == this.$t('zhu-xiang-mu') || this.radio==this.$t('projectclassification')){
  887. for(let i in res.data.costList){
  888. alltime += parseFloat(res.data.costList[i].cost)
  889. }
  890. }else if(this.radio==this.$t('lable.department')){
  891. for(let i in res.data.costList){
  892. alltime += parseFloat(res.data.costList[i].costTime)
  893. }
  894. }else if(this.radio == this.namess){
  895. for(let i in res.data){
  896. alltime += parseFloat(res.data[i].cost)
  897. }
  898. }else if(this.theCustomListFlg){
  899. for(let i in res.data.list){
  900. alltime += parseFloat(res.data.list[i].cost)
  901. }
  902. }
  903. this.totalTime111 = alltime
  904. // additionName // 未转译的数据另外存储一份,用作 DOM 上渲染
  905. if(this.user.userNameNeedTranslate == '1') {
  906. for(var i in res.data.costList) {
  907. res.data.costList[i].additionName = res.data.costList[i].departmentName
  908. }
  909. }
  910. this.allListData = res.data
  911. this.page = 1
  912. if(this.user.userNameNeedTranslate == '1' && this.radio == this.$t('lable.department')) {
  913. let arr = []
  914. for(var i in this.allListData.costList) {
  915. let obj = {}
  916. obj.type = this.allListData.costList[i].type
  917. obj.id = this.allListData.costList[i].departmentName
  918. arr.push(obj)
  919. }
  920. this.dealWithTranslation(arr)
  921. } else {
  922. this.jieliu_echarts()
  923. }
  924. } else {
  925. this.radioLoading = false
  926. this.$message({
  927. message: res.msg,
  928. type: "error"
  929. });
  930. }
  931. },
  932. error => {
  933. this.radioLoading = false
  934. this.$message({
  935. message: error,
  936. type: "error"
  937. });
  938. });
  939. },
  940. dealWithTranslation(items) {
  941. if (WWOpenData.initCanvas) {
  942. WWOpenData.initCanvas()
  943. }
  944. const myFunOne = async () => {
  945. const result = await new Promise((resolve, reject) => {
  946. if(WWOpenData.prefetch) {
  947. WWOpenData.prefetch({ items }, (err, data) => {
  948. if (err) { return reject(err) }
  949. resolve(data)
  950. })
  951. }
  952. })
  953. for(var i in this.allListData.costList) {
  954. this.allListData.costList[i].departmentName = result.items[i].data
  955. }
  956. this.jieliu_echarts()
  957. }
  958. myFunOne()
  959. },
  960. dealWithTranslationPlone(items, dataList) {
  961. if (WWOpenData.initCanvas) {
  962. WWOpenData.initCanvas()
  963. }
  964. const myFunOne = async () => {
  965. const result = await new Promise((resolve, reject) => {
  966. if(WWOpenData.prefetch) {
  967. WWOpenData.prefetch({ items }, (err, data) => {
  968. if (err) { return reject(err) }
  969. resolve(data)
  970. })
  971. }
  972. })
  973. for(var i in this.allListData.list) {
  974. if(result.items[i]) {
  975. this.allListData.list[i].name = result.items[i].data
  976. }
  977. }
  978. this.gtff()
  979. }
  980. myFunOne()
  981. },
  982. jieliu_echarts(){
  983. var _this = this;
  984. // 更具数据的长度去加每个柱子的间距
  985. var xList = []
  986. var yList = []
  987. var list
  988. var totalMoneyCost;
  989. var totalHours = 0.0;
  990. if(this.radio == this.$t('other.project') || this.radio == this.$t('projectclassification') || this.radio==this.$t('lable.department') || this.radio == this.$t('zhu-xiang-mu')) {
  991. // this.allListData = res.data.costList
  992. this.total = this.allListData.costList ? this.allListData.costList.length : 0
  993. list = this.allListData.costList.slice(0+50*(this.page-1),49+50*(this.page-1))
  994. for(var i in list) {
  995. if(i>20) {
  996. this.widthHtval = +this.widthHtval + 60
  997. } else {
  998. this.widthHtval = document.body.clientWidth - 230
  999. }
  1000. }
  1001. // list = res.data.costList
  1002. totalMoneyCost = ((this.radio==this.$t('other.project') || this.radio == this.$t('projectclassification'))?this.allListData.totalMoneyCost:this.allListData.totalCostMoney);
  1003. for(var i in list) {
  1004. if(this.radio==this.$t('other.project') || this.radio == this.$t('zhu-xiang-mu')) {
  1005. if(this.radio == this.$t('other.project')){
  1006. xList.push(list[i].project);
  1007. }else{
  1008. xList.push(list[i].mainProjectName);
  1009. }
  1010. let item = {
  1011. "value": this.yAxisValue==0?(list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney:(list[i].cost ? list[i].cost.toFixed(1) : 0),
  1012. "id": list[i].id || i,
  1013. }
  1014. if(this.permissions.countCost){
  1015. // item.money = list[i].costMoney.toFixed(2)
  1016. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  1017. }
  1018. if(this.permissions.countHours){
  1019. item.cost = list[i].cost
  1020. totalHours += parseFloat(list[i].cost);
  1021. }
  1022. yList.push(item);
  1023. } else if(this.radio == this.$t('lable.department')){
  1024. xList.push(list[i].departmentName);
  1025. let item = {
  1026. // "value": this.yAxisValue==0 ? list[i].costMoney.toFixed(2) || list[i].costMoney: list[i].costTime.toFixed(1),
  1027. "value": this.yAxisValue==0 ? (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney: (list[i].costTime ? list[i].costTime.toFixed(1) : 0),
  1028. "id": list[i].departmentId,
  1029. "hasSubDept": list[i].hasSubDept
  1030. }
  1031. if(this.permissions.countCost){
  1032. // item.money = list[i].costMoney.toFixed(2)
  1033. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  1034. }
  1035. if(this.permissions.countHours){
  1036. item.cost = list[i].costTime
  1037. totalHours += parseFloat(list[i].costTime);
  1038. }
  1039. yList.push(item);
  1040. }else {
  1041. xList.push(list[i].categoryName);
  1042. let item = {
  1043. // "value": this.yAxisValue==0?list[i].costMoney.toFixed(2) || list[i].costMoney:list[i].cost.toFixed(1),
  1044. "value": this.yAxisValue==0?(list[i].costMoney ? list[i].costMoney.toFixed(2) : 0) || list[i].costMoney:(list[i].cost ? list[i].cost.toFixed(1) : 0),
  1045. "id": list[i].id || i,
  1046. }
  1047. if(this.permissions.countCost){
  1048. // item.money = list[i].costMoney.toFixed(2)
  1049. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  1050. }
  1051. if(this.permissions.countHours){
  1052. item.cost = list[i].cost
  1053. totalHours += parseFloat(list[i].cost);
  1054. }
  1055. yList.push(item);
  1056. }
  1057. }
  1058. }
  1059. else if(this.theCustomListFlg) {
  1060. // this.allListData = res.data.list ? res.data.list : []
  1061. this.total = this.allListData.list ? this.allListData.list.length : 0
  1062. list = this.total ? this.allListData.list.slice(0+50*(this.page-1),49+50*(this.page-1)) : []
  1063. // list = res.data.list
  1064. for(var i in list) {
  1065. xList.push(list[i].name);
  1066. let item = {
  1067. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  1068. "id": list[i].id || i,
  1069. }
  1070. if(this.permissions.countCost){
  1071. // item.money = list[i].costMoney.toFixed(2)
  1072. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  1073. totalMoneyCost += parseFloat(list[i].costMoney);
  1074. }
  1075. if(this.permissions.countHours){
  1076. item.cost = list[i].cost
  1077. totalHours += parseFloat(list[i].cost);
  1078. }
  1079. yList.push(item);
  1080. }
  1081. }
  1082. else {
  1083. //自定义列表:data:{cost:3, costMoney:222}
  1084. this.total = this.allListData ? this.allListData.length : 0
  1085. // if(this.total){
  1086. list = this.allListData.slice(0+50*(this.page-1),49+50*(this.page-1))
  1087. // }else{
  1088. // list =
  1089. // }
  1090. // list = this.total ? : []
  1091. for(var i in list) {
  1092. xList.push(list[i].name);
  1093. let item = {
  1094. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  1095. "id": list[i].id || i,
  1096. }
  1097. if(this.permissions.countCost){
  1098. // item.money = list[i].costMoney.toFixed(2)
  1099. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  1100. totalMoneyCost += parseFloat(list[i].costMoney);
  1101. }
  1102. if(this.permissions.countHours){
  1103. item.cost = list[i].cost
  1104. totalHours += parseFloat(list[i].cost);
  1105. }
  1106. yList.push(item);
  1107. }
  1108. }
  1109. totalHours = this.totalTime111.toFixed(1);
  1110. var myChart = echarts.init(document.getElementById("container"));
  1111. myChart.resize({
  1112. width: this.widthHtval
  1113. })
  1114. _this.myChart = myChart;
  1115. if(totalMoneyCost) {
  1116. this.zhishin = totalMoneyCost.toFixed(2)
  1117. }
  1118. if(this.radio == this.$t('other.project') || this.radio == this.$t('zhu-xiang-mu') || this.radio == this.$t('ren-yuan') || this.radio == this.$t('projectclassification') || this.radio==this.$t('lable.department')) {
  1119. var option = {
  1120. title: {
  1121. text: this.$t('otalhourscost') + ':' + ((this.permissions.countCost) ? this.$t('costof') + ' ' + this.zhishin + ' ' +this.$t('yuan') + ',' : '') + ((this.permissions.countHours) ? this.$t('time.duration') + ' ' +totalHours+ ' ' +this.$t('time.hour') : ''),
  1122. left:'left',
  1123. },
  1124. // 工具箱
  1125. toolbox: {
  1126. show: true,
  1127. feature:{
  1128. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1129. }
  1130. },
  1131. tooltip:{
  1132. trigger:'axis',
  1133. formatter: function (params,ticket,callback) {
  1134. _this.params = params;
  1135. var res
  1136. if(_this.user.userNameNeedTranslate != '1') {
  1137. var res = params[0].name + "<br/>" +
  1138. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1139. + _this.$t('yuan')+"<br/>" : '') +
  1140. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1141. } else {
  1142. var res = "<ww-open-data type='departmentName' :openid='"+ _this.allListData.costList[params[0].dataIndex].additionName +"'></ww-open-data>" + "<br/>" +
  1143. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1144. + _this.$t('yuan')+"<br/>" : '') +
  1145. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1146. }
  1147. return res;
  1148. }
  1149. },
  1150. xAxis: {
  1151. data: xList,
  1152. axisLabel: {
  1153. interval:0,rotate:20
  1154. }
  1155. },
  1156. yAxis: [{
  1157. type : 'value',
  1158. axisLabel: {
  1159. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1160. }
  1161. }],
  1162. series: [{
  1163. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1164. type: 'bar',
  1165. barMaxWidth: 30,
  1166. data: yList,
  1167. label: {
  1168. normal: {
  1169. show: true,
  1170. position: 'top',
  1171. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1172. }
  1173. }
  1174. }],
  1175. grid: {
  1176. left: '100px',
  1177. }
  1178. };
  1179. } else {
  1180. var option = {
  1181. title: {
  1182. // text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
  1183. text: this.$t('otalhourscost')+ ':' + ((this.permissions.countCost) ? this.$t('costof') + ' ' + this.zhishin + ' ' + this.$t('yuan')+ ',' : '') + ((this.permissions.countHours) ? this.$t('time.duration') + ' ' + totalHours + ' ' + this.$t('time.hour') : ''),
  1184. left:'left',
  1185. },
  1186. // 工具箱
  1187. toolbox: {
  1188. show: true,
  1189. feature:{
  1190. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1191. }
  1192. },
  1193. tooltip:{
  1194. trigger:'axis',
  1195. formatter: function (params,ticket,callback) {
  1196. var res = params[0].name + "<br/>" +
  1197. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1198. + _this.$t('yuan')+"<br/>" : '') +
  1199. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1200. _this.params = params;
  1201. return res;
  1202. }
  1203. },
  1204. xAxis: {
  1205. data: xList,
  1206. axisLabel: {
  1207. interval:0,rotate:20
  1208. }
  1209. },
  1210. yAxis: [{
  1211. type : 'value',
  1212. axisLabel: {
  1213. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1214. }
  1215. }],
  1216. series: [{
  1217. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1218. type: 'bar',
  1219. barMaxWidth: 30,
  1220. data: yList,
  1221. label: {
  1222. normal: {
  1223. show: true,
  1224. position: 'top',
  1225. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1226. }
  1227. }
  1228. }],
  1229. grid: {
  1230. left: '100px',
  1231. }
  1232. };
  1233. }
  1234. myChart.setOption(option,{notMerge: true});
  1235. myChart.getZr().on('click', params => {
  1236. const pointInPixel = [params.offsetX, params.offsetY];
  1237. if (myChart.containPixel('grid', pointInPixel)) {
  1238. if(_this.radio==this.$t('other.project')) {
  1239. if (_this.dateRange != null) {
  1240. if (this.user.timeType.fixMonthcost == 0) {
  1241. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1242. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1243. } else {
  1244. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1245. +"?startDate="+_this.dateRange+"&endDate="+_this.dateRange);
  1246. }
  1247. } else {
  1248. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1249. }
  1250. } else if (_this.radio==this.$t('lable.department')) {
  1251. if (_this.params[0].data.hasSubDept) {
  1252. if (_this.parentDeptId != _this.params[0].data.id) {
  1253. _this.parentDeptId = _this.params[0].data.id;
  1254. _this.parentDeptStack.push(_this.parentDeptId);
  1255. _this.jieliu();
  1256. }
  1257. // _this.jieliu();
  1258. } else {
  1259. if (_this.dateRange != null) {
  1260. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
  1261. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1262. } else {
  1263. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1264. }
  1265. }
  1266. }
  1267. }
  1268. });
  1269. },
  1270. // 左右滚动
  1271. scrollFunction () {
  1272. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  1273. if (this.domObj.attachEvent) { // IE
  1274. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  1275. } else if (this.domObj.addEventListener) {
  1276. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  1277. }
  1278. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  1279. },
  1280. mouseScroll(event) { // google 浏览器下
  1281. let detail = event.wheelDelta || event.detail
  1282. let moveForwardStep = -1
  1283. let moveBackStep = 1
  1284. let step = 0
  1285. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  1286. event.preventDefault() // 阻止浏览器默认事件
  1287. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  1288. },
  1289. // 判断后端给的字段
  1290. // 获取自定义
  1291. getZDY() {
  1292. this.http.post('/user-custom/getUserCustomTitle',{},res => {
  1293. if(res.code == 'ok'){
  1294. this.theCustomList = res.data.result
  1295. this.theCustomListPlantLIst = res.data.field
  1296. }else {
  1297. this.$message({
  1298. message: res.msg,
  1299. type: 'error'
  1300. })
  1301. }
  1302. },error => {
  1303. this.$message({
  1304. message: error,
  1305. type: 'error'
  1306. })
  1307. })
  1308. },
  1309. // 获取部门
  1310. getDepartmentList() {
  1311. this.http.post( this.port.manage.depList, {},
  1312. res => {
  1313. if (res.code == "ok") {
  1314. let dptlist = JSON.parse(JSON.stringify(res.data));
  1315. this.departmentList = this.changeArr(dptlist);
  1316. } else {
  1317. this.$message({
  1318. message: res.msg,
  1319. type: "error"
  1320. });
  1321. }
  1322. },error => {
  1323. this.$message({
  1324. message: error,
  1325. type: "error"
  1326. });
  1327. });
  1328. },
  1329. changeArr(arr) {
  1330. for (var i = 0; i < arr.length; i++) {
  1331. if(arr[i].id != -1 && arr[i].id != 0) {
  1332. if (arr[i].children != null && arr[i].children.length>0) {
  1333. arr[i].children = this.changeArr(arr[i].children);
  1334. }
  1335. arr[i].id && (arr[i].value = arr[i].id);
  1336. delete arr[i].id;
  1337. }
  1338. }
  1339. for(var i in arr) {
  1340. if(arr[i].id == -1 || arr[i].id == 0) {
  1341. arr.splice(i,1)
  1342. }
  1343. }
  1344. return arr;
  1345. },
  1346. // 自定义事件
  1347. selectCal(obj) {
  1348. if(obj.distinction == 1) {
  1349. let arr = []
  1350. for(var i in obj.arrUserList) {
  1351. arr.push(obj.arrUserList[i].id)
  1352. }
  1353. this.exportParam.userIds = arr
  1354. } else if(obj.distinction == 2) {
  1355. this.personnelValue = obj.name
  1356. this.personnel()
  1357. } else if(obj.distinction == 4) {
  1358. this.exportParam.userId = obj.id
  1359. }
  1360. },
  1361. vueCasader(obj) {
  1362. if(obj.distinction == 1) {
  1363. let arr = []
  1364. arr.push(obj.id)
  1365. this.exportParam.deptId = arr
  1366. }
  1367. }
  1368. },
  1369. created() {
  1370. this.myChart = null
  1371. },
  1372. mounted() {
  1373. this.containerHeight = window.innerHeight - 200
  1374. // this.containerHeight = window.innerHeight - 130
  1375. const that = this;
  1376. window.onresize = function temp() {
  1377. this.containerHeight = window.innerHeight - 130
  1378. // this.containerHeight = window.innerHeight - 200
  1379. };
  1380. if(this.permissions.countCost){
  1381. this.yAxisValue = '0'
  1382. }else{
  1383. this.yAxisValue = '1'
  1384. }
  1385. if (this.user.timeType.fixMonthcost == 0) {
  1386. if (this.$route.query.startDate != null) {
  1387. this.dateRange = [this.$route.query.startDate, this.$route.query.endDate];
  1388. } else {
  1389. //默认查看本月
  1390. var now = new Date();
  1391. var t = util.formatDate.format(now, 'yyyy-MM-dd');
  1392. var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
  1393. this.dateRange = [startStr,t];
  1394. }
  1395. this.exportParam.dateRange = this.dateRange;
  1396. } else if (this.user.timeType.fixMonthcost == 1) {
  1397. if (this.$route.query.startDate != null) {
  1398. this.dateRange = this.$route.query.startDate;
  1399. } else {
  1400. //默认查看本月
  1401. var startStr = util.formatDate.format(new Date(), 'yyyy-MM');
  1402. this.dateRange = startStr;
  1403. }
  1404. this.exportParam.dateRange = this.dateRange;
  1405. }
  1406. this.radio = this.$t('other.project')
  1407. this.getEchart();
  1408. var _this = this;
  1409. window.addEventListener("resize", function() {
  1410. _this.myChart.resize();
  1411. });
  1412. // this.getDepartment();
  1413. this.getMyProjectList();
  1414. this.getUsers()
  1415. this.jutishez()
  1416. this.scrollFunction()
  1417. // 判断
  1418. if(this.user.timeType.userCustomStatic) {
  1419. this.getZDY()
  1420. }
  1421. this.getDepartmentList()
  1422. },
  1423. beforeDestroy () {
  1424. var myChart = echarts.init(document.getElementById("container"));
  1425. myChart.clear()
  1426. },
  1427. };
  1428. </script>
  1429. <style lang="scss" scoped>
  1430. #container {
  1431. // display: inline-block;
  1432. display: block;
  1433. position: absolute;
  1434. // width: 100% !important;
  1435. margin-top: 60px;
  1436. }
  1437. .ryuans {
  1438. top: -50px;
  1439. }
  1440. .prompt {
  1441. position: absolute;
  1442. right: 10px;
  1443. top: 0;
  1444. }
  1445. .poss {
  1446. position: fixed;
  1447. bottom: 10px;
  1448. right: 1%;
  1449. box-sizing: border-box;
  1450. }
  1451. </style>
  1452. <style lang="scss">
  1453. </style>