<template>
  <div class="app-container">
    <div class="Pd20">
      <el-row type="flex" :gutter="10">
        <el-col :span="6">
          <el-button type="primary" plain size="mini" @click="drawer = true">
            <i class="el-icon-plus el-icon--left"></i>
            创建视频分析任务
          </el-button>
        </el-col>
        <el-col :span="6"> </el-col>
        <el-col :span="6"> </el-col>
        <el-col :span="6" :offset="6">
          <el-input
            v-model="searchValue"
            size="mini"
            style="width: 160px"
            clearable
            placeholder="请输入内容"
          ></el-input>
          <el-button
            type="primary"
            size="mini"
            @click="search"
            style="margin-left: 10px"
          >
            <i class="el-icon-search el-icon--left"></i>
            搜索
          </el-button>
        </el-col>
      </el-row>
      <el-table :data="tableList" class="Mt20">
        <el-table-column
          label="任务ID"
          align="center"
          prop="id"
        ></el-table-column>
        <el-table-column
          label="任务名称"
          align="center"
          prop="name"
        ></el-table-column>
        <el-table-column
          label="关联算法"
          align="center"
          prop="aboutAslgorithm"
        ></el-table-column>
        <el-table-column label="任务启用状态" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.status"
              active-color="#13ce66"
              inactive-color="#ff4949"
            ></el-switch>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              size="mini"
              @click="() => editBut(scope.row)"
            >
              编辑
            </el-button>
            <el-button
              type="text"
              class="danger"
              size="mini"
              @click="() => deleteBut(scope.row)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <el-drawer :visible.sync="drawer" size="80%" :wrapperClosable="false">
        <span slot="title">创建视频分析任务</span>
        <add-video-anlysis-tasks
          :editData="currentRow"
          @close-drawer="closeDrawer()"
        ></add-video-anlysis-tasks>
      </el-drawer>
    </div>
  </div>
</template>

<script>
import addVideoAnlysisTasks from "@/views/VideoAnalysisTasks/modules/addVideoAnlysisTasks.vue";
export default {
  name: "VideoAnalysisTasks",
  props: {},
  components: { "add-video-anlysis-tasks": addVideoAnlysisTasks },
  data() {
    return {
      searchValue: "", // 搜索框的值
      tableList: [
        {
          id: 1,
          name: "视频分析任务1",
          aboutAslgorithm: "这是一个视频分析任务",
          status: 0, // 0：禁用 1：启用
        },
      ],
      queryParams: {
        pageNum: 1, // 当前页码
        pageSize: 10, // 每页显示的数量
      },
      total: 0, // 总数量
      /* 创建摄像头相关 */
      drawer: false, // 控制弹窗的显示
      currentRow: null, // 当前行数据存储
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {},
  methods: {
    // 新增
    append() {
      this.currentRow = ""; // 存储当前行数据
      this.drawer = true; // 打开抽屉
    },
    // 搜索
    search() {},
    // 分页
    getList() {},
    // 删除
    deleteBut(row) {
      this.$confirm("确认删除吗？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      });
    },
    // 编辑
    editBut(row) {
      this.currentRow = row; // 存储当前行数据
      this.drawer = true; // 打开抽屉
    },
    // 关闭抽屉
    closeDrawer() {
      this.drawer = false; // 关闭抽屉
      //需要重新获取列表数据
      this.getList();
    },
  },
};
</script>

<style scoped lang="scss">
.Pd20 {
  padding: 20px;
  background: #fff;
  position: relative;
  height: calc(100vh - 125px);
}
.Mt20 {
  margin-top: 20px;
}
.danger {
  color: #f5222d;
}
.active {
  color: #52c41a;
}
::v-deep .el-drawer__header {
  margin-bottom: 0;
}
</style>
