<template>
  <div>
    <el-card style="width: 480px">
      <div style="padding: 10px;background-color:#F5F5F5;width: 440px">
        <el-button style="margin-left: 90%;font-size: 30px" type="text" icon="el-icon-circle-plus-outline" @click="handleAdd('form')"/>
      </div>
      <el-table
        v-loading="loading"
        :data="tableData"
        :header-cell-style="tableHeader"
        :cell-style="tableCell"
        element-loading-text="数据加载中"
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(0, 0, 0, 0.2)"
        tooltip-effect="dark"
        style="width: 440px">
        <el-table-column align="center" label="角色编号" width="110">
          <template slot-scope="scope">
            {{ scope.row.角色编号 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="角色功能" width="210">
          <template slot-scope="scope">
            {{ scope.row.角色功能 }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="编辑" min-width="100px">
          <template slot-scope="scope">
            <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.row)"/>
            <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"/>
          </template>
        </el-table-column>
      </el-table>
      <!--      <div class="block" style="margin-top: 10px;">-->
      <!--        <el-pagination-->
      <!--          :current-page="pageCurrent"-->
      <!--          :page-sizes="[10, 20, 30, 40, 50]"-->
      <!--          :page-size="pageSize"-->
      <!--          :total="total"-->
      <!--          layout="total, sizes, prev, pager, next, jumper"-->
      <!--          @size-change="handleSizeChange"-->
      <!--          @current-change="handleCurrentChange"/>-->
      <!--      </div>-->
    </el-card>
    <el-dialog :visible.sync="dialogFormVisible1" title="新增角色" width="300px">
      <el-form ref="form" :model="form" :rules="rules" label-position="top" label-width="120px">
        <el-form-item label="角色名称" prop="角色功能" style="margin-left: 20px">
          <el-input
            v-model="form.角色功能"
            clearable
            size="small"
            placeholder="角色功能"
            style="height:50px;width: 90%"
            class="input12"/>
        </el-form-item>
        <el-form-item style="margin-left: 65px;margin-top: 40px;">
          <el-button class="button12" @click="dialogFormVisible1 = false">取消</el-button>
          <el-button :disabled="addDisable" class="button11" @click="submitAdd1('form')">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
    <el-dialog :visible.sync="dialogFormVisible2" title="编辑角色" width="300px">
      <el-form ref="form2" :model="form2" :rules="rules2" label-position="top" label-width="120px">
        <el-form-item label="角色名称" prop="角色功能" style="margin-left: 20px">
          <el-input
            v-model="form2.角色功能"
            clearable
            size="small"
            placeholder="角色功能"
            style="height:50px;width: 90%"
            class="input12"/>
        </el-form-item>
        <el-form-item style="margin-left: 65px;margin-top: 40px;">
          <el-button class="button12" @click="dialogFormVisible2 = false">取消</el-button>
          <el-button :disabled="submitDisable" class="button11" @click="submitAdd2('form1')">确认</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { ExecDatabase } from '@/main'
export default {
  data() {
    return {
      handleAdd_disable: false,
      RoleFunctioning: '',
      loading: false,
      tableData: [],
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      name: '',
      num: '', // 角色编号
      form: {
        角色功能: ''
      },
      form2: {
        角色功能: ''
      },
      rules: {
        角色功能: [{ required: true, message: '请输入角色名称', trigger: 'blur' }]
      },
      rules2: {
        角色功能: [{ required: true, message: '请输入角色名称', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      var param = []
      var Data = this.CreateData('11', '菜单系统模块_项目角色_查询数据_MESWORK', param)
      ExecDatabase(Data).then(response => {
        this.tableData = response.data
        this.total = response.data.total
      })
    },
    tableHeader() {
      return 'background-color: rgb(250, 250, 250);' +
        'border-bottom: 3px rgb(170, 170, 170) solid;' +
        'color: rgb(35, 35, 35);' +
        'font-weight: 5000;' +
        'padding: 15px 10px'
    },
    tableCell() {
      return 'border-color: #E8E8E8;padding: 0px'
    },
    handleEdit(row) {
      if (this.$refs['form2'] !== undefined) {
        this.$refs['form2'].resetFields()
      }
      this.handleAdd_disable = false
      this.dialogFormVisible2 = true
      this.form2.角色功能 = row.角色功能
      this.num = row.角色编号
    },
    submitAdd2(formName) { // 编辑角色功能
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.handleAdd_disable = true
          var param = []
          param[0] = ['角色功能', this.form2.角色功能]
          param[1] = ['角色编号', this.num]
          var Data = this.CreateData('12', '菜单系统模块_项目角色_修改数据_MESWORK', param)
          ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('编辑成功')
              this.fetchData()
              this.dialogFormVisible2 = false
            } else { this.$message.error('编辑失败') }
          })
        }
      })
    },
    submitAdd1(formName) { // 增加角色功能
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.handleAdd_disable = true
          var param = []
          param[0] = ['角色功能', this.form.角色功能]
          var Data = this.CreateData('12', '菜单系统模块_项目角色_增加_MESWORK', param)
          ExecDatabase(Data).then(response => {
            if (response.data[0].result === '1') {
              this.$message.success('增加成功')
              this.form.角色功能 = ''
              this.fetchData()
              this.dialogFormVisible1 = false
            } else { this.$message.error('增加失败') }
          })
        }
      })
    },
    handleAdd() {
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.handleAdd_disable = false
      this.dialogFormVisible1 = true
    },
    handleDelete(row) { // 删除
      this.$confirm('此操作将永久删除该行, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        var param = []
        param[0] = ['角色编号', row.角色编号]
        var Data = this.CreateData('12', '菜单系统模块_项目角色_删除_MESWORK', param)
        ExecDatabase(Data).then(response => {
          if (response.data[0].result === '1') {
            this.$message.success('删除成功')
          } else {
            this.$message.error('删除失败')
          }
          this.fetchData()
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
<style scoped>
  >>>.el-dialog__header {
    padding-left: 50px;
  }
</style>

