<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: 120px">
            <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="companyName" label="单位名称" width="200">
      </el-table-column>
      <el-table-column label="LOGO">
        <template slot-scope="{}">
          <img src="@/assets/img.png" alt="" style="height: 30px" />
        </template>
      </el-table-column>
      <el-table-column prop="fullName" label="单位全名"> </el-table-column>
      <el-table-column prop="shortName" label="单位简称"> </el-table-column>
      <el-table-column prop="link" label="官网链接" width="200">
      </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-input v-model="form.name4" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="logo:" :label-width="formLabelWidth">
          <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
          
            multiple
            :limit="3"
          >
            <el-button size="small" type="primary">选择文件</el-button>
            <div slot="tip" class="el-upload__tip">
              只能上传jpg/png文件，且不超过500kb
            </div>
          </el-upload>
        </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-item label="单位简称:" :label-width="formLabelWidth">
          <el-input v-model="form.name6" 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>
export default {
  data() {
    return {
      tableData: [
        {
          companyName: "上海永天科技股份有限公司",
          logo: "",
          fullName: "上海永天科技股份有限公司",
          shortName: "上海永天",
          link: "http://www.chinausky.com",
        },
        {
          companyName: "上海永天科技股份有限公司",
          logo: "",
          fullName: "上海永天科技股份有限公司",
          shortName: "上海永天",
          link: "http://www.chinausky.com",
        },
        {
          companyName: "上海永天科技股份有限公司",
          logo: "",
          fullName: "上海永天科技股份有限公司",
          shortName: "上海永天",
          link: "http://www.chinausky.com",
        },
        {
          companyName: "上海永天科技股份有限公司",
          logo: "",
          fullName: "上海永天科技股份有限公司",
          shortName: "上海永天",
          link: "http://www.chinausky.com",
        },
      ],
      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>