<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>
        <div class="filter-item">
          隶属单位:
          <el-select v-model="value2" placeholder="" style="width: 110px">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
        <div class="filter-item">
          机构类型:
          <el-select v-model="value3" placeholder="" style="width: 100px">
            <el-option
              v-for="item in options3"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>

        <div class="filter-item">
          组织机构代码:
          <el-input
            v-model="input"
            placeholder=""
            style="width: 120px"
          ></el-input>
        </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="companyName" label="单位名称" width="200">
      </el-table-column>
      <el-table-column prop="companyCode" label="单位编号" width="100">
      </el-table-column>
      <el-table-column prop="department" label="部门" width="100">
      </el-table-column>
      <el-table-column prop="superName" label="隶属单位"> </el-table-column>
      <el-table-column prop="type" label="机构类型"> </el-table-column>
      <el-table-column prop="orgCode" width="120" label="组织机构代码">
      </el-table-column>
      <el-table-column prop="chargeMan" label="负责人" width="80">
      </el-table-column>
      <el-table-column prop="contact" label="联系方式"> </el-table-column>

      <el-table-column label="操作" width="150">
        <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-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="单位编号:" :label-width="formLabelWidth">
          <el-input v-model="form.name2" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="部门:" :label-width="formLabelWidth">
          <el-input v-model="form.name3" autocomplete="off"></el-input>
        </el-form-item>

        <el-form-item label="隶属单位:" :label-width="formLabelWidth">
          <el-select
            v-model="form.region"
            placeholder="请选择活动区域"
            style="width: 100%"
          >
            <el-option label="区域一" value="shanghai"></el-option>
            <el-option label="区域二" value="beijing"></el-option>
          </el-select>
        </el-form-item>

        <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"></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>
//aa 1：引入api文件
import { getList } from "@/api/orgnization";


export default {
  data() {
    return {

      //aa 2：声明变量
      page:{
        current:1,
        size:20,
        total:0

      },
      query:{},
      list: [],






      tableData: [
        {
          companyName: "上海永天科技股份有限公司",
          companyCode: "0001",
          department: "技术部",
          superName: "上海永天",
          type: "机构类型",
          orgCode: "465798651698",
          chargeMan: "张三",
          contact: "16621076543",
        },
        {
          companyName: "上海永天科技股份有限公司",
          companyCode: "0002",
          department: "技术部",
          superName: "上海永天",
          type: "机构类型",
          orgCode: "465798651698",
          chargeMan: "张三",
          contact: "16621076543",
        },
        {
          companyName: "上海永天科技股份有限公司",
          companyCode: "0003",
          department: "技术部",
          superName: "上海永天",
          type: "机构类型",
          orgCode: "465798651698",
          chargeMan: "张三",
          contact: "16621076543",
        },
        {
          companyName: "上海永天科技股份有限公司",
          companyCode: "0004",
          department: "技术部",
          superName: "上海永天",
          type: "机构类型",
          orgCode: "465798651698",
          chargeMan: "张三",
          contact: "16621076543",
        },
      ],
      multipleSelection: [],

      options: [
        {
          value: "1",
          label: "单位1",
        },
        {
          value: "2",
          label: "单位2",
        },
        {
          value: "3",
          label: "单位3",
        },
      ],
      value: "",

      options2: [
        {
          value: "1",
          label: "隶属单位1",
        },
        {
          value: "2",
          label: "隶属单位2",
        },
        {
          value: "3",
          label: "隶属单位3",
        },
      ],
      value2: "",

      options3: [
        {
          value: "1",
          label: "类型1",
        },
        {
          value: "2",
          label: "类型2",
        },
        {
          value: "3",
          label: "类型3",
        },
      ],
      value3: "",

      input: "",

      dialogFormVisible: false,
      form: {
        name: "",
        region: "",
        region2: "",
        date1: "",
        date2: "",
        delivery: false,
        type: [],
        resource: "",
        desc: "",
      },
      formLabelWidth: "120px",
    };
  },

  created() {
    //aa 2:钩子里调用查询组件
    this.fetchData();
  },



  methods: {
    //aa 3请求接口
     fetchData(){
      getList(this.query,this.page.current,this.page.size).then(response=>{
        //  this.list = response.data;
        //  this.page.total=response.data.total;
          console.log('response',response)
      })
    },




    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>