{$layout} {$template "menu"}

<!-- <p class="comment" v-if="tasks.length == 0">暂时还没有证书申请任务。</p> -->
<b-empty v-if="tasks.length == 0">暂时还没有证书申请任务。</b-empty>

<div class="ui message blue" v-if="isRunning">
  有任务在执行中，可能需要的时间较长，请耐心等待。
</div>

<div class="margin"></div>
<b-table v-if="tasks.length > 0" :columns="columns" :data-source="tasks" :row-key="'id'" :bordered="false" size="middle"
  :pagination="false" :loading="isRunning">
  <!-- ACME用户 -->
  <template slot="acmeUserSlot" slot-scope="{ text, record }">
    <div>
      {{record.acmeUser.email}}
      <div style="margin-top: 1em">
        <tiny-basic-label class="olive" v-if="record.authType == 'dns'">DNS</tiny-basic-label>
        <tiny-basic-label class="olive" v-if="record.authType == 'http'">HTTP</tiny-basic-label>
      </div>
    </div>
  </template>

  <!-- 证书域名 -->
  <template slot="domainsSlot" slot-scope="{ text, record }">
    <div v-for="domain in record.domains">
      <span class="ui label small basic">{{domain}}</span>
    </div>
  </template>

  <!-- 到期时间 -->
  <template slot="endTimeSlot" slot-scope="{ text, record }">
    <div v-if="record.cert != null">{{record.cert.endTime}}</div>
    <span v-else class="disabled">-</span>
  </template>

  <!-- 更新时间 -->
  <template slot="updateTimeSlot" slot-scope="{ text, record }">
    <div v-if="record.log != null">
      <span class="green" v-if="record.log.isOk">{{record.log.createdTime}}</span>
      <link-red v-if="!record.log.isOk" title="任务执行失败，点击查看详情"
        @click.prevent="showError(record.log.error)">{{record.log.createdTime}}</link-red>
    </div>
    <span v-else class="disabled">尚未执行</span>
  </template>

  <!-- 自动续期 -->
  <template slot="autoRenewSlot" slot-scope="{ text,record }">
    <span v-if="record.autoRenew" class="green">
      <i class="pi pi-check" style="font-size: 12px; padding: 4px;"></i>
    </span>
    <span v-else class="disabled"><i class="pi pi-minus" style="font-size: 12px; padding: 4px;"></i></span>
  </template>
  <!-- 关联证书 -->
  <template slot="certSlot" slot-scope="{ text, record }">
    <div v-if="record.cert != null">
      <a href="" @click.prevent="viewCert(record.cert.id)">
        <link-icon title="查看关联证书"></link-icon>
      </a>
    </div>
    <span v-else class="disabled">-</span>
  </template>

  <!-- 操作 -->
  <template slot="actionSlot" slot-scope="{ text, record }">
    <a-button type="link" @click.prevent="updateTask(record.id)" :disabled="isRunning">
      <i class="pi pi-pencil" style="font-size: 12px; padding: 4px;"></i> 修改
    </a-button>
    <a-button type="link" @click.prevent="runTask(record.id)" :disabled="isRunning">
      <i class="pi pi-play" style="font-size: 12px; padding: 4px;"></i> 执行
    </a-button>
    <a-button type="link" @click.prevent="deleteTask(record.id)" :disabled="isRunning">
      <i class="pi pi-trash" style="font-size: 12px; padding: 4px;"></i> 删除
    </a-button>
  </template>
</b-table>

<div class="page" v-html="page"></div>