 <!--
   @Author: husanfeng
   @qq:1136014061
   @Date: 2018-09-21
   @Last Modified by: husanfeng
   @Last Modified time: 2018-09-21
 -->
<template>
  <div class="page-selectAccounting">
    <EMSTable action="query" :server="server" :stripe="false" ref="configTable" :columns="propsColumns" :params="searchForm" :highlight-row="true" :onSelectionChange="onSelectRow">
      <Form label-position="top" inline :model="searchForm" ref="searchForm" slot="search-bar" class="ivu-form-no-margin-bottom">
        <Form-item prop="employeeNumber" label="业务员编号">
          <Input type="text" v-model="searchForm.employeeNumber" clearable/>
        </Form-item>
        <Form-item prop="employeeName" label="业务员姓名">
          <Input type="text" v-model="searchForm.employeeName" clearable/>
        </Form-item>

      </Form>
      <div slot="handle-bar">
        <Button @click.native="search()" type="warning" icon="search">查询</Button>
        <Button @click.native="reset" type="info" icon="loop">重置</Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
import { EMSTable } from "ems-components";
import Server from "./server.js";
const server = new Server();
export default {
  name: "SelectCustomerEdit",
  components: {
    EMSTable
  },
  props: {
    title: {
      type: String,
      default: "客户查询"
    },
    _companyCode:{
      type:String,
      required:true,
    }
  },
  data() {
    return {
      server: server,
      //搜索表单的属性
      searchForm: {
        employeeName: "",
        employeeNumber: "",
        companyCode:this._companyCode
      },
      propsColumns: [
        {
          type: "selection",
          align: "center",
          width: 40,
          fixed: "left"
        },
        {
          title: "业务员编号",
          align: "center",
          key: "employeeNumber",
          minWidth: 200,
          render: (h, params) => {
            let val = params.row.employeeNumber;
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell ivu-table-cell-ellipsis",
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: "业务员姓名",
          align: "center",
          key: "employeeName",
          minWidth: 200,
          render: (h, params) => {
            let val = params.row.employeeName;
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell ivu-table-cell-ellipsis",
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: "起始日期",
          align: "center",
          key: "startDateActive",
          minWidth: 200,
          render: (h, params) => {
            let val =
              params.row.startDateActive + "-" + params.row.endDateActive;
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell ivu-table-cell-ellipsis",
                  title: val
                }
              },
              val
            );
          }
        }
      ]
    };
  },
  created() {
    this.$emit("SetTitle", this.title);
    // this.$emit("SetPageSize", 800);
  },
  mounted() {},
  methods: {
    //点击表格行 触发该事件
    onSelectRow(selected) {
      if (selected.length == 0) {
        return;
      }
      if (selected.length > 1) {
        this.$Message.warning({
          content: `只能选择一条数据`,
          duration: 5
        });
        return;
      }
      this.$emit("Close", selected[0]);
    },
    search(page = 1) {
      //搜索数据
      this.$refs["configTable"].load(this.searchForm, page);
    },
    reset() {
      this.$refs["searchForm"].resetFields();
      this.search(1);
    }
  }
};
</script>
<style>
.page-selectAccounting .ivu-form-item-content {
  display: block;
}
</style>