<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <a-button type="primary" icon="download" @click="handleExportXls('任务日志')">导出</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"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown> -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        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,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" 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>

        <span 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 @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <log-dataX-job-modal ref="modalForm" @ok="modalFormOk"></log-dataX-job-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LogDataXJobModal from './modules/LogDataXJobModal'

  export default {
    name: 'LogDataXJobList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      LogDataXJobModal
    },
    data () {
      return {
        description: 'job_log管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'执行器主键ID',
            align:"center",
            dataIndex: 'jobGroup'
          },
          {
            title:'任务主键ID',
            align:"center",
            dataIndex: 'jobId'
          },
          {
            title:'jobDesc',
            align:"center",
            dataIndex: 'jobDesc'
          },
          {
            title:'执行器地址(本次执行的地址)',
            align:"center",
            dataIndex: 'executorAddress'
          },
          {
            title:'执行器任务handler',
            align:"center",
            dataIndex: 'executorHandler'
          },
          {
            title:'执行器任务参数',
            align:"center",
            dataIndex: 'executorParam'
          },
          {
            title:'执行器任务分片参数',
            // ，格式如 1/2
            align:"center",
            dataIndex: 'executorShardingParam'
          },
          {
            title:'失败重试次数',
            align:"center",
            dataIndex: 'executorFailRetryCount'
          },
          {
            title:'调度时间',
            align:"center",
            dataIndex: 'triggerTime',
            customRender:function (text) {
              return !text?"":(text.length>10?text.substr(0,10):text)
            }
          },
          {
            title:'调度结果',
            align:"center",
            dataIndex: 'triggerCode'
          },
          // {
          //   title:'调度-日志',
          //   align:"center",
          //   dataIndex: 'triggerMsg'
          // },
          // {
          //   title:'执行-时间',
          //   align:"center",
          //   dataIndex: 'handleTime',
          //   customRender:function (text) {
          //     return !text?"":(text.length>10?text.substr(0,10):text)
          //   }
          // },
          // {
          //   title:'执行-状态',
          //   align:"center",
          //   dataIndex: 'handleCode'
          // },
          // {
          //   title:'执行-日志',
          //   align:"center",
          //   dataIndex: 'handleMsg'
          // },
          // {
          //   title:'告警状态',
          //   // 0-默认、1-无需告警、2-告警成功、3-告警失败
          //   align:"center",
          //   dataIndex: 'alarmStatus_dictText'
          // },
          // {
          //   title:'datax进程Id',
          //   align:"center",
          //   dataIndex: 'processId'
          // },
          // {
          //   title:'增量表max id',
          //   align:"center",
          //   dataIndex: 'maxId'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/kzksDataXJobLog/jobLog/list",
          exportXlsUrl: "/kzksDataXJobLog/jobLog/exportXls",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'int',value:'jobGroup',text:'执行器主键ID'})
        fieldList.push({type:'int',value:'jobId',text:'任务，主键ID'})
        fieldList.push({type:'string',value:'jobDesc',text:'jobDesc'})
        fieldList.push({type:'string',value:'executorAddress',text:'执行器地址，本次执行的地址'})
        fieldList.push({type:'string',value:'executorHandler',text:'执行器任务handler'})
        fieldList.push({type:'string',value:'executorParam',text:'执行器任务参数'})
        fieldList.push({type:'string',value:'executorShardingParam',text:'执行器任务分片参数，格式如 1/2'})
        fieldList.push({type:'int',value:'executorFailRetryCount',text:'失败重试次数'})
        fieldList.push({type:'date',value:'triggerTime',text:'调度-时间'})
        fieldList.push({type:'int',value:'triggerCode',text:'调度-结果'})
        fieldList.push({type:'string',value:'triggerMsg',text:'调度-日志'})
        fieldList.push({type:'date',value:'handleTime',text:'执行-时间'})
        fieldList.push({type:'int',value:'handleCode',text:'执行-状态'})
        fieldList.push({type:'string',value:'handleMsg',text:'执行-日志'})
        fieldList.push({type:'int',value:'alarmStatus',text:'告警状态：0-默认、1-无需告警、2-告警成功、3-告警失败'})
        fieldList.push({type:'string',value:'processId',text:'datax进程Id'})
        fieldList.push({type:'int',value:'maxId',text:'增量表max id'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>