<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 查询区域 begin -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="名称">
             <a-input v-model="queryParam.name" placeholder="请输入名称"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span class="table-page-search-submitButtons table-operator">
              <a-button type="primary" icon="search" @click="searchQuery">查询</a-button>
              <a-button type="primary" icon="reload" @click="searchReset">重置</a-button>
              <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                <span>{{ toggleSearchStatus ? '收起' : '展开' }}</span>
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a> -->
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域 end -->

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
      <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('base_energy_rate')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload> -->
      <!-- 高级查询区域 -->
      <!-- <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            <span>删除</span>
          </a-menu-item>
        </a-menu>
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>
    <!-- 操作按钮区域 end -->

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

      <a-alert type="info" showIcon style="margin-bottom: 16px;">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"
        @change="handleTableChange"
      >

        <!-- 内嵌table区域 begin -->
        <!-- <template slot="expandedRowRender" slot-scope="record">
          <a-tabs tabPosition="top">
            <a-tab-pane tab="详情" key="baseEnergyRateDetail" forceRender>
              <energy-rate-detail-sub-table :record="record"/>
            </a-tab-pane>
          </a-tabs>
        </template> -->
        <!-- 内嵌table区域 end -->

        <!-- <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template> -->

        <template slot="imgSlot" slot-scope="text,record">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" :preview="record.id" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>


        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

        <template slot="action" slot-scope="text, record">
          <a @click="handleEdit(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>

        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

    <!-- 表单区域 -->
    <energy-rate-modal ref="modalForm" @ok="modalFormOk"/>
    <!-- 详情 -->
    <energy-rate-detail ref="equipmentDetail"></energy-rate-detail>

  </a-card>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import EnergyRateModal from './modules/EnergyRateModal'
  import EnergyRateDetailSubTable from './subTables/EnergyRateDetailSubTable'
  import '@/assets/less/TableExpand.less'
  import EnergyRateDetail from './modules/EnergyRateDetail.vue'

  export default {
    name: 'EnergyRateList',
    mixins: [JeecgListMixin],
    components: {
      EnergyRateModal,
      EnergyRateDetailSubTable,
        EnergyRateDetail,
    },
    data() {
      return {
        description: 'base_energy_rate列表管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '名称',
            align: 'center',
            dataIndex: 'name',
            customCell: this.customCellDetail
          },
          {
            title: '能源分类',
            align: 'center',
            dataIndex: 'energytypeid_dictText',
          },
          {
            title: '费率类型',
            align: 'center',
            dataIndex: 'ratetype_dictText',
          },
          {
            title: '单位',
            align: 'center',
            dataIndex: 'rateunit',
          },
          {
            title: '费率有效期开始',
            align: 'center',
            dataIndex: 'begintime',
          },
          {
            title: '费率有效期结束',
            align: 'center',
            dataIndex: 'endtime',
          },
          {
            title: '备注',
            align: 'center',
            dataIndex: 'remark',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            width:147,
            scopedSlots: { customRender: 'action' },
          },
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
        url: {
          list: '/energyRate/energyRate/list',
          delete: '/energyRate/energyRate/delete',
          deleteBatch: '/energyRate/energyRate/deleteBatch',
          exportXlsUrl: '/energyRate/energyRate/exportXls',
          importExcelUrl: '/energyRate/energyRate/importExcel',
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      }
    },
    methods: {
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      customCellDetail(record){
        return {
          style: {
            'color': "#1890ff",
            'cursor': "pointer",
          },
          on: { 
            // 点击事件
            click: (event) => {
              this.$refs.equipmentDetail.detail(record);
            },
          },
        };
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'energyrateid',text:'能源费率ID',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'name',text:'名称',dictCode:''})
        fieldList.push({type:'int',value:'energytypeid',text:'能源分类ID',dictCode:''})
        fieldList.push({type:'string',value:'ratetype',text:'费率类型',dictCode:''})
        fieldList.push({type:'string',value:'rateunit',text:'单位',dictCode:''})
        fieldList.push({type:'date',value:'begintime',text:'费率有效期开始'})
        fieldList.push({type:'date',value:'endtime',text:'费率有效期结束'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>