<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="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.workStatus"
                :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="getQuery">搜 索</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="UN_FLOATING_PERSONNEL" label="固定人员数" />
      <el-table-column prop="FLOATING_PERSONNEL" label="流动人员数" />
      <el-table-column prop="STATUS" label="服务确认状态" >
        <template slot-scope="{row}">
          <span v-if="row.STATUS === 0">待确认</span>
          <span v-if="row.STATUS === 1">已确认</span>
          <span v-if="row.STATUS === -1">已打回</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="getInfo(row.SERVICE_COMPANY_MAP_ID)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div>
        <el-button type="primary" @click="handleAdd">新 增</el-button>
      </div>
      <pagination :total="listQuery.total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" layout="total, prev, pager, next, jumper" @pagination="getList" />
    </div>

    <info ref="info"/>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import Info from './info'
export default {
  components: { Pagination, Info },
  directives: { waves },
  inject: ['setActiveName'],
  data() {
    return {
      loading: true,
      remoteControl: {
        add: false,
        del: false,
        edit: false
      },
      listQuery: {
        page: 1,
        limit: 10,
        total: 0
      },
      list: [],
      form: {
        STATUS: '',
        NAME: '',
        KEYWORDS: ''
      },
      dic: {
        workStatus: []
      }
    }
  },
  created() {
    this.getList()
    this.getDict()
  },
  methods: {
    getRowKey(row) {
      return row.SERVICE_COMPANY_MAP_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.listQuery = {
        page: 1,
        limit: 10,
        total: 0
      }
      this.getList()
    },
    // 获取列表
    getList() {
      this.loading = true
      requestFN(
        '/service_corp/getServiceList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        this.form
      ).then((data) => {
        this.loading = false
        this.list = data.list
        this.listQuery.total = data.page.totalResult
        this.hasButton()
      }).catch((e) => {
        this.loading = false
      })
    },

    getInfo(SERVICE_COMPANY_MAP_ID) {
      this.$refs.info.init({ SERVICE_COMPANY_MAP_ID })
    },
    // 获取数据字典数据
    getDict() {
      requestFN(
        '/service_corp/getDic',
        {
          vector: JSON.stringify(['workStatus'])
        }
      ).then((data) => {
        if (data.code === '0') {
          this.dic.workStatus = data.dic.workStatus
        } else {
          this.$message.error(data.errorMessage)
        }
      }).catch((e) => {
      })
    },
    handleAdd() {
      this.setActiveName('Add')
    },
    resetting() {
      this.form = {
        STATUS: '',
        NAME: ''
      }
      this.getQuery()
    }

  }
}

</script>
