<template>
  <div>
    <div class="btn-box">
      <el-button type="primary" icon="el-icon-plus" @click="onCreate">新增</el-button>
    </div>
    <el-table
      v-loading="loading"
      :data="data"
      border
      style="width: 100%"
    >
      <el-table-column
        type="index"
        label="序号"
        width="100"
        align="center"
      />
      <el-table-column
        prop="app_name"
        label="应用名称"
        width="240"
        show-overflow-tooltip
      />
      <el-table-column
        prop="content"
        label="任务描述"
        show-overflow-tooltip
      />
      <el-table-column
        prop=""
        label="操作"
        width="160"
      >
        <template slot-scope="scope">
          <el-link :underline="false" type="primary" @click="onEdit(scope.row)">编辑</el-link>
          <el-divider direction="vertical" />
          <el-link :underline="false" type="danger" @click="onDel(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { deleteHelper } from '@/api/helper'
export default {
  props: {
    data: {
      type: Array,
      default() {
        return []
      }
    },
    loading: {
      type: Boolean,
      default() {
        return false
      }
    }
  },
  methods: {
    onCreate() {
      localStorage.removeItem('helper')
      this.$router.push({ path: '/helper/config' })
    },
    onEdit(row) {
      localStorage.setItem('helper', JSON.stringify(row))
      this.$router.push({ path: '/helper/config' })
    },
    onDel(row) {
      this.$confirm('是否确认删除该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteHelper({ id: row.id }).then((res) => {
          this.$message.success(res.m || '操作成功')
          this.$emit('refresh')
        })
      })
    },
    handleRefresh() {
      this.$emit('refresh')
    }
  }
}
</script>

<style lang="scss" scoped>
.btn-box {
  text-align: right;
  margin-bottom: 15px;
}
</style>
