<template>
  <div class="app-container detail" style="background-color: rgb(238, 241, 245);">
    <div style="padding-top: 10px;background: #fff;height: 100%;">

      <el-row>
        <el-col :span="24" style="padding-left: 15px;">
          <div style="height: 45px;" @click="$router.go(-1)">
            <el-button size="medium" type="text" style="font-size: 18px; color: rgb(7, 63, 112);float: left;">返回
            </el-button>
            <div style="float: left;margin-top: 8px;margin-left: 5px;"><img src="../../../assets/logo/fanhui.png" style="width: 25px;" alt=""></div>
          </div>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="16" style="padding: 10px;">
          <div style="height: 100%;">
            <el-table :data="dataListdetail1" style="width: 100%">
              <el-table-column label="设备名称" align="center" prop="deviceName" />
              <el-table-column label="设备编号" align="center" prop="deviceCode" />
              <el-table-column label="设备类型" align="center" prop="deviceType">
                <template slot-scope="scope">
                  <span v-if="scope.row.deviceType == '3'">流量计</span>
                  <span v-if="scope.row.deviceType == '4'">压力表</span>
                </template>
              </el-table-column>
              <el-table-column label="标况累计量(m³)" align="center" prop="standardConditionAccumulation" />
            </el-table>

            <el-table :data="dataListdetail2" style="width: 100%;margin-top: 20px;">
              <el-table-column label="工况累计量(m³)" align="center" prop="workingConditionAccumulation" />
              <el-table-column label="剩余量(m³)" align="center" prop="residualQuantity" />
              <el-table-column label="标况流量(m³/h)" align="center" prop="standardConditionFlow" />
              <el-table-column label="工况流量(m³/h)" align="center" prop="workingConditionFlow" />
            </el-table>


            <el-table :data="dataListdetail3" style="width: 100%;margin-top: 20px;">
              <el-table-column label="温度(℃)" align="center" prop="temperature" />
              <el-table-column label="压力(KPa)" align="center" prop="pressure" />
              <el-table-column label="上报时间" align="center" prop="reportTime" />
              <el-table-column label="设备状态" align="center" prop="deviceStatus">
              </el-table-column>
            </el-table>
          </div>
        </el-col>
        <el-col :span="8" style="padding: 10px;padding-left: 0px;">
          <div id="marbox" style="height: 350px; border: 1px solid rgb(218, 213, 213);margin-top: -45px;">
            <div style="width: 100%;height: 100%" id="container"></div>
          </div>
        </el-col>
      </el-row>



      <template v-if="$route.query.deviceType !='0'">
        <el-row  v-if="form.deviceType != '4'">
          <el-col :span="12" style="padding: 10px;">
            <div id="main1" style="height:300px;background-color: rgb(247 247 247);padding: 5px;">
              <div v-if = "form.deviceReportDataList == null" class="div-null">
                <p>暂无数据</p>
              </div>
            </div>
          </el-col>
          <el-col :span="12" style="padding: 10px;">
            <div id="main2" style="height:300px;background-color: rgb(247 247 247);padding: 5px;">
              <div v-if = "form.deviceReportDataList == null" class="div-null">
                <p>暂无数据</p>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12" style="padding: 10px;" v-if="form.deviceType != '4'">
            <div id="main3" style="height:300px;background-color: rgb(247 247 247);padding: 5px;">
              <div v-if = "form.deviceReportDataList == null" class="div-null">
                <p>暂无数据</p>
              </div>
            </div>
          </el-col>
          <el-col :span="12" style="padding: 10px;">
            <div id="main4" style="margin-left: 5px;height:300px;background-color: rgb(247 247 247);padding: 5px;">
              <div v-if = "form.deviceReportDataList == null" class="div-null">
                <p>暂无数据</p>
              </div>
            </div>
          </el-col>
        </el-row>
        <!-- <div v-if="form.deviceType != '4'" style="height: 320px;width: 100%;margin-top: 15px;padding: 10px;"> -->


      <!-- </div> -->


        <!-- <div style="height: 320px;width: 100%;padding: 10px;margin-top: 10px;"> -->


        <!-- </div> -->
      </template>



    </div>

  </div>
</template>

<script>

  import { realtimeData, getData } from "@/api/dataMonitoring/reportData";
  import { deviceTree } from "@/api/device/deviceInfo";
  import gaodeMap from "utils/gaodeMap.js";
  import { map, DEVICE_TYPE } from "utils/gaodeMap.js";
  import { inspectorList } from "@/api/system/user";
  import echarts from 'echarts';
  //   Vue.prototype.$echarts = echarts;

  export default {
    name: "RealtimeData",
    components: {
    },
    data() {
      return {
        order_list:[],
        inspector: [],
        isDisplay: false,
        dialogImageUrl: '',
        dialogVisible: false,
        disabled: false,
        imageUrl: '',
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 设备监控表格数据
        dataListdetail: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 工单基础信息表格数据
        basicsInfoList: [],
        // feedbackList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 工单状态字典
        typeOptions: [],
        pickerOptions: [],
        // 工单类型字典
        ordertypeOptions: [],
        // 设备树选项
        deviceOptions: [
          {
            label: "设备列表",
            childList: []
          }
        ],
        defaultProps: {
          children: "childList",
          label: "label"
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          orderType: null,
          orderName: null,
          orderStatus: null,
          appointInspector: null,
          allotTime: null,
          actualInspector: null,
          actualTime: null,
          remarks: null
        },
        // 表单参数
        form: [],
        activity: {},
        // 表单校验
        rules: {
        },
        active: 0,
        deviceId: "",
        showAndHide: false,
        dataListdetail1: [],
        dataListdetail2: [],
        dataListdetail3: [],
      };
    },

    created() {
      // 如果是跳转来的，则接受初始化参数
      // this.user_id = this.$route.query.id; //详细信息页接收参数
      this.deviceId = +this.$route.query.deviceId;
      // this.getList();
      this.getDicts("t_order_status").then(response => {
        this.typeOptions = response.data;
      });
      this.getDicts("t_order_type").then(response => {
        this.ordertypeOptions = response.data;
      });
      // this.getData();
    },
    mounted() {
      let gaoMap = new gaodeMap("石家庄");
      this.gaoMap = gaoMap;
      this.getData();
    },
    methods: {
      getInspectorList() {
        this.loading = true;
        inspectorList().then(response => {
          this.inspector = response.data;
          this.loading = false;
        });

      },

      initData(getData1, getData2, getData3) {
        // 基于准备好的dom，初始化echarts实例
        var myChart1 = echarts.init(document.getElementById('main1'));


        // 绘制图表
        myChart1.setOption({
          title: {
            text: '标况流量、工况流量'
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['标况流量', '工况流量']
          },
          xAxis: {
            type: 'category',
            // data: this.dataX,
            // data: ['23', '44', '77', '34', '56', '88', '38', '68', '55', '99', '44', '33'],
            data: getData3,
            boundaryGap: false, //控制日期是否在中间显示
            axisLabel: {
              show: true, //是否显示日期
              interval: 0, //强制显示全部 // rotate: 40,//倾斜的角度
              textStyle: {
                color: '#000', //日期的颜色
                fontSize: 12 //字体的大小
              }
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // x轴的颜色
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                color: '#000' //数字的颜色
              },
              inside: false //控制数据是否在内侧还是外侧显示
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // 折线的颜色
              }
            }
          },
          series: [
            {
              // data: this.dataY,
              name: '标况流量',
              // data: [820, 232, 901, 534, 1290, 330, 1320, 345, 654, 189, 980, 234],
              data: getData1,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#efc883', //折线点的颜色
                  lineStyle: {
                    color: '#efc883' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            },
            {
              // data: this.dataY,
              name: '工况流量',
              // data: [500, 600, 700, 300, 1100, 130, 1200, 820, 932, 901, 934, 1290],
              data: getData2,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#053B6A', //折线点的颜色
                  lineStyle: {
                    color: '#053B6A' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            }
          ]
        });

      },


      drawPieChart(getData4, getData5, getData3) {
        // 基于准备好的dom，初始化echarts实例
        var myChart2 = echarts.init(document.getElementById('main2'));

        // 绘制图表
        myChart2.setOption({
          title: {
            text: '标况累积量、工况累积量'
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['标况累积量', '工况累积量']
          },
          xAxis: {
            type: 'category',
            // data: this.dataX,
            data: getData3,
            boundaryGap: false, //控制日期是否在中间显示
            axisLabel: {
              show: true, //是否显示日期
              interval: 0, //强制显示全部 // rotate: 40,//倾斜的角度
              textStyle: {
                color: '#000', //日期的颜色
                fontSize: 12 //字体的大小
              }
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // x轴的颜色
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                color: '#000' //数字的颜色
              },
              inside: false //控制数据是否在内侧还是外侧显示
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // 折线的颜色
              }
            }
          },
          series: [
            {
              // data: this.dataY,
              name: '标况累积量',
              data: getData4,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#efc883', //折线点的颜色
                  lineStyle: {
                    color: '#efc883' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            },
            {
              // data: this.dataY,
              name: '工况累积量',
              data: getData5,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#053B6A', //折线点的颜色
                  lineStyle: {
                    color: '#053B6A' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            }
          ]
        });
      },
      main3(getData6, getData3) {
        // 基于准备好的dom，初始化echarts实例
        var myChart3 = echarts.init(document.getElementById('main3'));


        // 绘制图表
        myChart3.setOption({
          title: {
            text: '温度'
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['温度']
          },
          xAxis: {
            type: 'category',
            // data: this.dataX,
            data: getData3,
            boundaryGap: false, //控制日期是否在中间显示
            axisLabel: {
              show: true, //是否显示日期
              interval: 0, //强制显示全部 // rotate: 40,//倾斜的角度
              textStyle: {
                color: '#000', //日期的颜色
                fontSize: 12 //字体的大小
              }
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // x轴的颜色
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                color: '#000' //数字的颜色
              },
              inside: false //控制数据是否在内侧还是外侧显示
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // 折线的颜色
              }
            }
          },
          series: [
            {
              // data: this.dataY,
              name: '温度',
              data: getData6,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#efc883', //折线点的颜色
                  lineStyle: {
                    color: '#efc883' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            }
          ]
        });

      },
      main4(getData7, getData3) {
        // 基于准备好的dom，初始化echarts实例
        var myChart4 = echarts.init(document.getElementById('main4'));

        // 绘制图表
        myChart4.setOption({
          title: {
            text: '压力'
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            data: ['压力']
          },
          xAxis: {
            type: 'category',
            // data: this.dataX,
            data: getData3,
            boundaryGap: false, //控制日期是否在中间显示
            axisLabel: {
              show: true, //是否显示日期
              interval: 0, //强制显示全部 // rotate: 40,//倾斜的角度
              textStyle: {
                color: '#000', //日期的颜色
                fontSize: 12 //字体的大小
              }
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // x轴的颜色
              }
            }
          },
          yAxis: {
            type: 'value',
            axisLabel: {
              formatter: '{value}',
              textStyle: {
                color: '#000' //数字的颜色
              },
              inside: false //控制数据是否在内侧还是外侧显示
            },
            axisLine: {
              lineStyle: {
                color: '#ccc' // 折线的颜色
              }
            }
          },
          series: [
            {
              // data: this.dataY,
              name: '压力',
              data: getData7,
              type: 'line',
              symbol: 'circle', //是否显示实心的折线圆点
              smooth: true, //让折线有弧度
              symbolSize: 7, //折线圆点的大小
              itemStyle: {
                normal: {
                  color: '#efc883', //折线点的颜色
                  lineStyle: {
                    color: '#efc883' //折线的颜色
                  },
                  label: { show: true } //是否在折线点上显示数字
                }
              }
            }
          ]
        });

      },



      handleRemove(file) {
        console.log(file);
      },
      handlePictureCardPreview(file) {
        this.dialogImageUrl = file.url;
        this.dialogVisible = true;
      },
      handleDownload(file) {
        console.log(file);
      },

      getData() {
        getData(this.deviceId).then(response => {
          const { deviceName, deviceCode, deviceType, standardConditionAccumulation,
            workingConditionAccumulation, residualQuantity, standardConditionFlow, workingConditionFlow, temperature, pressure, reportTime, deviceStatus } = response.data;
          const obj1 = { deviceName, deviceCode, deviceType, standardConditionAccumulation };
          const obj2 = { workingConditionAccumulation, residualQuantity, standardConditionFlow, workingConditionFlow };
          const obj3 = { temperature, pressure, reportTime, deviceStatus };
          this.dataListdetail1.push(obj1);
          this.dataListdetail2.push(obj2);
          this.dataListdetail3.push(obj3);
          this.form = response.data;
          this.active = parseInt(response.data.orderStatus) + 1;
          this.gaoMap.resetMapCenter([this.form.longitude, this.form.latitude]);
          this.gaoMap.addMarker(DEVICE_TYPE.WORKORDER, this.form)
            console.log("this.form.longitude",this.form.longitude)
          console.log("this.form", this.form)

          // if (this.form.length > 0) {

          // }
          // for (var i = 0; i < this.form.length; i++) {
          //   let obj = this.form[i];
          //   this.gaoMap.addMarker(DEVICE_TYPE.WORKORDER, obj)
          // }

          var getData1 = [];
          var getData2 = [];
          var getData3 = [];
          var getData4 = [];
          var getData5 = [];
          var getData6 = [];
          var getData7 = [];
          //先进行赋值
          for (let i = 0; i < this.form.deviceReportDataList.length; i++) {
            getData1.push( this.form.deviceReportDataList[i].standardConditionFlow)
            getData2.push(this.form.deviceReportDataList[i].workingConditionFlow)
            getData3.push(this.form.deviceReportDataList[i].reportTime)
            getData4.push(this.form.deviceReportDataList[i].standardConditionAccumulation)
            getData5.push(this.form.deviceReportDataList[i].workingConditionAccumulation)
            getData6.push(this.form.deviceReportDataList[i].temperature)
            getData7.push(this.form.deviceReportDataList[i].pressure)


          }
          this.initData(getData1, getData2, getData3);
          this.drawPieChart(getData4, getData5, getData3);
          this.main3(getData6, getData3);
          this.main4(getData7, getData3);
          console.log(this.form.deviceReportDataList)
          console.log("getData1",getData1)
          console.log("getData2",getData2)
          console.log("getData3",getData3)







          if (this.form.orderType == '1') {
            // 获取设备列表树
            let data = {
              key1: this.form.deviceInfoList,
              key2: this.form.pipeList
            };
            deviceTree(data).then(response => {
              this.deviceOptions[0].childList = response.data;
            });
          }
        });
      },

    }
  }
</script>
<style>
  .div-null{
    width: 100%;
    height: 300px;
    text-align: center;
    line-height: 250px;
  }
  .el-tree-node__content {
    width: 150px;
  }

  .el-divider--horizontal {
    display: block;
    height: 1px;
    width: 100%;
    margin: 20px 0;
  }

  .feedbackTime-div {
    float: left;
    margin-left: 150px;
    margin-top: 10px;
  }

  .feedbackTime {
    height: 120px;
    width: 120px;
    float: left;
    margin-left: 15px;
    margin-top: 5px;
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .el-card__body {
    padding: 5px 20px 20px 20px;
  }

  .detail .el-form {
    width: 20%;
  }

  .detail .el-form-item {
    margin-bottom: 0px;
  }

  .el-tree {
    margin-top: 5px;
  }

  .avatar-uploader {
    width: 25%;
    float: left;
  }

  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }

  li {
    font-size: 15px;
    font-weight: 900;
  }
</style>
