<template>
  <div class="page-selectAccounting">
    <EMSTable
      ref="configTable"
      action="query"
      :server="server"
      :stripe="false"
      :columns="propsColumns"
      :params="searchForm"
      :highlight-row="true"
      :onSelectionChange="onSelectRow"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        :model="searchForm"
        label-position="top"
        class="ivu-form-no-margin-bottom"
      >
        <Form-item
          prop="customerNumber"
          label="客户编码"
        >
          <Input
            v-model="searchForm.customerNumber"
            type="text"
            clearable
          />
        </Form-item>
        <Form-item
          prop="customerName"
          label="客户名称"
        >
          <Input
            v-model="searchForm.customerName"
            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: 'SelectCustomerEdit',
  props: {
    title: {
      type: String,
      default: '客户查询'
    },
    customerName: {
      type: String,
      default: ''
    },
    compCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      server: server,
      // 搜索表单的属性
      searchForm: {
        customerNumber: '',
        customerName: this.customerName,
        compCode: this.compCode
      },
      propsColumns: [
        {
          type: 'selection',
          align: 'center',
          width: 60,
          fixed: 'left'
        },
        {
          title: '客户名称',
          align: 'left',
          key: 'customerName',
          minWidth: 100,
          render: (h, params) => {
            const val = params.row.customerName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '客户编码',
          align: 'left',
          key: 'customerNumber',
          width: 100,
          render: (h, params) => {
            const val = params.row.customerNumber;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '客户地点',
          align: 'left',
          key: 'partySiteName',
          minWidth: 200,
          render: (h, params) => {
            const val = params.row.partySiteName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '银行账号',
          align: 'left',
          key: 'bankAccount',
          minWidth: 100,
          render: (h, params) => {
            const val = params.row.bankAccount;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '公司名称',
          align: 'left',
          key: 'orgName',
          minWidth: 100,
          render: (h, params) => {
            const val = params.row.orgName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
      ]
    };
  },
  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>
<style>
.page-selectAccounting .ivu-form-item-content {
  display: block;
}
</style>
