<template>
  <el-row>
    <el-row>
      <el-form ref="searchForm" :model="searchForm" label-width="80px">
        <search-white-board :show-more="true" @search="search">
          <div slot="base">
            <el-row style="line-height: 40px; text-align: right;">
              <el-col :span="2" :offset="1"><label class="search-label">岗位名称</label></el-col>
              <el-col :span="5">
                <el-input v-model.trim="searchForm.name" placeholder="请输入岗位名称" clearable @keyup.enter.native="search" />
              </el-col>
            </el-row>
          </div>

          <div slot="more">
            <el-row style="line-height: 40px; text-align: right;">
              <el-col :span="2"><label class="search-label">是否删除</label></el-col>
              <el-col :span="5" style="text-align: left;">
                <el-switch v-model="searchForm.isDel" active-color="#13ce66" inactive-color="#ff4949" @change="search" />
              </el-col>
            </el-row>
          </div>
        </search-white-board>
      </el-form>
    </el-row>

    <el-row>
      <white-board>
        <el-row>
          <el-col :span="2" :offset="22" style="text-align: right;">
            <el-button icon="el-icon-plus" type="success" plain @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>

        <el-row style="padding: 10px 0px;">
          <el-table :data="tableData" style="width: 100%;" highlight-current-row stripe>
            <el-table-column prop="id" label="标识" width="150" />
            <el-table-column prop="name" label="岗位名称" show-overflow-tooltip />
            <el-table-column prop="remarks" label="备注" show-overflow-tooltip />
            <el-table-column label="更新时间" width="135">
              <template slot-scope="scope">
                <el-row>{{ scope.row.updateByName }}</el-row>
                <el-row>{{ scope.row.updateAt }}</el-row>
              </template>
            </el-table-column>
            <el-table-column label="操作" width="150" fixed="right">
              <template slot-scope="scope">
                <el-button type="primary" plain @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                <el-button v-if="!scope.row.isDel" type="danger" plain @click="handleIsDel(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-row>

        <el-row>
          <el-pagination :current-page="searchForm.page" :page-sizes="[10, 20, 50, 100]" :page-size="50" layout="total, sizes, prev, pager, next, jumper" :total="total" small @size-change="changeSizeChange" @current-change="changeCurrentChange" />
        </el-row>
      </white-board>
    </el-row>
    <edit-job-dialog :visible="dialogVisible" :dialog-title="dialogTitle" :form="form" @cancelDialog="cancelDialog" @refresh="list" />
  </el-row>
</template>

<script>
import jobApi from '@/api/platform/jobApi'
import EditJobDialog from '@/views/platform/system/job/editJobDialog'

export default {
  name: 'Job',
  components: {
    'edit-job-dialog': EditJobDialog
  },
  data() {
    return {
      searchForm: {
        name: '',
        isDel: false,
        page: 1,
        size: 50
      },
      total: 0,
      tableData: [],
      dialogTitle: '',
      dialogVisible: false,
      form: {
        id: '',
        name: '',
        remarks: '',
        sort: 0
      }
    }
  },
  mounted() {
    this.list()
  },
  methods: {
    cancelDialog(visible) {
      this.dialogVisible = visible
    },
    search() {
      this.searchForm.page = 1
      this.list()
    },
    handleAdd() {
      this.form = {
        id: '',
        name: '',
        remarks: '',
        sort: 0
      }
      this.dialogTitle = '新增'
      this.dialogVisible = true
    },
    handleEdit(index, row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.dialogTitle = '编辑'
      this.dialogVisible = true
    },
    handleIsDel(index, row) {
      jobApi.handleIsDel(row.id).then(data => {
        this.list()
      })
    },
    list() {
      this.tableData = []
      jobApi.page(this.searchForm).then(data => {
        this.total = data.total
        this.tableData = data.data
      })
    },
    changeSizeChange(val) {
      this.searchForm.size = val
      this.list()
    },
    changeCurrentChange(val) {
      this.searchForm.page = val
      this.list()
    }
  }
}
</script>

<style scoped>
  .distpicker-address-wrapper select{
    padding: 0px;
    height: 28px;
    color: #606266;
    font-size: 0.5rem;line-height: 0.3
  }
</style>
