/*
 * @Author: Anmin
 * @Email:changanmin1@crc.com.hk
 * @Date: 2019-03-15 14:19:17
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-03-15 15:22:15
 * @description:  选择SBU
 * @JIRA:
 */

<template>
  <!-- 选择 SBU -->
  <div>
    <EMSTableNew
      ref="configTable"
      :highlightRow="true"
      :action="action"
      :stripe="false"
      :columns="propsColumns"
      :params="searchForm"
      :onSelectionChange="onSelectRow"
      :rowClickHandle="rowClick"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        inline
        :model="searchForm"
        :label-width="120"
      >
        <FormItem
          prop="coaCode"
          label="SBU编码"
        >
          <Input
            v-model="searchForm.coaCode"
            placeholder="请输入"
            type="text"
          />
        </FormItem>
        <FormItem
          prop="coaName"
          label="SBU专用段名称"
        >
          <Input
            v-model="searchForm.coaName"
            placeholder="请输入"
            type="text"
          />
        </FormItem>
      </Form>
      <div slot="handle-bar">
        <Button
          type="warning"
          @click.native="search"
        >
          查询
        </Button>
        <Button
          type="default"
          @click.native="reset"
        >
          重置
        </Button>
      </div>
    </EMSTableNew>
  </div>
</template>
<script>
export default {
  name: 'SelectSBU',
  props: {
    title: {
      type: String,
      default: '选择SBU专用段'
    }
  },
  data() {
    return {
      // action: '/ems-base-data/coa/findPageForSpecialAll',
      action: '/ems-base-application/coa/findPageForSpecialAll',
      searchForm: {
        coaCode: '',
        coaName: ''
      },
      propsColumns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          resizable: true,
          align: 'center',
        },
        {
          title: 'SBU编码',
          align: 'left',
          key: 'coaCode',
          minWidth: 100,
          resizable: true,
          render: (h, params) => {
            const val = params.row.coaCode || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: 'SBU专用段名称',
          align: 'left',
          key: 'coaName',
          minWidth: 300,
          render: (h, params) => {
            const val = params.row.coaName || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell 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);
    },
    rowClick(selection) {
      if (selection) {
        this.$emit('Close', selection);
      }
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .handle-bar-solt {
  top: 2px !important;
}
/deep/ .ivu-table .ivu-table-cell {
  padding-right: 0 !important;
}
.search_bar{
  margin-bottom: 14px;
}
</style>

