<template>
  <PageTableNew
    ref="projectTable"
    class="reset-search-form"
    :params="searchForm"
    :initParam="searchForm"
    action="/ems-process-service/psc/procdef/pscActReProcdef/list/page"
    :columns="columns"
    :onSelectionChange="onSelectionChange"
  >
    <Form
      ref="searchForm"
      slot="search-bar"
      class="ivu-form-no-margin-bottom"
      :label-width="100"
      inline
    > 
      <FormItem
        prop="isRunVersion"
        label="是否正在运行"
      >
        <Select
          v-model="searchForm.isRunVersion"
          transfer
          size="small"
          clearable
        >
          <Option value="0">
            是
          </Option>
          <Option value="1">
            否
          </Option>
        </Select>
      </FormItem>
      <FormItem
        prop="procdefName"
        label="流程名称"
      >
        <Input
          v-model="searchForm.procdefName"
          size="small"
          placeholder="请输入"
        ></Input>
      </FormItem>
      <FormItem
        prop="version"
        label="流程版本"
      >
        <Input
          v-model="searchForm.version"
          size="small"
          placeholder="请输入"
        ></Input>
      </FormItem>
      <div class="search_btns ivu-form-item">
        <Button
          type="warning"
          size="small"
          @click.native="search"
        >
          {{ $t('查询') }}
        </Button>
        <Button
          size="small"
          @click.native="reset"
        >
          {{ $t('重置') }}
        </Button>
      </div>
    </Form>
  </PageTableNew>
</template>
<script>
export default {
  name: 'SelectProcess',
  components: {},
  directives: {},
  props: {
    title: {
      type: String,
      default() {
        return '请选择流程';
      }
    }
  },
  data() {
    return {
      searchForm: {
        procdefName: '',
        version: '',
        isRunVersion: '0'
        // createDate: ""
      },
      columns: [
        {
          type: 'selection',
          width: 60,
          align: 'center'
        },
        {
          title: '流程名称',
          key: 'procdefName',
          align: 'left',
          minWidth: 180,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.procdefName || ''
                }
              },
              params.row.procdefName || ''
            );
          }
        },

        {
          title: '流程编码',
          key: 'procdefId',
          align: 'left',
          minWidth: 250,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.procdefId || ''
                }
              },
              params.row.procdefId || ''
            );
          }
        },
        {
          title: '当前版本', // 2018/10/ 17:10 于海宁 版本改为当前运行版本
          key: 'version',
          align: 'left',
          width: 70
        },
        {
          title: '是否正在运行',
          align: 'left',
          key: 'isRunVersionView',
          width: 100,
          render: (h, params) => {
            return params.row.isRunVersionView ? h(
              'span',
              params.row.isRunVersionView
            ) : null;
          }
        },
        {
          title: '创建时间',
          key: 'createDate',
          align: 'left',
          width: 170,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.createDate || ''
                }
              },
              params.row.createDate || ''
            );
          }
        },
        {
          title: '更新时间',
          key: 'updateDate',
          align: 'left',
          width: 170,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell-ellipsis',
                  title: params.row.updateDate || ''
                }
              },
              params.row.updateDate || ''
            );
          }
        }
      ]
    };
  },
  computed: {},
  watch: {},
  created: function() {
    this.$emit('SetTitle', this.title);
    this.$emit('SetSize', 1104);
    // this.search();
  },
  beforeMount: function() { },
  mounted: function() {
    this.$emit('SetPageSize', window.innerWidth * 0.65);
  },
  beforeDestroy: function() { },
  destroyed: function() { },
  methods: {
    search(page = 1) {
      this.$refs.projectTable.load(this.searchForm, page);
    },
    reset() {
      this.searchForm.procdefName = '';
      this.searchForm.version = '';
      this.searchForm.isRunVersion = '0';

      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]);
    }
  }
};
</script>
<style lang="less" scoped>
</style>
