/*
 * @Author: Anmin
 * @Email:changanmin1@crc.com.hk
 * @Date: 2018-12-19 11:38:12
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-06-28 10:30:23
 * @description:  预算科目Table
 */
<template>
  <EMSTableNew
    ref="budgetSubjectTable"
    :action="action"
    :onSelectionChange="onSelectRow"
    :columns="columns"
    :params="searchForm"
    :rowClickHandle="rowClick"
    >
    <Form
      ref="searchForm"
      slot="search-bar"
      :model="searchForm"
      :label-width="120"
    >
    <Row>
      <Col span="8">
        <FormItem
          prop="code"
          label="科目编码"
        >
          <Input
            v-model="searchForm.code"
            type="text"
            placeholder="请输入"
            clearable
          />
        </FormItem>
      </Col>
      <Col span="8">
        <FormItem
          prop="name"
          label="科目名称"
        >
          <Input
            v-model="searchForm.name"
            type="text"
            placeholder="请输入"
            clearable
          />
        </FormItem>
      </Col>
      <Col span="8">
        <FormItem
          prop="buCode"
          label="所属BU"
        >
          <DataSelect
            v-model="searchForm.buCode"
            placeholder="请选择"
            transfer
            clearable
            code="BU"
            :disabled="disableBU"
            @loadFinish="({valueMap = null} = {})=>dataSet.BU= valueMap"
          ></DataSelect>
        </FormItem>
      </Col>
    </Row>
    </Form>
    <div slot="handle-bar">
      <Button
        type="warning"
        @click.native="search"
      >
        查询
      </Button>
      <Button
        type="default"
        @click.native="reset"
      >
        重置
      </Button>
    </div>
  </EMSTableNew>
</template>
<script>
export default {
  name: 'SelectBudgetSubject',
  props: {
    title: {
      type: String,
      default: '选择预算科目'
    },
    isParent: {
      type: String,
      default: ''
    },
    buCode: {
      type: String,
      default: ''
    },
    disableBU: {
      type: Boolean,
      default: false
    },
    isFilter: {
      type: String,
      default: ''
    },
    ouCode: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      action: '/budget-service/budgetAppSubjectTemplate/list',
      searchForm: {
        subjectName: '',
        isParent: this.isParent,
        buCode: '',
        valid: true,
        isFilter: this.isFilter,
        ouCode : this.ouCode
      },
      dataSet: {
        BU: null
      },
      columns: [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center',
          resizable: true
        },
        {
          title: '科目编码',
          align: 'left',
          key: 'code',
          minWidth: 100,
          resizable: true,
          render: (h, params) => {
            const val = params.row.code || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '科目名称',
          align: 'left',
          key: 'name',
          minWidth: 300,
          resizable: true,
          render: (h, params) => {
            const val = params.row.name || '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: '所属BU',
          minWidth: 80,
          align: 'left',
          key: 'buCode',
          render: (h, params) => {
            const val = params.row.buCode && this.dataSet.BU ? this.dataSet.BU[params.row.buCode] : '';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
      ]
    };
  },
  computed: {},
  created() {
    this.$emit('SetTitle', this.title);
    this.searchForm.buCode = this.buCode;
  },
  mounted() {},
  methods: {
    onSelectRow(data) {
      if (data.length == 0) return;
      this.$emit('Close', data[0]);
    },
    search() {
      this.$refs.budgetSubjectTable.load(this.searchForm);
    },
    reset() {
      this.$refs.searchForm.resetFields();
      this.$refs.budgetSubjectTable.load(this.searchForm);
    },
    rowClick(selection) {
      if (selection) {
        this.$emit('Close', selection);
      }
    }
  }
};
</script>
<style scoped>
.emstable-wrap-new .search-form form {
  height: 82px !important;
}
.emstable-wrap-new /deep/ .handle-bar-solt {
  top: 42px;
  right: 0;
}
.emstable-wrap-new .handle-bar .ivu-btn-default {
  margin-right: 0;
}
</style>