cost.vue 79 KB

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