<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-left">
        <div class="filter-item">
          状态:
          <el-select v-model="value" placeholder="" style="width: 100px">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <el-button type="primary" icon="el-icon-search" class="search-button"
          >搜索</el-button
        >
      </div>

      <div class="handle-button-right">
        <el-button
          icon="el-icon-plus"
          type="success"
          @click="dialogFormVisible = true"
          >新增</el-button
        >
        <el-button icon="el-icon-delete" type="danger" @click="batchDelete"
          >删除</el-button
        >
        <el-button type="warning">
          <svg-icon icon-class="export" />
          导出
        </el-button>
      </div>
    </div>

    <el-divider></el-divider>
    <el-table
      :data="tableData"
      stripe
      border
      :header-cell-style="{ background: '#EBF1FF', color: '#606266' }"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="40"> </el-table-column>

      <el-table-column prop="state" label="状态"> </el-table-column>
      <el-table-column prop="passLength" label="密码长度"> </el-table-column>
      <el-table-column prop="passProperty" label="密码属性" width="300">
      </el-table-column>
      <el-table-column prop="lock" label="账号锁定"> </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            icon="el-icon-edit"
            style="color:#406CE5 "
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            icon="el-icon-delete"
            style="color: #F27979"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-dialog title="新增" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="状态:" :label-width="formLabelWidth">
          <el-select v-model="form.region2" placeholder="" style="width: 100%">
            <el-option label="状态一" value="1"></el-option>
            <el-option label="状态二" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="密码长度:" :label-width="formLabelWidth">
          <el-input v-model="form.name4" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="密码属性:" :label-width="formLabelWidth">
          <el-input
            v-model="form.name5"
            autocomplete="off"
            disabled
            placeholder="大写字母、小写字母与数字组合"
          >
            <!-- <span slot="suffix">ddfdfd</span> -->
          </el-input>
        </el-form-item>
        <el-form-item label="账号锁定:" :label-width="formLabelWidth">
          <el-input v-model="form.name6" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button
          @click="dialogFormVisible = false"
          style="background: #f6f6f6"
          >取 消</el-button
        >
        <el-button type="primary" @click="dialogFormVisible = false"
          >提 交</el-button
        >
      </div>
    </el-dialog>
  </div>
</template>


<script>
export default {
  data() {
    return {
      tableData: [
        {
          state: "启用",
          passLength: "8-12个字符",
          passProperty: "大写字母、小写字母与数字组合",
          lock: "5次错误锁定",
        },
        {
          state: "禁用",
          passLength: "8-12个字符",
          passProperty: "大写字母、小写字母与数字组合",
          lock: "5次错误锁定",
        },
        {
          state: "禁用",
          passLength: "8-12个字符",
          passProperty: "大写字母、小写字母与数字组合",
          lock: "5次错误锁定",
        },
        {
          state: "禁用",
          passLength: "8-12个字符",
          passProperty: "大写字母、小写字母与数字组合",
          lock: "5次错误锁定",
        },
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "状态1",
        },
        {
          value: "2",
          label: "状态2",
        },
        {
          value: "3",
          label: "状态3",
        },
      ],
      value: "",

      input: "",

      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        region2: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "100px",
    };
  },
  methods: {
    handleEdit(index, row) {
      alert(index, row);
    },
    handleDelete(index, row) {
      this.$confirm("确定删除该数据吗?", "删除", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.tableData.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    batchDelete() {
      let multData = this.multipleSelection;
      let tableData = this.tableData;
      let multDataLen = multData.length;
      let tableDataLen = tableData.length;

      for (let i = 0; i < multDataLen; i++) {
        for (let y = 0; y < tableDataLen; y++) {
          if (JSON.stringify(tableData[y]) == JSON.stringify(multData[i])) {
            //判断是否相等，相等就删除
            this.tableData.splice(y, 1);
            console.log("aa");
          }
        }
      }
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
  },
};
</script>