<template>
  <div>
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="80px">
      <el-form-item label="配置名称:" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入薪资配置名称" clearable size="small"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="name" label="薪资配置名称" />
      <el-table-column prop="salary" label="薪资金额(元)" />
      <el-table-column width="150" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit-outline" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
    />

    <ChangeSalaryBase ref="changeSalaryBase" @success="getList"/>
  </div>
</template>

<script>

import ChangeSalaryBase from "@/views/school/salary/comps/ChangeSalaryBase.vue";
import {delSalaryBase, list} from "@/api/school/salary";

export default {
  name: 'SalaryBase',
  components: {ChangeSalaryBase},
  data(){
    return{
      loading: true,
      single: true,
      multiple: true,
      total: 0,
      dataList: [],
      open: false,
      queryParams:{
        name:'',
        pageNum:1,
        pageSize: 10,
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    handleAdd(){
      this.$refs.changeSalaryBase.handleAdd()
    },
    handleUpdate(row){
      this.$refs.changeSalaryBase.handleUpdate(row)
    },
    handleDelete(){
      this.$confirm('是否确认删除?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function() {
        return delSalaryBase({id:row.id})
      }).then((res) => {
        this.getList()
        this.msgSuccess(res.msg)
      }).catch(function() {})
    },
    getList(){
      this.loading=false
      list(this.queryParams).then(res=>{
        this.total=res.data.total
        this.dataList=res.data.rows
      })
    },
    handleQuery(){
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery(){
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>
