<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-range-picker date-format="YYYY-MM-DD" v-model="queryParams.date" @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="columns2"
        :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 * as echarts from 'echarts'
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: '',
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      loading: true,
      // 数据
      tpmequiponoffsectionList: [],
      // 查询参数
      queryParams: {
        date: [],
        day_begin: '',
        day_end: '',
        pageNum: 1,
        pageSize: 1000,
        equipmentid: '1780110297413861377',
        tagtype: null,
      },
      dataSource: [],
      url: {
        list: '/emsStatistics/searchEquipmentDetail',
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'equipmentid_dictText',
        },
        {
          title: '设备编号',
          align: 'center',
          dataIndex: 'equipmentcode',
        },
        {
          title: '日期',
          align: 'center',
          dataIndex: 'day',
        },
        {
          title: '总时长(分钟)',
          align: 'center',
          dataIndex: 'duration',
        },
        {
          title: '运行时长(分钟)',
          align: 'center',
          dataIndex: 'onduration',
        },
        {
          title: '待机时长(分钟)',
          align: 'center',
          dataIndex: 'pauseduration',
        },
        {
          title: '关机时长(分钟)',
          align: 'center',
          dataIndex: 'offduration',
        },
      ],
      columns2: [
        {
          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.push(now)
      this.queryParams.date.push(now)
      this.queryParams.day_begin = now
      this.queryParams.day_end = 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)
        })
      })
    },
    handleQuery() {
      var _this = this
      _this.loading = true
      getAction(this.url.list, _this.queryParams).then((response) => {
        _this.tpmequiponoffsectionList = response.result
        // Generate mock data
        _this.equipments = []
        _this.onduration = []
        _this.pauseduration = []
        _this.offduration = []
        _this.tpmequiponoffsectionList.forEach(function (equipment, key) {
          _this.equipments.push(equipment.equipmentid_dictText + '[' + equipment.equipmentcode + ']')
          _this.onduration.push(equipment.onduration)
          _this.pauseduration.push(equipment.pauseduration)
          _this.offduration.push(equipment.offduration)
        })

        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>
