 <!--
   @Author: husanfeng
   @qq:1136014061
   @Date: 2018-09-21
   @Last Modified by: husanfeng
   @Last Modified time: 2018-09-21
 -->
<template>
  <div>
    <EMSTable
      ref="configTable"
      action="query"
      :server="server"
      :stripe="false"
      :columns="propsColumns"
      :params="searchForm"
      :highlight-row="true"
      :onSelectionChange="onSelectRow"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        label-position="top"
        inline
        :model="searchForm"
        class="ivu-form-no-margin-bottom"
      >
        <Form-item
          prop="costCenterCode"
          label="成本中心编码"
        >
          <Input
            v-model="searchForm.costCenterCode"
            type="text"
            clearable
          />
        </Form-item>
        <Form-item
          prop="costCenterName"
          label="成本中心名称"
        >
          <Input
            v-model="searchForm.costCenterName"
            type="text"
            clearable
          />
        </Form-item>
      </Form>
      <div slot="handle-bar">
        <Button
          type="warning"
          icon="search"
          @click.native="search()"
        >
          查询
        </Button>
        <Button
          type="info"
          icon="loop"
          @click.native="reset"
        >
          重置
        </Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
import Server from './server.js';
const server = new Server();
export default {
  name: 'SelectmdCostCenterList',
  components: {
  },
  props: {
    title: {
      type: String,
      default: '客户查询'
    },
    compCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      server: server,
      // 搜索表单的属性
      searchForm: {
        ouCode: this.compCode,
        costCenterName: '',
        costCenterCode: '',
        securityEnabled: 1
      },
      propsColumns: [
        {
          type: 'selection',
          align: 'center',
          width: 60,
          fixed: 'left'
        },
        {
          title: '成本中心名称',
          align: 'left',
          key: 'costCenterName',
          minWidth: 200,
          render: (h, params) => {
            const val = params.row.costCenterName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '成本中心编码',
          align: 'left',
          key: 'costCenterCode',
          minWidth: 200,
          render: (h, params) => {
            const val = params.row.costCenterCode;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
        // {
        //   title: "所属单位编码",
        //   align: "left",
        //   key: "companyCode",
        //   minWidth: 200
        // }
      ]
    };
  },
  created() {
    this.$emit('SetTitle', this.title);
  },
  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>
