<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="88px">
      <el-form-item label="普通耳号" prop="ordinaryEarNumber">
        <el-input
            v-model="queryParams.ordinaryEarNumber"
            placeholder="请输入普通耳号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="牧场名称" prop="ranchName">
        <el-input
            v-model="queryParams.ranchName"
            placeholder="请输入牧场名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电子耳号" prop="electronicTags">
        <el-input
            v-model="queryParams.electronicTags"
            placeholder="请输入电子耳号"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="品种" prop="variety">
        <el-input
            v-model="queryParams.variety"
            placeholder="请输入品种"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="配种状态" prop="breedingStatus">
        <el-select v-model="queryParams.breedingStatus" placeholder="请选择配种状态" clearable>
          <el-option label="待配种" value="1"></el-option>
          <el-option label="配种中" value="2"></el-option>
          <el-option label="休息期" value="3"></el-option>
          <el-option label="淘汰" value="4"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['breed_ram_file:breed_ram_file:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['breed_ram_file:breed_ram_file:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['breed_ram_file:breed_ram_file:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['breed_ram_file:breed_ram_file:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div style="margin-bottom: 10px;">
      <el-button type="info" plain icon="Setting" @click="openColumnDialog">显示列</el-button>
    </div>

    <el-table
        v-loading="loading"
        :data="breedRamFileList"
        @selection-change="handleSelectionChange"
        style="width: 100%"
        border
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
          v-if="columns['id'].visible"
          label="种公羊ID"
          align="center"
          prop="id"
          width="100"
          fixed="left"
          sortable
      />
      <el-table-column
          v-if="columns['ordinaryEarNumber'].visible"
          label="普通耳号"
          align="center"
          prop="ordinaryEarNumber"
          width="120"
          fixed="left"
          sortable
      />
      <el-table-column
          v-if="columns['ranchName'].visible"
          label="牧场名称"
          align="center"
          prop="ranchName"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['sheepfoldName'].visible"
          label="羊舍"
          align="center"
          prop="sheepfoldName"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['electronicTags'].visible"
          label="电子耳号"
          align="center"
          prop="electronicTags"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['variety'].visible"
          label="品种"
          align="center"
          prop="variety"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['sheepCategory'].visible"
          label="羊只类别"
          align="center"
          prop="sheepCategory"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['currentStatus'].visible"
          label="当前状态"
          align="center"
          prop="currentStatus"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['birthday'].visible"
          label="生日"
          align="center"
          prop="birthday"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['dynamicInfo'].visible"
          label="动态"
          align="center"
          prop="dynamicInfo"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['monthAge'].visible"
          label="月龄"
          align="center"
          prop="monthAge"
          width="80"
          sortable
      />
      <el-table-column
          v-if="columns['birthWeight'].visible"
          label="出生体重"
          align="center"
          prop="birthWeight"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['weaningDate'].visible"
          label="断奶日期"
          align="center"
          prop="weaningDate"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.weaningDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['weaningDayAge'].visible"
          label="断奶日龄"
          align="center"
          prop="weaningDayAge"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['weaningWeight'].visible"
          label="断奶体重"
          align="center"
          prop="weaningWeight"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['weaningDailyGain'].visible"
          label="断奶日增重"
          align="center"
          prop="weaningDailyGain"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['postWeaningDailyGain'].visible"
          label="断奶后日增重"
          align="center"
          prop="postWeaningDailyGain"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['currentWeight'].visible"
          label="当前体重"
          align="center"
          prop="currentWeight"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['currentWeightDate'].visible"
          label="当前体重称重日期"
          align="center"
          prop="currentWeightDate"
          width="140"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.currentWeightDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['activityLevel'].visible"
          label="活动量"
          align="center"
          prop="activityLevel"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['sexualStatus'].visible"
          label="性欲情况"
          align="center"
          prop="sexualStatus"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['scrotumCircumference'].visible"
          label="阴囊周长"
          align="center"
          prop="scrotumCircumference"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['spermCollectionTime'].visible"
          label="采精时间"
          align="center"
          prop="spermCollectionTime"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.spermCollectionTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['spermVolume'].visible"
          label="精液量"
          align="center"
          prop="spermVolume"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['spermVitality'].visible"
          label="精液活力"
          align="center"
          prop="spermVitality"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['spermDensity'].visible"
          label="精液密度"
          align="center"
          prop="spermDensity"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['spermQuality'].visible"
          label="精液品质"
          align="center"
          prop="spermQuality"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['breedingStatus'].visible"
          label="配种状态"
          align="center"
          prop="breedingStatus"
          width="100"
          sortable
      >
        <template #default="scope">
          <dict-tag :options="breeding_status" :value="scope.row.breedingStatus"/>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['lastPlanTime'].visible"
          label="上次计划时间"
          align="center"
          prop="lastPlanTime"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.lastPlanTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['currentPlanTime'].visible"
          label="本次计划时间"
          align="center"
          prop="currentPlanTime"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.currentPlanTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['comment'].visible"
          label="备注"
          align="center"
          prop="comment"
          width="100"
          sortable
      >
        <template #default="scope">
          <el-tooltip :content="scope.row.comment" placement="top">
            <span style="display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
              {{ scope.row.comment }}
            </span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['proteinRateEbv'].visible"
          label="蛋白率%EBV"
          align="center"
          prop="proteinRateEbv"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['milkFatRateEbv'].visible"
          label="乳脂率%EBV"
          align="center"
          prop="milkFatRateEbv"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['scsEbv'].visible"
          label="乳体细胞EBV"
          align="center"
          prop="scsEbv"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['growthPerformanceEbv'].visible"
          label="生长性能EBV"
          align="center"
          prop="growthPerformanceEbv"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['resistanceEbv'].visible"
          label="抗逆性EBV"
          align="center"
          prop="resistanceEbv"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['reproductionPerformanceEbv'].visible"
          label="繁殖性能EBV"
          align="center"
          prop="reproductionPerformanceEbv"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['bodyTypeEbv'].visible"
          label="体型性状EBV"
          align="center"
          prop="bodyTypeEbv"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['comprehensiveBreedingValue'].visible"
          label="综合育种值"
          align="center"
          prop="comprehensiveBreedingValue"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['fatherNumber'].visible"
          label="父号"
          align="center"
          prop="fatherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['motherNumber'].visible"
          label="母号"
          align="center"
          prop="motherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['grandfatherNumber'].visible"
          label="祖父"
          align="center"
          prop="grandfatherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['grandmotherNumber'].visible"
          label="祖母"
          align="center"
          prop="grandmotherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['maternalGrandfatherNumber'].visible"
          label="外祖父"
          align="center"
          prop="maternalGrandfatherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['maternalGrandmotherNumber'].visible"
          label="外祖母"
          align="center"
          prop="maternalGrandmotherNumber"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['isCoreFlock'].visible"
          label="是否核心羊群"
          align="center"
          prop="isCoreFlock"
          width="120"
          sortable
      >
        <template #default="scope">
          <dict-tag :options="yes_no" :value="scope.row.isCoreFlock"/>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['isBreedingUse'].visible"
          label="是否种用"
          align="center"
          prop="isBreedingUse"
          width="100"
          sortable
      >
        <template #default="scope">
          <dict-tag :options="yes_no" :value="scope.row.isBreedingUse"/>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['pregnancyCheck'].visible"
          label="孕检"
          align="center"
          prop="pregnancyCheck"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['totalMatedEwes'].visible"
          label="总配母羊数"
          align="center"
          prop="totalMatedEwes"
          width="110"
          sortable
      />
      <el-table-column
          v-if="columns['naturalPregnancyCheckEwes'].visible"
          label="本交孕检母羊数"
          align="center"
          prop="naturalPregnancyCheckEwes"
          width="130"
          sortable
      />
      <el-table-column
          v-if="columns['naturalConceptionRate'].visible"
          label="本交受孕率%"
          align="center"
          prop="naturalConceptionRate"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['artificialPregnancyCheckEwes'].visible"
          label="人工孕检母羊数"
          align="center"
          prop="artificialPregnancyCheckEwes"
          width="130"
          sortable
      />
      <el-table-column
          v-if="columns['artificialConceptionRate'].visible"
          label="人工受孕率%"
          align="center"
          prop="artificialConceptionRate"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['ramMotherMilkVolume'].visible"
          label="公羊母亲奶量"
          align="center"
          prop="ramMotherMilkVolume"
          width="120"
          sortable
      />
      <el-table-column
          v-if="columns['milkProductionEbv'].visible"
          label="产奶量估计育种值"
          align="center"
          prop="milkProductionEbv"
          width="140"
          sortable
      />
      <el-table-column
          v-if="columns['accuracy'].visible"
          label="准确性"
          align="center"
          prop="accuracy"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['informationCount'].visible"
          label="信息数"
          align="center"
          prop="informationCount"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['isPaternityTested'].visible"
          label="是否亲子鉴定"
          align="center"
          prop="isPaternityTested"
          width="120"
          sortable
      >
        <template #default="scope">
          <dict-tag :options="yes_no" :value="scope.row.isPaternityTested"/>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['createBy'].visible"
          label="创建人"
          align="center"
          prop="createBy"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['createTime'].visible"
          label="创建日期"
          align="center"
          prop="createTime"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          v-if="columns['updateBy'].visible"
          label="修改人"
          align="center"
          prop="updateBy"
          width="100"
          sortable
      />
      <el-table-column
          v-if="columns['updateTime'].visible"
          label="修改日期"
          align="center"
          prop="updateTime"
          width="120"
          sortable
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          fixed="right"
          width="160"
      >
        <template #default="scope">
          <el-button link type="primary" icon="View" @click="handleDetail(scope.row)" v-hasPermi="['breed_ram_file:breed_ram_file:query']">详情</el-button>
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['breed_ram_file:breed_ram_file:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['breed_ram_file:breed_ram_file:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

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

    <!-- 添加或修改种公羊档案对话框 -->
    <el-dialog :title="title" v-model="open" width="1200px" append-to-body>
      <el-form ref="breedRamFileRef" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="普通耳号" prop="ordinaryEarNumber">
              <el-input v-model="form.ordinaryEarNumber" placeholder="请输入普通耳号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="牧场名称" prop="ranchName">
              <el-input v-model="form.ranchName" placeholder="请输入牧场名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="羊舍名称" prop="sheepfoldName">
              <el-input v-model="form.sheepfoldName" placeholder="请输入羊舍名称" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="电子耳号" prop="electronicTags">
              <el-input v-model="form.electronicTags" placeholder="请输入电子耳号" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="品种" prop="variety">
              <el-input v-model="form.variety" placeholder="请输入品种" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="羊只类别" prop="sheepCategory">
              <el-input v-model="form.sheepCategory" placeholder="请输入羊只类别" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="当前状态" prop="currentStatus">
              <el-input v-model="form.currentStatus" placeholder="请输入当前状态" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生日" prop="birthday">
              <el-date-picker clearable
                              v-model="form.birthday"
                              type="date"
                              value-format="YYYY-MM-DD"
                              placeholder="请选择生日">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="配种状态" prop="breedingStatus">
              <el-select v-model="form.breedingStatus" placeholder="请选择配种状态">
                <el-option label="待配种" value="1"></el-option>
                <el-option label="配种中" value="2"></el-option>
                <el-option label="休息期" value="3"></el-option>
                <el-option label="淘汰" value="4"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否核心羊群" prop="isCoreFlock">
              <el-radio-group v-model="form.isCoreFlock">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否种用" prop="isBreedingUse">
              <el-radio-group v-model="form.isBreedingUse">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否亲子鉴定" prop="isPaternityTested">
              <el-radio-group v-model="form.isPaternityTested">
                <el-radio :label="1">是</el-radio>
                <el-radio :label="0">否</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注" prop="comment">
              <el-input v-model="form.comment" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </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>

    <!-- 列显示设置对话框 -->
    <el-dialog v-model="columnDialogVisible" title="显示列设置" width="800px">
      <div style="max-height: 400px; overflow-y: auto;">
        <el-checkbox-group v-model="selectedColumns" style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;">
          <el-checkbox label="id">种公羊ID</el-checkbox>
          <el-checkbox label="ordinaryEarNumber">普通耳号</el-checkbox>
          <el-checkbox label="ranchName">牧场名称</el-checkbox>
          <el-checkbox label="sheepfoldName">羊舍</el-checkbox>
          <el-checkbox label="electronicTags">电子耳号</el-checkbox>
          <el-checkbox label="variety">品种</el-checkbox>
          <el-checkbox label="sheepCategory">羊只类别</el-checkbox>
          <el-checkbox label="currentStatus">当前状态</el-checkbox>
          <el-checkbox label="birthday">生日</el-checkbox>
          <el-checkbox label="dynamicInfo">动态</el-checkbox>
          <el-checkbox label="monthAge">月龄</el-checkbox>
          <el-checkbox label="birthWeight">出生体重</el-checkbox>
          <el-checkbox label="weaningDate">断奶日期</el-checkbox>
          <el-checkbox label="weaningDayAge">断奶日龄</el-checkbox>
          <el-checkbox label="weaningWeight">断奶体重</el-checkbox>
          <el-checkbox label="weaningDailyGain">断奶日增重</el-checkbox>
          <el-checkbox label="postWeaningDailyGain">断奶后日增重</el-checkbox>
          <el-checkbox label="currentWeight">当前体重</el-checkbox>
          <el-checkbox label="currentWeightDate">当前体重称重日期</el-checkbox>
          <el-checkbox label="activityLevel">活动量</el-checkbox>
          <el-checkbox label="sexualStatus">性欲情况</el-checkbox>
          <el-checkbox label="scrotumCircumference">阴囊周长</el-checkbox>
          <el-checkbox label="spermCollectionTime">采精时间</el-checkbox>
          <el-checkbox label="spermVolume">精液量</el-checkbox>
          <el-checkbox label="spermVitality">精液活力</el-checkbox>
          <el-checkbox label="spermDensity">精液密度</el-checkbox>
          <el-checkbox label="spermQuality">精液品质</el-checkbox>
          <el-checkbox label="breedingStatus">配种状态</el-checkbox>
          <el-checkbox label="lastPlanTime">上次计划时间</el-checkbox>
          <el-checkbox label="currentPlanTime">本次计划时间</el-checkbox>
          <el-checkbox label="comment">备注</el-checkbox>
          <el-checkbox label="proteinRateEbv">蛋白率%EBV</el-checkbox>
          <el-checkbox label="milkFatRateEbv">乳脂率%EBV</el-checkbox>
          <el-checkbox label="scsEbv">乳体细胞EBV</el-checkbox>
          <el-checkbox label="growthPerformanceEbv">生长性能EBV</el-checkbox>
          <el-checkbox label="resistanceEbv">抗逆性EBV</el-checkbox>
          <el-checkbox label="reproductionPerformanceEbv">繁殖性能EBV</el-checkbox>
          <el-checkbox label="bodyTypeEbv">体型性状EBV</el-checkbox>
          <el-checkbox label="comprehensiveBreedingValue">综合育种值</el-checkbox>
          <el-checkbox label="fatherNumber">父号</el-checkbox>
          <el-checkbox label="motherNumber">母号</el-checkbox>
          <el-checkbox label="grandfatherNumber">祖父</el-checkbox>
          <el-checkbox label="grandmotherNumber">祖母</el-checkbox>
          <el-checkbox label="maternalGrandfatherNumber">外祖父</el-checkbox>
          <el-checkbox label="maternalGrandmotherNumber">外祖母</el-checkbox>
          <el-checkbox label="isCoreFlock">是否核心羊群</el-checkbox>
          <el-checkbox label="isBreedingUse">是否种用</el-checkbox>
          <el-checkbox label="pregnancyCheck">孕检</el-checkbox>
          <el-checkbox label="totalMatedEwes">总配母羊数</el-checkbox>
          <el-checkbox label="naturalPregnancyCheckEwes">本交孕检母羊数</el-checkbox>
          <el-checkbox label="naturalConceptionRate">本交受孕率%</el-checkbox>
          <el-checkbox label="artificialPregnancyCheckEwes">人工孕检母羊数</el-checkbox>
          <el-checkbox label="artificialConceptionRate">人工受孕率%</el-checkbox>
          <el-checkbox label="ramMotherMilkVolume">公羊母亲奶量</el-checkbox>
          <el-checkbox label="milkProductionEbv">产奶量估计育种值</el-checkbox>
          <el-checkbox label="accuracy">准确性</el-checkbox>
          <el-checkbox label="informationCount">信息数</el-checkbox>
          <el-checkbox label="isPaternityTested">是否亲子鉴定</el-checkbox>
          <el-checkbox label="createBy">创建人</el-checkbox>
          <el-checkbox label="createTime">创建日期</el-checkbox>
          <el-checkbox label="updateBy">修改人</el-checkbox>
          <el-checkbox label="updateTime">修改日期</el-checkbox>
        </el-checkbox-group>
      </div>
      <div style="margin-top: 20px; display: flex; justify-content: space-between; align-items: center;">
        <el-checkbox v-model="isAllSelected" @change="toggleAllSelection">全选</el-checkbox>
        <div>
          <el-button type="primary" @click="confirmColumnSettings">提交</el-button>
          <el-button @click="resetColumnSettings">重置</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="BreedRamFile">
import { listBreedRamFile, getBreedRamFile, delBreedRamFile, addBreedRamFile, updateBreedRamFile } from "@/api/ram_file/breed_ram_file.js"

const { proxy } = getCurrentInstance()
const { breeding_status } = proxy.useDict('breeding_status')
const { yes_no } = proxy.useDict('yes_no')

const breedRamFileList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")
const columnDialogVisible = ref(false)
const selectedColumns = ref([
  'id', 'ordinaryEarNumber', 'ranchName', 'sheepfoldName', 'electronicTags', 'variety', 'sheepCategory', 'currentStatus', 'birthday', 'dynamicInfo', 'monthAge', 'birthWeight', 'weaningDate', 'weaningDayAge', 'weaningWeight', 'weaningDailyGain', 'postWeaningDailyGain', 'currentWeight', 'currentWeightDate', 'activityLevel', 'sexualStatus', 'scrotumCircumference', 'spermCollectionTime', 'spermVolume', 'spermVitality', 'spermDensity', 'spermQuality', 'breedingStatus', 'lastPlanTime', 'currentPlanTime', 'comment', 'proteinRateEbv', 'milkFatRateEbv', 'scsEbv', 'growthPerformanceEbv', 'resistanceEbv', 'reproductionPerformanceEbv', 'bodyTypeEbv', 'comprehensiveBreedingValue', 'fatherNumber', 'motherNumber', 'grandfatherNumber', 'grandmotherNumber', 'maternalGrandfatherNumber', 'maternalGrandmotherNumber', 'isCoreFlock', 'isBreedingUse', 'pregnancyCheck', 'totalMatedEwes', 'naturalPregnancyCheckEwes', 'naturalConceptionRate', 'artificialPregnancyCheckEwes', 'artificialConceptionRate', 'ramMotherMilkVolume', 'milkProductionEbv', 'accuracy', 'informationCount', 'isPaternityTested', 'createBy', 'createTime', 'updateBy', 'updateTime'
])
const isAllSelected = ref(false)
const columns = reactive({
  id: { visible: true },
  ordinaryEarNumber: { visible: true },
  ranchName: { visible: true },
  sheepfoldName: { visible: true },
  electronicTags: { visible: true },
  variety: { visible: true },
  sheepCategory: { visible: true },
  currentStatus: { visible: true },
  birthday: { visible: true },
  dynamicInfo: { visible: true },
  monthAge: { visible: true },
  birthWeight: { visible: true },
  weaningDate: { visible: true },
  weaningDayAge: { visible: true },
  weaningWeight: { visible: true },
  weaningDailyGain: { visible: true },
  postWeaningDailyGain: { visible: true },
  currentWeight: { visible: true },
  currentWeightDate: { visible: true },
  activityLevel: { visible: true },
  sexualStatus: { visible: true },
  scrotumCircumference: { visible: true },
  spermCollectionTime: { visible: true },
  spermVolume: { visible: true },
  spermVitality: { visible: true },
  spermDensity: { visible: true },
  spermQuality: { visible: true },
  breedingStatus: { visible: true },
  lastPlanTime: { visible: true },
  currentPlanTime: { visible: true },
  comment: { visible: true },
  proteinRateEbv: { visible: true },
  milkFatRateEbv: { visible: true },
  scsEbv: { visible: true },
  growthPerformanceEbv: { visible: true },
  resistanceEbv: { visible: true },
  reproductionPerformanceEbv: { visible: true },
  bodyTypeEbv: { visible: true },
  comprehensiveBreedingValue: { visible: true },
  fatherNumber: { visible: true },
  motherNumber: { visible: true },
  grandfatherNumber: { visible: true },
  grandmotherNumber: { visible: true },
  maternalGrandfatherNumber: { visible: true },
  maternalGrandmotherNumber: { visible: true },
  isCoreFlock: { visible: true },
  isBreedingUse: { visible: true },
  pregnancyCheck: { visible: true },
  totalMatedEwes: { visible: true },
  naturalPregnancyCheckEwes: { visible: true },
  naturalConceptionRate: { visible: true },
  artificialPregnancyCheckEwes: { visible: true },
  artificialConceptionRate: { visible: true },
  ramMotherMilkVolume: { visible: true },
  milkProductionEbv: { visible: true },
  accuracy: { visible: true },
  informationCount: { visible: true },
  isPaternityTested: { visible: true },
  createBy: { visible: true },
  createTime: { visible: true },
  updateBy: { visible: true },
  updateTime: { visible: true }
})

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    ordinaryEarNumber: null,
    ranchName: null,
    electronicTags: null,
    variety: null,
    breedingStatus: null,
  },
  rules: {
    ordinaryEarNumber: [
      { required: true, message: "普通耳号不能为空", trigger: "blur" }
    ],
  }
})

const { queryParams, form, rules } = toRefs(data)

/** 查询种公羊档案列表 */
function getList() {
  loading.value = true
  listBreedRamFile(queryParams.value).then(response => {
    breedRamFileList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    ordinaryEarNumber: null,
    ranchId: null,
    ranchName: null,
    sheepfoldId: null,
    sheepfoldName: null,
    electronicTags: null,
    varietyId: null,
    variety: null,
    sheepCategory: null,
    currentStatus: null,
    birthday: null,
    dynamicInfo: null,
    monthAge: null,
    birthWeight: null,
    weaningDate: null,
    weaningDayAge: null,
    weaningWeight: null,
    weaningDailyGain: null,
    postWeaningDailyGain: null,
    currentWeight: null,
    currentWeightDate: null,
    activityLevel: null,
    sexualStatus: null,
    scrotumCircumference: null,
    spermCollectionTime: null,
    spermVolume: null,
    spermVitality: null,
    spermDensity: null,
    spermQuality: null,
    breedingStatus: null,
    lastPlanTime: null,
    currentPlanTime: null,
    comment: null,
    proteinRateEbv: null,
    milkFatRateEbv: null,
    scsEbv: null,
    growthPerformanceEbv: null,
    resistanceEbv: null,
    reproductionPerformanceEbv: null,
    bodyTypeEbv: null,
    comprehensiveBreedingValue: null,
    fatherNumber: null,
    motherNumber: null,
    grandfatherNumber: null,
    grandmotherNumber: null,
    maternalGrandfatherNumber: null,
    maternalGrandmotherNumber: null,
    isCoreFlock: 0,
    isBreedingUse: 0,
    pregnancyCheck: null,
    totalMatedEwes: null,
    naturalPregnancyCheckEwes: null,
    naturalConceptionRate: null,
    artificialPregnancyCheckEwes: null,
    artificialConceptionRate: null,
    ramMotherMilkVolume: null,
    milkProductionEbv: null,
    accuracy: null,
    informationCount: null,
    isPaternityTested: 0,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    isDelete: null
  }
  proxy.resetForm("breedRamFileRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加种公羊档案"
}

/** 详情按钮操作 */
function handleDetail(row) {
  reset()
  const _id = row.id || ids.value
  getBreedRamFile(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "种公羊档案详情"
  })
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getBreedRamFile(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改种公羊档案"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["breedRamFileRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBreedRamFile(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addBreedRamFile(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 取消按钮 */
function cancel() {
  open.value = false
  reset()
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除种公羊档案编号为"' + _ids + '"的数据项？').then(function() {
    return delBreedRamFile(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('bas_ram_file/bas_ram_file/export', {
    ...queryParams.value
  }, `bas_ram_file_${new Date().getTime()}.xlsx`)
}

// 打开列设置对话框
function openColumnDialog() {
  const savedColumns = localStorage.getItem('breedRamSelectedColumns')
  if (savedColumns) {
    selectedColumns.value = JSON.parse(savedColumns)
    Object.keys(columns).forEach(column => {
      columns[column].visible = selectedColumns.value.includes(column)
    })
  }
  columnDialogVisible.value = true
}

// 全选功能
function toggleAllSelection() {
  if (isAllSelected.value) {
    selectedColumns.value = Object.keys(columns)
  } else {
    selectedColumns.value = []
  }
  updateColumnVisibility()
}

// 更新列的显示状态
function updateColumnVisibility() {
  Object.keys(columns).forEach(column => {
    columns[column].visible = selectedColumns.value.includes(column)
  })
}

// 确认列设置
function confirmColumnSettings() {
  updateColumnVisibility()
  localStorage.setItem('breedRamSelectedColumns', JSON.stringify(selectedColumns.value))
  columnDialogVisible.value = false
}

// 重置列设置
function resetColumnSettings() {
  selectedColumns.value = Object.keys(columns)
  updateColumnVisibility()
  localStorage.setItem('breedRamSelectedColumns', JSON.stringify(selectedColumns.value))
}

getList()
</script>

<style scoped>
:deep(.el-checkbox) {
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 10px;
  margin: 5px;
  width: calc(30% - 20px);
}
</style>