<!--选择证明人-->
<template>
  <div>
    <EMSTable
      :server="server"
      :action="action"
      ref="ETable"
      :params="initParams"
      :columns="columns"
      :highlight-row="true"
      :rowClickHandle="rowClick"
    >
      <Form ref="searchForm" slot="search-bar" label-position="top" inline>
        <Form-item prop="userName" label="名称">
          <Input type="text" :maxlength="30" v-model="searchForm.userName" placeholder="请输入"></Input>
        </Form-item>
        <Form-item prop="userCode" label="账号">
          <Input type="text" :maxlength="30" v-model="searchForm.userCode" placeholder="请输入"></Input>
        </Form-item>
        <Form-item prop="companyDescr" label="公司">
          <Input type="text" :maxlength="30" v-model="searchForm.companyDescr" placeholder="请输入"></Input>
        </Form-item>
        <Form-item prop="orgName" label="部门">
          <Input type="text" :maxlength="30" v-model="searchForm.orgName" placeholder="请输入"></Input>
        </Form-item>
      </Form>
      <div slot="handle-bar">
        <Button @click="search" type="warning" icon="search">确定</Button>
        <Button @click="reset" type="info" icon="loop">重置</Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
import util from "../../util/util";

export default {
  components: {},
  props: {
    title: {
      type: String,
      default: "证明人"
    },
    maxLength: {
      type: Number,
      default: 1
    },
    businessLine: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      action: "/ems/ems-base-application/sysorg/findSubEmployees/allSubEmployeesByCondition",
      selections: [],
      searchForm: {
        businessLine: this.businessLine, //业务线
        ouCode: "",
        userCode: "", //用户账号
        userName: "", //用户名称
        companyDescr: "", //公司
        orgName: "" //部门
      },
      columns: [
        {
          title: `账号`,
          align: "center",
          key: "code",
          width: 150
        },
        {
          title: `编号`,
          align: "center",
          key: "id",
          width: 150
        },
        {
          title: `名称`,
          align: "center",
          key: "title",
          width: 150
        },
        {
          title: `公司`,
          align: "center",
          key: "ouName",
          width: 150
        },
        {
          title: `部门`,
          align: "center",
          key: "orgName",
          width: 150
        },
        {
          title: `岗位`,
          align: "center",
          key: "jobCodeDescr",
          width: 150
        }
      ]
    };
  },
  computed: {
    initParams() {
      return JSON.parse(JSON.stringify(this.searchForm));
    }
  },
  created: function() {
    const vm = this;
    this.$emit("SetTitle", `请选择${this.title}`);
    this.$emit("SetPageSize", window.innerWidth * 0.85);
    this.$emit("SetPageActions", [
      {
        text: "确定",
        theme: "primary",
        handle: () => {
          if (vm.selections.length > vm.maxLength) {
            return vm.$Message.error(`最多选择 ${vm.maxLength} 个`);
          }
          vm.$emit("Close", vm.selections);
        }
      },
      {
        text: "取消",
        theme: "primary",
        handle: () => {
          vm.$emit("Close");
        }
      }
    ]);
  },
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    search(page = 1) {
      this.$refs["ETable"].load(this.searchForm, page);
    },
    reset() {
      this.$refs["searchForm"].resetFields();
      this.search(1);
    },
    // 确定
    onOk() {
      let selected = this.$refs["ETable"].getSelectioned() || [];
      this.$emit("Close", selected[0]);
    },
    // 清空
    clear() {
      this.$emit("Close", []);
    },
    onSelectionChange(selection) {
      this.selections = selection;
    },
    rowClick(selection) {
      if (selection) {
        this.$emit("Close", selection);
      }
    }
  },
  watch: {},
  directives: {}
};
</script>
<style lang="less">
</style>
