<template>
    <el-dialog title="检测模板选择"
    v-if="showFlag"
    :visible.sync="showFlag"
    :modal= false
    width="60%"
    center
    >
    <el-form :model="queryParams" @submit.native.prevent ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
        <el-form-item label="检测模板编号" prop="templateCode">
          <el-input
            v-model="queryParams.templateCode"
            placeholder="请输入检测模板编号"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="检测模板名称" prop="templateName">
          <el-input
            v-model="queryParams.templateName"
            placeholder="请输入检测模板名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品编码" prop="itemCode">
          <el-input
            v-model="queryParams.itemCode"
            placeholder="请输入产品名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="产品名称" prop="itemName">
          <el-input
            v-model="queryParams.itemName"
            placeholder="请输入产品名称"
            clearable
            @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="qctemplateList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
        <el-table-column width="50" align="center" >
            <template v-slot="scope">
                <el-radio v-model="selectedIndexId" :label="scope.row.id" @change="handleRowChange(scope.row)">{{""}}</el-radio>
            </template>
        </el-table-column>
      <el-table-column label="检测模板编号" align="center" prop="templateCode" >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
            v-hasPermi="['mes:qc:qctemplate:query']"
          >{{scope.row.templateCode}}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="检测模板名称" align="center" prop="templateName" />
      <el-table-column label="检测种类" align="center" prop="qcTypesParam" >
        <template slot-scope="scope">
          <dict-tag :options="dict.type.mes_qc_type" :value="scope.row.qcTypesParam"/>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center" prop="enableFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enableFlag"/>
        </template>
      </el-table-column>
    </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">确 定</el-button>
        <el-button @click="showFlag=false">取 消</el-button>
    </div>
    </el-dialog>
</template>

<script>
import { listQctemplate, getQctemplate, delQctemplate, addQctemplate, updateQctemplate } from "@/api/mes/qc/qctemplate";
export default {
  name: "QcindexSelect",
  props: ['qcType'],
  dicts: ['mes_index_type','mes_qc_type', 'sys_yes_no'],
  data() {
    return {
      showFlag:false,
      // 遮罩层
      loading: true,
      // 选中数组
      selectedIndexId: null,
      selectedRows: undefined,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检测项表格数据
      qcindexList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      inputTypeOptions: [{"label":"输入框","value":1},{"label":"选择框","value":2}],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        indexCode: null,
        indexName: null,
        indexType: null,
        qcTool: null,
      },
      // 表单参数
      form: {}
    };
  },
  watch: {
    showFlag () {
      if(this.showFlag) {
        this.getList();
      }
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询检测项列表 */
    getList() {
      this.loading = true;
      const params = this.queryParams
      if (this.qcType) {
        params['qcType'] = this.qcType
      }
      listQctemplate(params).then(response => {
        this.qctemplateList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        templateId: null,
        templateCode: null,
        templateName: null,
        qcTypesParam: [],
        enableFlag: 'Y',
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.autoGenFlag = false;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.indexId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    handleCurrent(row){
        if(row){
            this.selectedRows = row;
        }
    },
    handleRowDbClick(row){
      if(row){
        this.selectedRows = row;
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      debugger;
      if(row){
        this.selectedRows = row;
      }
    },
    //选中确认
    confirmSelect(){
        if(this.selectedIndexId ==null || this.selectedIndexId==0){
            this.$notify({
                title:'提示',
                type:'warning',
                message: '请至少选择一条数据!'
            });
            return;
        }
        this.$emit('onSelected',this.selectedRows);
        this.showFlag = false;
    }

  }
};
</script>
