cost.vue 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  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="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. }
  1132. if(this.radio == this.$t('other.project') || this.radio == this.$t('zhu-xiang-mu') || this.radio == this.$t('ren-yuan') || this.radio == this.$t('projectclassification') || this.radio==this.$t('lable.department')) {
  1133. var option = {
  1134. title: {
  1135. text: this.$t('otalhourscost') + ':' + ((this.permissions.countCost) ? this.$t('costof') + ' ' + this.zhishin + ' ' +this.$t('yuan') + ',' : '') + ((this.permissions.countHours) ? this.$t('time.duration') + ' ' +totalHours+ ' ' +this.$t('time.hour') : ''),
  1136. left:'left',
  1137. },
  1138. // 工具箱
  1139. toolbox: {
  1140. show: true,
  1141. feature:{
  1142. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1143. }
  1144. },
  1145. tooltip:{
  1146. trigger:'axis',
  1147. formatter: function (params,ticket,callback) {
  1148. _this.params = params;
  1149. var res
  1150. if(_this.user.userNameNeedTranslate != '1') {
  1151. var res = params[0].name + "<br/>" +
  1152. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1153. + _this.$t('yuan')+"<br/>" : '') +
  1154. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1155. } else {
  1156. var res = "<ww-open-data type='departmentName' :openid='"+ _this.allListData.costList[params[0].dataIndex].additionName +"'></ww-open-data>" + "<br/>" +
  1157. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1158. + _this.$t('yuan')+"<br/>" : '') +
  1159. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1160. }
  1161. return res;
  1162. }
  1163. },
  1164. xAxis: {
  1165. data: xList,
  1166. axisLabel: {
  1167. interval:0,rotate:20
  1168. }
  1169. },
  1170. yAxis: [{
  1171. type : 'value',
  1172. axisLabel: {
  1173. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1174. }
  1175. }],
  1176. series: [{
  1177. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1178. type: 'bar',
  1179. barMaxWidth: 30,
  1180. data: yList,
  1181. label: {
  1182. normal: {
  1183. show: true,
  1184. position: 'top',
  1185. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1186. }
  1187. }
  1188. }],
  1189. grid: {
  1190. left: '100px',
  1191. }
  1192. };
  1193. } else {
  1194. var option = {
  1195. title: {
  1196. // text: '工时成本总计' + this.zhishin + '元, 时长'+totalHours+'小时',
  1197. text: this.$t('otalhourscost')+ ':' + ((this.permissions.countCost) ? this.$t('costof') + ' ' + this.zhishin + ' ' + this.$t('yuan')+ ',' : '') + ((this.permissions.countHours) ? this.$t('time.duration') + ' ' + totalHours + ' ' + this.$t('time.hour') : ''),
  1198. left:'left',
  1199. },
  1200. // 工具箱
  1201. toolbox: {
  1202. show: true,
  1203. feature:{
  1204. saveAsImage:{show:this.user.userNameNeedTranslate == 1 ? false : true},restore:{show:true}, magicType:{ type:['line','bar']},
  1205. }
  1206. },
  1207. tooltip:{
  1208. trigger:'axis',
  1209. formatter: function (params,ticket,callback) {
  1210. var res = params[0].name + "<br/>" +
  1211. ((_this.permissions.countCost) ? _this.$t('workcost')+" : " + params[0].data.money
  1212. + _this.$t('yuan')+"<br/>" : '') +
  1213. ((_this.permissions.countHours) ? _this.$t('screening.workTime')+" : " + params[0].data.cost + _this.$t('time.hour') : '');
  1214. _this.params = params;
  1215. return res;
  1216. }
  1217. },
  1218. xAxis: {
  1219. data: xList,
  1220. axisLabel: {
  1221. interval:0,rotate:20
  1222. }
  1223. },
  1224. yAxis: [{
  1225. type : 'value',
  1226. axisLabel: {
  1227. formatter:this.yAxisValue==0?'{value} ('+this.$t('yuan')+')':'{value}'+this.$t('time.hour')
  1228. }
  1229. }],
  1230. series: [{
  1231. name: this.yAxisValue==0?this.$t('workcost')+'('+this.$t('yuan')+')':this.$t('screening.workTime')+'('+this.$t('time.hour')+')',
  1232. type: 'bar',
  1233. barMaxWidth: 30,
  1234. data: yList,
  1235. label: {
  1236. normal: {
  1237. show: true,
  1238. position: 'top',
  1239. formatter: `{c} ${this.yAxisValue==0 ? '元' : '小时'}`,
  1240. }
  1241. }
  1242. }],
  1243. grid: {
  1244. left: '100px',
  1245. }
  1246. };
  1247. }
  1248. myChart.setOption(option,{notMerge: true});
  1249. myChart.getZr().on('click', params => {
  1250. const pointInPixel = [params.offsetX, params.offsetY];
  1251. if (myChart.containPixel('grid', pointInPixel)) {
  1252. if(_this.radio==this.$t('other.project')) {
  1253. if (_this.dateRange != null) {
  1254. if (this.user.timeType.fixMonthcost == 0) {
  1255. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1256. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1257. } else {
  1258. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name
  1259. +"?startDate="+_this.dateRange+"&endDate="+_this.dateRange);
  1260. }
  1261. } else {
  1262. _this.$router.push("/cost/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1263. }
  1264. } else if (_this.radio==this.$t('lable.department')) {
  1265. if (_this.params[0].data.hasSubDept) {
  1266. if (_this.parentDeptId != _this.params[0].data.id) {
  1267. _this.parentDeptId = _this.params[0].data.id;
  1268. _this.parentDeptStack.push(_this.parentDeptId);
  1269. _this.jieliu();
  1270. }
  1271. // _this.jieliu();
  1272. } else {
  1273. if (_this.dateRange != null) {
  1274. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name
  1275. +"?startDate="+_this.dateRange[0]+"&endDate="+_this.dateRange[1]);
  1276. } else {
  1277. _this.$router.push("/costDep/" + _this.params[0].data.id + "/" + _this.params[0].name);
  1278. }
  1279. }
  1280. }
  1281. }
  1282. });
  1283. },
  1284. // 左右滚动
  1285. scrollFunction () {
  1286. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  1287. if (this.domObj.attachEvent) { // IE
  1288. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  1289. } else if (this.domObj.addEventListener) {
  1290. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  1291. }
  1292. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  1293. },
  1294. mouseScroll(event) { // google 浏览器下
  1295. let detail = event.wheelDelta || event.detail
  1296. let moveForwardStep = -1
  1297. let moveBackStep = 1
  1298. let step = 0
  1299. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  1300. event.preventDefault() // 阻止浏览器默认事件
  1301. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  1302. },
  1303. // 判断后端给的字段
  1304. // 获取自定义
  1305. getZDY() {
  1306. this.http.post('/user-custom/getUserCustomTitle',{},res => {
  1307. if(res.code == 'ok'){
  1308. this.theCustomList = res.data.result
  1309. this.theCustomListPlantLIst = res.data.field
  1310. }else {
  1311. this.$message({
  1312. message: res.msg,
  1313. type: 'error'
  1314. })
  1315. }
  1316. },error => {
  1317. this.$message({
  1318. message: error,
  1319. type: 'error'
  1320. })
  1321. })
  1322. },
  1323. // 获取部门
  1324. getDepartmentList() {
  1325. this.http.post( this.port.manage.depList, {},
  1326. res => {
  1327. if (res.code == "ok") {
  1328. let dptlist = JSON.parse(JSON.stringify(res.data));
  1329. this.departmentList = this.changeArr(dptlist);
  1330. } else {
  1331. this.$message({
  1332. message: res.msg,
  1333. type: "error"
  1334. });
  1335. }
  1336. },error => {
  1337. this.$message({
  1338. message: error,
  1339. type: "error"
  1340. });
  1341. });
  1342. },
  1343. changeArr(arr) {
  1344. for (var i = 0; i < arr.length; i++) {
  1345. if(arr[i].id != -1 && arr[i].id != 0) {
  1346. if (arr[i].children != null && arr[i].children.length>0) {
  1347. arr[i].children = this.changeArr(arr[i].children);
  1348. }
  1349. arr[i].id && (arr[i].value = arr[i].id);
  1350. delete arr[i].id;
  1351. }
  1352. }
  1353. for(var i in arr) {
  1354. if(arr[i].id == -1 || arr[i].id == 0) {
  1355. arr.splice(i,1)
  1356. }
  1357. }
  1358. return arr;
  1359. },
  1360. // 自定义事件
  1361. selectCal(obj) {
  1362. if(obj.distinction == 1) {
  1363. let arr = []
  1364. for(var i in obj.arrUserList) {
  1365. arr.push(obj.arrUserList[i].id)
  1366. }
  1367. this.exportParam.userIds = arr
  1368. } else if(obj.distinction == 2) {
  1369. this.personnelValue = obj.name
  1370. this.personnel()
  1371. } else if(obj.distinction == 4) {
  1372. this.exportParam.userId = obj.id
  1373. }
  1374. },
  1375. vueCasader(obj) {
  1376. if(obj.distinction == 1) {
  1377. let arr = []
  1378. arr.push(obj.id)
  1379. this.exportParam.deptId = arr
  1380. }
  1381. }
  1382. },
  1383. created() {
  1384. this.myChart = null
  1385. },
  1386. mounted() {
  1387. this.containerHeight = window.innerHeight - 200
  1388. // this.containerHeight = window.innerHeight - 130
  1389. const that = this;
  1390. window.onresize = function temp() {
  1391. this.containerHeight = window.innerHeight - 130
  1392. // this.containerHeight = window.innerHeight - 200
  1393. };
  1394. if(this.permissions.countCost){
  1395. this.yAxisValue = '0'
  1396. }else{
  1397. this.yAxisValue = '1'
  1398. }
  1399. if (this.user.timeType.fixMonthcost == 0) {
  1400. if (this.$route.query.startDate != null) {
  1401. this.dateRange = [this.$route.query.startDate, this.$route.query.endDate];
  1402. } else {
  1403. //默认查看本月
  1404. var now = new Date();
  1405. var t = util.formatDate.format(now, 'yyyy-MM-dd');
  1406. var startStr = util.formatDate.format(new Date(), 'yyyy-MM') + "-01";
  1407. this.dateRange = [startStr,t];
  1408. }
  1409. this.exportParam.dateRange = this.dateRange;
  1410. } else if (this.user.timeType.fixMonthcost == 1) {
  1411. if (this.$route.query.startDate != null) {
  1412. this.dateRange = this.$route.query.startDate;
  1413. } else {
  1414. //默认查看本月
  1415. var startStr = util.formatDate.format(new Date(), 'yyyy-MM');
  1416. this.dateRange = startStr;
  1417. }
  1418. this.exportParam.dateRange = this.dateRange;
  1419. }
  1420. this.radio = this.$t('other.project')
  1421. this.getEchart();
  1422. var _this = this;
  1423. window.addEventListener("resize", function() {
  1424. _this.myChart.resize();
  1425. });
  1426. // this.getDepartment();
  1427. this.getMyProjectList();
  1428. this.getCategoryList();
  1429. this.getUsers()
  1430. this.jutishez()
  1431. this.scrollFunction()
  1432. // 判断
  1433. if(this.user.timeType.userCustomStatic) {
  1434. this.getZDY()
  1435. }
  1436. this.getDepartmentList()
  1437. },
  1438. beforeDestroy () {
  1439. var myChart = echarts.init(document.getElementById("container"));
  1440. myChart.clear()
  1441. },
  1442. };
  1443. </script>
  1444. <style lang="scss" scoped>
  1445. #container {
  1446. // display: inline-block;
  1447. display: block;
  1448. position: absolute;
  1449. // width: 100% !important;
  1450. margin-top: 60px;
  1451. }
  1452. .ryuans {
  1453. top: -50px;
  1454. }
  1455. .prompt {
  1456. position: absolute;
  1457. right: 10px;
  1458. top: 0;
  1459. }
  1460. .poss {
  1461. position: fixed;
  1462. bottom: 10px;
  1463. right: 1%;
  1464. box-sizing: border-box;
  1465. }
  1466. </style>
  1467. <style lang="scss">
  1468. </style>