<template>
  <el-dialog
    title="实时检测"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    @close="handleClose"
    width="1200px"
  >
  <h3>淮河社区居民委员会机井(6544425)</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>在线</span>
        </el-col>
        <el-col :span="12">
          <label>水泵：</label>
          <span>开</span>
        </el-col>
      </el-row>
      <div class="right_content">
        <label>详细地址：</label>
        <span>河南省/郑州市/二七区/淮河路街道/淮河社区居民委员会</span>
      </div>
      <el-row class="right_content">
        <el-col :span="6">
          <label>计量模式：</label>
          <span>水电双计</span>
        </el-col>
        <el-col :span="12">
          <label>水泵功率：</label>
          <span>3W</span>
        </el-col>
      </el-row>
      <div class="right_content" style="margin:0">
        <label>灌溉面积：</label>
        <span>125亩</span>
      </div>
    </el-col>
  </el-row>
  <h3>实时数据</h3>
  <b-table
    ref="tableRef"
    :args="{ 'highlight-current-row': true }"
    :data="loadData"
    :columns="columns"
    isShowIndex
    :showPagination="false"
  >
    <template #styleImg="scope">
      <el-image
        :src="scope.row.imgPreview"
        :preview-src-list="[scope.row.imgPreview]"
        slot="error"
        class="image-slot"
        style="width: 100px; height: 50px"
      >
        <div slot="error" class="image-slot"></div>
      </el-image>
    </template>
    <template #codeNo="scope">           
      <el-link
        type="primary"
        :underline="false"
        @click="goDetail(scope.row)"
        >{{ scope.row.traceCodeApplyConcat }}</el-link
      >
    </template>
    <template #status="scope">
      <span style="display:flex;align-items:center;justify-content:center">
        <span class="status"></span>
        {{ scope.row.name }}
      </span>
    </template>
    <template #useNumber="scope">
      {{ scope.row.useNumber + '/' + scope.row.totalNumber }}
    </template>
    <template #finishGoodName="scope">
      {{ scope.row.finishGoodName&&scope.row.finishgoodNo?scope.row.finishGoodName + '-' + scope.row.finishgoodNo:'' }}
    </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">
      <el-button type="info" plain @click="resetForm('baseForm')"
        >取消</el-button
      >
      <el-button
        type="primary"
        style="margin-left:16px;"
        @click="submitForm('baseForm')"
        :disabled="dialogSubmitLoading"
        :loading="dialogSubmitLoading"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import { assign, omit } from 'lodash-es';
import { UPLOAD_TYPE_MAP } from '@/utils/constants';
import LeftImg from '../assets/img.svg'
import BTable from '@/components/Table'
export default {
  name: 'realTimeMonitor',
  props: {
    data: {
      default() {
        return {};
      }
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      LeftImg: LeftImg,
      imageUploadType: UPLOAD_TYPE_MAP.FARMING_RECORD,
      columns: [
        {
          label: '农户姓名',
          prop: 'person',
          customRender: '',
          align: 'center'
        },
        {
          label: '手机号',
          prop: 'area',
          customRender: '',
          align: 'center'
        },
        {
          label: '瞬时流量( m³/s)',
          prop: 'name',
          customRender: '',
          align: 'center'
        },
        {
          label: '累计流量(m³)',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '电压(v)',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '水位(m)',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '状态',
          prop: 'phone',
          customRender: '',
          align: 'center'
        },{
          label: '上传时间',
          prop: 'phone',
          customRender: '',
          align: 'center'
        }
      ],
      dialogSubmitLoading: false,
      dialogVisible: false,
      baseForm: {
        productValue: '',
        productName: '',
        stockAmount: '',
        goodsUnit: '',
        goodsSpecValue: '',
        imageArr1: [],
        supplierId: '',
        imageArr2: []
      },
      productList: [],
      syinfoList: [],
      processList: [],
      hasFetched: false,
      landList: [], //基地列表
      rules: {
        stockAmount: [
          { required: true, message: '请选择负责人', trigger: 'blur' }
        ],
        sourceinfoId: [
          { required: true, message: '请选择管辖范围', trigger: 'blur' }
        ],
        productName: [
          { required: true, message: '请输入协会名称', trigger: 'blur' }
        ],
        supplierId: [
          { required: false, message: '请输入协会介绍', trigger: 'blur' }
        ],
        goodsSpecValue: [
          { required: true, message: '请选择规格', trigger: 'blur' }
        ]
      }
    };
  },
  components:{
    BTable
  },
  watch: {
    visible(val) {
      if (val !== this.dialogVisible) {
        this.dialogVisible = val;
        if (val) {
          assign(this.baseForm, this.data);
          if (!this.hasFetched) {
            this.getProductList();
            this.getSyinfoList();
            this.getProcessList();
            this.hasFetched = true;
          }
        }
      }
    },
    data: {
      deep: true,
      handler(val) {
        // console.log(val)
        assign(this.baseForm, val);
        // console.log(this.baseForm)
      }
    }
  },
  created() {},
  mounted() {},
  methods: {
    loadData(parameter) {
      const queryform = this.form;
      const payload = omit(assign({}, parameter, queryform, {orderByColumn:'tarcecodeapplyCreateddate',isAsc:'desc'}), []);
      return this.getTableData(payload);
    },
    getTableData(payload) {
      return Promise.resolve({
        data: [{
            person:"王大虎",
            area: '2016-05-02',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1518 弄'
          }, {
            person:"王大虎",
            area: '2016-05-04',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1517 弄'
          }, {
            person:"王大虎",
            area: '2016-05-01',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1519 弄'
          }, {
            person:"王大虎",
            area: '2016-05-03',
            name: '王小虎',
            phone: 1588888888,
            address: '上海市普陀区金沙江路 1516 弄'
          }]
      })
    },
    getProductList() {
    },
    getSyinfoList() {
    },
    getProcessList() {
    },
    goProductsPage() {
      this.handleClose();
      this.$router.push({
        path: '/Products',
        query: {}
      });
    },
    goSourceInfoPage() {
      this.handleClose();
      this.$router.push({
        path: '/sourceInfo',
        query: {
          type: 'add'
        }
      });
    },
    goProcessPage() {
      this.handleClose();
      this.$router.push({
        path: '/basicsettings/process',
        query: {}
      });
    },
    resetForm(formName) {
      this.dialogVisible = false;
    },
    resetFormData() {
      this.baseForm = {};
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        console.log(valid)
      })
    },

    handleClose() {
      this.$emit('update:visible', false);
      this.resetForm('baseForm');
    },
    handleSuccess() {
      this.resetForm('baseForm');
      this.$emit('update:visible', false);
      this.$emit('success');
    },
    handleKeyUp(target, key) {
      target[key] = target[key].match(/\d+(\.\d{0,2})?/)
        ? target[key].match(/\d+(\.\d{0,2})?/)[0]
        : '';
    }
  }
};
</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>
