index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <div class="app-container" ref="searchBar">
  3. <el-date-picker v-model="inputDatetime" :clearable="false" class="inputDatetime filter-item" type="daterange"
  4. range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;margin-right: 10px;"
  5. :picker-options="pickerOptions" />
  6. <el-button class="el-icon-arrow-left elIconArrowLeft" :disabled="Beforedisabled" @click="handleBefore" />
  7. <el-button class="el-icon-arrow-right elIconArrowRight" :disabled="Nextdisabled" @click="handleNext" />
  8. <el-button class="successBorder" @click="form_search">查询</el-button>
  9. <h3 style="text-align: center;">每日拌料车次</h3>
  10. <div id="chartLine1" :style="{height:height,width:width}" />
  11. </div>
  12. </template>
  13. <script>
  14. import echarts from 'echarts'
  15. require('echarts/theme/macarons')
  16. import Cookies from 'js-cookie'
  17. import {
  18. parseTime
  19. } from '@/utils/index.js'
  20. import {
  21. GetDataByName,
  22. postJson,
  23. GetReportform,
  24. whichWeek
  25. } from '@/api/common'
  26. export default {
  27. name: 'FormulaStatistics',
  28. data() {
  29. return {
  30. width: '100%',
  31. height: document.documentElement.clientHeight - 85 - 150 + 'px',
  32. startTime: parseTime(new Date(), '{y}-{m}-{d}'),
  33. endTime: parseTime(new Date(), '{y}-{m}-{d}'),
  34. inputDatetime: [new Date(), new Date()],
  35. Beforedisabled: false,
  36. Nextdisabled: false,
  37. pickerOptions: {
  38. onPick: ({
  39. maxDate,
  40. minDate
  41. }) => {
  42. this.pickerMinDate = minDate.getTime()
  43. if (maxDate) {
  44. this.pickerMinDate = ''
  45. }
  46. },
  47. // 限制不能选择明天之后的日期
  48. disabledDate: (time) => {
  49. if (this.pickerMinDate !== '') {
  50. const one = 31 * 24 * 3600 * 1000
  51. const minTime = this.pickerMinDate - one
  52. let maxTime = this.pickerMinDate + one
  53. // console.log(minTime, 'minTime')
  54. // console.log(maxTime, 'maxTime')
  55. // console.log(new Date(), 'new Date()')
  56. // console.log(Date.now(), 'Date.now()')
  57. // console.log(time.getTime(), 'time.getTime()')
  58. if (maxTime > new Date()) {
  59. maxTime = Date.now() + 8.64e7
  60. }
  61. return time.getTime() < minTime || time.getTime() > maxTime
  62. }
  63. return time.getTime() > Date.now() + 8.64e7
  64. }
  65. },
  66. chart1: {
  67. chartLine: null,
  68. chartLine_data: {},
  69. tableKey: 1,
  70. list: [],
  71. total: 0,
  72. listLoading: true,
  73. statisticsList: [],
  74. chart1Data1: [],
  75. isChart: true,
  76. isTable: false,
  77. table: {
  78. tableKey: 1,
  79. list: [],
  80. total: 0,
  81. listLoading: false
  82. }
  83. }
  84. }
  85. },
  86. created() {
  87. // this.getChart1()
  88. this.getChart1()
  89. },
  90. methods: {
  91. handleBefore() {
  92. if (this.inputDatetime !== '' && this.inputDatetime !== null) {
  93. var start = new Date(this.inputDatetime[0].setDate(this.inputDatetime[0].getDate() - 1))
  94. var stop = new Date(this.inputDatetime[1].setDate(this.inputDatetime[1].getDate() - 1))
  95. if (stop > Date.now()) {
  96. this.Nextdisabled = true
  97. this.Beforedisabled = false
  98. } else {
  99. this.Nextdisabled = false
  100. this.Beforedisabled = false
  101. }
  102. this.inputDatetime.length = 0
  103. this.inputDatetime.push(start, stop)
  104. this.$forceUpdate()
  105. }
  106. this.startTime = parseTime(this.inputDatetime[0], '{y}-{m}-{d}')
  107. this.endTime = parseTime(this.inputDatetime[1], '{y}-{m}-{d}')
  108. this.getList()
  109. },
  110. handleNext() {
  111. if (this.inputDatetime !== '' && this.inputDatetime !== null) {
  112. var start2 = new Date(this.inputDatetime[0].setDate(this.inputDatetime[0].getDate() + 1))
  113. var stop2 = new Date(this.inputDatetime[1].setDate(this.inputDatetime[1].getDate() + 1))
  114. if (stop2 > Date.now()) {
  115. this.Nextdisabled = true
  116. this.Beforedisabled = false
  117. } else {
  118. this.Nextdisabled = false
  119. this.Beforedisabled = false
  120. }
  121. this.inputDatetime.length = 0
  122. this.inputDatetime.push(start2, stop2)
  123. this.$forceUpdate()
  124. }
  125. this.startTime = parseTime(this.inputDatetime[0], '{y}-{m}-{d}')
  126. this.endTime = parseTime(this.inputDatetime[1], '{y}-{m}-{d}')
  127. this.getChart1()
  128. },
  129. form_search() {
  130. this.getChart1()
  131. },
  132. getChart1() {
  133. this.chart1.listLoading = true
  134. const url = 'authdata/formulastatistics'
  135. const data = {}
  136. // data.parammaps = {}
  137. data.pastureId = Cookies.get('pastureid')
  138. data.startTime = parseTime(this.inputDatetime[0], '{y}-{m}-{d}')
  139. data.endTime = parseTime(this.inputDatetime[1], '{y}-{m}-{d}')
  140. postJson(url, data).then(response => {
  141. if (response.data !== null) {
  142. this.chart1.chartLine_data = {}
  143. this.chart1.chartLine_data = response.data
  144. // this.chart1.chartLine_data.xdata = ['业务系统1', '业务系统2', '业务系统3', '业务系统4', '业务系统5', '业务系统6', '业务系统7']
  145. // // this.chart1.chartLine_data.data1 = ['高危', '中低', '低危','']
  146. // this.chart1.chartLine_data.data1 = ['高危', '中低', '低危']
  147. // this.chart1.chartLine_data.data2 = [
  148. // [50, 60, 59, 50, 50, 50, 50],
  149. // [70, 70, 70, 70, 70, 70, 0],
  150. // [70, 70, 70, 70, 70, 70, 70]
  151. // ]
  152. } else {
  153. this.chart1.chartLine_data = []
  154. }
  155. this.roadChartLine1(this.chart1.chartLine_data)
  156. setTimeout(() => {
  157. this.chart1.listLoading = false
  158. }, 100)
  159. })
  160. },
  161. roadChartLine1(chartLine_data) {
  162. if (this.chart1.chartLine != null) {
  163. this.chart1.chartLine.dispose()
  164. }
  165. this.chart1.chartLine = echarts.init(document.getElementById('chartLine1'))
  166. var option = {
  167. tooltip:{
  168. // trigger: 'axis'
  169. formatter: (param, ticket, callback) => {
  170. var str = ''
  171. str += param.name + '<br>' + param.marker + ' ' + param.seriesName +':' +param.value
  172. console.log(ticket,'ticket')
  173. return str
  174. }
  175. },
  176. grid: {
  177. top: '30%',
  178. left: '3%',
  179. right: '10%',
  180. // bottom: '3%',
  181. containLabel: true
  182. },
  183. legend: {
  184. data:chartLine_data.data1
  185. },
  186. xAxis: {
  187. data: chartLine_data.xdata,
  188. type: 'category',
  189. axisLabel: {
  190. showMaxLabel: true
  191. }
  192. },
  193. yAxis: {
  194. type: 'value',
  195. max: function(value) {
  196. return (value.max+1)
  197. }
  198. },
  199. series: (function() {
  200. var serie = []
  201. if (chartLine_data.data2 !== null) {
  202. for (var i = 0; i < chartLine_data.data2.length; i++) {
  203. var item = {
  204. name: chartLine_data.data1[i],
  205. type: 'bar',
  206. stack: '总量',
  207. label: {
  208. show: true,
  209. formatter: function(params) {
  210. const a = params.value
  211. if (a > 0) {
  212. return a
  213. } else {
  214. return ''
  215. }
  216. },
  217. color: 'black'
  218. },
  219. emphasis: {
  220. focus: 'series'
  221. },
  222. data: chartLine_data.data2[i]
  223. }
  224. serie.push(item)
  225. }
  226. var item2 = {
  227. name: '',
  228. type: 'bar',
  229. stack: '总量',
  230. label: {
  231. show: true,
  232. position: 'top',
  233. formatter: function(params) {
  234. const a = params.value
  235. if (a > 0) {
  236. return a
  237. } else {
  238. return ''
  239. }
  240. }
  241. },
  242. emphasis: {
  243. focus: 'series'
  244. },
  245. data: chartLine_data.data2[chartLine_data.data2.length -1]
  246. }
  247. serie.push(item2)
  248. }
  249. return serie
  250. }())
  251. };
  252. var series = option.series
  253. function getSum(params) {
  254. var datavalue = 0
  255. for (var i = 0; i < series.length; i++) {
  256. datavalue += series[i].data[params.dataIndex]
  257. }
  258. return datavalue
  259. }
  260. series[series.length - 1].label.formatter = getSum
  261. this.chart1.chartLine.setOption(option, true);
  262. this.chart1.chartLine.on('legendselectchanged', (obj) => {
  263. function getSum (params) {
  264. var datavalue = 0
  265. for (var i = 0; i < series.length; i++) {
  266. if (obj.selected[series[i].name]) {
  267. datavalue += series[i].data[params.dataIndex]
  268. }
  269. }
  270. return datavalue
  271. }
  272. series[series.length - 1].label.formatter = getSum
  273. this.chart1.chartLine.setOption(option)
  274. })
  275. // this.chart1.chartLine.setOption(option, true);
  276. },
  277. }
  278. }
  279. </script>