
<template>
  <div>
    <EMSTableNew
      ref="configTable"
      :action="action"
      :columns="propsColumns"
      :params="searchForm"
      :rowClickHandle="onSelectRow"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        :model="searchForm"
        style="height: auto !important;"
        :label-width="100"
      >
        <Row>
          <Col :span="8">
            <FormItem
              prop="subcategoryCode"
              label="业务小类编码"
            >
              <Input
                v-model="searchForm.subcategoryCode"
                placeholder="请输入"
                clearable
                type="text"
                :maxlength="30"
              />
            </FormItem>
          </Col>
          <Col :span="8">
            <FormItem
              prop="subcategoryName"
              label="业务小类名称"
            >
              <Input
                v-model="searchForm.subcategoryName"
                placeholder="请输入"
                clearable
                type="text"
                :maxlength="30"
              />
            </FormItem>
          </Col>  
          <Col :span="8">
            <div class="search_btns ivu-form-item">
              <Button
                type="warning"
                @click.native="search()"
              >
                查询
              </Button>
              <Button
                @click.native="reset"
              >
                重置
              </Button>
            </div>
          </Col>
        </Row>
      </Form>
      
    </EMSTableNew>
  </div>
</template>
<script>
export default {
  name: 'SelectCategory ',
  directives: {},
  props: {
    title: {
      type: String,
      default: '请选择业务小类'
    },
    // 是否开启多选
    selection: {
      type: Boolean,
      default: false
    },
    config: {
      type: Object,
      default: () => {
        return {};
      }
    },
  },
  data() {
    return {
      action: '/ems-base-application/subcategory/findSubcategoryPage',
      selectionData: null,
      /* 搜索框组 */
      searchForm: {
        businessLineCode: [],
        categoryName: '', // 大类名称
        categoryCode: '', // 业务类别
        subcategoryCode: '', // 业务小类编码
        subcategoryName: '', // 业务小类名称
        valid: '', // 有效性
        lang: '' // 多语言编码
      },
      propsColumns: [
        {
          title:'序号',
          type: 'index',
          width: 60,
          resizable: true,
        },
        {
          title: '业务小类编码',
          resizable: true,
          key: 'subcategoryCode'
        },
        {
          title: '业务小类名称',
          resizable: true,
          key: 'subcategoryName'
        }
      ]
    };
  },
  created: function() {
    console.log(this.config)
    this.searchForm.categoryName = this.config.categoryName || ''
    this.searchForm.categoryCode = this.config.categoryCode || ''
    this.$emit('SetTitle', this.title);
    const buttons = [
      {
        text: '确认',
        action: 'save',
        theme: 'warning',
        handle: () => {
          this.save();
        }
      },
      {
        text: '关闭',
        action: 'close',
        handle: () => {
          this.$emit('Close');
        }
      }
    ];
    this.selection && this.$emit('SetPageActions', buttons);
    this.selection && this.$emit('SetTitle', "请选择业务小类");
  },
  beforeMount: function() {},
  mounted: function() {},
  beforeDestroy: function() {},
  destroyed: function() {},
  methods: {
    save() {
      if (this.selection) {
        this.$emit('Close', this.selectionData);
      }
    },
    // 点击数据行
    onSelectRow(selected) {
      this.$emit('Close', selected);
    },
    /**
     * 弹出 业务类别 选择页面
     */
    getBusinessBigClass({ title = '', code = '' } = {}) {
      console.log('157hang',selected)
      this.searchForm.categoryName = title;
      this.searchForm.categoryCode = code;
    },
    /**
     * 业务小类查询 搜索方法
     */
    search(page) {
      this.$refs.configTable.load(this.searchForm, page);
    },
    /**
     * 业务小类查询 重置方法
     * 1.重置所有搜索条件
     * 2.重新拉取数据
     */
    reset() {
      this.$refs.searchForm.resetFields();
      this.search(1);
    }
  }
};
</script>
<style>
</style>
