detail.vue 12 KB

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