/*
 * @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: 选择WBS项目管理
 */
<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="wbsCode" label="WBS项目编码">
              <Input v-model="searchForm.wbsCode" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem prop="wbsDescribe" label="WBS项目描述">
              <Input v-model="searchForm.wbsDescribe" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>

          <Col span="8">
            <FormItem prop="costcenterDescribe" label="责任成本中心描述">
              <Input v-model="searchForm.costcenterDescribe" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem prop="projectLeadName" label="WBS项目负责人">
              <Input v-model="searchForm.projectLeadName" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem prop="companyCode" label="公司名称">
              <Input v-model="searchForm.companyCode" placeholder="请输入" type="text"></Input>
            </FormItem>
          </Col>
          <Col span="8">
            <FormItem prop="emsIsValidity" label="启用">
              <Input v-model="searchForm.emsIsValidity" 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 "请选择成本中心";
      },
    },
    action: {
      type: String,
      default() {
        return "/ems-base-application/wbsProject/findByPage";
      },
    },
    // 其他参数
    extparams: {
      type: Object,
      default() {
        return {};
      },
    },
  },
  data() {
    return {
      searchForm: {
        wbsCode: "",
        wbsDescribe: "",
        companyCode: "",
        projectLeadName: "",
        emsIsValidity: "", // 启用
      },
    };
  },
  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: this.$t("WBS项目编码"),
          align: "left",
          key: "wbsCode",
          width: 180,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.wbsCode,
                },
              },
              params.row.wbsCode
            );
          },
        },

        {
          title: this.$t("WBS项目描述"),
          align: "left",
          key: "wbsDescribe",
          width: 200,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.wbsDescribe,
                },
              },
              params.row.wbsDescribe
            );
          },
        },

        {
          title: this.$t("责任成本中心编码"),
          width: 130,
          resizable: true,
          align: "left",
          key: "costcenterCode",
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costcenterCode,
                },
              },
              params.row.costcenterCode
            );
          },
        },
        {
          title: this.$t("责任成本中心描述"),
          align: "left",
          key: "costcenterDescribe",
          width: 150,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.costcenterDescribe,
                },
              },
              params.row.costcenterDescribe
            );
          },
        },

        {
          title: this.$t("WBS项目负责人"),
          width: 120,
          resizable: true,
          align: "left",
          key: "projectLeadName",
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.projectLeadName,
                },
              },
              params.row.projectLeadName
            );
          },
        },
        {
          title: this.$t("公司代码"),
          width: 120,
          resizable: true,
          align: "lrft",
          key: "companyCode",
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.companyCode,
                },
              },
              params.row.companyCode
            );
          },
        },
        {
          title: this.$t("公司名称"),
          width: 220,
          resizable: true,
          align: "left",
          key: "companyName",
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell-ellipsis",
                  title: params.row.companyName,
                },
              },
              params.row.companyName
            );
          },
        },
        {
          title: this.$t("启用"),
          align: "left",
          key: "emsIsValidity ",
          width: 120,
          render: (h, params) => {
            return h("div", {}, params.row.emsIsValidity == "Y" ? "是" : "否");
          },
        },

        {
          title: this.$t("最后更新时间"),
          minWidth: 150,
          resizable: true,
          align: "left",
          key: "updatedTime",
          render: (h, params) => {
            let d = params.row.updatedTime || "";
            if (d) {
              d = new Date(d);
              if (d.Format) {
                d = d.Format("yyyy-MM-dd  hh:mm:ss");
              }
            }
            return h("div", {}, d);
          },
        },
      ];
    },
    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>
