cost.vue 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520
  1. <template>
  2. <section>
  3. <el-row style="padding-bottom: 0px;text-align:center;margin-top:20px;z-index: 999;">
  4. <el-col :span="6" >
  5. <div ><span style="color:#999;">{{ $t('chartY') }} </span>
  6. <el-radio-group v-model="yAxisValue" @change="onYAxisChange" size="small">
  7. <el-radio-button label="0" v-if="permissions.countCost">{{ $t('accordingtothecost') }}</el-radio-button>
  8. <el-radio-button label="1" v-if="permissions.countHours">{{ $t('accordingtoworkinghours') }}</el-radio-button>
  9. </el-radio-group></div>
  10. </el-col>
  11. <el-col :span="14" style="display: flex;flex-wrap: wrap;justify-content: flex-end;">
  12. <el-date-picker v-show="user.timeType.fixMonthcost==0" size="small"
  13. v-model="dateRange" :editable="false"
  14. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  15. @change="getEchart"
  16. :clearable="true"
  17. :range-separator="$t('other.to')"
  18. type="daterange"
  19. :start-placeholder="$t('time.startDate')"
  20. :end-placeholder="$t('time.endDate')"
  21. ></el-date-picker>
  22. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  23. v-model="dateRange" :editable="false" size="small"
  24. format="yyyy-MM" value-format="yyyy-MM"
  25. @change="getEchart"
  26. :clearable="false"
  27. type="month"
  28. ></el-date-picker>
  29. <el-radio-group v-model="radio" @change="getEchart" style="margin-left:10px;" size="small" :disabled="radioLoading">
  30. <el-radio-button :label="$t('other.project')"></el-radio-button>
  31. <el-radio-button :label="$t('zhu-xiang-mu')" v-if="user.timeType.mainProjectState"></el-radio-button>
  32. <el-radio-button :label="$t('projectclassification')" v-if="user.companyId != '1071'"></el-radio-button>
  33. <el-radio-button :label="$t('lable.department')" v-if="permissions.viewAllSummary || permissions.viewMagDeptSummary"></el-radio-button>
  34. <el-radio-button :label="$t('ren-yuan')" v-if="permissions.countPersonnel"></el-radio-button>
  35. <el-radio-button :label="namess" v-if="jichu.customDegreeActive == 1"></el-radio-button>
  36. <el-radio-button v-for="item in theCustomList" :key="item.id" :label="item.name"></el-radio-button>
  37. </el-radio-group>
  38. <el-select v-if="radio == $t('other.project')||radio == namess " v-model="proJuctId" :placeholder="$t('defaultText.pleaseSelectSnItem')" clearable filterable size="small" @change="getEchart" style="margin-left:10px">
  39. <el-option v-for="(item) in projectList" :key="item.id" :label="item.projectName + (item.projectCode ? item.projectCode : '')" :value="item.id">
  40. <span style="float: left;color: #8492a6;">{{ item.projectCode }}</span>
  41. <span style="float: right;font-size: 13px;margin-left: 20px">{{ item.projectName }}</span>
  42. </el-option>
  43. </el-select>
  44. <!--
  45. <el-select v-model="customName" filterable placeholder="请选择" style="margin-top: 10px;width: 350px" v-if="theCustomListFlg" @change="jieliu()">
  46. <el-option v-for="item in customList" :key="item.id" :label="item.name" :value="item.name"></el-option>
  47. </el-select> -->
  48. <el-select v-model="personnelValue" filterable clearable :placeholder="hasReportUserList.length == 0 ? $t('nodata') : $t('pleaseselectpersonnel')" size="small" style="margin-top: 10px;width: 350px" v-if="(radio == $t('ren-yuan'))&& user.userNameNeedTranslate != '1'" @change="personnel()"
  49. :disabled="hasReportUserList.length == 0 ? true : false">
  50. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.name">
  51. <span style="float: left">{{ item.name }}</span>
  52. <span style="float: right; color: #8492a6; font-size: 13px;margin-left: 20px" v-if="item.jobNumber">{{ item.jobNumber }}</span>
  53. </el-option>
  54. </el-select>
  55. <span style="text-align: left">
  56. <selectCat v-if="radio == $t('ren-yuan') && user.userNameNeedTranslate == '1'" :size="'small'" :widthStr="'350'" :distinction="'2'" :subject="hasReportUserList" :clearable="true" @selectCal="selectCal" :disabled="hasReportUserList.length == 0 ? true : false"></selectCat>
  57. </span>
  58. </el-col>
  59. <el-col :span="4">
  60. <el-button @click="exportProjectData" v-if="theCustomListFlg" size="small">{{ $t('reporderived') }}</el-button>
  61. <el-button @click="showExportDialog" v-else size="small">{{ $t('reporderived') }}</el-button>
  62. </el-col>
  63. </el-row>
  64. <!-- <div id="clearfix" :style="'width:'+widthHtval+'px;position: relative; height:'+containerHeight+'px;'">
  65. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  66. </div> -->
  67. <div id="clearfix" :class="radio == $t('ren-yuan') ? 'ryuans' : ''" :style="'overflow-x: auto;width:100%;padding-bottom: 100px; position: relative; height:'+containerHeight+'px;'" v-loading="radioLoading">
  68. <div id="container" :style="'height:'+(containerHeight - 20)+'px;width:100%'"></div>
  69. <div class="poss">
  70. <el-pagination
  71. @size-change="echartsSizeChange"
  72. @current-change="echartsCurrentChange"
  73. :current-page="page"
  74. :page-sizes="[50]"
  75. :page-size="50"
  76. layout="total, sizes, prev, pager, next"
  77. :total="total">
  78. </el-pagination>
  79. </div>
  80. </div>
  81. <!-- <div>
  82. <div id="container" :style="'height:'+containerHeight+'px;width:100%'"></div>
  83. </div> -->
  84. <div style="position:fixed;top:170px;left:600px;" v-show="radio==$t('lable.department') && parentDeptId != null">
  85. <el-button @click="backToParentDept">{{ $t('returnsuperior') }}</el-button>
  86. </div>
  87. <!--导出报表条件选择 -->
  88. <el-dialog :title="$t('timeReportExport')" v-if="exportDialog" :visible.sync="exportDialog" :close-on-click-modal="false" customClass="customWidth" width="500px">
  89. <el-form ref="form3" :model="exportParam" >
  90. <el-form-item prop="projectId" :label="$t('defaultText.selectProject')" v-if="radio != $t('ren-yuan') && radio != $t('projectclassification') && radio != $t('lable.department') && radio != $t('zhu-xiang-mu')">
  91. <el-select v-model="exportParam.projectId" :placeholder="$t('other.allProject')" clearable style="width:350px;" filterable="true" popper-class="projectSelectPopperClass">
  92. <el-option v-for="item in projectList" :key="item.id" :label="item.projectName + item.projectCode" :value="item.id">
  93. <span style="float: left;color: #8492a6;">{{ item.projectCode }}</span>
  94. <span style="float: right;font-size: 13px;">{{ item.projectName }}</span>
  95. </el-option>
  96. </el-select>
  97. </el-form-item>
  98. <el-form-item prop="exportContent" label="导出内容" v-if="permissions.countCost && permissions.countHours && (radio == $t('other.project') || radio == $t('projectclassification'))">
  99. <el-select v-model="exportParam.exportContent" style="width:350px;" filterable="true" popper-class="projectSelectPopperClass">
  100. <el-option label="工时和成本" value="hoursAndCost"></el-option>
  101. <el-option label="仅工时" value="hours"></el-option>
  102. <el-option label="仅成本" value="cost"></el-option>
  103. </el-select>
  104. </el-form-item>
  105. <el-form-item :label="$t('departmentchoice')" v-if="radio == $t('other.project')">
  106. <el-cascader v-if="user.userNameNeedTranslate != 1" v-model="exportParam.deptId" :options="departmentList" :placeholder="$t('defaultText.pleaseChoose')"
  107. :props="{ checkStrictly: true, expandTrigger: 'hover' }" clearable filterable style="width:350px;"
  108. ></el-cascader>
  109. <vueCascader :size="'medium'" :widthStr="'350'" :clearable="true" :subject="departmentList" :radios="true" :distinction="'1'" @vueCasader="vueCasader" v-if="user.userNameNeedTranslate == 1"></vueCascader>
  110. </el-form-item>
  111. <el-form-item prop="projectCategoryId" :label="$t('projectclassification')" v-if="radio == $t('projectclassification')">
  112. <el-select v-model="exportParam.projectCategoryId" :placeholder="$t('classificationitems')" clearable style="width:350px;" filterable="true">
  113. <el-option v-for="item in categoryList" :key="item.id" :label="item.name" :value="item.id">
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item prop="userIds" :label="$t('screening.selectPeople')" v-if="radio == $t('ren-yuan')">
  118. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userIds" :placeholder="$t('lable.allStaff')" multiple="true" clearable style="width:350px;" filterable="true">
  119. <el-option v-for="item in hasReportUserList" :key="item.id" :label="item.name" :value="item.id"></el-option>
  120. </el-select>
  121. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :widthStr="'350'" :filterable="true" :subject="hasReportUserList" :clearable="true" :multiSelect="true" @selectCal="selectCal" :distinction="'1'"></selectCat>
  122. </el-form-item>
  123. <el-form-item prop="userIds" :label="$t('screening.selectPeople')" v-if="radio == $t('other.project') || radio == $t('projectclassification')">
  124. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userIds" :placeholder="$t('lable.allStaff')" multiple="true" clearable style="width:350px;" filterable="true">
  125. <el-option v-for="item in users" :key="item.id" :label="item.name" :value="item.id"></el-option>
  126. </el-select>
  127. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :widthStr="'350'" :filterable="true" :subject="users" :clearable="true" :multiSelect="true" @selectCal="selectCal" :distinction="'1'"></selectCat>
  128. </el-form-item>
  129. <el-form-item prop="projectId" :label="user.timeType.fixMonthcost==0?$t('time.dateRange'):$t('Selectmonth')">
  130. <el-date-picker v-show="user.timeType.fixMonthcost==0"
  131. v-model="exportParam.dateRange" :editable="false"
  132. format="yyyy-MM-dd" value-format="yyyy-MM-dd"
  133. :clearable="false"
  134. :range-separator="$t('other.to')"
  135. type="daterange"
  136. :start-placeholder="$t('time.startDate')"
  137. :end-placeholder="$t('time.endDate')"
  138. ></el-date-picker>
  139. <el-date-picker v-show="user.timeType.fixMonthcost==1"
  140. v-model="dateRange" :editable="false"
  141. format="yyyy-MM" value-format="yyyy-MM"
  142. @change="getEchart"
  143. :clearable="true"
  144. type="month"
  145. ></el-date-picker>
  146. </el-form-item>
  147. <el-form-item :label="$t('screening.selectPeople')" v-if="false">
  148. <el-select v-if="user.userNameNeedTranslate != '1'" v-model="exportParam.userId" :placeholder="$t('lable.allStaff')" style="width: 350px" filterable="true" clearable="true">
  149. <span v-for="(item, index) in users" :key="index">
  150. <el-option :label="item.name" :value="item.id"></el-option>
  151. </span>
  152. </el-select>
  153. <selectCat v-if="user.userNameNeedTranslate == '1'" :size="'medium'" :distinction="'4'" :widthStr="'350'" :subject="users" :clearable="true" @selectCal="selectCal"></selectCat>
  154. </el-form-item>
  155. <el-form-item prop="type" :label="$t('choosethestyle')" v-if="radio == $t('other.project') || radio == $t('projectclassification')">
  156. <el-select v-model="exportParam.type" :placeholder="$t('choosethestyle')" style="width:350px;" >
  157. <el-option :label="radio == $t('projectclassification') ? $t('classifiedontheline') : $t('Itemontheline')" value="0"></el-option>
  158. <el-option :label="radio == $t('projectclassification') ? $t('classifiedcolumns') : $t('itemisonthecolumn')" value="1"></el-option>
  159. </el-select>
  160. <div class="prompt">
  161. <el-popover placement="top" width="1200" trigger="hover">
  162. <img src="../../assets/image/hanglie.png" alt="" width="100%" v-if="this.radio != $t('projectclassification')">
  163. <img src="../../assets/image/hanglie_corp.png" alt="" width="100%" v-else>
  164. <i class="el-icon-question" slot="reference" />
  165. </el-popover>
  166. </div>
  167. </el-form-item>
  168. <el-form-item v-if="exportParam.type == 1 && permissions.countHours && (radio == $t('other.project'))">
  169. <el-checkbox v-model="exportParam.withPercent" >含项目工时占比</el-checkbox>
  170. </el-form-item>
  171. <el-form-item v-if="radio == $t('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. //是否含工时占比显示
  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(list[i].project);
  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. }
  1042. if(this.permissions.countCost){
  1043. // item.money = list[i].costMoney.toFixed(2)
  1044. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  1045. }
  1046. if(this.permissions.countHours){
  1047. item.cost = list[i].costTime
  1048. totalHours += parseFloat(list[i].costTime);
  1049. }
  1050. yList.push(item);
  1051. }else {
  1052. xList.push(list[i].categoryName);
  1053. let item = {
  1054. // "value": this.yAxisValue==0?list[i].costMoney.toFixed(2) || list[i].costMoney:list[i].cost.toFixed(1),
  1055. "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),
  1056. "id": list[i].id || i,
  1057. }
  1058. if(this.permissions.countCost){
  1059. // item.money = list[i].costMoney.toFixed(2)
  1060. item.money = (list[i].costMoney ? list[i].costMoney.toFixed(2) : 0)
  1061. }
  1062. if(this.permissions.countHours){
  1063. item.cost = list[i].cost
  1064. totalHours += parseFloat(list[i].cost);
  1065. }
  1066. yList.push(item);
  1067. }
  1068. }
  1069. }
  1070. else if(this.theCustomListFlg) {
  1071. // this.allListData = res.data.list ? res.data.list : []
  1072. this.total = this.allListData.list ? this.allListData.list.length : 0
  1073. list = this.total ? this.allListData.list.slice(0+50*(this.page-1),49+50*(this.page-1)) : []
  1074. // list = res.data.list
  1075. for(var i in list) {
  1076. xList.push(list[i].name);
  1077. let item = {
  1078. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  1079. "id": list[i].id || i,
  1080. }
  1081. if(this.permissions.countCost){
  1082. // item.money = list[i].costMoney.toFixed(2)
  1083. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  1084. totalMoneyCost += parseFloat(list[i].costMoney);
  1085. }
  1086. if(this.permissions.countHours){
  1087. item.cost = list[i].cost
  1088. totalHours += parseFloat(list[i].cost);
  1089. }
  1090. yList.push(item);
  1091. }
  1092. }
  1093. else {
  1094. //自定义列表:data:{cost:3, costMoney:222}
  1095. this.total = this.allListData ? this.allListData.length : 0
  1096. // if(this.total){
  1097. list = this.allListData.slice(0+50*(this.page-1),49+50*(this.page-1))
  1098. // }else{
  1099. // list =
  1100. // }
  1101. // list = this.total ? : []
  1102. for(var i in list) {
  1103. xList.push(list[i].name);
  1104. let item = {
  1105. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  1106. "id": list[i].id || i,
  1107. }
  1108. if(this.permissions.countCost){
  1109. // item.money = list[i].costMoney.toFixed(2)
  1110. item.money = list[i].costMoney ? list[i].costMoney.toFixed(2) : 0
  1111. totalMoneyCost += parseFloat(list[i].costMoney);
  1112. }
  1113. if(this.permissions.countHours){
  1114. item.cost = list[i].cost
  1115. totalHours += parseFloat(list[i].cost);
  1116. }
  1117. yList.push(item);
  1118. }
  1119. }
  1120. totalHours = this.totalTime111.toFixed(1);
  1121. var myChart = echarts.init(document.getElementById("container"));
  1122. myChart.resize({
  1123. width: this.widthHtval
  1124. })
  1125. _this.myChart = myChart;
  1126. if(totalMoneyCost) {
  1127. this.zhishin = totalMoneyCost.toFixed(2)
  1128. }
  1129. 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')) {
  1130. var option = {
  1131. title: {
  1132. 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') : ''),
  1133. left:'left',
  1134. },
  1135. // 工具箱
  1136. toolbox: {
  1137. show: true,
  1138. feature:{
  1139. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1140. }
  1141. },
  1142. tooltip:{
  1143. trigger:'axis',
  1144. formatter: function (params,ticket,callback) {
  1145. _this.params = params;
  1146. var res
  1147. if(_this.user.userNameNeedTranslate != '1') {
  1148. var res = params[0].name + "<br/>" +
  1149. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1150. + _this.$t('yuan')+"<br/>" : '') +
  1151. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1152. } else {
  1153. var res = "<ww-open-data type='departmentName' :openid='"+ _this.allListData.costList[params[0].dataIndex].additionName +"'></ww-open-data>" + "<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. }
  1158. return res;
  1159. }
  1160. },
  1161. xAxis: {
  1162. data: xList,
  1163. axisLabel: {
  1164. interval:0,rotate:20
  1165. }
  1166. },
  1167. yAxis: [{
  1168. type : 'value',
  1169. axisLabel: {
  1170. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1171. }
  1172. }],
  1173. series: [{
  1174. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1175. type: 'bar',
  1176. barMaxWidth: 30,
  1177. data: yList,
  1178. label: {
  1179. normal: {
  1180. show: true,
  1181. position: 'top',
  1182. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1183. }
  1184. }
  1185. }],
  1186. grid: {
  1187. left: '100px',
  1188. }
  1189. };
  1190. } else {
  1191. var option = {
  1192. title: {
  1193. // text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
  1194. 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') : ''),
  1195. left:'left',
  1196. },
  1197. // 工具箱
  1198. toolbox: {
  1199. show: true,
  1200. feature:{
  1201. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1202. }
  1203. },
  1204. tooltip:{
  1205. trigger:'axis',
  1206. formatter: function (params,ticket,callback) {
  1207. var res = params[0].name + "<br/>" +
  1208. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1209. + _this.$t('yuan')+"<br/>" : '') +
  1210. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1211. _this.params = params;
  1212. return res;
  1213. }
  1214. },
  1215. xAxis: {
  1216. data: xList,
  1217. axisLabel: {
  1218. interval:0,rotate:20
  1219. }
  1220. },
  1221. yAxis: [{
  1222. type : 'value',
  1223. axisLabel: {
  1224. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1225. }
  1226. }],
  1227. series: [{
  1228. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1229. type: 'bar',
  1230. barMaxWidth: 30,
  1231. data: yList,
  1232. label: {
  1233. normal: {
  1234. show: true,
  1235. position: 'top',
  1236. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1237. }
  1238. }
  1239. }],
  1240. grid: {
  1241. left: '100px',
  1242. }
  1243. };
  1244. }
  1245. myChart.setOption(option,{notMerge: true});
  1246. myChart.getZr().on('click', params => {
  1247. const pointInPixel = [params.offsetX, params.offsetY];
  1248. if (myChart.containPixel('grid', pointInPixel)) {
  1249. if(_this.radio==this.$t('other.project')) {
  1250. if (_this.dateRange != null) {
  1251. if (this.user.timeType.fixMonthcost == 0) {
  1252. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1253. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1254. } else {
  1255. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1256. +"?startDate="+_this.dateRange+"&endDate="+_this.dateRange);
  1257. }
  1258. } else {
  1259. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1260. }
  1261. } else if (_this.radio==this.$t('lable.department')) {
  1262. if (_this.params[0].data.hasSubDept) {
  1263. if (_this.parentDeptId != _this.params[0].data.id) {
  1264. _this.parentDeptId = _this.params[0].data.id;
  1265. _this.parentDeptStack.push(_this.parentDeptId);
  1266. _this.jieliu();
  1267. }
  1268. // _this.jieliu();
  1269. } else {
  1270. if (_this.dateRange != null) {
  1271. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
  1272. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1273. } else {
  1274. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1275. }
  1276. }
  1277. }
  1278. }
  1279. });
  1280. },
  1281. // 左右滚动
  1282. scrollFunction () {
  1283. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  1284. if (this.domObj.attachEvent) { // IE
  1285. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  1286. } else if (this.domObj.addEventListener) {
  1287. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  1288. }
  1289. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  1290. },
  1291. mouseScroll(event) { // google 浏览器下
  1292. let detail = event.wheelDelta || event.detail
  1293. let moveForwardStep = -1
  1294. let moveBackStep = 1
  1295. let step = 0
  1296. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  1297. event.preventDefault() // 阻止浏览器默认事件
  1298. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  1299. },
  1300. // 判断后端给的字段
  1301. // 获取自定义
  1302. getZDY() {
  1303. this.http.post('/user-custom/getUserCustomTitle',{},res => {
  1304. if(res.code == 'ok'){
  1305. this.theCustomList = res.data.result
  1306. this.theCustomListPlantLIst = res.data.field
  1307. }else {
  1308. this.$message({
  1309. message: res.msg,
  1310. type: 'error'
  1311. })
  1312. }
  1313. },error => {
  1314. this.$message({
  1315. message: error,
  1316. type: 'error'
  1317. })
  1318. })
  1319. },
  1320. // 获取部门
  1321. getDepartmentList() {
  1322. this.http.post( this.port.manage.depList, {},
  1323. res => {
  1324. if (res.code == "ok") {
  1325. let dptlist = JSON.parse(JSON.stringify(res.data));
  1326. this.departmentList = this.changeArr(dptlist);
  1327. } else {
  1328. this.$message({
  1329. message: res.msg,
  1330. type: "error"
  1331. });
  1332. }
  1333. },error => {
  1334. this.$message({
  1335. message: error,
  1336. type: "error"
  1337. });
  1338. });
  1339. },
  1340. changeArr(arr) {
  1341. for (var i = 0; i < arr.length; i++) {
  1342. if(arr[i].id != -1 && arr[i].id != 0) {
  1343. if (arr[i].children != null && arr[i].children.length>0) {
  1344. arr[i].children = this.changeArr(arr[i].children);
  1345. }
  1346. arr[i].id && (arr[i].value = arr[i].id);
  1347. delete arr[i].id;
  1348. }
  1349. }
  1350. for(var i in arr) {
  1351. if(arr[i].id == -1 || arr[i].id == 0) {
  1352. arr.splice(i,1)
  1353. }
  1354. }
  1355. return arr;
  1356. },
  1357. // 自定义事件
  1358. selectCal(obj) {
  1359. if(obj.distinction == 1) {
  1360. let arr = []
  1361. for(var i in obj.arrUserList) {
  1362. arr.push(obj.arrUserList[i].id)
  1363. }
  1364. this.exportParam.userIds = arr
  1365. } else if(obj.distinction == 2) {
  1366. this.personnelValue = obj.name
  1367. this.personnel()
  1368. } else if(obj.distinction == 4) {
  1369. this.exportParam.userId = obj.id
  1370. }
  1371. },
  1372. vueCasader(obj) {
  1373. if(obj.distinction == 1) {
  1374. let arr = []
  1375. arr.push(obj.id)
  1376. this.exportParam.deptId = arr
  1377. }
  1378. }
  1379. },
  1380. created() {
  1381. this.myChart = null
  1382. },
  1383. mounted() {
  1384. this.containerHeight = window.innerHeight - 200
  1385. // this.containerHeight = window.innerHeight - 130
  1386. const that = this;
  1387. window.onresize = function temp() {
  1388. this.containerHeight = window.innerHeight - 130
  1389. // this.containerHeight = window.innerHeight - 200
  1390. };
  1391. if(this.permissions.countCost){
  1392. this.yAxisValue = '0'
  1393. }else{
  1394. this.yAxisValue = '1'
  1395. }
  1396. if (this.user.timeType.fixMonthcost == 0) {
  1397. if (this.$route.query.startDate != null) {
  1398. this.dateRange = [this.$route.query.startDate, this.$route.query.endDate];
  1399. } else {
  1400. //默认查看本月
  1401. var now = new Date();
  1402. var t = util.formatDate.format(now, 'yyyy-MM-dd');
  1403. var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
  1404. this.dateRange = [startStr,t];
  1405. }
  1406. this.exportParam.dateRange = this.dateRange;
  1407. } else if (this.user.timeType.fixMonthcost == 1) {
  1408. if (this.$route.query.startDate != null) {
  1409. this.dateRange = this.$route.query.startDate;
  1410. } else {
  1411. //默认查看本月
  1412. var startStr = util.formatDate.format(new Date(), 'yyyy-MM');
  1413. this.dateRange = startStr;
  1414. }
  1415. this.exportParam.dateRange = this.dateRange;
  1416. }
  1417. this.radio = this.$t('other.project')
  1418. this.getEchart();
  1419. var _this = this;
  1420. window.addEventListener("resize", function() {
  1421. _this.myChart.resize();
  1422. });
  1423. // this.getDepartment();
  1424. this.getMyProjectList();
  1425. this.getUsers()
  1426. this.jutishez()
  1427. this.scrollFunction()
  1428. // 判断
  1429. if(this.user.timeType.userCustomStatic) {
  1430. this.getZDY()
  1431. }
  1432. this.getDepartmentList()
  1433. },
  1434. beforeDestroy () {
  1435. var myChart = echarts.init(document.getElementById("container"));
  1436. myChart.clear()
  1437. },
  1438. };
  1439. </script>
  1440. <style lang="scss" scoped>
  1441. #container {
  1442. // display: inline-block;
  1443. display: block;
  1444. position: absolute;
  1445. // width: 100% !important;
  1446. margin-top: 60px;
  1447. }
  1448. .ryuans {
  1449. top: -50px;
  1450. }
  1451. .prompt {
  1452. position: absolute;
  1453. right: 10px;
  1454. top: 0;
  1455. }
  1456. .poss {
  1457. position: fixed;
  1458. bottom: 10px;
  1459. right: 1%;
  1460. box-sizing: border-box;
  1461. }
  1462. </style>
  1463. <style lang="scss">
  1464. </style>