<template>
  <el-dialog
    :title="$t('尺码组选择')"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal="false"
    width="80%"
    center
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="90px"
    >
      <el-form-item :label="$t('尺码组编码')" prop="sizeGroupCode">
        <el-input
          v-model="queryParams.sizeGroupCode"
         
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('尺码组名称')" prop="sizeGroupName">
        <el-input
          v-model="queryParams.sizeGroupName"
         
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="$t('尺码组类型')" prop="sizeType">
        <el-select
          v-model="queryParams.sizeType"
         
          clearable
        >
          <el-option :label="$t('请选择字典生成')" value="" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('是否启用')" prop="enableFlag">
        <el-input
          v-model="queryParams.enableFlag"
         
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >{{ $t('common.search') }}</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >{{ $t('common.reset') }}</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="brandList"
      @current-change="handleCurrent"
      @row-dblclick="handleRowDbClick"
    >
      <el-table-column width="50" align="center">
        <template v-slot="scope">
          <el-radio
            v-model="selectedGroupId"
            :label="scope.row.sizeGroupId"
            @change="handleRowChange(scope.row)"
            >{{ "" }}</el-radio
          >
        </template>
      </el-table-column>
      <el-table-column :label="$t('尺码组id')" align="center" prop="sizeGroupId" />
      <el-table-column :label="$t('尺码组编码')" align="center" prop="sizeGroupCode" />
      <el-table-column :label="$t('尺码组名称')" align="center" prop="sizeGroupName" />
      <el-table-column :label="$t('尺码组类型')" align="center" prop="sizeType" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.size_type" :value="scope.row.sizeType"/>
        </template>
      </el-table-column>
      <el-table-column :label="$t('是否启用')" align="center" prop="enableFlag" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">{{ $t('common.confirm') }}</el-button>
      <el-button @click="showFlag = false">{{ $t('common.cancel') }}</el-button>
    </div>
  </el-dialog>
</template>

<script>


import { listGroup } from "@/api/mes/md/sizeGroup";

export default {
  name: "MdSizeGroupSelectSingle",
  components: {},
  dicts: ['size_type'],
  data() {
    return {
      showFlag: false,
      // 选中数组
      selectedGroupId: undefined,
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 尺码组表格数据
      brandList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sizeGroupCode: null,
        sizeGroupName: null,
        sizeType: null,
        enableFlag: null,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询尺码组列表 */
    getList() {
      this.loading = true;
      listGroup(this.queryParams).then((response) => {
        this.brandList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    //双击选中
    handleRowDbClick(row) {
      if (row) {
        this.selectedRows = row;
        this.$emit("onSelected", this.selectedRows);
        this.showFlag = false;
      }
    },
    //确定选中
    confirmSelect() {
      if (this.selectedGroupId == null || this.selectedGroupId == 0) {
        this.$notify({
          title: this.$t('common.sys_tip'),
          type: "warning",
          message: this.$t('请至少选择一条数据!'),
        });
        return;
      }
      this.$emit("onSelected", this.selectedRows);
      this.showFlag = false;
    },
  },
};
</script>
