<template>
  <div class="value-set-get-parent">
    <BasePageTable
      ref="valueSetTable"
      :action="action"
      :highlightRow="true"
      :columns="columns"
      :initParam="formSearch"
      :onSelectionChange="onSelectionChange"
      border
    >
      <Form
        ref="formSearch"
        slot="search-bar"
        :model="formSearch"
        label-position="right"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <FormItem
          prop="vsCode"
          :label="$t('值集代码')"
        >
          <Input
            v-model="formSearch.vsCode"
            size="small"
            :placeholder="$t('请输入')"
          />
        </FormItem>
        <FormItem
          prop="vsName"
          :label="$t('值集名称')"
        >
          <Input
            v-model="formSearch.vsName"
            size="small"
            :placeholder="$t('请输入')"
          />
        </FormItem>
      </Form>
      <div slot="handle-bar">
        <Button
          style="margin-right:15px;"
          type="warning"
          size="small"
          icon="ios-search"
          @click="search()"
        >
          {{ this.$t("查询") }}
        </Button>
        <Button
          type="primary"
          size="small"
          icon="md-sync"
          @click="reset()"
        >
          {{ this.$t("重置") }}
        </Button>
      </div>
    </BasePageTable>
    <DataSelect
      v-show="false"
      code="YES_OR_NO"
      @loadFinish="loadFinish($event, 'YES_OR_NO')"
    />
    <DataSelect
      v-show="false"
      code="Value_Source"
      @loadFinish="loadFinish($event, 'Value_Source')"
    />
    <DataSelect
      v-show="false"
      code="Value_Set_Type"
      @loadFinish="loadFinish($event, 'Value_Set_Type')"
    />
  </div>
</template>
<script>
import { selectInputUrls } from '../server.js';
export default {
  data() {
    return {
      action: '/ems-base-application/mams/sys/valueset/list/page',
      formSearch: {
        vsCode: '',
        vsName: '',
        enabled: 1
      },
      dataSet: {
        YES_OR_NO: null,
        Value_Source: null,
        Value_Set_Type: null
      },
      columns: [
        {
          type: 'selection',
          width: 50,
          align: 'center'
        },
        {
          title: '序号',
          type: 'index',
          align: 'center',
          width: 80
        },
        {
          title: this.$t('值集代码'),
          align: 'center',
          key: 'vsCode',
          minWidth: 150,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.vsCode || ''
                }
              },
              params.row.vsCode || ''
            );
          }
        },
        {
          title: this.$t('值集名称'),
          align: 'center',
          key: 'vsName',
          minWidth: 150,
          render: (h, params) => {
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.vsName || ''
                }
              },
              params.row.vsName || ''
            );
          }
        },
        {
          title: this.$t('值集类型'),
          align: 'center',
          key: 'vsType',
          width: 100,
          render: (h, params) => {
            let vsTypeVal = '';
            if (this.dataSet.Value_Set_Type) {
              vsTypeVal = this.dataSet.Value_Set_Type[params.row.vsType] || '';
            }
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: vsTypeVal
                }
              },
              vsTypeVal
            );
          }
        },
        {
          title: this.$t('值来源'),
          align: 'center',
          key: 'vsValueSource',
          width: 100,
          render: (h, params) => {
            let vsValueSourceVal = '';
            if (this.dataSet.Value_Source) {
              vsValueSourceVal = this.dataSet.Value_Source[params.row.vsValueSource] || '';
            }
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: vsValueSourceVal
                }
              },
              vsValueSourceVal
            );
          }
        },
        {
          title: this.$t('启用'),
          align: 'center',
          key: 'enabled',
          width: 70,
          render: (h, params) => {
            let validVal = '';
            if (this.dataSet.YES_OR_NO) {
              validVal = this.dataSet.YES_OR_NO[params.row.enabled];
            }
            return h(
              'div', {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: validVal
                }
              },
              validVal
            );
          }
        }
      ]
    };
  },
  created: function() {
    this.$emit('SetTitle', this.$t('选择父值集'));
    this.$emit('SetPageSize', 1000);
  },
  methods: {
    loadFinish(data, code) {
      this.dataSet[code] = data.valueMap;
    },
    search(page) {
      this.$refs.valueSetTable.load(this.formSearch, page);
    },
    reset() {
      this.$refs.formSearch.resetFields();
      this.search(1);
    },
    onSelectionChange(list) {
      if (list && list.length) {
        this.$emit('Close', list[0]);
      }
    }
  }
};
</script>
<style lang="less">
.value-set-get-parent {
  .base-page-table {
    .run-search-bar {
      .search-bar {
        height: auto;
      }
    }
  }
  .search-form-more {
    display: none;
  }
}
</style>
