/*
 * @Author: Anmin
 * @Email:changanmin1@crc.com.hk
 * @Date: 2019-03-14 11:35:45
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-07-07 02:22:45
 * @description:  COA
 */

<template>
  <EMSTableNew
    ref="searchForm"
    :action="action"
    :params="searchForm"
    :columnsFn="columns"
    :highlight-row="true"
    :onSelectionChange="onSelectionChange"
    :rowClickHandle="rowClick"
  >
    <Form
      ref="searchForm"
      slot="search-bar"
      :model="searchForm"
      :label-width="80"
        inline
    >
      <FormItem
        prop="buCode"
        label="BU"
      >
        <Input
          v-model="searchForm.buCode"
          type="text"
          placeholder="请输入"
          :disabled="buCode !==''"
        ></Input>
      </FormItem>
      <FormItem
        prop="coaCode"
        label="值代码"
      >
        <Input
          v-model="searchForm.coaCode"
          type="text"
          placeholder="请输入"
        ></Input>
      </FormItem>
      <FormItem
        prop="coaName"
        label="值名称"
      >
        <Input
          v-model="searchForm.coaName"
          placeholder="请输入"
          type="text"
        ></Input>
      </FormItem>
    </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: 'SelectCOA',
  directives: {},
  props: {
    title: {
      type: String,
      default() {
        return '请选择COA';
      }
    },
    action: {
      type: String,
      default() {
        return '';
      }
    },
    buCode: {
      type: String,
      default() {
        return ''
      }
    }
  },
  data() {
    return {
      searchForm: {
        coaCode: '',
        coaName: '',
        buCode:'',
        emsIsValidity:'Y',
        isValidity:'Y',
        coaType: '4'
      }
    };
  },
  created: function() {
    this.searchForm.buCode = this.buCode
    this.$emit('SetTitle', this.title);
  },
  methods: {
    columns() {
      return [
        {
          title: '序号',
          type: 'index',
          width: 60,
          align: 'center',
          resizable: true
        },
        {
          title: '值集代码',
          align: 'center',
          key: 'coaType',
          width: 100
        },
        {
          title: '值代码',
          align: 'center',
          key: 'coaCode',
          width: 140,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.coaCode
                }
              },
              params.row.coaCode
            );
          }
        },
        {
          title: '值名称',
          align: 'center',
          key: 'coaName ',
          minWidth: 150,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.coaName
                }
              },
              params.row.coaName
            );
          }
        },
        {
          title: '所属BU',
          align: 'center',
          key: 'buCode',
          minWidth: 80
        },
        {
          title: '层级',
          align: 'center',
          key: 'coaLevel',
          width: 80,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.coaLevel
                }
              },
              params.row.coaLevel
            );
          }
        },
        {
          title: '父级',
          width: 80,
          align: 'center',
          key: 'parentValue ',
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.parentValue
                }
              },
              params.row.parentValue
            );
          }
        },
        // {
        //   title: '有效日期起',
        //   align: 'center',
        //   key: 'effectiveDateStart ',
        //   width: 80,
        //   render: (h, params) => {
        //     return h(
        //       'div',
        //       {
        //         attrs: {
        //           class: 'ivu-table-cell ivu-table-cell-ellipsis',
        //           title: params.row.effectiveDateStart
        //         }
        //       },
        //       params.row.effectiveDateStart
        //     );
        //   }
        // },
        // {
        //   title: '有效日期止',
        //   align: 'center',
        //   key: 'effectiveDateEnd ',
        //   width: 80,
        //   render: (h, params) => {
        //     return h(
        //       'div',
        //       {
        //         attrs: {
        //           class: 'ivu-table-cell ivu-table-cell-ellipsis',
        //           title: params.row.effectiveDateEnd
        //         }
        //       },
        //       params.row.effectiveDateEnd
        //     );
        //   }
        // },
        // {
        //   title: 'ERP有效性',
        //   align: 'center',
        //   key: 'isValidity ',
        //   width: 90,
        //   render: (h, params) => {
        //     return params.row.isValidity ? h(
        //       'Tag',
        //       {
        //         props: {
        //           type: 'dot',
        //           color: params.row.isValidity == 'Y' ? 'warning' : 'error'
        //         }
        //       },
        //       params.row.isValidity == 'Y' ? '有效' : '无效'
        //     ) : null;
        //   }
        // },
        // {
        //   title: 'EMS有效性',
        //   align: 'center',
        //   key: 'emsIsValidity ',
        //   width: 90,
        //   render: (h, params) => {
        //     return params.row.emsIsValidity ? h(
        //       'Tag',
        //       {
        //         props: {
        //           type: 'dot',
        //           color: params.row.emsIsValidity == 'Y' ? 'warning' : 'error'
        //         }
        //       },
        //       params.row.emsIsValidity == 'Y' ? '有效' : '无效'
        //     ) : null;
        //   }
        // }
      ];
    },
    search(page = 1) {
      this.$refs.searchForm.load(this.searchForm, page);
    },
    reset() {
      this.searchForm.coaCode = '';
      this.searchForm.coaName = '';
      this.search(1);
    },
    // 点击数据行
    onSelectionChange(selected) {
      if (selected.length == 0) {
        return;
      }
      if (selected.length > 1) {
        this.$Message.warning({
          content: '只能选择一条数据',
          duration: 5
        });
        return;
      }
      this.$emit('Close', selected[0]);
    },
    // 获取产品 /ems-base-data/coa/findPageForProductAll
    // 获取关联方 /ems-base-data/coa/findPageForRelativeAll
    // 获取地区 /ems-base-data/coa/findPageForAreaAll
    // 获取专用 /ems-base-data/coa/findPageForSpecialAll
    // 获取备用 /ems-base-data/coa/findPageForSpareAll,
    rowClick(selection) {
      if (selection) {
        this.$emit('Close', selection);
      }
    }
  }
};
</script>
<style scoped>
/deep/ .handle-bar-solt {
  top: 2px !important;
}
/deep/ .ivu-table .ivu-table-cell {
  padding-right: 0 !important;
}
.search_bar{
  margin-bottom: 14px;
}
</style>

