<template>
    <div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px" style="margin-bottom: 0px;">
      <!--
      <el-form-item label="订单编码" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品编号" prop="materialCode">
        <el-input
          v-model="queryParams.materialCode"
          placeholder="请输入产品编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item label="工单生产日期" prop="ymdms">
        <el-date-picker clearable
          v-model="queryParams.ymdms"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择工单生产日期"
          style="width:205px"
          >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
		</el-form>
		<el-row :gutter="20">
			<el-col :sm="24" :lg="24">
				<span style="font-size: 20px;margin: 40%;color: cadetblue;">{{title}}</span>
			</el-col>
		</el-row>
		<el-row :gutter="20">
				<div style="border: 1px solid #cfdee4;">
				    <div id="orderline" style="width:100%;height:500px"></div>
				</div>
		</el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons')
import { getXJChartData} from "@/api/quality/qcTable";
import moment from "moment/moment";
export default {
  name: "XJChart",
  components: {},
  data() {
    return {
        title:"巡检小时不良率折线图",
        // 查询参数
        queryParams: {
          ymdms: null,
          workorderCode: null,
          workorderName: null,
          parentOrder: null,
          orderId: null,
          orderCode: null,
          productId: null,
          productCode: null,
          prodType: null,
          productName: null,
          productSpc: null,
          productDate: null,
          createTimeStart:null,
          createTimeEnd:null
        }
      }
  },
	mounted(){
    this.getDate();
    this.getList();
  },
	methods: {
    /**获取默认查询时间段**/
		getDate() {
			let start = this.Fungetdate (0)
			this.queryParams.ymdms =start
		},
		Fungetdate (num) {
			var dd = new Date();
			dd.setDate(dd.getDate() + num);
			var y = dd.getFullYear();
			var m = dd.getMonth() + 1;//获取当前月份的日期
			var d = dd.getDate();
			return y + "-" + m +"-"+d;
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.getList();
		},

		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm");
			this.getDate();
			this.handleQuery();
		},
		getList() {

			let myChart = this.$echarts.init(document.getElementById('orderline'))
			getXJChartData(this.queryParams).then(data => {

        if(data == ''){
          return
        }
        let seriesResult =  data.series;
        seriesResult.forEach(se => {
            se.type = 'line';//bar//line
        });

				myChart.setOption({
              tooltip: {
                trigger: 'axis'
              },
              legend: {
                data: data.legendData
              },
              grid: {
                left: '3%',
                right: '4%',
                bottom: '3%',
                containLabel: true
              },
              toolbox: {
                feature: {
                  saveAsImage: {}
                }
              },
              xAxis: {
                type: 'category',
                boundaryGap: false,
                data: data.xAxisData
              },
              yAxis: {
                type: 'value',
                axisLabel: {
                  formatter: '{value} %'
                }
              },
              series: seriesResult
          },
          true
			  )
			})
		}
	}
};
</script>
<style lang="scss" scoped>
.tagbox {
  display: flex;
  /* overflow: scroll; */
  position: relative;
  width: 80%;
  padding-left: 26px;
  margin-bottom: 15px;
  .tagboxlabel{
    width: 100px;
    text-align: right;
    vertical-align: middle;
    font-size: 14px;
    color: black;
    line-height: 40px;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    margin-right: 12px;
  }
  .tag {
    width: 720px;
    border: 1px #DCDFE6 solid;
    height: 60px;
    padding: 5px 15px;
    overflow-y: scroll;
    .tagitem{
      margin-left: 5px;
    }
  }
  .button1{
    width: 37px;
    height: 37px;
    position: absolute;
        right: -39px;
    top: 2px;

  }
}
</style>


