<template>
  <el-table :data="data.tableData" class="bg-title" style="width: 100%">
    <el-table-column prop="name" label="业务名称"> </el-table-column>
    <el-table-column prop="appId" label="APPID" width="300"> </el-table-column>
    <el-table-column prop="startUsing" label="状态" key="slot" sortable>
      <template #default="scope">
        <div class="flex flex-row items-center" @click="change(scope.row)">
          <div class="point bg-green-500"></div>
          <span style="margin-left: 10px">启用</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="公开" sortable key="slot" width="180">
      <template #default="scope">
        <div class="flex flex-row items-center" @click="change(scope.row)">
          <div class="point bg-red-500"></div>
          <span style="margin-left: 10px">公开</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建日期" sortable> </el-table-column>
    <el-table-column label="操作" key="slot">
      <template #default="scope">
        <el-button type="text" size="small">删除</el-button>
        <el-button type="text" size="small">配置</el-button>
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import { useRouter } from 'vue-router';
import { reactive } from 'vue';
import { useStore } from 'vuex';

const router = useRouter();
const store = useStore();

const data = reactive({
  tableData: [
    {
      appId: '描述01',
      createTime: '2016-05-02',
      id: '1',
      name: '王小虎',
      pub: 0,
      startUsing: 0,
    },
    {
      appId: '描述02',
      createTime: '2016-05-04',
      id: '2',
      name: '王小虎',
      pub: 1,
      startUsing: 1,
    },
    {
      appId: '描述03',
      createTime: '2016-05-01',
      id: '3',
      name: '王小虎',
      pub: 0,
      startUsing: 1,
    },
    {
      appId: '描述04',
      createTime: '2016-05-03',
      id: '4',
      name: '王小虎',
      pub: 1,
      startUsing: 0,
    },
  ],
});

function change(row) {
  console.log('row: ', row);
}

function handleClick(row) {
  console.log(row);
  router.push({ name: 'business-detail', query: { id: row.id } });
  store.commit('plugin/setBusinessInfo', row);
}
</script>

<style scoped>
.bg-title >>> thead tr th {
  color: #333;
  background: #fafafa;
  border-top: 1px solid #e8e8e8;
}
.bg-title >>> thead tr th:first-child {
  border-left: 1px solid #e8e8e8;
}
.bg-title >>> thead tr th:last-child {
  border-right: 1px solid #e8e8e8;
}

.point {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
</style>
