<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>
          <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>
        </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: 'zxjg',
          align: 'center',
          key: 'zxjg'
        },
      ],
      pagination: {//分页
        pageNo: 1,
        pageSize: 10,
        total: 10,
        current: 1,
        defaultCurrent: 1,
        showQuickJumper: true,
        onChange: this.pageChange
      },
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      this.$ajax.post({
        url: this.$api.GET_IFTTT_RULES_LIST
      }).then(res => {
        this.list = this.$com.confirm(res, 'data.content', [])
      })
    },
    pageChange(val) {
      this.pagination.pageNo = val
      this.pagination.current = val
      // this.getCompanyList()
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    }
  }
}
</script>
