<template>
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="110px">
      <el-row :gutter="2">
        <el-col :span="10">
          <el-form-item label="分公司名称" prop="NAME">
            <el-input id="FIRST_PARTY_NAME" ref="NAME" v-model="form.FIRST_PARTY_NAME" placeholder="这里请输入公司名称..."/>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="分公司名称" prop="NAME">
            <el-input id="NAME" ref="NAME" v-model="form.NAME" placeholder="这里请输入公司名称..."/>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="服务状态" prop="EMPLOYMENT_TYPE">
            <el-select v-model="form.STATUS" placeholder="请选择" style="width: 100%;">
              <el-option
                v-for="item in dic.userWorkStatus"
                :key="item.value"
                :label="item.name"
                :value="item.value"/>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" @click="search">搜 索</el-button>
          <el-button @click="resetting">重 置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table
      v-loading="loading"
      ref="multipleTable"
      :data="list"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column :reserve-selection="true" type="selection" width="55" align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="FIRST_PARTY_NAME" label="分公司名称" />
      <el-table-column prop="NAME" label="姓名" />
      <el-table-column prop="department_name" label="部门" />
<!--      <el-table-column prop="post_name" label="工种" />-->
      <el-table-column prop="type_name" label="人员类型" />
      <el-table-column prop="START_TIME" label="开始服务时间" />
      <el-table-column prop="END_TIME" label="结束服务时间" />
      <el-table-column prop="work_status_name" label="服务状态">
        <template slot-scope="{row}">
          {{ translate(row) }}
        </template>
      </el-table-column>
      <el-table-column prop="status_name" label="服务状态" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="applyFor(row)">停止服务申请</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="listQuery.total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" layout="total, prev, pager, next, jumper" @pagination="getList" />
    </div>
    <apply-for ref="applyFor"/>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import applyFor from './applyFor'

export default {
  components: { Pagination, applyFor },
  directives: { waves },
  inject: ['setActiveName', 'setHeirloom'],
  data() {
    return {
      loading: true,
      remoteControl: {
        add: false,
        del: false,
        edit: false
      },
      listQuery: {
        page: 1,
        limit: 10,
        total: 0
      },
      list: [],
      form: {
        FIRST_PARTY_NAME: '',
        STATUS: '',
        NAME: '',
        KEYWORDS: ''
      },
      dic: {
        userWorkStatus: []
      }
    }
  },
  created() {
    this.getList()
    this.getDict()
  },
  methods: {
    getRowKey(row) {
      return row.SERVICE_COMPANY_MAP_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    // 获取列表
    getList() {
      this.loading = true
      requestFN(
        '/employ/getList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        this.form
      ).then((data) => {
        this.loading = false
        this.list = data.list
        this.total = data.page.totalResult
        this.hasButton()
      }).catch((e) => {
        this.loading = false
      })
    },
    search() {
      this.getList()
    },
    getInfo(e) {
      this.setActiveName('Panel')
      this.setHeirloom({ touristModeFlag: true, SERVICE_COMPANY_MAP_ID: e.SERVICE_COMPANY_MAP_ID })
    },
    // 获取数据字典数据
    getDict() {
      requestFN(
        '/employ/getDic',
        {
          vector: JSON.stringify(['userWorkStatus'])
        }
      ).then((data) => {
        if (data.code === '0') {
          this.dic.userWorkStatus = data.dic.userWorkStatus
        } else {
          this.$message.error(data.errorMessage)
        }
      }).catch((e) => {
      })
    },
    resetting() {
      this.form = {
        FIRST_PARTY_NAME: '',
        STATUS: '',
        NAME: '',
        KEYWORDS: ''
      }
    },
    translate(row) {
      for (let i = 0; i < this.dic.userWorkStatus; i++) {
        if (row.STATUS === this.dic.userWorkStatus[i].value) { return this.dic.userWorkStatus[i].name }
      }
    },
    applyFor(row) {
      this.$refs.applyFor.init(row)
    }

  }
}

</script>
