detail.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item>
  7. <el-button type="text" @click="backToList" icon="el-icon-back" class="back">{{ $t('fan-hui') }}</el-button>
  8. </el-form-item>
  9. <el-form-item class="divLine"></el-form-item>
  10. <el-form-item>
  11. <span class="workName">{{detailName}}</span>
  12. </el-form-item>
  13. <el-form-item style="float:right;" v-if="permissions.countCost">
  14. <span style="font-size:18px;">{{ $t('xiang-mu-cheng-ben') }}:<span class="themeFontColor">{{cost.toFixed(2)}}{{ $t('yuan') }}</span></span>
  15. </el-form-item>
  16. </el-form>
  17. </el-col>
  18. <el-col :span="24" style="margin-top:10px;padding-bottom: 0px;text-align:center;">
  19. <el-radio-group v-model="radio" @change="getList">
  20. <el-radio-button :label="$t('ren-yuan')"></el-radio-button>
  21. <el-radio-button :label="$t('other.taskGroup')" v-if="user.company.packageProject != 0"></el-radio-button>
  22. <el-radio-button :label="$t('lable.subproject')" v-if="user.timeType.mainProjectState != '1' && user.companyId != '1071'"></el-radio-button>
  23. <el-radio-button :label="$t('jie-duan')" v-if="user.company.packageProject != 0 && user.companyId != '1071'"></el-radio-button>
  24. </el-radio-group>
  25. </el-col>
  26. <div id="clearfix" :style="'overflow-x: auto;width:100%;padding-bottom: 0px; position: relative; height:'+containerHeight+'px;'">
  27. <div id="container" :style="'height:' + tableHeight + 'px'"></div>
  28. </div>
  29. </section>
  30. </template>
  31. <script>
  32. import util from "../../common/js/util";
  33. export default {
  34. data() {
  35. return {
  36. yAxisValue: localStorage.yAxisValue,
  37. startDate:null,
  38. endDate: null,
  39. detailId: this.$route.params.id,
  40. detailName: this.$route.params.name,
  41. radio:this.$t('ren-yuan'),
  42. user: JSON.parse(sessionStorage.getItem("user")),
  43. permissions: JSON.parse(sessionStorage.getItem("permissions")),
  44. cost: 0,
  45. tableHeight: 0,
  46. echart: null,
  47. };
  48. },
  49. methods: {
  50. //返回
  51. backToList() {
  52. if (this.startDate != null) {
  53. this.$router.push("/cost?startDate="+this.startDate+"&endDate="+this.endDate);
  54. } else {
  55. this.$router.push("/cost");
  56. }
  57. },
  58. //获取项目列表
  59. getList() {
  60. this.listLoading = true;
  61. var url = "";
  62. if (this.radio==this.$t('ren-yuan')) {
  63. url = this.port.project.projectCost;
  64. } else if (this.radio==this.$t('other.taskGroup')) {
  65. url = '/project/getCostByGroup';
  66. } else if (this.radio==this.$t('lable.subproject')) {
  67. url = '/sub-project/getTimeCost';
  68. } else {
  69. url = "/project/getCostInStage";
  70. }
  71. this.http.post(url, {
  72. id: this.detailId,
  73. startDate: this.startDate,
  74. endDate: this.endDate,
  75. },
  76. res => {
  77. //
  78. for(var i in res.data.costList) {
  79. if(i>20) {
  80. this.widthHtval = +this.widthHtval + 40
  81. } else {
  82. this.widthHtval = document.body.clientWidth - 230
  83. }
  84. }
  85. //
  86. this.listLoading = false;
  87. var _this = this;
  88. if (res.code == "ok") {
  89. if(this.user.userNameNeedTranslate == 1 && this.radio == this.$t('ren-yuan')) {
  90. let arr = []
  91. for(var i in res.data.costList) {
  92. let obj = {}
  93. obj.type = 'userName'
  94. obj.id = res.data.costList[i].name
  95. arr.push(obj)
  96. }
  97. this.dealWithTranslation(arr, res.data.costList, res.data.totalMoneyCost)
  98. // this.pullAway(res.data.costList, res.data.totalMoneyCost)
  99. } else {
  100. this.pullAway(res.data.costList, res.data.totalMoneyCost)
  101. }
  102. } else {
  103. this.$message({
  104. message: res.msg,
  105. type: "error"
  106. });
  107. }
  108. },
  109. error => {
  110. this.listLoading = false;
  111. this.$message({
  112. message: error,
  113. type: "error"
  114. });
  115. });
  116. },
  117. dealWithTranslation(items, dataArr, cosess) {
  118. if (WWOpenData.initCanvas) {
  119. WWOpenData.initCanvas()
  120. }
  121. const myFunOne = async () => {
  122. const result = await new Promise((resolve, reject) => {
  123. if(WWOpenData.prefetch) {
  124. WWOpenData.prefetch({ items }, (err, data) => {
  125. if (err) { return reject(err) }
  126. resolve(data)
  127. })
  128. }
  129. })
  130. for(var i in dataArr) {
  131. dataArr[i].name = result.items[i].data
  132. }
  133. this.pullAway(dataArr, cosess)
  134. }
  135. myFunOne()
  136. },
  137. // 抽离出来的方法
  138. pullAway(datalist, cosess) {
  139. // var xList = [],yList = [] , list = res.data.costList;
  140. var _this = this;
  141. var xList = [],yList = [] , list = datalist;
  142. // this.cost = res.data.totalMoneyCost;
  143. this.cost = cosess;
  144. for(var i in list) {
  145. if(this.radio == this.$t('other.taskGroup')){
  146. xList.push(list[i].GroupName);
  147. }else{
  148. xList.push(list[i].name);
  149. }
  150. yList.push({
  151. "value": this.yAxisValue==0?list[i].costMoney:list[i].cost,
  152. "cost": list[i].cost,
  153. "money": list[i].costMoney,
  154. });
  155. }
  156. var myChart = echarts.init(document.getElementById("container"));
  157. // 设置宽度
  158. myChart.resize({
  159. width: this.widthHtval
  160. })
  161. _this.myChart = myChart;
  162. var option = {
  163. // 工具箱
  164. toolbox: {
  165. show: true,
  166. feature:{
  167. saveAsImage:{
  168. show: this.user.userNameNeedTranslate == 1 ? false : true
  169. },
  170. restore:{
  171. show:true
  172. },
  173. magicType:{
  174. type:['line','bar']
  175. }
  176. }
  177. },
  178. grid : {
  179. top : 80, //距离容器上边界40像素
  180. bottom: 100, //距离容器下边界30像素
  181. left: 150,
  182. right: 150
  183. },
  184. tooltip:{
  185. trigger:'axis',
  186. formatter: function (params,ticket,callback) {
  187. var res
  188. if(_this.user.userNameNeedTranslate == 1 && _this.radio == _this.$t('ren-yuan')) {
  189. res = ((_this.permissions.countCost) ? _this.$t('workcost') + ":" + params[0].data.money + _this.$t('yuan') + "</br>" : '') +
  190. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + ":" + params[0].data.cost + _this.$t('time.hour') + "</br>" : '')
  191. } else {
  192. res = ((_this.permissions.countCost) ? _this.$t('workcost') + ":" + params[0].data.money + _this.$t('yuan') + "</br>" : '') +
  193. ((_this.permissions.countHours) ? _this.$t('screening.workTime') + ":" + params[0].data.cost + _this.$t('time.hour') + "</br>" : '')
  194. }
  195. return res;
  196. }
  197. },
  198. xAxis: {
  199. data: xList,
  200. axisLabel: {
  201. interval:0,rotate:20
  202. }
  203. },
  204. yAxis: [{
  205. type : 'value',
  206. axisLabel: {
  207. formatter:this.yAxisValue==0?'{value} (元)':'{value}(小时)'
  208. }
  209. }],
  210. series: [{
  211. name: this.yAxisValue==0?_this.$t('workcost')+'('+_this.$t('yuan')+')':_this.$t('screening.workTime')+'('+_this.$t('time.hour')+')',
  212. type: 'bar',
  213. barMaxWidth: 30,
  214. data: yList,
  215. label: {
  216. normal: {
  217. show: true,
  218. position: 'top',
  219. // formatter: `{c} ${this.yAxisValue == 0 ? '元' : '小时'}`,
  220. formatter: function (params) {
  221. var value = params.value.toFixed(1);
  222. const totalValue = _this.yAxisValue == 0 ? value + '元' : value + 'h';
  223. const dayValue = _this.yAxisValue == 0 ? 0 : (value/_this.user.timeType.allday).toFixed(1);
  224. return `${totalValue}${_this.yAxisValue == 0?'':('/'+dayValue+'人天')}`;
  225. }
  226. }
  227. }
  228. }]
  229. };
  230. myChart.setOption(option,{notMerge: true});
  231. },
  232. // 左右滚动
  233. scrollFunction () {
  234. this.domObj = document.getElementById('clearfix') // 通过id获取要设置的div
  235. if (this.domObj.attachEvent) { // IE
  236. this.domObj.attachEvent('onmousewheel', this.mouseScroll)
  237. } else if (this.domObj.addEventListener) {
  238. this.domObj.addEventListener('DOMMouseScroll', this.mouseScroll, false)
  239. }
  240. this.domObj.onmousewheel = this.domObj.onmousewheel = this.mouseScroll
  241. },
  242. mouseScroll(event) { // google 浏览器下
  243. let detail = event.wheelDelta || event.detail
  244. let moveForwardStep = -1
  245. let moveBackStep = 1
  246. let step = 0
  247. step = detail > 0 ? moveForwardStep * 100 : moveBackStep * 100
  248. event.preventDefault() // 阻止浏览器默认事件
  249. this.domObj.scrollLeft = this.domObj.scrollLeft + step
  250. },
  251. },
  252. created() {
  253. let height = window.innerHeight;
  254. this.tableHeight = height - 145;
  255. const that = this;
  256. window.onresize = function temp() {
  257. that.tableHeight = window.innerHeight - 145;
  258. };
  259. },
  260. mounted() {
  261. this.startDate = this.$route.query.startDate;
  262. this.endDate = this.$route.query.endDate;
  263. this.getList();
  264. var _this = this;
  265. window.addEventListener("resize", function() {
  266. _this.myChart.resize();
  267. });
  268. this.scrollFunction()
  269. }
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. @import "../../assets/scss/handle";
  274. .themeFontColor {
  275. @include font_color("color");
  276. }
  277. .toolbar {
  278. .el-form-item {
  279. font-size: 14px;
  280. vertical-align: middle;
  281. }
  282. .back {
  283. font-size: 16px;
  284. cursor: pointer;
  285. }
  286. .divLine {
  287. width: 2px;
  288. background: #c3c3c3;
  289. height: 100%;
  290. }
  291. .workName {
  292. color: #333;
  293. font-size: 18px;
  294. }
  295. .workHours {
  296. @include font_color("color");
  297. font-size: 18px;
  298. }
  299. }
  300. #container {
  301. float: left;
  302. width: 100%;
  303. }
  304. </style>
  305. <style lang="scss">
  306. </style>