departmentChart.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <!-- 部门统计图 外部 报表 订单统计 -->
  3. <div id="departmentChart" :style="{ width: '100%', height: '500px' }"></div>
  4. </template>
  5. <script>
  6. import * as echarts from 'echarts'
  7. import { depChart } from '@api/reportForms/order-statistics.js'
  8. export default {
  9. name: 'DepartmentChart', // 部门统计图
  10. data() {
  11. return {
  12. queryParam: {
  13. vendorType: '外部'
  14. // customer: '', //客户
  15. // endYearMonth: '',
  16. // startYearMonth: '',
  17. // cdepName: ''
  18. },
  19. // newData: {
  20. cdepNameArr: [], //部门 数组
  21. iquantityArr: [], //实际数量
  22. inatMoneyArr: [] //本币金额
  23. // }
  24. }
  25. },
  26. mounted() {
  27. // this.getDepChartData()
  28. },
  29. created() {
  30. // 初次加载当月
  31. this.firstDepData()
  32. },
  33. methods: {
  34. // 初次加载
  35. firstDepData() {
  36. this.$nextTick(() => {
  37. //let nowDate = new Date()
  38. //let date = {
  39. // year: nowDate.getFullYear(),
  40. // month: nowDate.getMonth() + 1
  41. //}
  42. //if (date.month >= 1 && date.month <= 9) {
  43. // date.month = '0' + date.month
  44. //}
  45. //var time = date.year + '-' + date.month
  46. //this.queryParam.startYearMonth = time
  47. //this.queryParam.endYearMonth = time
  48. // this.queryParam.vendorType = '内部'
  49. depChart(this.queryParam).then(res => {
  50. if (res.result) {
  51. // console.log('部门统计图数据', res.result)
  52. res.result.forEach(item => {
  53. this.cdepNameArr.push(item.cdepName)
  54. this.iquantityArr.push(item.iquantity)
  55. this.inatMoneyArr.push(item.inatMoney)
  56. })
  57. // console.log('部门三数组', this.cdepNameArr, this.iquantityArr, this.inatMoneyArr)
  58. }
  59. //2、后图
  60. this.$nextTick(() => {
  61. this.initEcharts()
  62. })
  63. })
  64. })
  65. },
  66. // 1、查询 重置方法 先获取 chart 数据
  67. getDepChartData() {
  68. this.queryParam.vendorType = '外部'
  69. depChart(this.queryParam).then(res => {
  70. if (res.result) {
  71. // console.log('部门统计图数据', res.result)
  72. res.result.forEach(item => {
  73. this.cdepNameArr.push(item.cdepName)
  74. this.iquantityArr.push(item.iquantity)
  75. this.inatMoneyArr.push(item.inatMoney)
  76. })
  77. // console.log('部门三数组', this.cdepNameArr, this.iquantityArr, this.inatMoneyArr)
  78. }
  79. //2、后图
  80. this.$nextTick(() => {
  81. this.initEcharts()
  82. })
  83. })
  84. },
  85. initEcharts() {
  86. const myChart = echarts.init(document.getElementById('departmentChart')) //dark
  87. const option = {
  88. title: {
  89. bpttom: '20',
  90. text: '部门统计表',
  91. textStyle: {
  92. fontSize: 18,
  93. color: '#5470c6'
  94. }
  95. },
  96. tooltip: {
  97. trigger: 'axis',
  98. axisPointer: {
  99. type: 'cross',
  100. crossStyle: {
  101. color: '#999'
  102. }
  103. },
  104. textStyle: {
  105. fontSize: 18
  106. }
  107. },
  108. legend: {
  109. textStyle: {
  110. fontSize: 16,
  111. color: '#5470c6'
  112. },
  113. data: ['实际数量', '本币金额']
  114. },
  115. grid: {
  116. show: true, //是否显示直角坐标系网格。[ default: false ]
  117. left: '6%', // 组件离容器左侧的距离。
  118. right: '6%',
  119. borderColor: 'none', //网格的边框颜色
  120. bottom: '20%'
  121. },
  122. xAxis: {
  123. type: 'category',
  124. axisLabel: {
  125. interval: 0 //控制X轴刻度全部显示
  126. // rotate: 30 //倾斜角度
  127. },
  128. axisPointer: {
  129. type: 'shadow'
  130. },
  131. data: this.cdepNameArr
  132. },
  133. yAxis: [
  134. {
  135. type: 'value',
  136. name: '实际数量'
  137. // min: 1000000,
  138. // max: 120000000
  139. // interval: 10000000,
  140. // axisLabel: {
  141. // formatter: '{value} ml'
  142. // }
  143. },
  144. {
  145. type: 'value',
  146. name: '本币金额'
  147. // min: 0,
  148. // max: 10000000,
  149. // interval: 50000
  150. // axisLabel: {
  151. // formatter: '{value} °C'
  152. // }
  153. }
  154. ],
  155. series: [
  156. {
  157. name: '实际数量',
  158. type: 'bar',
  159. // tooltip: {
  160. // valueFormatter: function(value) {
  161. // // return value + ' ml';
  162. // }
  163. // },
  164. itemStyle: {
  165. color: 'orange'
  166. // normal:{
  167. // 颜色: function ( params ) {
  168. // //注意,如果颜色太少,后面的颜色不会自动循环。最好再定义几个颜色
  169. // 变量colorList = [ '#c23531' ,'#2f4554' , '#61a0a8' , '#d48265' ,'#91c7ae' ,'#749f83' , '#ca8622' ]
  170. // 返回颜色列表[参数. 数据索引]
  171. // }
  172. // }
  173. },
  174. barWidth: '30%',
  175. data: this.iquantityArr
  176. },
  177. {
  178. name: '本币金额',
  179. type: 'line',
  180. tooltip: {
  181. // valueFormatter: function(value) {
  182. // // return value + ' ml'
  183. // }
  184. },
  185. yAxisIndex: 1,
  186. data: this.inatMoneyArr
  187. }
  188. ]
  189. }
  190. // 渲染
  191. myChart.setOption(option)
  192. // myChart.showLoading({
  193. // text: '暂无数据',
  194. // showSpinner: false, // 隐藏加载中的转圈动图
  195. // textColor: '#9d9d9d',
  196. // maskColor: 'rgba(255, 255, 255, 0.8)',
  197. // fontSize: '25px',
  198. // fontWeight: 'bold',
  199. // height: '100px',
  200. // fontFamily: 'Microsoft YaHei'
  201. // })
  202. window.addEventListener('resize', () => {
  203. if (myChart) {
  204. myChart.resize()
  205. }
  206. })
  207. }
  208. }
  209. // watch: {
  210. // // 3、监听数据变化
  211. // newData: {
  212. // deep: true,
  213. // handler() {
  214. // // 数据变化,执行
  215. // const { cdepNameArr, iquantityArr, inatMoneyArr } = this.newData
  216. // this.initEcharts(cdepNameArr, iquantityArr, inatMoneyArr)
  217. // console.log('监听 外部部门 数据变化')
  218. // }
  219. // }
  220. // }
  221. }
  222. </script>
  223. <style lang="less" scoped>
  224. @import '~@assets/less/common.less';
  225. @import '~@assets/less/overwriter.less';
  226. /deep/ .ant-table-thead > tr > th {
  227. text-align: center;
  228. // font-weight: 700;
  229. }
  230. /deep/ .ant-table-tbody {
  231. text-align: center;
  232. }
  233. // /deep/ th.replacecolor {
  234. // background-color: #ccc;
  235. // }
  236. /deep/ .ant-table.ant-table-bordered .ant-table-footer {
  237. border: none;
  238. padding: 0;
  239. }
  240. </style>