12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208 |
- <template>
- <div class="container">
- <el-row :gutter="20">
- <el-col :span="12">
- <div class="accuracy">
- <div class="accuracy_t">
- <div class="accuracy_t_l">
- <h4><span class="title"></span>准确性分析</h4>
- <el-select v-model="accuracy.value1" style="width:150px;margin-right: 5px;" class="filter-item" @change="changecattle('1')">
- <el-option v-for="item in accuracy.cattleTpyeList" :key="item.value" :label="item.label"
- :value="item.value"> </el-option>
- </el-select>
- <el-select v-model="accuracy.value2" style="width:150px;margin-right: 5px;" class="filter-item" @change="changeformula('1')">
- <el-option v-for="item in accuracy.formulaList" :key="item.value" :label="item.label"
- :value="item.value"> </el-option>
- </el-select>
- <el-date-picker v-model="accuracy.inputDatetime" :clearable="false" class="inputDatetime filter-item"
- type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
- style="width: 250px;" :picker-options="pickerOptions" @change="changeDate('1')" />
- </div>
- <div class="accuracy_t_r">
- <div class="exportTable button" @click="handleChart('accuracy')">切换图表</div>
- <div class="exportTable button" @click="handleExport('accuracy')">导出</div>
- </div>
- </div>
- <div class="accuracy_b">
- <el-tabs v-model="accuracy.activeName" @tab-click="handleTabClick">
- <el-tab-pane label="混料准确率" name="first" />
- <el-tab-pane label="混料正确率" name="second" />
- <el-tab-pane label="撒料准确率" name="third" />
- <el-tab-pane label="撒料正确率" name="fourth" />
- </el-tabs>
- <el-row :gutter="20">
- <el-col :span="6">
- <div class="maxdiv">
- <div class="title-t">最高</div>
- <div class="title-c">{{accuracy.chart1.lineData1.max_value}}%</div>
- <div class="title-b">NO.1 {{accuracy.chart1.lineData1.top_one_name}}</div>
- </div>
- </el-col>
- <el-col :span="6">
- <div class="mediandiv">
- <div class="title-t">中位值</div>
- <div class="title-c">{{accuracy.chart1.lineData1.middle_value}}%</div>
- <a class="title-b" @click="handleSeeRanking">查看排名</a>
- </div>
- </el-col>
- <el-col :span="6">
- <div class="mindiv">
- <div class="title-t">最低</div>
- <div class="title-c">{{accuracy.chart1.lineData1.min_value}}%</div>
- </div>
- </el-col>
- </el-row>
- <div v-if="accuracy.chart1.isChart">
- <div id="chartLine1" v-loading="accuracy.chart1.listLoading" style="height:310px;" />
- <a class="more" @click="handleMore">更多></a>
- </div>
- <div v-else>
- <el-table style="width: 100%" :max-height="320" :row-style="rowStyle" :cell-style="cellStyle" border
- :data="accuracy.chart1.tableDataList1">
- <template v-for="(item,key) in accuracy.chart1.tableTitleList1">
- <template>
- <el-table-column min-width="30" :key="item.value" :label="item.value" align="center">
- <template slot-scope="scope">
- <span v-if="key == 0">{{ scope.row[item.name] }}</span>
- <span v-else>{{ scope.row[item.name] }}%</span>
- </template>
- </el-table-column>
- </template>
- </template>
- </el-table>
- </div>
- </div>
- </div>
- </el-col>
- <el-col :span="12">
- <div class="time">
- <div class="time_t">
- <div class="time_t_l">
- <h4><span class="title"></span>执行时间</h4>
- <el-select v-model="time.value1" style="width:150px;margin-right: 5px;" class="filter-item" @change="changecattle('2')">
- <el-option v-for="item in time.cattleTpyeList" :key="item.value" :label="item.label"
- :value="item.value"> </el-option>
- </el-select>
- <!-- <el-select v-model="time.value2" style="width:150px;margin-right: 5px;" class="filter-item" @change="changeformula('2')">
- <el-option v-for="item in time.formulaList" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select> -->
- <el-date-picker v-model="time.inputDatetime" :clearable="false" class="inputDatetime filter-item"
- type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
- style="width: 250px;" :picker-options="pickerOptions" @change="changeDate('2')"/>
- </div>
- <div class="time_t_r">
- <div class="exportTable button" @click="handleChart('time')">切换图表</div>
- <div class="exportTable button" @click="handleExport('time')">导出</div>
- </div>
- </div>
- <div v-if="time.chart1.isChart">
- <div id="chartLine2" v-loading="time.chart1.listLoading" style="height:420px;" />
- </div>
- <div v-else style="margin: 10px 10px;">
- <el-table :data="time.chart1.tableDataList1" border style="width: 100%;" :max-height="410"
- :row-style="rowStyle" :cell-style="cellStyle" class="elTable">
- <el-table-column label="类型" min-width="80px" align="center">
- <el-table-column label="牧场" min-width="80px" align="center" prop="title" />
- </el-table-column>
- <el-table-column label="加料时间(分钟)" min-width="80px" align="center">
- <el-table-column label="最大值" min-width="80px" align="center" prop="add_feed_time_max_value" />
- <el-table-column label="上四分位数" min-width="80px" align="center" prop="add_feed_time_up_middle_value" />
- <el-table-column label="中位数" min-width="80px" align="center" prop="add_feed_time_middle_value" />
- <el-table-column label="下四分位数" min-width="80px" align="center" prop="add_feed_time_down_middle_value" />
- <el-table-column label="最小值" min-width="80px" align="center" prop="add_feed_time_min_value" />
- </el-table-column>
- <!-- <el-table-column label="搅拌延时(分钟)" min-width="80px" align="center">
- <el-table-column label="最大值" min-width="80px" align="center" prop="stir_time_max_value" />
- <el-table-column label="上四分位数" min-width="80px" align="center" prop="stir_time_up_middle_value" />
- <el-table-column label="中位数" min-width="80px" align="center" prop="stir_time_middle_value" />
- <el-table-column label="下四分位数" min-width="80px" align="center" prop="stir_time_down_middle_value" />
- <el-table-column label="最小值" min-width="80px" align="center" prop="stir_time_min_value" />
- </el-table-column> -->
- <el-table-column label="撒料时间(分钟)" min-width="80px" align="center">
- <el-table-column label="最大值" min-width="80px" align="center" prop="sprinkle_time_max_value" />
- <el-table-column label="上四分位数" min-width="80px" align="center" prop="sprinkle_time_up_middle_value" />
- <el-table-column label="中位数" min-width="80px" align="center" prop="sprinkle_time_middle_value" />
- <el-table-column label="下四分位数" min-width="80px" align="center" prop="sprinkle_time_down_middle_value" />
- <el-table-column label="最小值" min-width="80px" align="center" prop="sprinkle_time_min_value" />
- </el-table-column>
- </el-table>
- </div>
- </div>
- </el-col>
- </el-row>
- <el-row :gutter="20">
- <el-col :span="24">
- <div class="abnormal">
- <div class="abnormal_t">
- <div class="abnormal_t_l">
- <h4>
- <span class="title"></span>
- 撒料时间统计分析
- <el-tooltip class="item" effect="dark" placement="top-start">
- <div slot="content">
- 按时间段统计各牧场配方的撒料正常次数和异常次数,<br />
- 切换图表可查看详细数据
- </div>
- <span class="el-icon-question"></span>
- </el-tooltip>
- </h4>
- <el-select v-model="abnormal.value2" style="width:150px;margin-right: 5px;" class="filter-item" @change="changeformula('3')">
- <el-option v-for="item in abnormal.formulaList" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select>
- <el-date-picker v-model="abnormal.inputDatetime" :clearable="false" class="inputDatetime filter-item"
- type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
- style="width: 250px;" @change="changeDate('3')" />
- </div>
- <div class="abnormal_t_r">
- <div class="exportTable button" @click="handleChart('abnormal')">切换图表</div>
- <div class="exportTable button" @click="handleExport('abnormal')">导出</div>
- </div>
- </div>
- <div v-if="abnormal.chart1.isChart">
- <div id="chartLine3" v-loading="abnormal.chart1.listLoading" style="height:420px;" />
- </div>
- <div v-else style="margin: 10px 10px;">
- <el-select v-model="abnormal.value3" style="width:150px;margin-right: 5px;margin-bottom:10px;" class="filter-item" @change="changepasture('3')">
- <el-option v-for="item in abnormal.pastureList" :key="item.id" :label="item.name" :value="item.id" />
- </el-select>
- <el-select v-model="abnormal.value4" style="width:150px;margin-right: 5px;margin-bottom:10px;" class="filter-item" @change="changestate('3')">
- <el-option v-for="item in abnormal.stateList" :key="item.value" :label="item.label" :value="item.value">
- </el-option>
- </el-select>
- <span style="float: right;">共{{abnormal.chart1.tableDataList1.length}}次</span>
- <el-table :data="abnormal.chart1.tableDataList1" border style="width: 100%;" :max-height="310"
- :row-style="rowStyle" :cell-style="cellStyle" class="elTable">
- <el-table-column label="牧场" min-width="130px" align="center" prop="pasture_name" />
- <el-table-column label="栏舍" min-width="130px" align="center" prop="barn_name" />
- <el-table-column label="班次" min-width="130px" align="center" prop="class_number" />
- <el-table-column label="实际撒料时间" min-width="130px" align="center" prop="reality_sprinkle_feed_time" />
- </el-table>
- </div>
- </div>
- </el-col>
- </el-row>
- <el-dialog :title="textMap[accuracy.dialogStatus]" :visible.sync="accuracy.dialogFormVisible"
- :close-on-click-modal="false" width="50%">
- <div class="accuracy-content">
- <div v-if="accuracy.dialogStatus == 'more'" class="dialogmore" style="min-height: 100px;">
- <el-checkbox-group v-model="accuracy.more.checkedPasture">
- <el-checkbox border v-for="(item,index) in accuracy.more.pastureList" :label="item.id"
- :key="index">{{item.name}}</el-checkbox>
- </el-checkbox-group>
- </div>
- <div v-else class="seeRanking" style="min-height: 300px;">
- <el-tabs v-model="accuracy.seeRanking.activeName" @tab-click="handleSeeTabClick">
- <el-tab-pane label="混料准确率" name="first" />
- <el-tab-pane label="混料正确率" name="second" />
- <el-tab-pane label="撒料准确率" name="third" />
- <el-tab-pane label="撒料正确率" name="fourth" />
- </el-tabs>
- <div class="search">
- <el-input v-model="accuracy.seeRanking.top_rand_start" placeholder="准确率" style="width: 180px;" class="filter-item"
- type="number" clearable />
- <span style="margin-right: 5px;">-</span>
- <el-input v-model="accuracy.seeRanking.top_rand_end" placeholder="准确率" style="width: 180px;" class="filter-item"
- type="number" clearable />
- <el-button class="successBorder" @click="handleSearch">查询</el-button>
- </div>
- <el-table :key="accuracy.seeRanking.tableKey" v-loading="accuracy.seeRanking.listLoading"
- element-loading-text="给我一点时间" :data="accuracy.seeRanking.list" border fit highlight-current-row
- style="width: 100%;margin-bottom: 50px;" :row-style="rowStyle" :cell-style="cellStyle" class="elTable" height="500">
- <el-table-column type="selection" align="center" width="50" />
- <el-table-column label="排名" min-width="130px" align="center" type="index"/>
- <el-table-column label="牧场名称" min-width="130px" align="center" prop="pasture_name" />
- <el-table-column label="准确率" min-width="130px" align="center" prop="ratio" />
- </el-table>
- </div>
- <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom: 40px;">
- <el-button v-if="accuracy.dialogStatus == 'more'" class="cancelClose cancelClose"
- @click="accuracy.dialogFormVisible = false; ">关闭</el-button>
- <el-button v-else class="cancelClose1"
- @click="accuracy.dialogFormVisible = false; ">关闭</el-button>
- <el-button class="save" :disabled="isokDisable" v-if="accuracy.dialogStatus == 'more'"
- @click="createData()">确认</el-button>
- </div>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { postJson, getJson } from '@/api/common'
- import { mapGetters } from 'vuex'
- import { parseTime,json2excel } from '@/utils/index.js'
- // import echarts from 'echarts'
- import * as echarts from 'echarts';
- require('echarts/theme/macarons')
- import Cookies from 'js-cookie'
- export default {
- name: 'Dashboard',
- data() {
- return {
- pickerMinDate: '',
- pickerOptions: {
- onPick: ({
- maxDate,
- minDate
- }) => {
- this.pickerMinDate = minDate.getTime()
- if (maxDate) {
- this.pickerMinDate = ''
- }
- },
- // 限制不能选择明天之后的日期
- disabledDate: (time) => {
- if (this.pickerMinDate !== '') {
- const one = 31 * 24 * 3600 * 1000
- const minTime = this.pickerMinDate - one
- let maxTime = this.pickerMinDate + one
- if (maxTime > new Date()) {
- // maxTime = Date.now() + 8.64e7
- maxTime = Date.now()
- }
- return time.getTime() < minTime || time.getTime() > maxTime
- }
- return time.getTime() > Date.now()
- // return time.getTime() > Date.now() + 8.64e7
- }
- },
- pastureList: JSON.parse(sessionStorage.pastureList),
- accuracy: {
- value1: '',
- value2: '',
- inputDatetime: [new Date(), new Date()],
- cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
- formulaList: JSON.parse(sessionStorage.downlist).formula_list,
- activeName: 'first',
- chart1: {
- isChart: true,
- listLoading: false,
- chartLine: null,
- allChart1Data: {},
- allTable1Data: [],
- tableTitleList1: [],
- tableDataList1: [],
- lineData1: {},
- },
- dialogStatus: '',
- dialogFormVisible: false,
- more: {
- checkedPasture: [],
- pastureList: JSON.parse(sessionStorage.pastureList),
- },
- seeRanking: {
- activeName: 'first',
- tableKey: 0,
- listLoading: false,
- list: [],
- allData: {}
- },
- },
- time: {
- value1: '',
- value2: '',
- inputDatetime: [new Date(), new Date()],
- cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
- formulaList: JSON.parse(sessionStorage.downlist).formula_list,
- chart1: {
- isChart: true,
- listLoading: false,
- chartLine: null,
- lineData1: {},
- tableDataList1: [],
- },
- },
- abnormal: {
- value1: '',
- value2: '',
- value3:0,
- value4:0,
- inputDatetime: [new Date(), new Date()],
- cattleTpyeList: JSON.parse(sessionStorage.downlist).cattle_parent_category,
- formulaList: JSON.parse(sessionStorage.downlist).formula_list,
- pastureList:JSON.parse(sessionStorage.pastureList), //牧场
- stateList:[{label:'数据状态',value:0},{label:'正常撒料',value:1},{label:'异常撒料',value:2}],
- chart1: {
- isChart: true,
- listLoading: false,
- chartLine: null,
- lineData1: {},
- tableDataList1: [],
- },
- },
- textMap: {
- seeRanking: '查看排名',
- more: '更多'
- },
- isokDisable: false,
- rowStyle: {
- maxHeight: 30 + 'px',
- height: 30 + 'px'
- },
- cellStyle: {
- padding: 0 + 'px'
- },
- initData:[],seriesData:[]
- }
- },
- created() {
- // accuracy.inputDatetime
- this.abnormal.pastureList.unshift({id:0,name:'所有牧场'})
- this.accuracy.value1 = this.accuracy.cattleTpyeList[0].value
- this.time.value1 = this.time.cattleTpyeList[0].value
- this.abnormal.value1 = this.abnormal.cattleTpyeList[0].value
- this.accuracy.value2 = this.accuracy.formulaList[0].value
- this.time.value2 = this.time.formulaList[0].value
- this.abnormal.value2 = this.abnormal.formulaList[0].value
- this.getTimeFn()
- },
- methods: {
- getTimeFn() {
- const that = this
- const start1 = new Date()
- const end1 = new Date()
- start1.setTime(start1.getTime() - 3600 * 1000 * 24 * 6)
- end1.setTime(end1.getTime() - 3600 * 1000 * 24 * 0)
- that.accuracy.inputDatetime = [start1, end1]
- const start3 = new Date()
- const end3 = new Date()
- start3.setTime(start3.getTime() - 3600 * 1000 * 24 * 6)
- end3.setTime(end3.getTime() - 3600 * 1000 * 24 * 0)
- that.time.inputDatetime = [start3, end3]
- const start2 = new Date()
- const end2 = new Date()
- start2.setTime(start2.getTime() - 3600 * 1000 * 24 * 6)
- end2.setTime(end2.getTime() - 3600 * 1000 * 24 * 0)
- that.abnormal.inputDatetime = [start2, end2]
- that.getChart1List()
- that.getChart2List()
- that.getChart3List()
- },
- // getFormulaList() {
- // let page = 1
- // let page_size = 0
- // let url = '/api/v1/ops/feed_formula/list' + '?page=' + page + '&page_size=' + page_size
- // let data = {}
- // postJson(url, data).then(response => {
- // if (response.code == 200) {
- // this.accuracy.formulaList = response.data.list
- // this.time.formulaList = response.data.list
- // this.abnormal.formulaList = response.data.list
- // } else {
- // this.accuracy.formulaList = []
- // this.time.formulaList = []
- // this.abnormal.formulaList = []
- // }
- // this.getChart1List()
- // this.getChart2List()
- // this.getChart3List()
- // })
- // },
- getChart1List() {
- let url = '/api/v1/ops/dashboard/accuracy'
- let pasture_ids = []
- if(this.accuracy.more.checkedPasture.length > 0){
- pasture_ids = this.accuracy.more.checkedPasture
- }else{
- this.pastureList.forEach((item) => {
- pasture_ids.push(item.id)
- })
- }
- let data = {
- 'cattle_parent_category_id': this.accuracy.value1,
- 'start_date': parseTime(this.accuracy.inputDatetime[0], '{y}-{m}-{d}'),
- 'end_date': parseTime(this.accuracy.inputDatetime[1], '{y}-{m}-{d}'),
- 'pasture_ids': pasture_ids,
- 'feed_formula_id':this.accuracy.value2,
- }
- if (this.accuracy.value2 == '') {
- data.feed_formula_id = 0
- }
- postJson(url, data).then(response => {
- if (response.code == 200) {
- this.accuracy.chart1.allChart1Data = response.data.chart
- this.accuracy.chart1.allTable1Data = response.data.table.data_list
- if (this.accuracy.activeName == 'first') {
- this.accuracy.chart1.lineData1 = response.data.chart.mixed_fodder_accurate_ratio
- this.accuracy.chart1.tableDataList1 = response.data.table.data_list.mixed_fodder_accurate_ratio
- } else if (this.accuracy.activeName == 'second') {
- this.accuracy.chart1.lineData1 = response.data.chart.mixed_fodder_correct_ratio
- this.accuracy.chart1.tableDataList1 = response.data.table.data_list.mixed_fodder_correct_ratio
- } else if (this.accuracy.activeName == 'third') {
- this.accuracy.chart1.lineData1 = response.data.chart.sprinkle_fodder_accurate_ratio
- this.accuracy.chart1.tableDataList1 = response.data.table.data_list.sprinkle_fodder_accurate_ratio
- } else if (this.accuracy.activeName == 'fourth') {
- this.accuracy.chart1.lineData1 = response.data.chart.sprinkle_fodder_correct_ratio
- this.accuracy.chart1.tableDataList1 = response.data.table.data_list.sprinkle_fodder_correct_ratio
- }
- this.accuracy.chart1.tableTitleList1 = response.data.table.title_list
- console.log(this.accuracy.chart1.allChart1Data, 'allChart1Data')
- if (this.accuracy.chart1.isChart) {
- this.roadChartLine1(this.accuracy.chart1.lineData1)
- }
- console.log(this.accuracy.chart1.lineData1, '===')
- }
- })
- },
- handleTabClick(tab, event) {
- console.log(tab);
- if (tab.name == 'first') {
- this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.mixed_fodder_accurate_ratio
- this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.mixed_fodder_accurate_ratio
- } else if (tab.name == 'second') {
- this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.mixed_fodder_correct_ratio
- this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.mixed_fodder_correct_ratio
- } else if (tab.name == 'third') {
- this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.sprinkle_fodder_accurate_ratio
- this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_accurate_ratio
- } else if (tab.name == 'fourth') {
- this.accuracy.chart1.lineData1 = this.accuracy.chart1.allChart1Data.sprinkle_fodder_correct_ratio
- this.accuracy.chart1.tableDataList1 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_correct_ratio
- }
- this.accuracy.chart1.isChart = true
- this.roadChartLine1(this.accuracy.chart1.lineData1)
- },
- handleChart(item) {
- if (item == 'accuracy') {
- this.accuracy.chart1.isChart = !this.accuracy.chart1.isChart
- this.$nextTick(() => {
- if (this.accuracy.chart1.isChart) {
- this.roadChartLine1(this.accuracy.chart1.lineData1)
- }
- });
- } else if (item == 'time') {
- this.time.chart1.isChart = !this.time.chart1.isChart
- this.$nextTick(() => {
- if (this.time.chart1.isChart) {
- this.roadChartLine2(this.time.chart1.lineData1)
- }
- });
- } else {
- this.abnormal.chart1.isChart = !this.abnormal.chart1.isChart
- this.abnormal.value3 = 0
- this.abnormal.value4 = 0
- this.getChart3List()
- this.$nextTick(() => {
- if (this.abnormal.chart1.isChart) {
- this.roadChartLine3(this.abnormal.chart1.lineData1)
- }
- });
- }
- },
- handleExport(item) {
- if(item == 'accuracy'){
- var list1 = this.accuracy.chart1.allTable1Data.mixed_fodder_accurate_ratio
- var list2 = this.accuracy.chart1.allTable1Data.mixed_fodder_correct_ratio
- var list3 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_accurate_ratio
- var list4 = this.accuracy.chart1.allTable1Data.sprinkle_fodder_correct_ratio
- var titles = []
- var values = []
- for(let i =0;i<this.accuracy.chart1.tableTitleList1.length;i++){
- titles.push(this.accuracy.chart1.tableTitleList1[i].value)
- values.push(this.accuracy.chart1.tableTitleList1[i].name)
- }
- var excelDatasTabChart1 = [
- {
- tHeader: titles,
- filterVal: values,
- tableDatas: list1,
- sheetName: '混料准确率'
- },{
- tHeader: titles,
- filterVal: values,
- tableDatas: list2,
- sheetName: '混料正确率'
- },{
- tHeader: titles,
- filterVal: values,
- tableDatas: list3,
- sheetName: '撒料准确率'
- },{
- tHeader: titles,
- filterVal: values,
- tableDatas: list4,
- sheetName: '撒料正确率'
- }
- ]
- json2excel(excelDatasTabChart1, '准确性分析', true, 'xlsx')
- }else if(item == 'time'){
- import('@/vendor/Export5Excel').then(excel => {
- const multiHeader = [
- [
- '类型', '加料时间(分钟)', '', '', '', '', '撒料时间(分钟)', '', '', '', ''
- ]
- ]
- const multiHeader2 = [
- [
- '牧场', '最大值', '上四分位数', '中位数', '下四分位数', '最小值', '最大值', '上四分位数', '中位数', '下四分位数', '最小值'
- ]
- ]
- const filterVal = [
- 'title','add_feed_time_max_value','add_feed_time_up_middle_value','add_feed_time_middle_value','add_feed_time_down_middle_value','add_feed_time_min_value','sprinkle_time_max_value','sprinkle_time_up_middle_value','sprinkle_time_middle_value','sprinkle_time_down_middle_value','sprinkle_time_min_value'
- ]
- const data = this.time.chart1.tableDataList1.map((v) => filterVal.map((j) => v[j]))
- const merges = ['A1', 'B1:F1', 'G1:K1']
- excel.export_json_to_excel({ multiHeader, multiHeader2, data, filename: '执行时间', merges })
- })
- }else if(item == 'abnormal'){
- var excelDatasTabChart3 = [
- {
- tHeader: ['牧场','栏舍','班次','实际撒料时间'],
- filterVal: ['pasture_name','barn_name','class_number','reality_sprinkle_feed_time'],
- tableDatas: this.abnormal.chart1.tableDataList1,
- sheetName: ' 撒料时间统计分析'
- }
- ]
- json2excel(excelDatasTabChart3, ' 撒料时间统计分析', true, 'xlsx')
- }
- },
- handleSeeRanking() {
- this.accuracy.dialogStatus = 'seeRanking'
- this.accuracy.dialogFormVisible = true
- this.getSeeRankingList()
- },
- getSeeRankingList(item) {
- let url = '/api/v1/ops/dashboard/top_pasture'
- let pasture_ids = []
- this.pastureList.forEach((item) => {
- pasture_ids.push(item.id)
- })
- let dashboard_top_type = 0
- if(item){
- dashboard_top_type = item
- }else{
- dashboard_top_type = 0
- }
- let data = {
- 'cattle_parent_category_id': this.accuracy.value1,
- 'start_date':parseTime(this.accuracy.inputDatetime[0], '{y}-{m}-{d}'),
- 'end_date':parseTime(this.accuracy.inputDatetime[1], '{y}-{m}-{d}'),
- 'pasture_ids':pasture_ids,
- 'feed_formula_id':this.accuracy.value2,
- 'dashboard_top_type':dashboard_top_type
- }
- if (this.accuracy.value2 == '') {
- data.feed_formula_id = 0
- }
- if (this.accuracy.seeRanking.top_rand_start !== '') {
- data.top_rand_start = this.accuracy.seeRanking.top_rand_start
- }
- if (this.accuracy.seeRanking.top_rand_end !== '') {
- data.top_rand_end = this.accuracy.seeRanking.top_rand_end
- }
- postJson(url, data).then(response => {
- if (response.code == 200) {
- this.accuracy.seeRanking.allData = response.data
- if (this.accuracy.seeRanking.activeName == 'first') {
- this.accuracy.seeRanking.list = response.data.mixed_fodder_accurate_ratio
- } else if (this.accuracy.seeRanking.activeName == 'second') {
- this.accuracy.seeRanking.list = response.data.mixed_fodder_correct_ratio
- } else if (this.accuracy.seeRanking.activeName == 'third') {
- this.accuracy.seeRanking.list = response.data.sprinkle_fodder_accurate_ratio
- } else if (this.accuracy.seeRanking.activeName == 'fourth') {
- this.accuracy.seeRanking.list = response.data.sprinkle_fodder_correct_ratio
- }
- } else {
- this.accuracy.seeRanking.list = []
- }
- })
- },
- handleSeeTabClick(tab, ) {
- console.log(tab);
- if (tab.name == 'first') {
- this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.mixed_fodder_accurate_ratio
- } else if (tab.name == 'second') {
- this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.mixed_fodder_correct_ratio
- } else if (tab.name == 'third') {
- this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.sprinkle_fodder_accurate_ratio
- } else if (tab.name == 'fourth') {
- this.accuracy.seeRanking.list = this.accuracy.seeRanking.allData.sprinkle_fodder_correct_ratio
- }
- },
- handleSearch() {
- let dashboard_top_type = 0
- if(this.accuracy.seeRanking.activeName == 'first'){
- dashboard_top_type = 1
- }else if(this.accuracy.seeRanking.activeName == 'second'){
- dashboard_top_type = 2
- }else if(this.accuracy.seeRanking.activeName == 'third'){
- dashboard_top_type = 3
- }else{
- dashboard_top_type = 4
- }
- this.getSeeRankingList(dashboard_top_type)
- },
- handleMore() {
- this.accuracy.dialogStatus = 'more'
- this.getPastureList()
- },
- getPastureList() {
- let page = 1
- let page_size = 100
- let url = 'api/v1/ops/pasture/list' + '?page=' + page + '&page_size=' + page_size
- let data = {}
- postJson(url, data).then(response => {
- if (response.code == 200) {
- // this.accuracy.more.pastureList = response.data.list
- } else {
- // this.accuracy.more.pastureList = []
- }
- this.accuracy.dialogFormVisible = true
- })
- },
- getChart2List() {
- let url = '/api/v1/ops/dashboard/exec_time'
- let pasture_ids = []
- this.pastureList.forEach((item) => {
- pasture_ids.push(item.id)
- })
- let data = {
- 'cattle_parent_category_id': this.time.value1,
- // 'feed_formula_id':this.time.value2,
- 'start_date': parseTime(this.time.inputDatetime[0], '{y}-{m}-{d}'),
- 'end_date': parseTime(this.time.inputDatetime[1], '{y}-{m}-{d}'),
- 'pasture_ids': pasture_ids,
- }
- // if (this.time.value2 == '') {
- // data.feed_formula_id = 0
- // }
- postJson(url, data).then(response => {
- if (response.code == 200) {
- this.time.chart1.lineData1 = response.data.chart
- this.time.chart1.tableDataList1 = response.data.table_list
- if (this.time.chart1.isChart) {
- this.roadChartLine2(this.time.chart1.lineData1)
- }
- console.log(response.data, '===')
- }
- })
- },
- changecattle(item){
- if(item == '1'){
- this.getChart1List()
- }else if(item == '2'){
- this.getChart2List()
- }else if(item == '3'){
- this.getChart3List()
- }
- },
- changeformula(item){
- if(item == '1'){
- this.getChart1List()
- }else if(item == '2'){
- this.getChart2List()
- }else if(item == '3'){
- this.getChart3List()
- }
- },
- changeDate (item){
- if(item == '1'){
- this.getChart1List()
- }else if(item == '2'){
- this.getChart2List()
- }else if(item == '3'){
- if (this.abnormal.inputDatetime) {
- const startDate = this.abnormal.inputDatetime[0];
- const endDate = this.abnormal.inputDatetime[1];
- const days = Math.floor((endDate - startDate) / (1000 * 60 * 60 * 24)) + 1;
- console.log('所选天数:', days);
- if(days < 7){
- this.$message({type: 'error',message: '最少选择7天时间', duration: 2000})
- }else if(days > 365){
- this.$message({type: 'error',message: '最多选择365天时间', duration: 2000})
- }else{
- this.getChart3List()
- }
- }
- }
- },
- changepasture(){
- this.getChart3List()
- },
- changestate(){
- this.getChart3List()
- },
- getChart3List() {
- let pasture_ids = []
- if(this.abnormal.chart1.isChart){
- this.abnormal.value3 == 0
- this.abnormal.value4 == 0
- }
- if(this.abnormal.value3 == 0){
- this.pastureList.forEach((item) => {
- pasture_ids.push(item.id)
- })
- }else{
- pasture_ids.push(this.abnormal.value3)
- }
- let url = '/api/v1/ops/dashboard/sprinkle_time'
- let data = {
- 'start_date': parseTime(this.abnormal.inputDatetime[0], '{y}-{m}-{d}'),
- 'end_date': parseTime(this.abnormal.inputDatetime[1], '{y}-{m}-{d}'),
- 'pasture_ids': pasture_ids,
- 'feed_formula_id':this.abnormal.value2
- }
- data.state = this.abnormal.value4
- console.log(this.abnormal.value2,'====000')
- if (this.abnormal.value2 == '') {
- data.feed_formula_id = 0
- }
- postJson(url, data).then(response => {
- if (response.code == 200) {
- this.abnormal.chart1.lineData1 = response.data.chart
- this.abnormal.chart1.tableDataList1 = response.data.table_list
- if (this.abnormal.chart1.isChart) {
- this.roadChartLine3(this.abnormal.chart1.lineData1)
- }
- console.log(response.data, '===')
- }
- })
- },
- roadChartLine1(chartLine_data) {
- console.log(chartLine_data,'chartLine_data')
- console.log(this.accuracy.chart1.lineData1.max_value,'max')
- console.log(this.accuracy.chart1.lineData1.min_value,'min')
- if (this.accuracy.chart1.chartLine != null) {
- this.accuracy.chart1.chartLine.dispose()
- }
- this.accuracy.chart1.chartLine = echarts.init(document.getElementById('chartLine1'))
- var option = {
- animation: false,
- tooltip: {
- trigger: 'axis'
- },
- legend: {
- data: chartLine_data.pasture_name,
- left: 14,
- bottom: 0,
- },
- grid: {
- left: '3%',
- right: '14%',
- // top: '3%',
- containLabel: true
- },
- xAxis: [{
- data: chartLine_data.title,
- type: 'category',
- }],
- yAxis: [{
- type: 'value',
- min:0, //取0为最小刻度
- max: 100, //取100为最大刻度
- min:'min', //取最小值为最小刻度
- max: 'max', //取最大值为最大刻度
- min: function(value) {//取最小值向下取整为最小刻度
- return Math.floor(value.min)
- },
- max: function(value) {//取最大值向上取整为最大刻度
- return Math.ceil(value.max)
- },
- scale: true, //自适应
- minInterval: 2, //分割刻度
- axisLine: {
- lineStyle: {
- color: "#666", //最左侧Y轴颜色
- }
- },
- name: '(%)'
- }],
- color: ['#4b07fa', '#0f96fc', '#ff42a9', '#ff724c', '#05fbf0', '#ffae00', '#b705fa', '#9a60b4', '#3cff00'],
- series: [{
- name: '撒料正确率',
- type: 'bar',
- barWidth:10,
- data: chartLine_data.ratio
- }
- ]
- // series: function(e) {
- // var serie = [];
- // for (var i = 0; i < chartLine_data.pasture_name.length; i++) {
- // var item = {
- // name: chartLine_data.pasture_name[i],
- // data: chartLine_data.data_list[i],
- // type: 'bar',
- // barMaxWidth: 20, // 每一个都要设置
- // barMinWidth: 5
- // }
- // serie.push(item);
- // }
- // console.log(serie)
- // return serie;
- // }()
- };
- this.accuracy.chart1.chartLine.setOption(option)
- if (this.accuracy.chart1.chartLine !== null) {
- window.onresize = function() {
- this.accuracy.chart1.chartLine.resize()
- }
- }
- },
- roadChartLine2(chartLine_data) {
- if (this.time.chart1.chartLine != null) {
- this.time.chart1.chartLine.dispose()
- }
- this.time.chart1.chartLine = echarts.init(document.getElementById('chartLine2'))
- var option = {
- tooltip: {
- trigger: `item`,
- formatter: this.formatter
- }, // formatter可不设置
- color: `#8d8d8d`, // 箱线图线框的颜色
- grid: {
- left: '3%',
- right: 10,
- bottom: 10,
- // top: 20,
- containLabel: true,
- },
- legend: {
- // data: ['加料时间', '搅拌时间','撒料时间'],
- data: ['加料时间','撒料时间'],
- right: 14,
- top: 0,
- bottom: 10
- },
- // color: ['#42C7FF', '#20DB7C','#FCC858'],
- color: ['#42C7FF', '#FCC858'],
- xAxis: { // 此处设置与其他图表类似
- type: `category`,
- data:chartLine_data.title,
- axisLine: {
- //坐标轴轴线相关设置
- show: false,
- },
- axisLabel: {
- // 坐标轴刻度标签的相关设置
- show: true,
- showMaxLabel: true,
- },
- axisTick: {
- //刻度相关设置
- show: false, //让刻度隐藏
- },
- },
- yAxis: { // 此处设置与其他图表类似
- type: `value`,
- name:'(分钟)',
- splitArea: { show: false },
- axisLine: { lineStyle: { color: `#8d8d8d` } },
- },
- series: [
- {
- name:'加料时间',
- type: `boxplot`,
- itemStyle: { color: `#42C7FF` },
- data:chartLine_data.add_feed_time
- },
- // {
- // name:'搅拌时间',
- // type: `boxplot`,
- // itemStyle: { color: `#20DB7C` },
- // data:chartLine_data.stir_time
- // },
- {
- name:'撒料时间',
- type: `boxplot`,
- itemStyle: { color: `#FCC858` },
- data:chartLine_data.sprinkle_time
- }
- ],
- }
- this.time.chart1.chartLine.setOption(option)
- if (this.time.chart1.chartLine !== null) {
- window.onresize = function() {
- this.time.chart1.chartLine.resize()
- }
- }
- },
- formatter(param) {
- // console.log(param,'param')
- return [
- '执行时间/分钟<br/>'+
- '牧场: '+ param.name,
- '最大值: ' + param.data[1],
- '上四分位数: ' + param.data[2],
- '中位数: ' + param.data[3],
- '下四分位数: ' + param.data[4],
- '最小值: ' + param.data[5]
- ].join('<br/>')
- },
- roadChartLine3(chartLine_data) {
- console.log(chartLine_data,'===999')
- if (this.abnormal.chart1.chartLine != null) {
- this.abnormal.chart1.chartLine.dispose()
- }
- this.abnormal.chart1.chartLine = echarts.init(document.getElementById('chartLine3'))
- var option = {
- animation: false,
- tooltip: {
- trigger: 'axis',
- formatter: function (data) {
- console.log(data,'====')
- let a = parseFloat(data[0].data)
- let b = parseFloat(data[0].data) + parseFloat(data[1].data)
- let rate1 = 0
- let rate2 = 0
- if(data[0].data !== 0 && data[1].data !== 0){
- rate1 = (a/b * 100).toFixed(2)
- rate2 = 100 - (parseFloat(rate1))
- }else if(data[0].data == 100){
- rate1 = 100
- rate2 = 0
- }else if(data[1].data == 100){
- rate1 = 0
- rate2 = 100
- }else{
- rate1 = 0
- rate2 = 0
- }
- var res = "撒料时间"+ '<br/>' +"牧场:" + data[0].name + '<br/>' + data[0].marker + data[0].seriesName + '<br/>' + "总占比"+rate1+"%"+ '<span style="margin-left:10px;color:#ccc;">'+ a + '次'+'</span>'+ '<br/>' + data[1].marker + data[1].seriesName+':'+'<br/>' + "总占比"+rate2+"%"+ "<span style='margin-left:10px;color:#ccc;'>"+ data[1].data + '次' + "</span>"
- return res
- }
- },
- legend: {
- data: ['正常撒料次数', '异常撒料次数'],
- right: 14,
- top: 0,
- },
- grid: {
- // top: '20%',
- left: '3%',
- right: '14%',
- bottom: '13%',
- containLabel: true
- },
- xAxis: [{
- type: 'category',
- data: chartLine_data.title,
- }],
- yAxis: [{
- type: 'value',
- name:'(次)',
- axisLine: {
- lineStyle: {
- color: '#666'
- }
- },
- }],
- series: [{
- name: '正常撒料次数',
- type: 'bar',
- barWidth:25,
- stack: 'Ad',
- data: chartLine_data.sprinkle_number_list[0]
- },
- {
- name: '异常撒料次数',
- type: 'bar',
- stack: 'Ad',
- barWidth:25,
- data: chartLine_data.sprinkle_number_list[1]
- },
- ]
- };
- this.abnormal.chart1.chartLine.setOption(option)
- if (this.abnormal.chart1.chartLine !== null) {
- window.onresize = function() {
- this.abnormal.chart1.chartLine.resize()
- }
- }
- },
- createData(){
- console.log(this.accuracy.more.checkedPasture)
- console.log(this.accuracy.more.pastureList)
- this.getChart1List()
- this.accuracy.dialogFormVisible = false
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .container {
- margin: 10px 10px;
- }
- .accuracy,
- .time,
- .abnormal {
- background: #fff;
- height: 550px;
- border-radius: 5px;
- border: 2px solid #ededed;
- }
- .accuracy_t {
- margin-left: 10px;
- position: relative;
- .accuracy_t_l {
- h3 {
- line-height: 15px;
- }
- .title {
- width: 3px;
- height: 15px;
- background: red;
- display: inline-block;
- margin-right: 10px;
- }
- }
- .accuracy_t_r {
- position: absolute;
- top: 0;
- right: 0;
- .button {
- display: inline-block;
- margin-right: 10px;
- }
- }
- }
- .accuracy_b {
- margin: 0 10px;
- /deep/ .el-tabs__item {
- font-size: 12px
- }
- position: relative;
- }
- .more {
- position: absolute;
- bottom: -14px;
- right: -8px;
- color: blue;
- font-size: 12px;
- }
- .maxdiv,
- .mediandiv,
- .mindiv {
- text-align: center;
- .title-t {
- font-size: 12px;
- }
- .title-c {
- font-size: 14px;
- font-weight: bold;
- }
- .title-b {
- font-size: 14px;
- color: red;
- font-weight: bold;
- }
- }
- .maxdiv,
- .mediandiv {
- border-right: 2px solid #eee;
- }
- .mediandiv {
- .title-b {
- color: blue;
- }
- }
- .accuracy-content {
- /deep/ .el-checkbox {
- margin: 5px 5px;
- }
- /deep/ .is-bordered {
- margin-left: 5px;
- }
- }
- .time {
- .time_t {
- margin-left: 10px;
- position: relative;
- .time_t_l {
- h3 {
- line-height: 15px;
- }
- .title {
- width: 3px;
- height: 15px;
- background: red;
- display: inline-block;
- margin-right: 10px;
- }
- }
- .time_t_r {
- position: absolute;
- top: 0;
- right: 0;
- .button {
- display: inline-block;
- margin-right: 10px;
- }
- }
- }
- }
- .abnormal {
- background: #fff;
- margin-top: 10px;
- .abnormal_t {
- margin-left: 10px;
- position: relative;
- .abnormal_t_l {
- h3 {
- line-height: 15px;
- }
- .title {
- width: 3px;
- height: 15px;
- background: red;
- display: inline-block;
- margin-right: 10px;
- }
- }
- .abnormal_t_r {
- position: absolute;
- top: 0;
- right: 0;
- .button {
- display: inline-block;
- margin-right: 10px;
- }
- }
- }
- }
- .container {
- background: #fff;
- }
- </style>
|