<template>
  <div class="app-container">
    <!-- 筛选start -->
    <div class="filter-container mb-10">
      <div class="left">
        <div>
          <span class="" style="margin-right: 30px">用户管理列表</span>
          <el-button icon="el-icon-plus" type="success" @click="addItem()"
            >新增</el-button
          >
        </div>
        <div style="margin-top: 20px">
          <div class="filter-item" >
          姓名：
          <el-input
            v-model="userName"
            placeholder="请输入内容"
            style="width: 180px"
          ></el-input>
        </div>
        <div class="filter-item" >
          手机号：
          <el-input
            v-model="phone"
            placeholder="请输入内容"
            style="width: 180px"
          ></el-input>
        </div>

          <div class="filter-item">
            所属企业:
            <el-select
              v-model="region"
              placeholder="请选择"
              style="width: 150px"
            >
              <el-option label="企业一" value="1"></el-option>
              <el-option label="企业二" value="2"></el-option>
            </el-select>
          </div>

          <div class="filter-item">
            角色:
            <el-select
              v-model="role"
              placeholder="请选择"
              style="width: 200px"
            >
              <el-option label="角色1" value="1"></el-option>
              <el-option label="角色2" value="2"></el-option>
            </el-select>
          </div>
          <el-button type="primary" icon="el-icon-search" class="search-button"
            >查询</el-button
          >
        </div>
      </div>

      <div class="right">
        <el-button type="primary">导出</el-button>
      </div>
    </div>
    <!-- 筛选end -->

    <!-- 表格start -->
    <el-table
      :data="tableData"
      border
      stripe
      :header-cell-style="headClass"
    >
      <el-table-column prop="xh" label="序号" width="70">
      </el-table-column>
      <el-table-column prop="userName" label="姓名" width="">
      </el-table-column>
      <el-table-column prop="sex" label="性别" width="">
      </el-table-column>
      <el-table-column prop="contact" label="联系方式" width="">
      </el-table-column>
      <el-table-column prop="password" label="密码" width="">
      </el-table-column>
      <el-table-column prop="ownerCompany" label="所属企业" width="">
      </el-table-column>
      <el-table-column prop="role" label="角色" width="">
      </el-table-column>
      <el-table-column fixed="right" label="操作" width="180">
        <template #default="scope">
          <el-button
            @click="checkItem(scope.$index, scope.row)"
            type="text"
            size="small"
            class="delete-text"
            >查看</el-button
          >
          <el-button
            type="text"
            size="small"
            @click.prevent="editRow(scope.row)"
            >编辑</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 表格end -->

    <!-- 分页start -->
    <div class="paginationBlock">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage4"
        :page-sizes="[100, 200, 300, 400]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400"
      >
      </el-pagination>
    </div>

    <!-- 分页end -->

    <!--弹框组件开始-----------------------start-->
    <dialog-component

      :dialogTitle="dialogTitle"
      :itemInfo="tableItem"
      @closeDialog="closeDialog"
      :flag="showDialog"
    ></dialog-component>
    <!--弹框组件开始-----------------------end-->


  </div>
</template>

<script>

import { defineComponent, ref,reactive} from 'vue'

import DialogComponent from "./dialogComponent";

export default defineComponent({
  components: { DialogComponent},
  setup() {
    const userName = ref('')
    const phone = ref('')
    const region = ref('')
    const role = ref('')
    const currentPage4 = ref(4)
    const dialogTitle = ref('')
    const showDialog = ref(false)
    const tableData = ref([
      {
           xh: "1",
          userName: "张三",
          sex: "男",
          contact: "12345678989 ",
          password: "123456",
          role: "维保 ",
          ownerCompany: "伍继",
        },
         {
          xh: "1",
          userName: "张三",
          sex: "男",
          contact: "12345678989 ",
          password: "123456",
          ownerCompany: "伍继",
           role: "维保 ",
        }
    ])

    const handleSizeChange=(val)=> {
      console.log(`每页 ${val} 条`);
    }
    const handleCurrentChange=(val)=> {
      console.log(`当前页: ${val}`);
    }

    // // 表头样式设置
    const headClass=()=> {
      return "background:#FAFAFA;";
    }

    const tableItem = reactive([])
     // 添加操作
    const addItem=()=> {
      tableItem.value = {
        id: "",
        stationName: "",
        xh: "",
        userName: "",
        siteList: [],
        done: "",
        guaZai: "",
        checked: true,
      };
      dialogTitle.value = "新增";
      showDialog.value = true;

    }

     // 查看
    const checkItem=(row)=> {
      console.log(row)
      tableItem.value = row
      dialogTitle.value = '查看'
      showDialog.value = true
    }

    // 编辑操作
    const editRow = (row) => {
      console.log(row)
      tableItem.value = row
      dialogTitle.value = '编辑'
      showDialog.value = true
    }

    // 关闭操作
    const closeDialog = () => {
      showDialog.value = false
    }

    return {
       userName,
      phone,
      region,
      role,
      tableItem,
      currentPage4,
      dialogTitle,
      showDialog,
      tableData,
      handleSizeChange,
      handleCurrentChange,
      headClass,
      checkItem,
      addItem,
      editRow,
      closeDialog,
    }

  },
})
</script>


<style lang="scss" scoped>
</style>
