/*
 * @Author: Anmin
 * @Email:changanmin1@crc.com.hk
 * @Date: 2019-07-24 15:51:09
 * @Last Modified by: Anmin
 * @Last Modified time: 2019-07-24 15:59:56
 * @description:  选择项目
 * @JIRA:
 */
<template>
  <div>
    <EMSTableNew
      ref="projectTable"
      :params="searchForm"
      :columns="columns"
      :action="action"
      highlight-row
      :rowClickHandle="onRowClick"
    >
      <Form ref="searchForm" slot="search-bar" inline :label-width="120">
        <FormItem label="项目编码">
          <Input v-model="searchForm.projectCode" type="text" placeholder="请输入"></Input>
        </FormItem>
        <FormItem label="项目名称">
          <Input v-model="searchForm.projectName" type="text" placeholder="请输入"></Input>
        </FormItem>
      </Form>
      <div slot="handle-bar">
        <Button type="warning" @click.native="search">查询</Button>
        <Button type="default" @click.native="reset">重置</Button>
      </div>
    </EMSTableNew>
  </div>
</template>
<script>
export default {
  name: "SelectProject",
  props: {
    title: {
      type: String,
      default() {
        return "请选择项目";
      }
    },
    // 是否有效 Y-有效，N-无效
    isValidity: {
      type: String,
      default() {
        return "Y";
      }
    },
    // 是否允许过账 Y-允许，N-不允许
    isPost: {
      type: String,
      default() {
        return "Y";
      }
    },
    // 归属公司
    companyCode: {
      type: String,
      default() {
        return "";
      }
    },
    // 安全性筛选字段   若使用安全性筛选则传1
    securityEnabled: {
      type: String,
      default() {
        return "";
      }
    }
  },
  data() {
    return {
      // action: '/ems-base-data/project/findPagedProjectList',
      action: "/ems-base-application/project/findPagedProjectList",
      searchForm: {
        projectName: "",
        projectCode: "",
        isValidity: this.isValidity,
        isPost: this.isPost,
        ouCode: this.companyCode,
        securityEnabled: this.securityEnabled
      },
      columns: [
        {
          title: "BU编码",
          key: "buCode",
          width: 180,
          resizable: true
        },
        {
          title: "项目名称",
          minWidth: 180,
          resizable: true,
          render: (h, params) => {
            return h(
              "div",
              {
                attrs: {
                  class: "ivu-table-cell ivu-table-cell-ellipsis",
                  title: params.row.projectName
                }
              },
              params.row.projectName
            );
          }
        },
        {
          title: "项目编码",
          key: "projectCode",
          width: 180,
          resizable: true
        },
        {
          title: "是否有效",
          width: 110,
          resizable: true,
          render: (h, params) => {
            const val = params.row.isValidity ? '有效' : '无效';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        },
        {
          title: "是否允许过账",
          width: 130,
          render: (h, params) => {
            const val = params.row.isPost ? '有效' : '无效';
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: val
                }
              },
              val
            );
          }
        }
      ]
    };
  },
  created: function() {
    this.$emit("SetTitle", this.title);
  },
  mounted: function() {
    this.$emit("SetPageSize", window.innerWidth * 0.85);
  },
  methods: {
    search(page = 1) {
      this.$refs.projectTable.load(this.searchForm, page);
    },
    reset() {
      this.searchForm.projectName = "";
      this.searchForm.projectCode = "";
      this.search();
    },
    // 点击数据行
    onSelectionChange(selected) {
      if (selected.length == 0) {
        return;
      }
      if (selected.length > 1) {
        this.$Message.warning({
          content: "只能选择一条数据",
          duration: 5
        });
        return;
      }
      this.$emit("Close", selected[0]);
    },
    // 双击
    onRowClick(selected, index) {
      this.$emit("Close", selected);
    }
  }
};
</script>
<style lang="less" scoped>
/deep/  .emstable-wrap-new .handle-bar-solt {
    top: 4px !important;
  }
</style>
