<template>
  <div>
    <div class="i-layout-page-header">
      <PageHeader :title="$route.meta.title" :content="$route.meta.description" hidden-breadcrumb />
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <view-table ref="table" view-code="TaskQueue">
        <template slot-scope="{ row }" slot="command">
          <Button size="small" :title="$t('Front_Btn_Execute')" type="primary" custom-icon="fa fa-bolt" @click="execute(row)"></Button>
          <Button
            size="small"
            v-if="row.status == 'Pending' || row.status == 'Retry'"
            :title="$t('Front_Btn_Cancel')"
            type="warning"
            custom-icon="fa fa-times"
            @click="cancel(row)"
          ></Button>
        </template>
      </view-table>
    </Card>
  </div>
</template>
<script>
  import mixinPage from '../../mixins/page';
  import taskQueueApi from '../../api/taskQueue';

  export default {
    name: 'system-taskQueue',
    mixins: [mixinPage],
    components: {},
    data() {
      return {};
    },
    computed: {},
    created() {},
    methods: {
      // 执行
      execute(row) {
        this.confirm('Front_Msg_Sure_To_Start_Immediately', async () => {
          await taskQueueApi.execute(row.id);
          this.success('Front_Msg_Success');
          this.$refs.table.loadData();
        });
      },
      // 取消
      cancel(row) {
        this.confirm('Front_Msg_Sure_To_Cancel_Task', async () => {
          await taskQueueApi.cancel(row.id);
          this.success('Front_Msg_Success');
          this.$refs.table.loadData();
        });
      }
    }
  };
</script>
