<template>
  <div>
    <div class="content">
      <div class="absolute">
        <el-button type="primary" @click="isForm=true">添加新用户</el-button>
      </div>
      <dataTable :table-data="tableData" :columns="columns" :page-obj="pageObj" :breads="breads" :checklist="checklist">
        <el-table-column slot="operate" label="操作" align="center" fixed="right" width="100">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="handleEdit(scope.row)">编辑</el-button>
            <el-button type="text" size="small" @click="handleDelete(scope.row,scope.$index)">删除</el-button>
          </template>
        </el-table-column>
      </dataTable>
      <el-dialog :visible.sync="isForm" title="添加新用户" width="30%">
        <el-form :model="form" :rules="rules">
          <el-form-item label="姓名" prop="name">
            <el-input v-model="form.name" placeholder="请输入" style="width: 300px;"></el-input>
          </el-form-item>
          <el-form-item label="手机" prop="phone">
            <el-input v-model="form.phone" placeholder="请输入" style="width: 300px;"></el-input>
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="form.password" placeholder="请输入" style="width: 300px;" type="password"></el-input>
          </el-form-item>
          <el-form-item label="角色" prop="role">
            <el-select v-model="form.role" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="del">取 消</el-button>
          <el-button type="primary" @click="isForm = false">保存</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import dataTable from '@components/dataTable.vue'
export default {
  name: 'bidingList',
  components: {
    dataTable
  },
  data() {
    return {
      form: {
        name: '',
        phone: '',
        password: '',
        role: ''
      },
      options: [{
        value: '经理',
        label: '经理'
      }, {
        value: '专员',
        label: '专员'
      }],
      rules: {
        role: [{
          required: true,
          message: '请选择角色类型',
          trigger: 'change'
        }],
        name: [{
          required: true,
          message: '请填写姓名',
          trigger: 'blur'
        }],
        phone: [{
          required: true,
          message: '请填写手机',
          trigger: 'blur'
        }],
        password: [{
          required: true,
          message: '请填写密码',
          trigger: 'blur'
        }]
      },
      isForm: false,
      checklist: [{
        title: '姓名',
        type: 'input',
        model: 'name'
      },
      {
        title: '手机',
        type: 'input',
        model: 'phone'
      }
      ],
      breads: ['系统管理', '用户管理'],
      tableData: [{
        name: '胡彦斌',
        phone: '17822226666',
        role: '经理',
        data: '2017-10-01 12：00'
      }, {
        name: '胡彦斌',
        phone: '17822226666',
        role: '经理',
        data: '2017-10-01 12：00'
      },
      {
        name: '胡彦斌',
        phone: '17822226666',
        role: '专员',
        data: '2017-10-01 12：00'
      }
      ],
      columns: [{
        label: '姓名',
        prop: 'name'
      },
      {
        label: '手机',
        prop: 'phone'
      },
      {
        label: '角色',
        prop: 'role'
      },
      {
        label: '创建时间',
        prop: 'data',
        sortable: true
      },
      {
        slot: 'operate'
      }
      ], // 操作列

      pageObj: {
        size: 10,
        total: 1,
        currentPage: 1,
        sizes: [100, 200, 300],
        func: (currentPage) => {
          this.pageTurning(currentPage)
        }
      }
    }
  },
  methods: {
    // 删除
    handleDelete(id, index) {
      this.$confirm('确定要删除么？', '提示', {
        type: 'warning'
      })
        .then(() => {
          this.$message.success('删除成功')
          this.tableData1.splice(index, 1)
        })
        .catch(() => {})
    },
    // 编辑
    handleEdit(row) {
      this.form = row
      this.isForm = true
    },
    del() {
      this.form = {
        name: '',
        phone: '',
        password: '',
        role: ''
      }
      this.isForm = false
    }
  }
}
</script>

<style scoped>
	.absolute {
		position: absolute;
		top: 83px;
		right: 200px;
	}
</style>
