index.vue 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. <template>
  2. <div class="container">
  3. <el-row :gutter="20">
  4. <el-col :span="12">
  5. <div class="accuracy">
  6. <div class="accuracy_t">
  7. <div class="accuracy_t_l">
  8. <h4><span class="title"></span>准确性分析</h4>
  9. <el-select v-model="accuracy.value1" style="width:100px;margin-right: 5px;" class="filter-item" @change="changecattle('1')">
  10. <el-option v-for="item in accuracy.cattleTpyeList" :key="item.value" :label="item.label"
  11. :value="item.value"> </el-option>
  12. </el-select>
  13. <el-select v-model="accuracy.value2" style="width:100px;margin-right: 5px;" class="filter-item" @change="changeformula('1')">
  14. <el-option v-for="item in accuracy.formulaList" :key="item.value" :label="item.label" :value="item.value">
  15. </el-option>
  16. </el-select>
  17. <el-date-picker v-model="accuracy.inputDatetime" :clearable="false" class="inputDatetime filter-item"
  18. type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
  19. style="width: 250px;" :picker-options="pickerOptions" @change="changeDate('1')" />
  20. </div>
  21. <div class="accuracy_t_r">
  22. <div class="exportTable button" @click="handleChart('accuracy')">切换图表</div>
  23. <div class="exportTable button" @click="handleExport('accuracy')">导出</div>
  24. </div>
  25. </div>
  26. <div class="accuracy_b">
  27. <el-tabs v-model="accuracy.activeName" @tab-click="handleTabClick">
  28. <el-tab-pane label="混料准确率" name="first" />
  29. <el-tab-pane label="混料正确率" name="second" />
  30. <el-tab-pane label="撒料准确率" name="third" />
  31. <el-tab-pane label="撒料正确率" name="fourth" />
  32. </el-tabs>
  33. <el-row :gutter="20">
  34. <el-col :span="6">
  35. <div class="maxdiv">
  36. <div class="title-t">最高</div>
  37. <div class="title-c">{{accuracy.chart1.lineData1.max_value}}%</div>
  38. <div class="title-b">NO.1 {{accuracy.chart1.lineData1.top_one_name}}</div>
  39. </div>
  40. </el-col>
  41. <el-col :span="6">
  42. <div class="mediandiv">
  43. <div class="title-t">中位值</div>
  44. <div class="title-c">{{accuracy.chart1.lineData1.middle_value}}%</div>
  45. <a class="title-b" @click="handleSeeRanking">查看排名</a>
  46. </div>
  47. </el-col>
  48. <el-col :span="6">
  49. <div class="mindiv">
  50. <div class="title-t">最低</div>
  51. <div class="title-c">{{accuracy.chart1.lineData1.min_value}}%</div>
  52. </div>
  53. </el-col>
  54. </el-row>
  55. <div v-if="accuracy.chart1.isChart">
  56. <div id="chartLine1" v-loading="accuracy.chart1.listLoading" style="height:310px;" />
  57. <a class="more" @click="handleMore">更多&gt;</a>
  58. </div>
  59. <div v-else>
  60. <el-table style="width: 100%" :max-height="320" :row-style="rowStyle" :cell-style="cellStyle" border
  61. :data="accuracy.chart1.tableDataList1">
  62. <template v-for="item in accuracy.chart1.tableTitleList1">
  63. <template>
  64. <el-table-column min-width="30" :key="item.value" :label="item.value" align="center">
  65. <template slot-scope="scope">
  66. <span>{{ scope.row[item.name] }}</span>
  67. </template>
  68. </el-table-column>
  69. </template>
  70. </template>
  71. </el-table>
  72. </div>
  73. </div>
  74. </div>
  75. </el-col>
  76. <el-col :span="12">
  77. <div class="time">
  78. <div class="time_t">
  79. <div class="time_t_l">
  80. <h4><span class="title"></span>执行时间</h4>
  81. <el-select v-model="time.value1" style="width:100px;margin-right: 5px;" class="filter-item" @change="changecattle('2')">
  82. <el-option v-for="item in time.cattleTpyeList" :key="item.value" :label="item.label"
  83. :value="item.value"> </el-option>
  84. </el-select>
  85. <el-select v-model="time.value2" style="width:100px;margin-right: 5px;" class="filter-item" @change="changeformula('2')">
  86. <el-option v-for="item in time.formulaList" :key="item.value" :label="item.label" :value="item.value">
  87. </el-option>
  88. </el-select>
  89. <el-date-picker v-model="time.inputDatetime" :clearable="false" class="inputDatetime filter-item"
  90. type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
  91. style="width: 250px;" :picker-options="pickerOptions" @change="changeDate('2')"/>
  92. </div>
  93. <div class="time_t_r">
  94. <div class="exportTable button" @click="handleChart('time')">切换图表</div>
  95. <div class="exportTable button" @click="handleExport('time')">导出</div>
  96. </div>
  97. </div>
  98. <div v-if="time.chart1.isChart">
  99. <div id="chartLine2" v-loading="time.chart1.listLoading" style="height:420px;" />
  100. </div>
  101. <div v-else style="margin: 10px 10px;">
  102. <el-table :data="time.chart1.tableDataList1" border style="width: 100%;" :max-height="410"
  103. :row-style="rowStyle" :cell-style="cellStyle" class="elTable">
  104. <el-table-column label="类型" min-width="80px" align="center">
  105. <el-table-column label="牧场" min-width="80px" align="center" prop="title" />
  106. </el-table-column>
  107. <el-table-column label="加料时间" min-width="80px" align="center">
  108. <el-table-column label="最大值" min-width="80px" align="center" prop="add_feed_time_max_value" />
  109. <el-table-column label="上四分位数" min-width="80px" align="center" prop="add_feed_time_up_middle_value" />
  110. <el-table-column label="中位数" min-width="80px" align="center" prop="add_feed_time_middle_value" />
  111. <el-table-column label="下四分位数" min-width="80px" align="center" prop="add_feed_time_down_middle_value" />
  112. <el-table-column label="最小值" min-width="80px" align="center" prop="add_feed_time_min_value" />
  113. </el-table-column>
  114. <el-table-column label="搅拌延时" min-width="80px" align="center">
  115. <el-table-column label="最大值" min-width="80px" align="center" prop="stir_time_max_value" />
  116. <el-table-column label="上四分位数" min-width="80px" align="center" prop="stir_time_up_middle_value" />
  117. <el-table-column label="中位数" min-width="80px" align="center" prop="stir_time_middle_value" />
  118. <el-table-column label="下四分位数" min-width="80px" align="center" prop="stir_time_down_middle_value" />
  119. <el-table-column label="最小值" min-width="80px" align="center" prop="stir_time_min_value" />
  120. </el-table-column>
  121. <el-table-column label="撒料时间" min-width="80px" align="center">
  122. <el-table-column label="最大值" min-width="80px" align="center" prop="sprinkle_time_max_value" />
  123. <el-table-column label="上四分位数" min-width="80px" align="center" prop="sprinkle_time_up_middle_value" />
  124. <el-table-column label="中位数" min-width="80px" align="center" prop="sprinkle_time_middle_value" />
  125. <el-table-column label="下四分位数" min-width="80px" align="center" prop="sprinkle_time_down_middle_value" />
  126. <el-table-column label="最小值" min-width="80px" align="center" prop="sprinkle_time_min_value" />
  127. </el-table-column>
  128. </el-table>
  129. </div>
  130. </div>
  131. </el-col>
  132. </el-row>
  133. <el-row :gutter="20">
  134. <el-col :span="24">
  135. <div class="abnormal">
  136. <div class="abnormal_t">
  137. <div class="abnormal_t_l">
  138. <h4>
  139. <span class="title"></span>
  140. 撒料时间统计分析
  141. <el-tooltip class="item" effect="dark" placement="top-start">
  142. <div slot="content">
  143. 按时间段统计各牧场配方的每个班次之间<br />
  144. 的撒料间隔时间波动,切换图表可查看各<br />
  145. 班次撒料时间,在波动时间外的异常撒料<br />
  146. 时间数据标红显示
  147. </div>
  148. <span class="el-icon-question"></span>
  149. </el-tooltip>
  150. </h4>
  151. <el-select v-model="abnormal.value2" style="width:100px;margin-right: 5px;" class="filter-item" @change="changeformula('3')">
  152. <el-option v-for="item in abnormal.formulaList" :key="item.value" :label="item.label" :value="item.value">
  153. </el-option>
  154. </el-select>
  155. <el-date-picker v-model="abnormal.inputDatetime" :clearable="false" class="inputDatetime filter-item"
  156. type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
  157. style="width: 250px;" @change="changeDate('3')" />
  158. </div>
  159. <div class="abnormal_t_r">
  160. <div class="exportTable button" @click="handleChart('abnormal')">切换图表</div>
  161. <div class="exportTable button" @click="handleExport('abnormal')">导出</div>
  162. </div>
  163. </div>
  164. <div v-if="abnormal.chart1.isChart">
  165. <div id="chartLine3" v-loading="abnormal.chart1.listLoading" style="height:420px;" />
  166. </div>
  167. <div v-else style="margin: 10px 10px;">
  168. <el-select v-model="abnormal.value3" style="width:100px;margin-right: 5px;margin-bottom:10px;" class="filter-item" @change="changepasture('3')">
  169. <el-option v-for="item in abnormal.pastureList" :key="item.id" :label="item.name" :value="item.id" />
  170. </el-select>
  171. <el-select v-model="abnormal.value4" style="width:100px;margin-right: 5px;margin-bottom:10px;" class="filter-item" @change="changestate('3')">
  172. <el-option v-for="item in abnormal.stateList" :key="item.value" :label="item.label" :value="item.value">
  173. </el-option>
  174. </el-select>
  175. <span style="float: right;">共{{abnormal.chart1.tableDataList1.length}}次</span>
  176. <el-table :data="abnormal.chart1.tableDataList1" border style="width: 100%;" :max-height="410"
  177. :row-style="rowStyle" :cell-style="cellStyle" class="elTable">
  178. <el-table-column label="牧场" min-width="130px" align="center" prop="pasture_name" />
  179. <el-table-column label="栏舍" min-width="130px" align="center" prop="barn_name" />
  180. <el-table-column label="班次" min-width="130px" align="center" prop="class_number" />
  181. <el-table-column label="实际撒料时间" min-width="130px" align="center" prop="reality_sprinkle_feed_time" />
  182. </el-table>
  183. </div>
  184. </div>
  185. </el-col>
  186. </el-row>
  187. <el-dialog :title="textMap[accuracy.dialogStatus]" :visible.sync="accuracy.dialogFormVisible"
  188. :close-on-click-modal="false" width="50%">
  189. <div class="accuracy-content">
  190. <div v-if="accuracy.dialogStatus == 'more'" class="dialogmore" style="min-height: 100px;">
  191. <el-checkbox-group v-model="accuracy.more.checkedPasture">
  192. <el-checkbox border v-for="(item,index) in accuracy.more.pastureList" :label="item.id"
  193. :key="index">{{item.name}}</el-checkbox>
  194. </el-checkbox-group>
  195. </div>
  196. <div v-else class="seeRanking" style="min-height: 300px;">
  197. <el-tabs v-model="accuracy.seeRanking.activeName" @tab-click="handleSeeTabClick">
  198. <el-tab-pane label="混料准确率" name="first" />
  199. <el-tab-pane label="混料正确率" name="second" />
  200. <el-tab-pane label="撒料准确率" name="third" />
  201. <el-tab-pane label="撒料正确率" name="fourth" />
  202. </el-tabs>
  203. <div class="search">
  204. <el-input v-model="accuracy.seeRanking.top_rand_start" placeholder="准确率" style="width: 180px;" class="filter-item"
  205. type="number" clearable />
  206. <span style="margin-right: 5px;">-</span>
  207. <el-input v-model="accuracy.seeRanking.top_rand_end" placeholder="准确率" style="width: 180px;" class="filter-item"
  208. type="number" clearable />
  209. <el-button class="successBorder" @click="handleSearch">查询</el-button>
  210. </div>
  211. <el-table :key="accuracy.seeRanking.tableKey" v-loading="accuracy.seeRanking.listLoading"
  212. element-loading-text="给我一点时间" :data="accuracy.seeRanking.list" border fit highlight-current-row
  213. style="width: 100%;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable">
  214. <el-table-column type="selection" align="center" width="50" />
  215. <el-table-column label="排名" min-width="130px" align="center" prop="rank" />
  216. <el-table-column label="牧场名称" min-width="130px" align="center" prop="pasture_name" />
  217. <el-table-column label="准确率" min-width="130px" align="center" prop="ratio" />
  218. </el-table>
  219. </div>
  220. <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom: 40px;">
  221. <el-button v-if="accuracy.dialogStatus == 'more'" class="cancelClose cancelClose"
  222. @click="accuracy.dialogFormVisible = false; ">关闭</el-button>
  223. <el-button v-else class="cancelClose1"
  224. @click="accuracy.dialogFormVisible = false;getFormulaList(); ">关闭</el-button>
  225. <el-button class="save" :disabled="isokDisable" v-if="accuracy.dialogStatus == 'more'"
  226. @click="createData()">确认</el-button>
  227. </div>
  228. </div>
  229. </el-dialog>
  230. </div>
  231. </template>
  232. <script>
  233. import {
  234. postJson,
  235. getJson
  236. } from '@/api/common'
  237. import {
  238. mapGetters
  239. } from 'vuex'
  240. import {
  241. parseTime
  242. } from '@/utils/index.js'
  243. // import echarts from 'echarts'
  244. import * as echarts from 'echarts';
  245. require('echarts/theme/macarons')
  246. import Cookies from 'js-cookie'
  247. export default {
  248. name: 'Dashboard',
  249. data() {
  250. return {
  251. pickerMinDate: '',
  252. pickerOptions: {
  253. onPick: ({
  254. maxDate,
  255. minDate
  256. }) => {
  257. this.pickerMinDate = minDate.getTime()
  258. if (maxDate) {
  259. this.pickerMinDate = ''
  260. }
  261. },
  262. // 限制不能选择明天之后的日期
  263. disabledDate: (time) => {
  264. if (this.pickerMinDate !== '') {
  265. const one = 31 * 24 * 3600 * 1000
  266. const minTime = this.pickerMinDate - one
  267. let maxTime = this.pickerMinDate + one
  268. if (maxTime > new Date()) {
  269. // maxTime = Date.now() + 8.64e7
  270. maxTime = Date.now()
  271. }
  272. return time.getTime() < minTime || time.getTime() > maxTime
  273. }
  274. return time.getTime() > Date.now()
  275. // return time.getTime() > Date.now() + 8.64e7
  276. }
  277. },
  278. pastureList: JSON.parse(sessionStorage.pastureList),
  279. accuracy: {
  280. value1: '',
  281. value2: '',
  282. inputDatetime: [new Date(), new Date()],
  283. cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
  284. formulaList: JSON.parse(sessionStorage.downlist).formula_list,
  285. activeName: 'first',
  286. chart1: {
  287. isChart: true,
  288. listLoading: false,
  289. chartLine: null,
  290. allChart1Data: {},
  291. allTable1Data: [],
  292. tableTitleList1: [],
  293. tableDataList1: [],
  294. lineData1: {},
  295. },
  296. dialogStatus: '',
  297. dialogFormVisible: false,
  298. more: {
  299. checkedPasture: [],
  300. pastureList: JSON.parse(sessionStorage.pastureList),
  301. },
  302. seeRanking: {
  303. activeName: 'first',
  304. tableKey: 0,
  305. listLoading: false,
  306. list: [],
  307. allData: {}
  308. },
  309. },
  310. time: {
  311. value1: '',
  312. value2: '',
  313. inputDatetime: [new Date(), new Date()],
  314. cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
  315. formulaList: JSON.parse(sessionStorage.downlist).formula_list,
  316. chart1: {
  317. isChart: true,
  318. listLoading: false,
  319. chartLine: null,
  320. lineData1: {},
  321. tableDataList1: [],
  322. },
  323. },
  324. abnormal: {
  325. value1: '',
  326. value2: '',
  327. value3:0,
  328. value4:0,
  329. inputDatetime: [new Date(), new Date()],
  330. cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
  331. formulaList: JSON.parse(sessionStorage.downlist).formula_list,
  332. pastureList:JSON.parse(sessionStorage.pastureList), //牧场
  333. stateList:[{name:'数据状态',id:0},{name:'正常撒料',id:1},{name:'异常撒料',id:2}],
  334. chart1: {
  335. isChart: true,
  336. listLoading: false,
  337. chartLine: null,
  338. lineData1: {},
  339. tableDataList1: [],
  340. },
  341. },
  342. textMap: {
  343. seeRanking: '查看排名',
  344. more: '更多'
  345. },
  346. isokDisable: false,
  347. rowStyle: {
  348. maxHeight: 30 + 'px',
  349. height: 30 + 'px'
  350. },
  351. cellStyle: {
  352. padding: 0 + 'px'
  353. },
  354. initData:[],seriesData:[]
  355. }
  356. },
  357. created() {
  358. // accuracy.inputDatetime
  359. this.abnormal.pastureList.unshift({id:0,name:'所有牧场'})
  360. this.getTimeFn()
  361. },
  362. mounted() {
  363. this.accuracy.value1 = this.accuracy.cattleTpyeList[0].value
  364. this.time.value1 = this.time.cattleTpyeList[0].value
  365. this.abnormal.value1 = this.abnormal.cattleTpyeList[0].value
  366. this.accuracy.value2 = this.accuracy.formulaList[0].value
  367. this.time.value2 = this.time.formulaList[0].value
  368. this.abnormal.value2 = this.abnormal.formulaList[0].value
  369. },
  370. methods: {
  371. getTimeFn() {
  372. const that = this
  373. const start1 = new Date()
  374. const end1 = new Date()
  375. start1.setTime(start1.getTime() - 3600 * 1000 * 24 * 7)
  376. end1.setTime(end1.getTime() - 3600 * 1000 * 24 * 0)
  377. that.accuracy.inputDatetime = [start1, end1]
  378. const start3 = new Date()
  379. const end3 = new Date()
  380. start3.setTime(start3.getTime() - 3600 * 1000 * 24 * 7)
  381. end3.setTime(end3.getTime() - 3600 * 1000 * 24 * 0)
  382. that.time.inputDatetime = [start3, end3]
  383. const start2 = new Date()
  384. const end2 = new Date()
  385. start2.setTime(start2.getTime() - 3600 * 1000 * 24 * 31)
  386. end2.setTime(end2.getTime() - 3600 * 1000 * 24 * 1)
  387. that.abnormal.inputDatetime = [start2, end2]
  388. that.getFormulaList()
  389. },
  390. getFormulaList() {
  391. let page = 1
  392. let page_size = 0
  393. let url = '/api/v1/ops/feed_formula/list' + '?page=' + page + '&page_size=' + page_size
  394. let data = {}
  395. postJson(url, data).then(response => {
  396. if (response.code == 200) {
  397. this.accuracy.formulaList = response.data.list
  398. this.time.formulaList = response.data.list
  399. this.abnormal.formulaList = response.data.list
  400. } else {
  401. this.accuracy.formulaList = []
  402. this.time.formulaList = []
  403. this.abnormal.formulaList = []
  404. }
  405. this.getChart1List()
  406. this.getChart2List()
  407. this.getChart3List()
  408. })
  409. },
  410. getChart1List() {
  411. let url = '/api/v1/ops/dashboard/accuracy'
  412. let pasture_ids = []
  413. this.pastureList.forEach((item) => {
  414. pasture_ids.push(item.id)
  415. })
  416. let data = {
  417. 'cattle_parent_category_id': this.accuracy.value1,
  418. 'start_date': parseTime(this.accuracy.inputDatetime[0], '{y}-{m}-{d}'),
  419. 'end_date': parseTime(this.accuracy.inputDatetime[1], '{y}-{m}-{d}'),
  420. 'pasture_ids': pasture_ids,
  421. 'feed_formula_id':this.accuracy.value2,
  422. }
  423. if (this.accuracy.value2 == '') {
  424. data.feed_formula_id = 0
  425. }
  426. postJson(url, data).then(response => {
  427. if (response.code == 200) {
  428. this.accuracy.chart1.allChart1Data = response.data.chart
  429. this.accuracy.chart1.allTable1Data = response.data.table.data_list
  430. if (this.accuracy.activeName == 'first') {
  431. this.accuracy.chart1.lineData1 = response.data.chart.mixed_fodder_accurate_ratio
  432. this.accuracy.chart1.tableDataList1 = response.data.table.data_list.mixed_fodder_accurate_ratio
  433. } else if (this.accuracy.activeName == 'second') {
  434. this.accuracy.chart1.lineData1 = response.data.chart.mixed_fodder_correct_ratio
  435. this.accuracy.chart1.tableDataList1 = response.data.table.data_list.mixed_fodder_correct_ratio
  436. } else if (this.accuracy.activeName == 'third') {
  437. this.accuracy.chart1.lineData1 = response.data.chart.sprinkle_fodder_accurate_ratio
  438. this.accuracy.chart1.tableDataList1 = response.data.table.data_list.sprinkle_fodder_accurate_ratio
  439. } else if (this.accuracy.activeName == 'fourth') {
  440. this.accuracy.chart1.lineData1 = response.data.chart.sprinkle_fodder_correct_ratio
  441. this.accuracy.chart1.tableDataList1 = response.data.table.data_list.sprinkle_fodder_correct_ratio
  442. }
  443. this.accuracy.chart1.tableTitleList1 = response.data.table.title_list
  444. console.log(this.accuracy.chart1.allChart1Data, 'allChart1Data')
  445. if (this.accuracy.chart1.isChart) {
  446. this.roadChartLine1(this.accuracy.chart1.lineData1)
  447. }
  448. console.log(this.accuracy.chart1.lineData1, '===')
  449. }
  450. })
  451. },
  452. handleTabClick(tab, event) {
  453. console.log(tab);
  454. if (tab.name == 'first') {
  455. this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.mixed_fodder_accurate_ratio
  456. this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.mixed_fodder_accurate_ratio
  457. } else if (tab.name == 'second') {
  458. this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.mixed_fodder_correct_ratio
  459. this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.mixed_fodder_correct_ratio
  460. } else if (tab.name == 'third') {
  461. this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.sprinkle_fodder_accurate_ratio
  462. this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_accurate_ratio
  463. } else if (tab.name == 'fourth') {
  464. this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.sprinkle_fodder_correct_ratio
  465. this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_correct_ratio
  466. }
  467. this.accuracy.chart1.isChart = true
  468. this.roadChartLine1(this.accuracy.chart1.lineData1)
  469. },
  470. handleChart(item) {
  471. if (item == 'accuracy') {
  472. this.accuracy.chart1.isChart = !this.accuracy.chart1.isChart
  473. this.$nextTick(() => {
  474. if (this.accuracy.chart1.isChart) {
  475. this.roadChartLine1(this.accuracy.chart1.lineData1)
  476. }
  477. });
  478. } else if (item == 'time') {
  479. this.time.chart1.isChart = !this.time.chart1.isChart
  480. this.$nextTick(() => {
  481. if (this.time.chart1.isChart) {
  482. this.roadChartLine2(this.time.chart1.lineData1)
  483. }
  484. });
  485. } else {
  486. this.abnormal.chart1.isChart = !this.abnormal.chart1.isChart
  487. this.abnormal.value3 = 0
  488. this.abnormal.value4 = 0
  489. this.getChart3List()
  490. this.$nextTick(() => {
  491. if (this.abnormal.chart1.isChart) {
  492. this.roadChartLine3(this.abnormal.chart1.lineData1)
  493. }
  494. });
  495. }
  496. },
  497. handleExport() {},
  498. handleSeeRanking() {
  499. this.accuracy.dialogStatus = 'seeRanking'
  500. this.accuracy.dialogFormVisible = true
  501. this.getSeeRankingList()
  502. },
  503. getSeeRankingList(item) {
  504. let url = '/api/v1/ops/dashboard/top_pasture'
  505. let pasture_ids = []
  506. this.pastureList.forEach((item) => {
  507. pasture_ids.push(item.id)
  508. })
  509. let dashboard_top_type = 0
  510. if(item){
  511. dashboard_top_type = item
  512. }else{
  513. dashboard_top_type = 0
  514. }
  515. let data = {
  516. 'cattle_parent_category_id': this.accuracy.value1,
  517. 'start_date':parseTime(this.accuracy.inputDatetime[0], '{y}-{m}-{d}'),
  518. 'end_date':parseTime(this.accuracy.inputDatetime[1], '{y}-{m}-{d}'),
  519. 'pasture_ids':pasture_ids,
  520. 'feed_formula_id':this.accuracy.value2,
  521. 'dashboard_top_type':dashboard_top_type
  522. }
  523. if (this.accuracy.value2 == '') {
  524. data.feed_formula_id = 0
  525. }
  526. if (this.accuracy.seeRanking.top_rand_start !== '') {
  527. data.top_rand_start = this.accuracy.seeRanking.top_rand_start
  528. }
  529. if (this.accuracy.seeRanking.top_rand_end !== '') {
  530. data.top_rand_end = this.accuracy.seeRanking.top_rand_end
  531. }
  532. postJson(url, data).then(response => {
  533. if (response.code == 200) {
  534. this.accuracy.seeRanking.allData = response.data
  535. if (this.accuracy.seeRanking.activeName == 'first') {
  536. this.accuracy.seeRanking.list = response.data.mixed_fodder_accurate_ratio
  537. } else if (this.accuracy.seeRanking.activeName == 'second') {
  538. this.accuracy.seeRanking.list = response.data.mixed_fodder_correct_ratio
  539. } else if (this.accuracy.seeRanking.activeName == 'third') {
  540. this.accuracy.seeRanking.list = response.data.sprinkle_fodder_accurate_ratio
  541. } else if (this.accuracy.seeRanking.activeName == 'fourth') {
  542. this.accuracy.seeRanking.list = response.data.sprinkle_fodder_correct_ratio
  543. }
  544. } else {
  545. this.accuracy.seeRanking.list = []
  546. }
  547. })
  548. },
  549. handleSeeTabClick(tab, ) {
  550. console.log(tab);
  551. if (tab.name == 'first') {
  552. this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.mixed_fodder_accurate_ratio
  553. } else if (tab.name == 'second') {
  554. this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.mixed_fodder_correct_ratio
  555. } else if (tab.name == 'third') {
  556. this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.sprinkle_fodder_accurate_ratio
  557. } else if (tab.name == 'fourth') {
  558. this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.sprinkle_fodder_correct_ratio
  559. }
  560. },
  561. handleSearch() {
  562. let dashboard_top_type = 0
  563. if(this.accuracy.seeRanking.activeName == 'first'){
  564. dashboard_top_type = 1
  565. }else if(this.accuracy.seeRanking.activeName == 'second'){
  566. dashboard_top_type = 2
  567. }else if(this.accuracy.seeRanking.activeName == 'third'){
  568. dashboard_top_type = 3
  569. }else{
  570. dashboard_top_type = 4
  571. }
  572. this.getSeeRankingList(dashboard_top_type)
  573. },
  574. handleMore() {
  575. this.accuracy.dialogStatus = 'more'
  576. this.getPastureList()
  577. },
  578. getPastureList() {
  579. let page = 1
  580. let page_size = 100
  581. let url = 'api/v1/ops/pasture/list' + '?page=' + page + '&page_size=' + page_size
  582. let data = {}
  583. postJson(url, data).then(response => {
  584. if (response.code == 200) {
  585. // this.accuracy.more.pastureList = response.data.list
  586. } else {
  587. // this.accuracy.more.pastureList = []
  588. }
  589. this.accuracy.dialogFormVisible = true
  590. })
  591. },
  592. getChart2List() {
  593. let url = '/api/v1/ops/dashboard/exec_time'
  594. let pasture_ids = []
  595. this.pastureList.forEach((item) => {
  596. pasture_ids.push(item.id)
  597. })
  598. let data = {
  599. 'cattle_parent_category_id': this.time.value1,
  600. 'feed_formula_id':this.time.value2,
  601. 'start_date': parseTime(this.time.inputDatetime[0], '{y}-{m}-{d}'),
  602. 'end_date': parseTime(this.time.inputDatetime[1], '{y}-{m}-{d}'),
  603. 'pasture_ids': pasture_ids,
  604. }
  605. if (this.time.value2 == '') {
  606. data.feed_formula_id = 0
  607. }
  608. postJson(url, data).then(response => {
  609. if (response.code == 200) {
  610. this.time.chart1.lineData1 = response.data.chart
  611. this.time.chart1.tableDataList1 = response.data.table_list
  612. if (this.time.chart1.isChart) {
  613. this.roadChartLine2(this.time.chart1.lineData1)
  614. }
  615. console.log(response.data, '===')
  616. }
  617. })
  618. },
  619. changecattle(item){
  620. if(item == '1'){
  621. this.getChart1List()
  622. }else if(item == '2'){
  623. this.getChart2List()
  624. }else if(item == '3'){
  625. this.getChart3List()
  626. }
  627. },
  628. changeformula(item){
  629. if(item == '1'){
  630. this.getChart1List()
  631. }else if(item == '2'){
  632. this.getChart2List()
  633. }else if(item == '3'){
  634. this.getChart3List()
  635. }
  636. },
  637. changeDate (item){
  638. if(item == '1'){
  639. this.getChart1List()
  640. }else if(item == '2'){
  641. this.getChart2List()
  642. }else if(item == '3'){
  643. if (this.abnormal.inputDatetime) {
  644. const startDate = this.abnormal.inputDatetime[0];
  645. const endDate = this.abnormal.inputDatetime[1];
  646. const days = Math.floor((endDate - startDate) / (1000 * 60 * 60 * 24)) + 1;
  647. console.log('所选天数:', days);
  648. if(days < 7){
  649. this.$message({type: 'error',message: '最少选择7天时间', duration: 2000})
  650. }else if(days > 365){
  651. this.$message({type: 'error',message: '最多选择365天时间', duration: 2000})
  652. }else{
  653. this.getChart3List()
  654. }
  655. }
  656. }
  657. },
  658. changepasture(){
  659. this.getChart3List()
  660. },
  661. changestate(){
  662. this.getChart3List()
  663. },
  664. getChart3List() {
  665. let pasture_ids = []
  666. if(this.abnormal.chart1.isChart){
  667. this.abnormal.value3 == 0
  668. this.abnormal.value4 == 0
  669. }
  670. if(this.abnormal.value3 == 0){
  671. this.pastureList.forEach((item) => {
  672. pasture_ids.push(item.id)
  673. })
  674. }else{
  675. pasture_ids.push(this.abnormal.value3)
  676. }
  677. let url = '/api/v1/ops/dashboard/sprinkle_time'
  678. let data = {
  679. 'start_date': parseTime(this.abnormal.inputDatetime[0], '{y}-{m}-{d}'),
  680. 'end_date': parseTime(this.abnormal.inputDatetime[1], '{y}-{m}-{d}'),
  681. 'pasture_ids': pasture_ids,
  682. 'feed_formula_id':this.abnormal.value2
  683. }
  684. console.log(this.abnormal.value2,'====000')
  685. if (this.abnormal.value2 == '') {
  686. data.feed_formula_id = 0
  687. }
  688. postJson(url, data).then(response => {
  689. if (response.code == 200) {
  690. this.abnormal.chart1.lineData1 = response.data.chart
  691. this.abnormal.chart1.tableDataList1 = response.data.table_list
  692. if (this.abnormal.chart1.isChart) {
  693. this.roadChartLine3(this.abnormal.chart1.lineData1)
  694. }
  695. console.log(response.data, '===')
  696. }
  697. })
  698. },
  699. roadChartLine1(chartLine_data) {
  700. if (this.accuracy.chart1.chartLine != null) {
  701. this.accuracy.chart1.chartLine.dispose()
  702. }
  703. this.accuracy.chart1.chartLine = echarts.init(document.getElementById('chartLine1'))
  704. var option = {
  705. animation: false,
  706. tooltip: {
  707. trigger: 'axis'
  708. },
  709. legend: {
  710. data: chartLine_data.pasture_name,
  711. left: 14,
  712. bottom: 0,
  713. },
  714. grid: {
  715. left: '3%',
  716. right: '14%',
  717. // top: '3%',
  718. containLabel: true
  719. },
  720. xAxis: [{
  721. type: 'category',
  722. boundaryGap: false,
  723. data: chartLine_data.date_day,
  724. axisLabel: {
  725. showMinLabel: true,
  726. showMaxLabel: true,
  727. },
  728. axisLine: {
  729. lineStyle: {
  730. color: '#666'
  731. }
  732. },
  733. }],
  734. yAxis: [{
  735. type: 'value',
  736. name: '(%)',
  737. axisLine: {
  738. lineStyle: {
  739. color: '#666'
  740. }
  741. },
  742. }],
  743. color: ['#4b07fa', '#0f96fc', '#ff42a9', '#ff724c', '#05fbf0', '#ffae00', '#b705fa', '#9a60b4', '#3cff00'],
  744. series: function(e) {
  745. var serie = [];
  746. for (var i = 0; i < chartLine_data.pasture_name.length; i++) {
  747. var item = {
  748. name: chartLine_data.pasture_name[i],
  749. data: chartLine_data.data_list[i],
  750. type: 'line',
  751. smooth: true,
  752. itemStyle: {
  753. borderColor: '#fff',
  754. borderWidth: 2
  755. },
  756. label: {
  757. // normal: { show: true },
  758. },
  759. }
  760. serie.push(item);
  761. }
  762. console.log(serie)
  763. return serie;
  764. }()
  765. };
  766. this.accuracy.chart1.chartLine.setOption(option)
  767. if (this.accuracy.chart1.chartLine !== null) {
  768. window.onresize = function() {
  769. this.accuracy.chart1.chartLine.resize()
  770. }
  771. }
  772. },
  773. roadChartLine2(chartLine_data) {
  774. if (this.time.chart1.chartLine != null) {
  775. this.time.chart1.chartLine.dispose()
  776. }
  777. this.time.chart1.chartLine = echarts.init(document.getElementById('chartLine2'))
  778. var option = {
  779. tooltip: {
  780. trigger: `item`,
  781. formatter: this.formatter
  782. }, // formatter可不设置
  783. color: `#8d8d8d`, // 箱线图线框的颜色
  784. grid: {
  785. left: '3%',
  786. right: 10,
  787. bottom: 10,
  788. // top: 20,
  789. containLabel: true,
  790. },
  791. legend: {
  792. data: ['加料时间', '搅拌时间','撒料时间'],
  793. right: 14,
  794. top: 0,
  795. bottom: 10
  796. },
  797. color: ['#42C7FF', '#20DB7C','#FCC858'],
  798. xAxis: { // 此处设置与其他图表类似
  799. type: `category`,
  800. data:chartLine_data.title,
  801. axisLine: {
  802. //坐标轴轴线相关设置
  803. show: false,
  804. },
  805. axisLabel: {
  806. // 坐标轴刻度标签的相关设置
  807. show: true,
  808. showMaxLabel: true,
  809. },
  810. axisTick: {
  811. //刻度相关设置
  812. show: false, //让刻度隐藏
  813. },
  814. },
  815. yAxis: { // 此处设置与其他图表类似
  816. type: `value`,
  817. name:'(分钟)',
  818. splitArea: { show: false },
  819. axisLine: { lineStyle: { color: `#8d8d8d` } },
  820. },
  821. series: [
  822. {
  823. name:'加料时间',
  824. type: `boxplot`,
  825. itemStyle: { color: `#42C7FF` },
  826. data:chartLine_data.add_feed_time
  827. },{
  828. name:'搅拌时间',
  829. type: `boxplot`,
  830. itemStyle: { color: `#20DB7C` },
  831. data:chartLine_data.stir_time
  832. },{
  833. name:'撒料时间',
  834. type: `boxplot`,
  835. itemStyle: { color: `#FCC858` },
  836. data:chartLine_data.sprinkle_time
  837. }
  838. ],
  839. }
  840. this.time.chart1.chartLine.setOption(option)
  841. if (this.time.chart1.chartLine !== null) {
  842. window.onresize = function() {
  843. this.time.chart1.chartLine.resize()
  844. }
  845. }
  846. },
  847. formatter(param) {
  848. return [
  849. // '类别名称: ' + param.name,
  850. '最大值: ' + param.data[1],
  851. '上四分位数: ' + param.data[2],
  852. '中位数: ' + param.data[3],
  853. '下四分位数: ' + param.data[4],
  854. '最小值: ' + param.data[5]
  855. ].join('<br/>')
  856. },
  857. roadChartLine3(chartLine_data) {
  858. console.log(chartLine_data,'===999')
  859. if (this.abnormal.chart1.chartLine != null) {
  860. this.abnormal.chart1.chartLine.dispose()
  861. }
  862. this.abnormal.chart1.chartLine = echarts.init(document.getElementById('chartLine3'))
  863. var option = {
  864. animation: false,
  865. tooltip: {
  866. trigger: 'axis',
  867. formatter: function (data) {
  868. console.log(data,'====')
  869. let a = parseFloat(data[0].data)
  870. let b = parseFloat(data[0].data) + parseFloat(data[1].data)
  871. let rate1 = 0
  872. let rate2 = 0
  873. if(data[0].data !== 0 && data[1].data !== 0){
  874. rate1 = (a/b * 100).toFixed(2)
  875. rate2 = 100 - (parseFloat(rate1))
  876. }else{
  877. rate1 = 0
  878. rate2 = 0
  879. }
  880. var res = data[0].marker + data[0].seriesName + '<br/>'+ a + '次'+ "<span style='margin-left:10px;color:#ccc;'>总占比"+rate1+"%</span>"+'<br/>' + data[1].marker + data[1].seriesName+':'+'<br/>' + data[1].data + '次'+ "<span style='margin-left:10px;color:#ccc;'>总占比"+rate2+"%</span>"
  881. return res
  882. }
  883. },
  884. legend: {
  885. data: ['正常撒料次数', '异常撒料次数'],
  886. right: 14,
  887. top: 0,
  888. },
  889. grid: {
  890. // top: '20%',
  891. left: '3%',
  892. right: '14%',
  893. bottom: '13%',
  894. containLabel: true
  895. },
  896. xAxis: [{
  897. type: 'category',
  898. data: chartLine_data.title,
  899. }],
  900. yAxis: [{
  901. type: 'value',
  902. name:'(次)',
  903. axisLine: {
  904. lineStyle: {
  905. color: '#666'
  906. }
  907. },
  908. }],
  909. series: [{
  910. name: '正常撒料次数',
  911. type: 'bar',
  912. barWidth:50,
  913. data: chartLine_data.sprinkle_number_list[0]
  914. },
  915. {
  916. name: '异常撒料次数',
  917. type: 'bar',
  918. barWidth:50,
  919. data: chartLine_data.sprinkle_number_list[1]
  920. },
  921. ]
  922. };
  923. this.abnormal.chart1.chartLine.setOption(option)
  924. if (this.abnormal.chart1.chartLine !== null) {
  925. window.onresize = function() {
  926. this.abnormal.chart1.chartLine.resize()
  927. }
  928. }
  929. },
  930. }
  931. }
  932. </script>
  933. <style lang="scss" scoped>
  934. .container {
  935. margin: 10px 10px;
  936. }
  937. .accuracy,
  938. .time,
  939. .abnormal {
  940. background: #fff;
  941. height: 550px;
  942. border-radius: 5px;
  943. border: 2px solid #ededed;
  944. }
  945. .accuracy_t {
  946. margin-left: 10px;
  947. position: relative;
  948. .accuracy_t_l {
  949. h3 {
  950. line-height: 15px;
  951. }
  952. .title {
  953. width: 3px;
  954. height: 15px;
  955. background: red;
  956. display: inline-block;
  957. margin-right: 10px;
  958. }
  959. }
  960. .accuracy_t_r {
  961. position: absolute;
  962. top: 0;
  963. right: 0;
  964. .button {
  965. display: inline-block;
  966. margin-right: 10px;
  967. }
  968. }
  969. }
  970. .accuracy_b {
  971. margin: 0 10px;
  972. /deep/ .el-tabs__item {
  973. font-size: 12px
  974. }
  975. position: relative;
  976. }
  977. .more {
  978. position: absolute;
  979. bottom: -14px;
  980. right: -8px;
  981. color: blue;
  982. font-size: 12px;
  983. }
  984. .maxdiv,
  985. .mediandiv,
  986. .mindiv {
  987. text-align: center;
  988. .title-t {
  989. font-size: 12px;
  990. }
  991. .title-c {
  992. font-size: 14px;
  993. font-weight: bold;
  994. }
  995. .title-b {
  996. font-size: 14px;
  997. color: red;
  998. font-weight: bold;
  999. }
  1000. }
  1001. .maxdiv,
  1002. .mediandiv {
  1003. border-right: 2px solid #eee;
  1004. }
  1005. .mediandiv {
  1006. .title-b {
  1007. color: blue;
  1008. }
  1009. }
  1010. .accuracy-content {
  1011. /deep/ .el-checkbox {
  1012. margin: 5px 5px;
  1013. }
  1014. /deep/ .is-bordered {
  1015. margin-left: 5px;
  1016. }
  1017. }
  1018. .time {
  1019. .time_t {
  1020. margin-left: 10px;
  1021. position: relative;
  1022. .time_t_l {
  1023. h3 {
  1024. line-height: 15px;
  1025. }
  1026. .title {
  1027. width: 3px;
  1028. height: 15px;
  1029. background: red;
  1030. display: inline-block;
  1031. margin-right: 10px;
  1032. }
  1033. }
  1034. .time_t_r {
  1035. position: absolute;
  1036. top: 0;
  1037. right: 0;
  1038. .button {
  1039. display: inline-block;
  1040. margin-right: 10px;
  1041. }
  1042. }
  1043. }
  1044. }
  1045. .abnormal {
  1046. background: #fff;
  1047. margin-top: 10px;
  1048. .abnormal_t {
  1049. margin-left: 10px;
  1050. position: relative;
  1051. .abnormal_t_l {
  1052. h3 {
  1053. line-height: 15px;
  1054. }
  1055. .title {
  1056. width: 3px;
  1057. height: 15px;
  1058. background: red;
  1059. display: inline-block;
  1060. margin-right: 10px;
  1061. }
  1062. }
  1063. .abnormal_t_r {
  1064. position: absolute;
  1065. top: 0;
  1066. right: 0;
  1067. .button {
  1068. display: inline-block;
  1069. margin-right: 10px;
  1070. }
  1071. }
  1072. }
  1073. }
  1074. .container {
  1075. background: #fff;
  1076. }
  1077. </style>