<template>
  <div class="page-selectAccounting">
    <EMSTable
      ref="configTable"
      action="query"
      :server="server"
      :stripe="false"
      :columns="propsColumns"
      :params="searchForm"
      :highlight-row="true"
      :rowClickHandle="onSelectRow"
      :rowClickExpand="onExpHandler"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        :model="searchForm"
        label-position="top"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <Form-item
          prop="compName"
          :label="`${this.$t('收款单位')}${this.$t('名称')}`"
        >
          <Input
            v-model="searchForm.compName"
            type="text"
            clearable
          />
        </Form-item>
        <Form-item
          prop="bankAccountName"
          :label="this.$t('银行账户名')"
        >
          <Input
            v-model="searchForm.bankAccountName"
            type="text"
            clearable
          />
        </Form-item>
        <Form-item
          prop="bankAccountNum"
          :label="this.$t('银行账号')"
        >
          <Input
            v-model="searchForm.bankAccountNum"
            type="text"
            clearable
          />
        </Form-item>
        <Form-item
          prop="bankCurrencyCode"
          :label="this.$t('币种')"
        >
          <Input
            v-model="searchForm.bankCurrencyCode"
            type="text"
            clearable
          />
        </Form-item>
      </Form>
      <div slot="handle-bar">
        <Button
          type="warning"
          icon="search"
          @click.native="search()"
        >
          {{ this.$t('查询') }}
        </Button>
        <Button
          type="info"
          icon="loop"
          @click.native="reset"
        >
          {{ this.$t('重置') }}
        </Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
import Server from './server.js';
const server = new Server();
export default {
  name: 'SelectCompCodeList',
  props: {
    title: {
      type: String,
      default: '公司查询'
    }
  },
  data() {
    return {
      server: server,
      // 搜索表单的属性
      searchForm: {
        bankAccountName: '',
        bankAccountNum: '',
        compName: '',
        bankCurrencyCode: ''
      },
      propsColumns: [
        {
          title: `${this.$t('收款单位')}${this.$t('名称')}`,
          key: 'compName',
          align: 'left',
          render: (h, params) => {
            const val = params.row.compName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: this.$t('银行账户名'),
          key: 'bankAccountName',
          align: 'left',
          render: (h, params) => {
            const val = params.row.bankAccountName;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: this.$t('银行账号'),
          key: 'bankAccountNum',
          align: 'left',
          render: (h, params) => {
            const val = params.row.bankAccountNum;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: this.$t('币种'),
          key: 'bankCurrencyCode',
          align: 'left',
          render: (h, params) => {
            const val = params.row.bankCurrencyCode;
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
      ]
    };
  },
  created() {
    this.$emit('SetTitle', this.title);
    // this.$emit('SetPageSize',800);
  },
  mounted() {},
  methods: {
    // 点击表格行 触发该事件
    onSelectRow(row) {
      if (row.length == 0) {
        return;
      }
      if (row._blank) {
        this.$Message.warning({
          content: this.$t('请选择有内容的一行')
        });
        return;
      }
      this.$emit('Close', row);
    },
    search(page = 1) {
      // 搜索数据
      this.$refs.configTable.load(this.searchForm, page);
    },
    reset() {
      this.$refs.searchForm.resetFields();
      this.search(1);
    },
    onExpHandler() {}
  }
};
</script>
<style>
.page-selectAccounting .ivu-form-item-content {
  display: block;
}
</style>
