/*
 * @Author: Anmin
 * @Email:changanmin1@crc.com.hk
 * @Date: 2019-03-14 16:40:19
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-03-14 17:31:53
 * @description: 选择成本中心
 */
<template>
  <div>
    <EMSTableNew
      ref="costCenterTable"
      :action="action"
      :params="searchForm"
      :columnsFn="codeColumns"
      :highlight-row="true"
      :rowClickHandle="rowClick"
    >
      <Form ref="searchForm" slot="search-bar" :labelWidth="100" :model="searchForm" style="margin-bottom: 16px">
        <Row>
          <Col span="8">
            <FormItem prop="costCenterCode" label="成本中心编码">
              <Input v-model="searchForm.costCenterCode" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem prop="costCenterName" label="成本中心名称">
              <Input v-model="searchForm.costCenterName" placeholder="请输入" type="text"></Input>
            </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: "SelectCostCenter",
  directives: {},
  props: {
    title: {
      type: String,
      default() {
        return "请选择成本中心";
      },
    },
     companyCode: {
      type: String,
      default() {
        return "";
      },
    },
    action: {
      type: String,
      default() {
        return "/ems-base-application/mdCostCenter/findPage";
      },
    },
    // 其他参数
    extparams: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      searchForm: {
        costCenterCode: "",
        costCenterName: "",
        companyCode: this.companyCode
      },
    };
  },
  created: function () {
    this.$emit("SetTitle", this.title);
    this.searchForm = { ...this.searchForm, ...this.extparams };
  },
  methods: {
    // 获取成本中心
    codeColumns() {
      return [
        {
          title: "序号",
          type: "index",
          width: 60,
          resizable: true,
          align: "center",
        },
        {
          title: "成本中心编码",
          align: "left",
          key: "costCenterCode",
          width: 200,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costCenterCode,
                },
              },
              params.row.costCenterCode
            );
          },
        },
        {
          title: "成本中心名称",
          key: "costCenterName",
          align: "left",
          width: 200,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costCenterName,
                },
              },
              params.row.costCenterName
            );
          },
        },
        {
          title: "成本中心属性",
          key: "costCenterPropertyName",
          align: "left",
          width: 200,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costCenterPropertyName,
                },
              },
              params.row.costCenterPropertyName
            );
          },
        },
        {
          title: "负责人工号",
          resizable: true,
          key: "costcenterLeadCode",
          align: "left",
          width: 150,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costcenterLeadLDAP,
                },
              },
              params.row.costcenterLeadLDAP
            );
          },
        },
        {
          title: "负责人姓名",
          key: "costcenterLeadName",
          align: "left",
          minWidth: 150,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costcenterLeadName,
                },
              },
              params.row.costcenterLeadName
            );
          },
        },
      ];
    },
    search(page = 1) {
      this.$refs.costCenterTable.load(this.searchForm, page);
    },
    reset() {
      this.searchForm.costCenterCode = "";
      this.searchForm.costCenterName = "";
      this.search(1);
    },
    rowClick(selection) {
      if (selection) {
        this.$emit("Close", selection);
      }
    },
  },
};
</script>
