<template>
  <div class="app-container">
    <div class="filter-container">
      <!-- <el-input
        v-model="listQuery.groupName"
        placeholder="分组名称"
        class="filter-item"
        clearable
      /> -->

      <!-- <el-input
        v-model="listQuery.username"
        placeholder="请输入用户名"
        class="filter-item"
        clearable
      />

      <el-select
        v-model="listQuery.group"
        class="filter-item"
        placeholder="分组"
        clearable
      >
        <el-option
          v-for="(item, index) in groups"
          :key="index"
          :label="item.groupName"
          :value="item.id"
        />
      </el-select> -->

      <!-- <el-select
        v-model="listQuery.isShow"
        class="filter-item"
        placeholder="是否显示"
        clearable
      >
        <el-option label="显示" :value="true" />
        <el-option label="隐藏" :value="false" />
      </el-select> -->

      <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-search"
        @click="handleSearch"
        >搜索</el-button
      >

      <el-button class="filter-item" type="primary" @click="handleCreate"
        >新增分组</el-button
      >
      <!-- <el-button
        class="filter-item"
        type="primary"
        icon="el-icon-plus"
        @click="handleCreate"
        >新建员工帐号</el-button
      > -->
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
    >
      <el-table-column label="id" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.id }}</span>
        </template>
      </el-table-column>

      <el-table-column label="分组名称" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.groupName }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.isShow ? "显示" : "隐藏" }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        width="180"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-if="scope.row.type !== 0"
            type="primary"
            size="mini"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <!-- <el-button
            v-if="scope.row.type !== 0"
            type="primary"
            size="mini"
            @click="handleReset(scope.row)"
            >重置</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getList"
    /> -->

    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <el-form ref="form" model="form" label-width="100px">
        <el-form-item label="分组名称">
          <el-input v-model="form.groupName"></el-input>
        </el-form-item>
        <!-- <el-form-item label="分组Id"> -->
        <!-- <el-select v-model="form.groupId">
            <el-option
              v-for="(item, index) in groups"
              :key="index"
              :label="item.groupName"
              :value="item.id"
            />
          </el-select> -->
        <!-- <el-input v-model="form.id"></el-input> -->
        <!-- </el-form-item> -->
        <el-form-item label="是否显示">
          <el-radio-group v-model="form.isShow">
            <el-radio :label="true">显示</el-radio>
            <el-radio :label="false">隐藏</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitData">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { groupAdminUpdate, groupList } from "@/api/spdwzl";
// import Pagination from "@/components/Pagination/index";
// import { staffOptions } from "@/utils";
export default {
  //   components: { Pagination },
  filters: {
    typeFilter(type) {
      // 0-枪机,1-半球,2-快球,3-带云台枪机
      const typeMap = {
        0: "枪机",
        1: "半球",
        2: "快球",
        3: "带云台枪机",
      };
      return typeMap[type];
    },
  },
  data() {
    return {
      total: 0,
      list: [],
      listQuery: {
        // current: 1,
        // size: 10,
      },
      listLoading: false,
      //   staffOptions,
      cameraTypes: [
        {
          label: "枪机",
          value: 0,
        },
        {
          label: "半球",
          value: 1,
        },
        {
          label: "快球",
          value: 2,
        },
        {
          label: "带云台枪机",
          value: 3,
        },
      ],
      groups: [],
      groups1: [
        {
          id: 1,
          groupName: "1组",
          isShow: true,
        },
        {
          id: 2,
          groupName: "2组",
          isShow: true,
        },
        {
          id: 3,
          groupName: "3组",
          isShow: true,
        },
        {
          id: 4,
          groupName: "4组",
          isShow: true,
        },
      ],
      dialogVisible: false,
      form: { groupName: undefined, id: undefined, isShow: false },
    };
  },
  created() {
    // this.getBusinessList()
    // this.getGroupList();
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      groupList(this.listQuery).then((res) => {
        this.list = res.d;
        // this.total = res.d.total;
        this.listLoading = false;
      });
    },
    getGroupList() {
      groupList().then((res) => {
        console.log(res);
        this.groups = res.d;
      });
    },
    handleSearch() {
      this.listQuery.current = 1;
      this.getList();
    },
    handleCreate() {
      this.$router.push({
        path: "/staff/create",
      });
    },
    handerDetail(row) {
      const { id, type } = row;
      this.$router.push({
        path: "/staff/detail",
        query: { id, type },
      });
    },
    // 修改(提交)
    confirm({ data, close, hideLoading }) {
      update(data)
        .then((res) => {
          this.$message({
            type: "success",
            message: "操作成功!",
          });
          this.$refs["table"].getList();
          close();
        })
        .catch(() => {
          hideLoading();
        });
    },
    handleCreate() {
      this.dialogVisible = true;
      this.form = { groupName: undefined, id: undefined, isShow: false };
    },
    handleUpdate(row) {
      this.dialogVisible = true;
      this.form = Object.assign({}, row);
      //   this.form.id = id;
      // groupAdminUpdate
    },

    handleReset() {
      this.$confirm(`是否重置?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        remarkReset().then((res) => {
          console.log(res);
          if (res.c === 200) {
            this.$message.success("重置成功");
          }
        });
      });
    },
    submitData() {
      groupAdminUpdate(this.form).then((res) => {
        console.log(res);
        if (res.c === 200) {
          this.dialogVisible = false;
          this.$message.success("绑定成功");
          this.getList()    
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-input {
  width: 200px;
  margin-right: 10px;
}
.el-select {
  margin-right: 10px;
}
</style>
