<template>
  <div>
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :model="queryParams" ref="queryForm">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <j-search-select-tag v-model="queryParams.equipmentid" dict="tpm_equipment,equipmentname,id"  style="width: 100%"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="11" :md="12" :sm="24">
            <a-form-item label="查询日期">
              <a-date-picker v-model="queryParams.date" placeholder="选择日期" style="width:100%;" @change="handleQuery" />
            </a-form-item>
          </a-col>
          <!-- <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="参数类型">
              <j-dict-select-tag v-model="queryParams.tagtype"  placeholder="请输入优先级" dictCode="tpm_tag_type"/>
            </a-form-item>
          </a-col> -->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="handleQuery" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>    
    
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        class="j-table-force-nowrap"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.equipmentid"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
      </a-table>
    </div>
  </div>
</template>

<script>
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { httpAction, getAction } from '@/api/manage'
import { pvdata } from '../../module_ems/photovoltaic/pvdata'
export default {
  name: 'history',
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      loading: true,
      // 数据
      tpmequiponoffsectionList: [],
      // 查询参数
      queryParams: {
        date: '',
        pageNum: 1,
        pageSize: 1000,
        equipmentid: '1780110297413861377',
        // tagtype: null,
      },
      dataSource: [],
      url: {
        list: '/tpmParams/tpmParams/list',
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          title: '点位名称',
          align: 'center',
          // dataIndex: 'tagname',
          dataIndex: 'MeterCode',
        },
        {
          title: '时间',
          align: 'center',
          // dataIndex: 'logtime',
          dataIndex: 'Time',
        },
        {
          title: '值',
          align: 'center',
          // dataIndex: 'tagvalue2',
          dataIndex: 'Power',
        },
      ],
    }
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      var now = this.dateformat(new Date()).substring(0, 10)
      this.queryParams.date = now
      this.handleQuery()
      // this.getTest()
    })
  },
  methods: {
    /** 重置按钮操作 */
    resetQuery() {
      this.handleQuery()
    },
    dateformat(date) {
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      month = month < 10 ? '0' + month : month
      var strDate = date.getDate()
      strDate = strDate < 10 ? '0' + strDate : strDate
      var hour = date.getHours()
      hour = hour < 10 ? '0' + hour : hour
      var minute = date.getMinutes()
      minute = minute < 10 ? '0' + minute : minute
      var second = date.getSeconds()
      second = second < 10 ? '0' + second : second

      return year + '-' + month + '-' + strDate + ' ' + hour + ':' + minute + ':' + second
    },
    // 后端好了需要删掉    
    getTest() {
      var _this = this;
      _this.ipagination.current = 1
      var rowid=0;
      pvdata.mdcurveanalysisdata.forEach((item) => {
        item.data.forEach((i) => {
          i.id = rowid;
          _this.dataSource.push(i);
          rowid++;
        })
      })
    },
    handleQuery() {
      var _this = this
      if (!this.queryParams.equipmentid) {
        this.$message.error('请选择设备!')
        return
      }
      if (!this.queryParams.date) {
        this.$message.error('请选择查询日期!')
        return
      }
      _this.loading = true
      getAction(this.url.list, _this.queryParams).then((response) => {
        _this.dataSource = response.result

        this.loading = false
      })
    },
  },
}
</script>

<style lang="less" scoped>
@import '~@/assets/less/uStyle.less';
</style>
<style lang="less">
.trend-charts {
  padding: 10px;
  margin-top: 10px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
</style>
