/*
 * @Author: lisl
 * @Date: 2019-10-25
 * @Last Modified by: lisl
 * @Last Modified time: 2019-10-25
 * @description:  组件:移动起草模板选择
 */

<template>
  <div>
    <EMSTable
      ref="configTable"
      :highlightRow="true"
      action="/mobile-service/approvalConfigCtl/templeteQuery"
      :columnsFn="propsColumns"
      :params="searchForm"
      :onSelectionChange="onSelectRow"
    >
      <Form
        ref="searchForm"
        slot="search-bar"
        :model="searchForm"
        class="ivu-form-no-margin-bottom"
        inline
      >
        <!-- 表单  -->
        <FormItem
          prop="tmpName"
          label="模板名称"
        >
          <Input
            v-model="searchForm.tmpName"
            placeholder="请输入"
            clearable
            type="text"
            :maxlength="40"
          />
        </FormItem>
        <FormItem
          prop="tmpCode"
          label="模板编码"
        >
          <Input
            v-model="searchForm.tmpCode"
            placeholder="请输入"
            clearable
            type="text"
            :maxlength="40"
          />
        </FormItem>
      </Form>
      <div slot="handle-bar">
        <Button
          type="warning"
          icon="ios-search"
          @click="search()"
        >
          查询
        </Button>
        <Button
          type="info"
          icon="ios-refresh"
          @click.native="reset"
        >
          重置
        </Button>
      </div>
    </EMSTable>
  </div>
</template>
<script>
export default {
  name: 'SelectMobileTemplete',
  props: {
    title: {
      type: String,
      default: '请选择移动起草模板'
    }
  },
  data() {
    return {
      DataSetBu: null,
      // 搜索表单的属性
      searchForm: {
        tmpName: '', // 模板名称
        tmpCode: '', // 模板编码
        enabled: 'Y'// 启用停用
      }
    };
  },
  created() {
    this.$emit('SetTitle', this.title);
  },
  mounted() {},
  methods: {
    propsColumns() {
      return [
        {
          type: 'selection',
          width: 45,
          align: 'center'
        },
        {
          title: '模板名称',
          align: 'center',
          key: 'tmpName',
          minWidth: 150
        },
        {
          title: '模板编码',
          align: 'center',
          key: 'tmpCode',
          minWidth: 170
        },
        {
          title: '描述',
          align: 'center',
          key: 'remark',
          minWidth: 180,
          render: (h, params) => {
            return h(
              'div',
              {
                attrs: {
                  class: 'ivu-table-cell ivu-table-cell-ellipsis',
                  title: params.row.remark
                }
              },
              params.row.remark
            );
          }
        }
      ];
    },
    // 点击表格行 触发该事件
    onSelectRow(selected = []) {
      if (selected.length == 0) {
        return;
      }
      if (selected.length > 1) {
        this.$Message.warning({
          content: '只能选择一条数据',
          duration: 5
        });
        return;
      }
      this.$emit('Close', selected[0]);
    },
    search(page = 1) {
      // 搜索数据
      this.$refs.configTable.load(this.searchForm, page);
    },
    reset() {
      this.$refs.searchForm.resetFields();
      this.search(1);
    }
  }
};
</script>
