<template>
  <el-dialog title="颜色选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="80%"
    center
  >
    <el-row :gutter="20">
      <!--颜色数据-->
      <el-col :span="20" :xs="24">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="颜色编码" prop="colorCode">
            <el-input
              v-model="queryParams.colorCode"
              placeholder="请输入颜色编码"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="颜色名称" prop="colorName">
            <el-input
              v-model="queryParams.colorName"
              placeholder="请输入颜色名称"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="colorList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="颜色编码" width = "200" align="center" key="colorCode" prop="colorCode" v-if="columns[0].visible" >
            <template slot-scope="scope">
              <el-color-picker :value="scope.row.colorCode"></el-color-picker>
            </template>
          </el-table-column>
          <el-table-column label="颜色名称" align="left" key="colorName" prop="colorName" v-if="columns[1].visible" :show-overflow-tooltip="true" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
    <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="confirmSelect">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listColor} from "@/api/mes/md/color";
import { listAllUnitmeasure} from "@/api/mes/md/unitmeasure";
import {genCode} from "@/api/system/autocode/rule"
import { getToken } from "@/utils/auth";

export default {
  name: "ColorSingle",
  dicts: ['sys_yes_no','mes_item_product'],
  components: { },
  data() {
    return {
      showFlag:false,
      // 选中数组
      ids: [],
      selectedRows: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 物料产品表格数据
      colorList: null,
      // 部门树选项
      //itemTypeOptions: undefined,
      // 部门名称
      //itemTypeName: undefined,
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        colorCode: undefined,
        colorName: undefined,
      },
      // 列信息
      columns: [
        { key: 0, label: `颜色编码`, visible: true },
        { key: 1, label: `颜色名称`, visible: true },
        //{ key: 6, label: `创建时间`, visible: true }
      ]
    };
  },
  created() {
    this.getList();
    //this.getTreeselect();
  },
  methods: {
    /** 查询物料编码列表 */
    getList() {
      this.loading = true;
      listColor(this.queryParams).then(response => {
          this.colorList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.itemId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
      this.selectedRows = selection;
    },
    //确定选中
    confirmSelect(){
        if(this.ids ==[] || this.ids.length==0){
            this.$notify({
                title:'提示',
                type:'warning',
                message: '请至少选择一条数据!'
            });
            return;
        }
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
    }
  }
};
</script>
