<template>
  <el-dialog
    title="实时监测"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
    width="1200px"
  >
  <h3>{{ realDtaile.waterName }}</h3>
  <el-row style="margin-bottom: 20px;">
    <el-col :span="6">
      <el-image :src="LeftImg"/>
    </el-col>
    <el-col :span="18">
      <el-row class="right_content">
        <el-col :span="6">
          <label>设备状态：</label>
          <span>{{ realDtaile.tmnstatusRunstatusContent || '-' }}</span>
        </el-col>
        <el-col :span="12">
          <label>水泵：</label>
          <span>{{ tmnstatusRunstatus }}</span>
        </el-col>
      </el-row>
      <div class="right_content">
        <label>详细地址：</label>
        <span>{{ realDtaile.waterAddress  || '-' }}</span>
      </div>
      <el-row class="right_content">
        <el-col :span="6">
          <label>计量模式：</label>
          <span>水电双计</span>
        </el-col>
        <el-col :span="12">
          <label>水泵功率：</label>
          <span>-</span>
        </el-col>
      </el-row>
      <div class="right_content" style="margin:0">
        <label>灌溉面积：</label>
        <span>-</span>
      </div>
    </el-col>
  </el-row>
  <h3>实时数据</h3>
  <b-table
    ref="tableRef"
    :args="{ 'highlight-current-row': true }"
    :data="loadData"
    :columns="columns"
    isShowIndex
  >
     <template #pump_status="scope">           
      {{ scope.row.pump_status == 0 ? '关': '开' }}
    </template>
    <template #operate="scope">
      <el-link
        size="small"
        :underline="false"
        type="primary"
        style="margin-right: 10px"
        @click="realTime(scope.row)"
        >实时监测</el-link
      >
      <el-link
        size="small"
        :underline="false"
        type="primary"
        style="margin-right: 10px"
        @click="download(scope.row)"
        >灌溉记录</el-link
      >
    </template>
  </b-table>
  <div style="text-align: right;margin-top:20px">
   
  </div>
  </el-dialog>
</template>

<script>
import dayjs from 'dayjs'
import { assign, omit } from 'lodash-es';
import LeftImg from '../assets/img.svg'
import BTable from '@/components/Table'
import { getDataInfo } from '@/api/card/index2.js'
export default {
  name: 'realTimeMonitor',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    realDtaile: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      LeftImg: LeftImg,
      query: '',
      tmnstatusRunstatus: '关',
      columns: [
        {
          label: '农户姓名',
          prop: 'person',
          customRender: '',
          align: 'center'
        },
        {
          label: '手机号',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },
        {
          label: '瞬时流量( m³/s)',
          prop: 'cur_flow',
          customRender: '',
          align: 'center'
        },
        {
          label: '累计流量(m³)',
          prop: 'sum_water',
          customRender: '',
          align: 'center'
        },{
          label: '电压(v)',
          prop: 'voltage',
          customRender: '',
          align: 'center'
        },{
          label: '水位(m)',
          prop: 'liu_deep',
          customRender: '',
          align: 'center'
        },{
          label: '状态',
          prop: 'pump_status',
          customRender: 'pump_status',
          align: 'center'
        },{
          label: '上传时间',
          prop: 'timer',
          customRender: '',
          align: 'center'
        }
      ],
      dialogSubmitLoading: false,
      dialogVisible: false,
      baseForm: {
        productValue: '',
        productName: '',
        stockAmount: '',
        goodsUnit: '',
        goodsSpecValue: '',
        imageArr1: [],
        supplierId: '',
        imageArr2: []
      },
    };
  },
  components:{
    BTable
  },
  watch: {
    visible(val) {
      if (val !== this.dialogVisible) {
        this.dialogVisible = val;
      }
    },
    realDtaile: {
      handler(val) {
        this.query = val?.tmnId
        this.handleSearch()
      },
      deep: true
    }
  },
  methods: {
    resetForm(formName) {
      this.dialogVisible = false;
    },
    loadData(parameter) {
      const payload = omit(assign({}, parameter), []);
      return this.getTableData(payload);
    },
    handleSearch() {
      this.$refs.tableRef && this.$refs.tableRef.refresh(true);
    },
   async getTableData() {
     const res = await getDataInfo(this.query)
     const resData = res?.data
     const list = resData?.valve
     const list2 = resData?.nowData
     const resList = {}
     resList.person = '-'
     resList.phone = '-'
     resList.voltage = '-'
     resList.timer = dayjs().format('YYYY-MM-DD')
     resList.pump_status = list?.pump_status?.value
     this.tmnstatusRunstatus = resList.pump_status == 0 ? '关':'开'
     resList.sum_ele = list?.sum_ele?.value
     resList.sum_water = list?.sum_water?.value
     resList.cur_flow = list2?.cur_flow?.value
     resList.line_press = list2?.line_press?.value
     resList.liu_deep = list2?.liu_deep?.value
     const params = {
       data: [resList],
       total: 1
     }
     return new Promise((resolve, reject) => { 
      resolve(params)
     })
    },
    handleClose() {
      this.$emit('update:visible', false);
    },
  }
};
</script>

<style lang="scss" scoped>
.input-number {
  width: 100%;
}
h3{
  height: 14px;
  color: #333333;
  font-size: 14px;
  font-weight: 700;
  margin:0 0 20px 0;
}
.right_content{
  margin-bottom: 10px;
  label{
    color: #999;
    font-size: 14px;
    font-weight: 400;
  }
  span{
    color: #333333;
    font-size: 14px;
  }
}
.base-form {
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 20px;
}
</style>
<style lang="css" scoped>
::v-deep .el-dialog__header {
  border-bottom: 1px solid #ebeef5;
}
</style>
