<template>
  <div id="index">
    <el-row>
      <el-col :span="24" class="info">
        <el-col :span="24" class="top">
          <topInfo :topTitle="topTitle"></topInfo>
        </el-col>
        <el-col :span="24" class="search">
          <el-col :span="8" class="left">
            <span>查询编号</span>
            <el-input v-model="input" placeholder="请输入编码"></el-input>
          </el-col>
          <el-col :span="8" class="left">
            <span>查询名称</span>
            <el-input v-model="input" placeholder="请输入名称"></el-input>
          </el-col>
          <el-col :span="8" class="right">
            <el-button size="mini" type="primary" icon="el-icon-search">查询</el-button>
            <el-button size="mini" type="success" icon="el-icon-check" @click="addData()">添加企业，单位类别</el-button>
          </el-col>
        </el-col>
        <el-col :span="24" class="main">
          <el-table :data="tableData" style="width: 100%" border>
            <el-table-column label="序号" type="index" width="50" align="left"> </el-table-column>
            <el-table-column prop="num" label="编码" width="50" align="left"> </el-table-column>
            <el-table-column prop="title" label="名称" width="80" align="left"> </el-table-column>
            <el-table-column prop="zhizhao" label="执照编码" width="100" align="left"> </el-table-column>
            <el-table-column prop="tel" label="联系方式" width="120" align="left"> </el-table-column>
            <el-table-column prop="address" label="联系地址" width="230" align="left"> </el-table-column>
            <el-table-column prop="web" label="主页" width="140" align="left"> </el-table-column>
            <el-table-column prop="date" label="创建时间" width="100" align="left"> </el-table-column>
            <el-table-column label="操作" align="left">
              <template slot-scope="scoped">
                <el-button size="mini" type="primary" icon="el-icon-view" @click="openDialog(scoped.$index)"></el-button>
                <el-button size="mini" type="primary" icon="el-icon-edit" @click="addData(scoped.$index)"></el-button>
                <el-button size="mini" type="danger" icon="el-icon-delete" @click.native.prevent="deleteRow(scoped.$index, tableData)"></el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-col :span="24" class="page">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :current-page="currentPage"
              layout="total, prev, pager, next, jumper"
              :total="1"
            >
            </el-pagination>
          </el-col>
        </el-col>
      </el-col>
    </el-row>
    <el-dialog title="详细信息" :visible.sync="dialog">
      <el-col :span="24" class="dataInfo">
        <el-col :span="24"> 编码：{{ info.num }} </el-col>
        <el-col :span="24"> 名称：{{ info.title }} </el-col>
        <el-col :span="24"> 执照编码：{{ info.zhizhao }} </el-col>
        <el-col :span="24"> 联系方式：{{ info.tel }} </el-col>
        <el-col :span="24"> 联系地址：{{ info.address }} </el-col>
        <el-col :span="24">主页：{{ info.web }} </el-col>
        <el-col :span="24"> 创建时间：{{ info.date }} </el-col>
      </el-col>
    </el-dialog>
  </div>
</template>

<script>
import topInfo from '@/layout/public/top.vue';
import { teal } from 'color-name';
export default {
  name: 'index',
  props: {},
  components: {
    topInfo, //头部标题
  },
  data: () => ({
    topTitle: '企业信息管理',
    input: '',
    tableData: [
      {
        num: '01',
        title: '福瑞科技',
        zhizhao: '123456',
        tel: '17319450324',
        address: '吉林省长春市朝阳去力旺广场B座16楼1608',
        web: 'www.baidu.com',
        date: '2019-01-10',
      },
      {
        num: '02',
        title: '十条数据',
        zhizhao: '123456',
        tel: '17319450324',
        address: '吉林省长春市朝阳去力旺广场B座16楼1608',
        web: 'www.baidu.com',
        date: '2019-01-10',
      },
    ],
    currentPage: 1,
    dialog: false,
    info: {},
  }),
  created() {},
  computed: {},
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
    },
    addData(index) {
      if (index !== undefined) {
        let data = this.tableData[index];
      } else {
        this.form = {};
      }
      this.$router.push({ path: './detail' });
    },
    deleteRow(index, rows) {
      rows.splice(index, 1);
    },
    openDialog(index) {
      if (index !== undefined) {
        let data = JSON.parse(JSON.stringify(this.tableData[index]));
        data[`index`] = index;
        this.$set(this, `info`, data);
      }
      this.dialog = true;
    },
  },
};
</script>

<style lang="less" scoped>
.top {
  height: 40px;
  background-color: #f5f5f5;
}
.search {
  height: 40px;
  line-height: 40px;
  padding: 0 15px;
}
.search .left span {
  font-size: 13px;
  color: #393939;
}
.search .left .el-input {
  width: 50%;
}
/deep/.search .left .el-input .el-input__inner {
  height: 28px;
}
.main {
  width: 97%;
  margin: 0 15px;
}
/deep/.el-table th {
  padding: 5px 0;
  background: #f2f2f2;
}
/deep/.el-table td {
  padding: 5px 0;
}
/deep/.el-table tr {
  background: #f9f9f9;
}
/deep/.el-table tr:nth-child(2n) {
  background: #fff;
}
.page {
  text-align: center;
  padding: 30px 0;
}
/deep/ .el-dialog__body {
  min-height: 300px;
}
.dataInfo .el-col {
  font-size: 18px;
  padding: 0 0 20px 0;
}
</style>
