<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="元器件编号" prop="componentId" >

        <el-select v-model="queryParams.id" filterable placeholder="请输入元器件编号">
          <el-option
            v-for="item in componentInfo"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="元器件名称" prop="componentName" >
<!--        <el-input-->
<!--          v-model="queryParams.componentName"-->
<!--          placeholder="请输入元器件名称"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
        <el-select v-model="queryParams.componentName" filterable placeholder="请输入元器件名称">
          <el-option
            v-for="item in componentInfo"
            :value="item.componentName">
          </el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="生产厂家" prop="manufacturer">-->
<!--        <el-input-->
<!--          v-model="queryParams.manufacturer"-->
<!--          placeholder="请输入生产厂家"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="型号规格" prop="componentModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.componentModel"-->
<!--          placeholder="请输入型号规格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="型号规格" prop="componentModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.componentModel"-->
<!--          placeholder="请输入型号规格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="型号规格" prop="componentModel">
        <el-select v-model="queryParams.componentModel" filterable placeholder="请输入型号规格">
          <el-option
            v-for="item in componentInfo"
            :value="item.componentModel">
          </el-option>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="国产替代型号" prop="replaceDomesticModel">-->
<!--        <el-input-->
<!--          v-model="queryParams.replaceDomesticModel"-->
<!--          placeholder="请输入国产替代型号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="质量等级" prop="qualityGrade">-->
<!--        <el-input-->
<!--          v-model="queryParams.qualityGrade"-->
<!--          placeholder="请输入质量等级"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="质量等级" prop="qualityGrade">
      <el-select v-model="queryParams.qualityGrade" filterable placeholder="请选择质量等级">
        <el-option
          v-for="item in qualityoptions"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      </el-form-item>
<!--      <el-form-item label="供货周期" prop="deliveryCycle">-->
<!--        <el-input-->
<!--          v-model="queryParams.deliveryCycle"-->
<!--          placeholder="请输入供货周期"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供货量(个/年）" prop="supplyQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.supplyQuantity"-->
<!--          placeholder="请输入供货量(个/年）"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="价格" prop="unitPrice">-->
<!--        <el-input-->
<!--          v-model="queryParams.unitPrice"-->
<!--          placeholder="请输入价格"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="ZZKK等级" prop="zzkkLevel">-->
<!--        <el-input-->
<!--          v-model="queryParams.zzkkLevel"-->
<!--          placeholder="请输入ZZKK等级"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否在优选目录内" prop="inPreference">-->
<!--        <el-input-->
<!--          v-model="queryParams.inPreference"-->
<!--          placeholder="请输入是否在优选目录内"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="停产断档日期" prop="shutdownDate">-->
<!--        <el-date-picker clearable-->
<!--          v-model="queryParams.shutdownDate"-->
<!--          type="date"-->
<!--          value-format="yyyy-MM-dd"-->
<!--          placeholder="请选择停产断档日期">-->
<!--        </el-date-picker>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="封装形式" prop="encapsulationMode">-->
<!--        <el-input-->
<!--          v-model="queryParams.encapsulationMode"-->
<!--          placeholder="请输入封装形式"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大正向电流IFM" prop="paramIfm">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramIfm"-->
<!--          placeholder="请输入最大正向电流IFM"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大反向工作电压VRRM" prop="paramVrrm">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramVrrm"-->
<!--          placeholder="请输入最大反向工作电压VRRM"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大浪涌电流IFSM" prop="paramIfsm">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramIfsm"-->
<!--          placeholder="请输入最大浪涌电流IFSM"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="稳压状态下的动态电阻ZZ" prop="paramZz">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramZz"-->
<!--          placeholder="请输入稳压状态下的动态电阻ZZ"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大额定功率PCM" prop="paramPcm">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramPcm"-->
<!--          placeholder="请输入最大额定功率PCM"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大集电极电流ICM" prop="paramIcm">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramIcm"-->
<!--          placeholder="请输入最大集电极电流ICM"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最大集电极-基极电压VCBO" prop="paramVcbo">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramVcbo"-->
<!--          placeholder="请输入最大集电极-基极电压VCBO"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="集电极-发射极电压VCEO" prop="paramVceo">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramVceo"-->
<!--          placeholder="请输入集电极-发射极电压VCEO"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="发射极-基极电压VEBO" prop="paramVebo">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramVebo"-->
<!--          placeholder="请输入发射极-基极电压VEBO"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="漏源电压VDSS" prop="paramVdss">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramVdss"-->
<!--          placeholder="请输入漏源电压VDSS"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="漏极直流电流ID" prop="paramId">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramId"-->
<!--          placeholder="请输入漏极直流电流ID"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="漏-源通态电阻RDS(on)" prop="paramRdsOn">-->
<!--        <el-input-->
<!--          v-model="queryParams.paramRdsOn"-->
<!--          placeholder="请输入漏-源通态电阻RDS(on)"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="抗静电能力" prop="antistaticCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.antistaticCapacity"-->
<!--          placeholder="请输入抗静电能力"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="抗辐照能力" prop="radiationResistance">-->
<!--        <el-input-->
<!--          v-model="queryParams.radiationResistance"-->
<!--          placeholder="请输入抗辐照能力"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="重量" prop="weight">-->
<!--        <el-input-->
<!--          v-model="queryParams.weight"-->
<!--          placeholder="请输入重量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->

    </el-form>
    <div style="padding-left: 1000px">
      <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery" style="margin-right: 20px">搜索</el-button>
      <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
    </div>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['biz:component:add']"
        >新增</el-button>
      </el-col>
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['biz:component:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['biz:component:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="info"
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['biz:component:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['biz:component:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="componentList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="编号" align="center" prop="id" />
      <el-table-column label="元器件名称" align="center" prop="componentName" width="100"/>
      <el-table-column label="生产厂家" align="center" prop="manufacturer" />
      <el-table-column label="型号规格" align="center" prop="componentModel" />
      <el-table-column label="国产替代型号" align="center" prop="replaceDomesticModel" width="110"/>
      <el-table-column label="质量等级" align="center" prop="qualityGrade" />
      <el-table-column label="供货周期" align="center" prop="deliveryCycle" />
      <el-table-column label="供货量(个/年）" align="center" prop="supplyQuantity" width="120"/>
      <el-table-column label="价格" align="center" prop="unitPrice" />
      <el-table-column label="ZZKK等级" align="center" prop="zzkkLevel" width="100"/>
      <el-table-column label="是否在优选目录内" align="center" prop="inPreference" width="130"/>
      <el-table-column label="停产断档日期" align="center" prop="shutdownDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.shutdownDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="封装形式" align="center" prop="encapsulationMode" />
      <el-table-column label="最大正向电流IFM" align="center" prop="paramIfm" width="130"/>
      <el-table-column label="最大反向工作电压VRRM" align="center" prop="paramVrrm" width="170"/>
      <el-table-column label="最大浪涌电流IFSM" align="center" prop="paramIfsm" width="130"/>
      <el-table-column label="稳压状态下的动态电阻ZZ" align="center" prop="paramZz" width="170"/>
      <el-table-column label="最大额定功率PCM" align="center" prop="paramPcm" width="130"/>
      <el-table-column label="最大集电极电流ICM" align="center" prop="paramIcm" width="170"/>
      <el-table-column label="最大集电极-基极电压VCBO" align="center" prop="paramVcbo" width="200"/>
      <el-table-column label="集电极-发射极电压VCEO" align="center" prop="paramVceo" width="180"/>
      <el-table-column label="发射极-基极电压VEBO" align="center" prop="paramVebo" width="170"/>
      <el-table-column label="漏源电压VDSS" align="center" prop="paramVdss" width="140"/>
      <el-table-column label="漏极直流电流ID" align="center" prop="paramId" width="130"/>
      <el-table-column label="漏-源通态电阻RDS(on)" align="center" prop="paramRdsOn" width="170"/>
      <el-table-column label="抗静电能力" align="center" prop="antistaticCapacity" width="100"/>
      <el-table-column label="抗辐照能力" align="center" prop="radiationResistance" width="100"/>
      <el-table-column label="材料" align="center" prop="materials" />
      <el-table-column label="工艺" align="center" prop="craft" />
      <el-table-column label="重量" align="center" prop="weight" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['biz:component:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['biz:component:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 元器件详情导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px">
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改元器件对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form  style="border:1px solid #C0C0C0;padding: 5px;margin: auto" ref="form" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="元器件名称" prop="componentName">
          <el-input v-model="form.componentName" placeholder="请输入元器件名称" />
        </el-form-item>
        <el-form-item label="生产厂家" prop="manufacturer">
          <el-input v-model="form.manufacturer" placeholder="请输入生产厂家" />
        </el-form-item>
        <el-form-item label="型号规格" prop="componentModel">
          <el-input v-model="form.componentModel" placeholder="请输入型号规格" />
        </el-form-item>
        <el-form-item label="国产替代型号" prop="replaceDomesticModel">
          <el-input v-model="form.replaceDomesticModel" placeholder="请输入国产替代型号" />
        </el-form-item>
        <el-form-item label="质量等级" prop="qualityGrade">
          <el-input v-model="form.qualityGrade" placeholder="请输入质量等级" />
        </el-form-item>
        <el-form-item label="供货周期" prop="deliveryCycle">
          <el-input v-model="form.deliveryCycle" placeholder="请输入供货周期" />
        </el-form-item>
        <el-form-item label="供货量(个/年）" prop="supplyQuantity">
          <el-input v-model="form.supplyQuantity" placeholder="请输入供货量(个/年）" />
        </el-form-item>
        <el-form-item label="价格" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入价格" />
        </el-form-item>
        <el-form-item label="ZZKK等级" prop="zzkkLevel">
          <el-input v-model="form.zzkkLevel" placeholder="请输入ZZKK等级" />
        </el-form-item>
        <el-form-item label="是否在优选目录内" prop="inPreference">
          <el-input v-model="form.inPreference" placeholder="请输入是否在优选目录内" />
        </el-form-item>
        <el-form-item label="停产断档日期" prop="shutdownDate">
          <el-date-picker clearable
            v-model="form.shutdownDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择停产断档日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="封装形式" prop="encapsulationMode">
          <el-input v-model="form.encapsulationMode" placeholder="请输入封装形式" />
        </el-form-item>
        <el-form-item label="最大正向电流IFM" prop="paramIfm">
          <el-input v-model="form.paramIfm" placeholder="请输入最大正向电流IFM" />
        </el-form-item>
        <el-form-item label="最大反向工作电压VRRM" prop="paramVrrm">
          <el-input v-model="form.paramVrrm" placeholder="请输入最大反向工作电压VRRM" />
        </el-form-item>
        <el-form-item label="最大浪涌电流IFSM" prop="paramIfsm">
          <el-input v-model="form.paramIfsm" placeholder="请输入最大浪涌电流IFSM" />
        </el-form-item>
        <el-form-item label="稳压状态下的动态电阻ZZ" prop="paramZz">
          <el-input v-model="form.paramZz" placeholder="请输入稳压状态下的动态电阻ZZ" />
        </el-form-item>
        <el-form-item label="最大额定功率PCM" prop="paramPcm">
          <el-input v-model="form.paramPcm" placeholder="请输入最大额定功率PCM" />
        </el-form-item>
        <el-form-item label="最大集电极电流ICM" prop="paramIcm">
          <el-input v-model="form.paramIcm" placeholder="请输入最大集电极电流ICM" />
        </el-form-item>
        <el-form-item label="最大集电极-基极电压VCBO" prop="paramVcbo">
          <el-input v-model="form.paramVcbo" placeholder="请输入最大集电极-基极电压VCBO" />
        </el-form-item>
        <el-form-item label="集电极-发射极电压VCEO" prop="paramVceo">
          <el-input v-model="form.paramVceo" placeholder="请输入集电极-发射极电压VCEO" />
        </el-form-item>
        <el-form-item label="发射极-基极电压VEBO" prop="paramVebo">
          <el-input v-model="form.paramVebo" placeholder="请输入发射极-基极电压VEBO" />
        </el-form-item>
        <el-form-item label="漏源电压VDSS" prop="paramVdss">
          <el-input v-model="form.paramVdss" placeholder="请输入漏源电压VDSS" />
        </el-form-item>
        <el-form-item label="漏极直流电流ID" prop="paramId">
          <el-input v-model="form.paramId" placeholder="请输入漏极直流电流ID" />
        </el-form-item>
        <el-form-item label="漏-源通态电阻RDS(on)" prop="paramRdsOn">
          <el-input v-model="form.paramRdsOn" placeholder="请输入漏-源通态电阻RDS(on)" />
        </el-form-item>
        <el-form-item label="抗静电能力" prop="antistaticCapacity">
          <el-input v-model="form.antistaticCapacity" placeholder="请输入抗静电能力" />
        </el-form-item>
        <el-form-item label="抗辐照能力" prop="radiationResistance">
          <el-input v-model="form.radiationResistance" placeholder="请输入抗辐照能力" />
        </el-form-item>
        <el-form-item label="材料" prop="materials">
          <el-input v-model="form.materials" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="工艺" prop="craft">
          <el-input v-model="form.craft" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="重量" prop="weight">
          <el-input v-model="form.weight" placeholder="请输入重量" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listComponent, getComponent, delComponent, addComponent, updateComponent,getall } from "@/api/biz/component";
import { getToken } from "@/utils/auth";
export default {
  name: "Component",
  data() {
    return {
      componentInfo: null,

      // 选择质量等级
      qualityoptions:[{
        value: '等级1',
        label: '等级1'
      }, {
        value: '等级2',
        label: '等级2'
      }, {
        value: '等级3',
        label: '等级3'
      }, {
        value: '等级4',
        label: '等级4'
      }, {
        value: '等级5',
        label: '等级5'
      }]
      ,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 元器件表格数据
      componentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        componentName: null,
        manufacturer: null,
        componentModel: null,
        replaceDomesticModel: null,
        qualityGrade: null,
        deliveryCycle: null,
        supplyQuantity: null,
        unitPrice: null,
        zzkkLevel: null,
        inPreference: null,
        shutdownDate: null,
        encapsulationMode: null,
        paramIfm: null,
        paramVrrm: null,
        paramIfsm: null,
        paramZz: null,
        paramPcm: null,
        paramIcm: null,
        paramVcbo: null,
        paramVceo: null,
        paramVebo: null,
        paramVdss: null,
        paramId: null,
        paramRdsOn: null,
        antistaticCapacity: null,
        radiationResistance: null,
        materials: null,
        craft: null,
        weight: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/biz/component/importData"
      },
    };
  },
  async created() {
    try {
      this.componentInfo = await getall();
      console.log(this.componentInfo);
    } catch (error) {
      console.error("Error fetching component info:", error);
    }
    this.getList();
  },
  methods: {
    /** 查询元器件列表 */
    getList() {
      this.loading = true;

      listComponent(this.queryParams).then(response => {
        this.componentList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        componentName: null,
        manufacturer: null,
        componentModel: null,
        replaceDomesticModel: null,
        qualityGrade: null,
        deliveryCycle: null,
        supplyQuantity: null,
        unitPrice: null,
        zzkkLevel: null,
        inPreference: null,
        shutdownDate: null,
        encapsulationMode: null,
        paramIfm: null,
        paramVrrm: null,
        paramIfsm: null,
        paramZz: null,
        paramPcm: null,
        paramIcm: null,
        paramVcbo: null,
        paramVceo: null,
        paramVebo: null,
        paramVdss: null,
        paramId: null,
        paramRdsOn: null,
        antistaticCapacity: null,
        radiationResistance: null,
        materials: null,
        craft: null,
        weight: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加元器件";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getComponent(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改元器件";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateComponent(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addComponent(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除元器件编号为"' + ids + '"的数据项？').then(function() {
        return delComponent(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('biz/component/export', {
        ...this.queryParams
      }, `component_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "元器件批量导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('biz/component/importTemplate', {
      }, `component_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
// 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
