
<template>
  <div>
    <EMSTableNew
      ref="configTable"
      highlightRow
      :action="action"
      :columnsFn="propsColumns"
      :params="searchForm"
      :rowClickHandle="rowClick"
      class="table_class"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        :model="searchForm"
        :label-width="120"
      >
        <Row>
          <Col span="8">
            <FormItem
              prop="bookTypeCode"
              label="资产账簿编码"
            >
              <Input
                v-model="searchForm.bookTypeCode"
                placeholder="请输入"
                type="text"
                clearable
              />
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem
              prop="bookTypeName"
              label="资产账簿名称"
            >
              <Input
                v-model="searchForm.bookTypeName"
                placeholder="请输入"
                type="text"
                clearable
              />
            </FormItem>
          </col>
        </Row>
      </Form>
      <div slot="handle-bar">
        <Button
          type="warning"
          @click="search()"
        >
          查询
        </Button>
        <Button
          type="default"
          @click.native="reset"
        >
          重置
        </Button>
      </div>
    </EMSTableNew>
  </div>
</template>
<script>
export default {
  name: 'SelectAssetBook',
  props: {
    valid: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '选择资产账簿'
    },
    buCode: {
      type: String,
      default: ''
    },
    disableBU: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // action: '/ems-base-data/account/findPage',
      action: '/ems-base-application/assetsbook/page',
      DataSetBu: null,
      // 搜索表单的属性
      searchForm: {
        bookTypeCode: '',
        bookTypeName: '',
        buCode: ''
      }
    };
  },
  created() {
    this.$emit('SetTitle', this.title);
    this.searchForm.buCode = this.buCode;
    this.valid && (this.searchForm.valid = 'Y');
  },
  mounted() {},
  methods: {
    propsColumns() {
      const self = this;
      return [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center',
          resizable: true
        },
        {
          title: '资产账簿编码',
          align: 'left',
          key: 'bookTypeCode',
          resizable: true,
          minWidth: 100,
          render: (h, params) => {
            const val = params.row.bookTypeCode || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '资产账簿名称',
          align: 'left',
          key: 'bookTypeName',
          minWidth: 300,
          render: (h, params) => {
            const val = params.row.bookTypeName || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
      ];
    },
    // 点击表格行 触发该事件
    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>
.table_class /deep/ .handle-bar-solt {
  top: 2px !important;
}
</style>