<template>
  <div class="app-container">
    <el-form label-width="130px">
      <el-row>
        <el-col :span="6">
          <el-form-item label="关键字">
            <el-input v-model="KEYWORDS" placeholder="请输入关键字"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="分公司名称">
            <el-input v-model="CORP_NAME" placeholder="请输入分公司名称"/>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label-width="10px">
            <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
              搜索
            </el-button>
            <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
              重置
            </el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-table ref="multipleTable" :data="varList" :header-cell-style="{'font-weight': 'bold','color': '#000'}" tooltip-effect="dark" border fit highlight-current-row>
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="USERNAME" label="用户名" />
      <el-table-column prop="NAME" label="姓名" />
      <el-table-column prop="DEPARTMENT_NAME" label="部门" />
<!--      <el-table-column prop="PERSON_WORK_TYPE" label="工种" />-->
      <el-table-column prop="COMPANY_NAME" label="服务公司" />
      <el-table-column prop="STATUS" label="状态" >
        <template slot-scope="{row}">
          <span v-if="row.AUDIT_STATUS === 0">停止服务申请中</span>
          <span v-else>服务中</span>
        </template>
      </el-table-column>
      <el-table-column prop="START_TIME" label="服务开始时间" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button v-if="row.AUDIT_STATUS!==0 && row.serviceStatus === '1'" type="warning" icon="el-icon-edit" size="mini" @click="handleAdd(row.USER_ID,row.SERVICE_PROVIDER_ID,row.SERVICE_COMPANY_USER_MAP_ID)">停止服务</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div>
        <el-button type="success" icon="el-icon-finished" plain @click="showRecord">申请记录</el-button>
      </div>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>

    <apply ref="apply" @finish="getQuery"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import apply from './apply'
export default {
  components: { Pagination, apply },
  directives: { waves },
  data() {
    return {
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      varList: [],
      KEYWORDS: '',
      CORP_NAME: '',
      add: false,		// 新增按钮
      del: false,		// 删除按钮
      edit: false	// 修改按钮
    }
  },
  created() {
    this.getList()
    this.hasButton()
  },
  methods: {
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.listQuery = {
        page: 1,
        limit: 10
      }
      this.getList()
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.CORP_NAME = ''
      this.getQuery()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/user/regularUserList?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          CORP_NAME: this.CORP_NAME
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
      })
        .catch((e) => {
          this.listLoading = false
        })
    },

    handleAdd(USER_ID, SERVICE_PROVIDER_ID, SERVICE_COMPANY_USER_MAP_ID) {
      const map = {}
      map.USER_ID = USER_ID
      map.STOP_CORPINFO = SERVICE_PROVIDER_ID
      map.SERVICE_COMPANY_USER_MAP_ID = SERVICE_COMPANY_USER_MAP_ID
      this.$refs.apply.init(map)
    },

    showRecord() {
      this.$parent.activeName = 'record'
    },

    hasButton() {
      var keys = 'stopserver:add,stopserver:del,stopserver:edit,fhSms,email,fromExcel,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys, tm: new Date().getTime()
        }
      ).then((data) => {
        if (data.result == 'success') {
          this.add = data.stopserverfhadminadd	// 增
          this.del = data.stopserverfhadmindel	// 删
          this.edit = data.stopserverfhadminedit	// 改
          this.fromExcel = data.fromExcel	// 从excel导入权限
          this.toExcel = data.toExcel		// 导出到excel权限
        } else if (data.result == 'exception') {
          // showException('按钮权限', data.exception)// 显示异常
          console.info('按钮权限:', data.exception)
        }
      })
        .catch((e) => {
          this.listLoading = false
        })
    }
  }
}
</script>

