<template>
  <div class="supplier-list-selector">
    <div class="filter-container">
      <div class="filter-control">
        <span>服务商名称:</span>
        <el-input v-model="listQuery.name" size="mini" placeholder="服务商名称" @keyup.enter.native="filterList" />
      </div>
      <div class="filter-control">
        <el-button type="primary" size="mini" @click="filterList">查询</el-button>
      </div>
    </div>
    <el-table
      ref="multipleTable"
      :data="list"
      border
      fit
      highlight-current-row
      header-row-class-name="tableHeader"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column prop="name" label="服务商名称" align="center" />
      <el-table-column prop="serviceLevel" label="服务商级别" align="center">
        <template slot-scope="scope">
          <div>
            {{ scope.row.serviceLevel == '1' ? '一级' : scope.row.serviceLevel == '2' ? '二级' : '三级' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="serviceCategory" label="服务商类型" align="center">
        <template slot-scope="scope">
          <div>
            {{ scope.row.serviceLevel == '1' ? '个人' : '企业' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="contractStartDate" label="授权起始日期" align="center" />
      <el-table-column prop="contractEndDate" label="授权截止日期" align="center" />
      <el-table-column prop="status" label="状态" align="center">
        <template slot-scope="scope">
          <div>
            已{{ scope.row.status === 90 ? '上线' : '下线' }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="updateTime" label="添加时间" align="center" />
      <el-table-column prop="createBy" label="创建人" align="center" />
    </el-table>
    <!-- 页码 -->
    <pagination :total="total" :page.sync="listQuery.pageNum" :limit.sync="listQuery.pageSize" @pagination="getList" />
    <div class="control-footer">
      <el-button type="primary" @click="onCancel">取消</el-button>
      <el-button type="primary" @click="onConfirm">确认</el-button>
    </div>
  </div>
</template>
<script>
import { getProviderList } from '@/api/serviceSettlement/service'

export default {
  name: 'ClubListSelector',
  data() {
    return {
      listQuery: {
        authUserId: '',
        authParty: '',
        auditStatus: '',
        status: '',
        name: '',
        pageNum: 1, // 页码
        pageSize: 10 // 分页
      },
      list: [],
      total: 0,
      multipleSelection: []
    }
  },
  computed: {
  },
  created() {
    this.getList()
  },
  methods: {
    // 取消
    onCancel() {
      this.multipleSelection = []
      this.$emit('cancel', [])
    },

    // 确认
    onConfirm() {
      if (this.multipleSelection.length === 0) {
        this.$message.warning('选择列表不能为空')
        return
      }
      this.$emit('confirm', this.multipleSelection)
    },

    // 获取机构列表
    async getList() {
      const { data } = await getProviderList(this.listQuery)
      this.list = data.results
      this.total = data.totalRecord
    },

    // 筛选机构列表
    filterList() {
      this.listQuery.pageNum = 1
      this.getList()
    },

    // 设置选中的行
    setSelection() {
      this.list.forEach((row) => {})
    },

    // 表格列选择
    handleSelectionChange(rows) {
      this.multipleSelection = rows
    },

    // 表格索引
    indexMethod(index) {
      return index + this.listQuery.pageSize * (this.listQuery.pageNum - 1) + 1
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep {
  .pagination-container {
    padding: 0 !important;
  }
}
.control-footer {
  text-align: right;
  margin-top: 15px;
}
</style>
