cost.vue 79 KB

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