<template>
  <div class="routerWapper">
    <div class="portalDetailTitle" v-if="$route.name == 'executionLogList'">
      <span class="title">日志列表</span>

      <div class="layoutPadding">
        <div class="itemMargin">
            <a-alert type="info" show-icon>
              <p slot="description">
                已选择: {{selectedRowKeys.length}}
              </p>
            </a-alert>
        </div>

        <a-table class="elevator-table portalTable" :dataSource="list" :columns="columns" size="small" :pagination="pagination" rowKey="id" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
          <span  slot="operation" slot-scope="text, record"> 
            <span class="actionBtn" @click="edit(record)">编辑</span>
            <span class="actionBtn" @click="more(record)">更多</span>
          </span>
          <span  slot="no" slot-scope="text, record, index"> 
            {{index+1}}
          </span>
          <span slot="cffw" slot-scope="text, record, index">
            {{record.rule.trigger.name}}
          </span>

          <span slot="zxfw" slot-scope="text, record, index">
            {{record.rule.action.name}}
          </span>

          <span slot="time" slot-scope="text, record, index">
            {{$moment(record.time).format('YYYY-MM-DD HH:MM')}}
          </span>

          <span slot="message" slot-scope="text, record, index">
            {{!record.error?'成功': '失败'}}
          </span>
          <p slot="expandedRowRender" slot-scope="record" style="margin: 0; text-align: left">
            <a-row>规则：{{record.rule.rules}}</a-row>
            <a-row>日志：{{record.log}}</a-row>
          </p>

          <span slot="operation" slot-scope="text, record">
            <span class="actionBtn" @click="onDelete(record.id)">删除</span>
          </span>
        </a-table>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      selectedRowKeys: [],
      list: [],
      columns: [
        {
          title: '#',
          dataIndex: 'no',
          align: 'center',
          key: 'no',
          scopedSlots: {
            customRender: 'no',
          },
        },
        {
          title: '触发服务',
          dataIndex: 'cffw',
          align: 'center',
          key: 'cffw',
          scopedSlots: {
            customRender: 'cffw',
          },
        },
        {
          title: '执行服务',
          dataIndex: 'zxfw',
          align: 'center',
          key: 'zxfw',
          scopedSlots: {
            customRender: 'zxfw',
          },
        },
        {
          title: '执行时间',
          dataIndex: 'time',
          align: 'center',
          key: 'time',
          scopedSlots: {
            customRender: 'time',
          },
        },
        {
          title: '执行结果',
          dataIndex: 'message',
          align: 'center',
          key: 'message',
          scopedSlots: {
            customRender: 'message',
          },
        },
        {
          title: '操作',
          dataIndex: 'operation',
          key: 'operation',
          width: '120px',
          scopedSlots: {
            customRender: 'operation',
          },
        },
      ],
      pagination: {//分页
        pageNo: 1,
        pageSize: 10,
        total: 10,
        current: 1,
        defaultCurrent: 1,
        showQuickJumper: true,
        onChange: this.pageChange
      },
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    initPagination() {
      this.pagination.pageNo = 1
      this.pagination.current = 1
    },
    onDelete(id) {
      const that = this
      this.$modal.confirm({
        title: '提示',
        content: '确定删除该条记录吗？',
        okText: '确认',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          that.$ajax.delete({
            url: that.$api.DELETE_LOG_RECORD.replace('{id}', id)
          }).then(res => {
            if(res.code == '200') {
              that.$message.success('删除成功!')
              that.initPagination()
              that.getList()
            }
          })
        },
      })
    },
    getList() {
      this.$ajax.post({
        url: this.$api.GET_LOGS_LIST,
        params: {
          page: this.pagination.pageNo,
          size: 10
        }
      }).then(res => {
        this.list = this.$com.confirm(res, 'data.content', [])
        this.pagination.total = this.$com.confirm(res, 'data.totalElements', 0)
      })
    },
    pageChange(val) {
      this.pagination.pageNo = val
      this.pagination.current = val
      this.getList()
      
      // this.getCompanyList()
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    }
  }
}
</script>
