<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></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-table v-loading="loading" :data="InsectPestsMonitoringList" @selection-change="handleSelectionChange">
      <el-table-column label="上次识别数量" align="center" prop="oldCount"/>
      <el-table-column label="上次识别结果" align="center" prop="oldResults"/>
      <el-table-column label="上次标注后图片" align="center" prop="oldTaggingImgUrl" width="100">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">
              <image-preview :src="scope.row.oldTaggingImgUrl" :width="200" :height="200"/>
            </div>
            <image-preview :src="scope.row.oldTaggingImgUrl" :width="50" :height="50"/>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="最新识别数量" align="center" prop="newCount"/>
      <el-table-column label="最新识别结果" align="center" prop="results"/>
      <el-table-column label="最新标注后图片" align="center" prop="taggingImgUrl" width="100">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">
              <image-preview :src="scope.row.taggingImgUrl" :width="200" :height="200"/>
            </div>
            <image-preview :src="scope.row.taggingImgUrl" :width="50" :height="50"/>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="数据创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" width="100px" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleSee(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 详情 -->
    <el-dialog :title="title" :visible.sync="openSee" width="1000px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="设备编码" prop="deviceNumber" label-width="150px">
              <el-input v-model="form.deviceNumber" readonly/>
            </el-form-item>
            <el-form-item label="最新识别数量" prop="newCount" label-width="150px">
              <el-input v-model="form.newCount" readonly/>
            </el-form-item>
            <el-form-item label="最新识别结果" prop="results" label-width="150px">
              <el-input v-model="form.results" readonly/>
            </el-form-item>
            <el-form-item label="最新识别时间" prop="newTime" label-width="150px">
              <el-input  value-format="yyyy-MM-dd HH:mm:ss" v-model="form.newTime" readonly/>
            </el-form-item>
            <el-form-item label="标注后图片" prop="taggingImgUrl"  label-width="150px">
              <image-upload v-model="form.taggingImgUrl" :limit="1" :is-show-tip="false" :allow-upload="false"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新时间" prop="createTime" label-width="150px">
              <el-input v-model="form.createTime" readonly/>
            </el-form-item>
            <el-form-item label="上次识别数量" prop="oldCount" label-width="150px">
              <el-input v-model="form.oldCount" readonly/>
            </el-form-item>
            <el-form-item label="上次识别结果" prop="oldResults" label-width="150px">
              <el-input v-model="form.oldResults" readonly/>
            </el-form-item>
            <el-form-item label="上次识别时间" prop="oldTime" label-width="150px">
              <el-input value-format="yyyy-MM-dd HH:mm:ss" v-model="form.oldTime" readonly/>
            </el-form-item>
            <el-form-item label="上次标注后图片" prop="oldTaggingImgUrl"  label-width="150px">
              <image-upload v-model="form.oldTaggingImgUrl" :limit="1" :is-show-tip="false" :allow-upload="false"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { getInsectPests, selectInsectPestsMonitoringData } from '@/api/centerMonitor/device/device'

export default {
  name: 'InsectPestsMonitoring',
  data() {
    return {
      showLongitude: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 监测设备表格数据
      InsectPestsMonitoringList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      openSee: false,
      // 是否显示弹出层
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        downloadUrl: null,
        downloadUrlCompress: null,
        taggingImgUrl: null,
        taggingImgUrlCompress: null,
        deviceNumber: null,
        newTime: null,
        results: null,
        newCount: null,
        typeCount: null,
        oldCount: null,
        oldTime: null,
        oldResults: null,
        oldTypeCount: null,
        oldDownloadUrl: null,
        oldTaggingImgUrl: null,
        oldDownloadUrlCompress: null,
        oldTaggingImgUrlCompress: null,
      },
      // 表单参数
      form: {},
    }
  },
  created() {
    this.getList();
  },
  props: {
    deviceNumber: '',
    deviceType: "",
  },
  methods: {
    /** 查询监测设备列表 */
    getList() {
      this.loading = true
      this.queryParams.deviceNumber=this.deviceNumber
      selectInsectPestsMonitoringData(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.InsectPestsMonitoringList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false,
        this.openSee = false;
      this.reset()
    },
    /** 查询水压详情 */
    handleSee(row) {
      this.reset();
      const id = row.id || this.ids;
      getInsectPests(id).then(response => {
        this.form = response.data;
        this.openSee = true;
        this.title = "详情";
      });
    },
    // 表单重置
    reset() {
      this.form = {
        downloadUrl: null,
        downloadUrlCompress: null,
        taggingImgUrl: null,
        taggingImgUrlCompress: null,
        deviceNumber: null,
        newTime: null,
        results: null,
        newCount: null,
        typeCount: null,
        oldCount: null,
        oldTime: null,
        oldResults: null,
        oldTypeCount: null,
        oldDownloadUrl: null,
        oldTaggingImgUrl: null,
        oldDownloadUrlCompress: null,
        oldTaggingImgUrlCompress: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
  },
};
</script>
