<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="8" :lg="7" :md="8" :sm="24">
            <a-form-item label="海事机构">
              <j-tree-select
                v-model="queryParam.departId"
                placeholder="请选择机构"
                dict="view_depart,depart_nam,depart_no"
                pidField="updepart_no"
                pidValue="384"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="船舶名称">
              <j-input placeholder="请输入船舶名称" v-model="queryParam.shipNameCn"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="作业单位">
              <a-input placeholder="请输入作业单位" v-model="queryParam.comName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="实际开始时间">
              <a-range-picker
                style="width: 230px"
                v-model="realStartTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onDateChange"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item label="实际结束时间">
              <a-range-picker
                style="width: 230px"
                v-model="realEndTimeRange"
                format="YYYY-MM-DD"
                :placeholder="['开始时间', '结束时间']"
                @change="onDateChangeEnd"
              />
            </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="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button type="primary" icon="download" @click="handleExportXls('受电记录')" style="margin-left: 8px">导出</a-button>
<!--              <a @click="handleToggleSearch" style="margin-left: 8px">-->
<!--                {{ toggleSearchStatus ? '收起' : '展开' }}-->
<!--                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
<!--              </a>-->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="text" 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="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">查看</a>

<!--          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>-->
        </span>

        <span slot="comNo_dictText" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>
        <span slot="gemoId" slot-scope="text">
          <j-ellipsis :value="text" :length="15" />
        </span>

      </a-table>
    </div>

    <adChargingRecord-modal ref="modalForm" @ok="modalFormOk"></adChargingRecord-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import AdChargingRecordModal from './modules/AdChargingRecordModal'
  import JDate from '@/components/jeecg/JDate.vue'
  import JEllipsis from "@/components/jeecg/JEllipsis"
  import JTreeSelect from '@/components/jeecg/JTreeSelect'
  import JInput from '@/components/jeecg/JInput'

  export default {
    name: "AdChargingRecordList",
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JEllipsis,
      JTreeSelect,
      JInput,
      JDate,
      AdChargingRecordModal
    },
    data () {
      return {
        description: '受电记录管理页面',
        realStartTimeRange: [],
        realEndTimeRange: [],
        // 表头
        columns: [
          {
            title:'用电船舶',
            align:"center",
            dataIndex: 'shipNameCn'
          },
          {
            title:'联系方式',
            align:"center",
            dataIndex: 'phone'
          },
          {
            title:'作业单位',
            align:"center",
            dataIndex: 'comNo_dictText',
            scopedSlots: {customRender: 'comNo_dictText'},
          },
          {
            title:'作业地点',
            align:"center",
            dataIndex: 'gemoId_dictText',
            scopedSlots: {customRender: 'gemoId'},
          },
          {
            title:'管辖海事机构',
            align:"center",
            dataIndex: 'departNam'
          },
          {
            title:'用电开始时间',
            align:"center",
            dataIndex: 'realStartTime'
          },
          {
            title:'用电结束时间',
            align:"center",
            dataIndex: 'realEndTime'
          },
          {
            title:'用电量(kW-h)',
            align:"center",
            dataIndex: 'consumption'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            // fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/ad/adChargingRecord/list",
          exportXlsUrl: "/ad/adChargingRecord/exportXls",
        },
        dictOptions:{},
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      onDateChange: function(value, dateString) {
        this.queryParam.realStartTime_begin = dateString[0]
        this.queryParam.realStartTime_end = dateString[1]
      },
      onDateChangeEnd: function(value, dateString) {
        this.queryParam.realEndTime_begin = dateString[0]
        this.queryParam.realEndTime_end = dateString[1]
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>