<!--<template>-->
<!--  <div class="app-container">-->
<!--    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">-->
<!--      <el-form-item label="供体母羊耳号" prop="eweManageTags">-->
<!--        <el-input-->
<!--            v-model="queryParams.eweManageTags"-->
<!--            placeholder="请输入供体母羊耳号"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供体公羊耳号" prop="ramManageTags">-->
<!--        <el-input-->
<!--            v-model="queryParams.ramManageTags"-->
<!--            placeholder="请输入公羊耳号"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供体母羊品种" prop="eweVariety">-->
<!--        <el-input-->
<!--            v-model="queryParams.eweVariety"-->
<!--            placeholder="请输入母羊品种"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="供体公羊品种" prop="ramVariety">-->
<!--        <el-input-->
<!--            v-model="queryParams.ramVariety"-->
<!--            placeholder="请输入公羊品种"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="配种方式" prop="breedType">-->
<!--        <el-select v-model="queryParams.breedType" 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-option label="自然法请人工授精" value="5"></el-option>-->
<!--                                               </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="技术员" prop="technician">-->
<!--        <el-input-->
<!--            v-model="queryParams.technician"-->
<!--            placeholder="请输入技术员"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="孕检结果" prop="pregnancyResult">-->
<!--        <el-select v-model="queryParams.pregnancyResult" placeholder="请选择孕检结果" clearable>-->
<!--          <el-option label="怀孕" value="怀孕"></el-option>-->
<!--          <el-option label="空怀" value="空怀"></el-option>-->
<!--          <el-option label="疑似怀孕" value="疑似怀孕"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="是否孕检" prop="isPregnancyChecked">-->
<!--        <el-select v-model="queryParams.isPregnancyChecked" placeholder="请选择是否已孕检" clearable>-->
<!--          <el-option label="已孕检" value="1"></el-option>-->
<!--          <el-option label="未孕检" value="0"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建人" prop="createBy">-->
<!--        <el-input-->
<!--            v-model="queryParams.createBy"-->
<!--            placeholder="请输入创建人"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="创建日期" prop="createTime">-->
<!--        <el-date-picker clearable-->
<!--                        v-model="queryParams.createTime"-->
<!--                        type="date"-->
<!--                        value-format="YYYY-MM-DD"-->
<!--                        placeholder="请选择创建日期">-->
<!--        </el-date-picker>-->
<!--      </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="['Breeding_records:Breeding_records:add']"-->
<!--        >新增</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--            type="success"-->
<!--            plain-->
<!--            icon="Edit"-->
<!--            :disabled="single"-->
<!--            @click="handleUpdate"-->
<!--            v-hasPermi="['Breeding_records:Breeding_records:edit']"-->
<!--        >修改</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--            type="danger"-->
<!--            plain-->
<!--            icon="Delete"-->
<!--            :disabled="multiple"-->
<!--            @click="handleDelete"-->
<!--            v-hasPermi="['Breeding_records:Breeding_records:remove']"-->
<!--        >删除</el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--            type="warning"-->
<!--            plain-->
<!--            icon="Download"-->
<!--            @click="handleExport"-->
<!--            v-hasPermi="['Breeding_records:Breeding_records:export']"-->
<!--        >导出</el-button>-->
<!--      </el-col>-->
<!--      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

<!--    <el-table-->
<!--        v-loading="loading"-->
<!--        :data="Breeding_recordsList"-->
<!--        @selection-change="handleSelectionChange"-->
<!--        @sort-change="handleSortChange"-->
<!--        :default-sort="{prop: 'createTime', order: 'descending'}"-->
<!--    >-->
<!--      <el-table-column type="selection" width="55" align="center" />-->
<!--      &lt;!&ndash; 创建日期作为第一列,支持排序 &ndash;&gt;-->
<!--      <el-table-column-->
<!--          label="创建日期"-->
<!--          align="center"-->
<!--          prop="createTime"-->
<!--          width="180"-->
<!--          fixed="left"-->
<!--          sortable="custom"-->
<!--          sort-by="createTime"-->
<!--      >-->
<!--        <template #default="scope">-->
<!--          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="耳号" align="center" prop="eweManageTags" width="120" />-->
<!--      <el-table-column label="品种" align="center" prop="eweVariety" width="100" />-->
<!--      <el-table-column label="事件类型" align="center" width="100">-->
<!--        <template #default="scope">-->
<!--          <el-tag type="success">配种</el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="配种公羊" align="center" prop="ramManageTags" width="120" />-->
<!--      <el-table-column label="配种公羊品种" align="center" prop="ramVariety" width="120" />-->
<!--      <el-table-column label="配种方式" align="center" prop="matingType" width="140">-->
<!--        <template #default="scope">-->
<!--          <span>{{ getBreedTypeText(scope.row.breedType) }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="月龄" align="center" prop="eweMonthAge" width="80" />-->
<!--      <el-table-column label="配种时羊只类别" align="center" prop="sheepType" width="120" />-->
<!--      <el-table-column label="胎次" align="center" prop="eweParity" width="80" />-->
<!--      <el-table-column label="配次" align="center" prop="matingCount" width="80" />-->
<!--      <el-table-column label="发情后配种时间(小时)" align="center" prop="timeSincePlanning" width="140">-->
<!--        <template #default="scope">-->
<!--          <span>{{ scope.row.timeSincePlanning || 0 }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="当前羊舍" align="center" prop="eweSheepfoldName" width="120" />-->
<!--      <el-table-column label="技术员" align="center" prop="technician" width="100" />-->
<!--      <el-table-column label="羊只备注" align="center" prop="eweComment" width="120" show-overflow-tooltip />-->
<!--      <el-table-column label="繁育状态" align="center" prop="eweBreedStatus" width="100" />-->
<!--      <el-table-column label="是否性控" align="center" prop="eweControlled" width="100">-->
<!--        <template #default="scope">-->
<!--          <el-tag :type="scope.row.eweControlled === 1 ? 'success' : 'info'">-->
<!--            {{ scope.row.eweControlled === 1 ? '是' : '否' }}-->
<!--          </el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="耗精量" align="center" prop="breedDrugs" width="100" />-->

<!--      &lt;!&ndash; 孕检相关字段 &ndash;&gt;-->
<!--      <el-table-column label="孕检状态" align="center" width="100">-->
<!--        <template #default="scope">-->
<!--          <el-tag :type="scope.row.isPregnancyChecked === 1 ? 'success' : 'warning'">-->
<!--            {{ scope.row.isPregnancyChecked === 1 ? '已孕检' : '未孕检' }}-->
<!--          </el-tag>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="孕检日期" align="center" prop="pregnancyCheckDate" width="120">-->
<!--        <template #default="scope">-->
<!--          <span>{{ scope.row.pregnancyCheckDate ? parseTime(scope.row.pregnancyCheckDate, '{y}-{m}-{d}') : '-' }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="孕检结果" align="center" prop="pregnancyResult" width="100">-->
<!--        <template #default="scope">-->
<!--          <el-tag v-if="scope.row.pregnancyResult"-->
<!--                  :type="getPregnancyResultType(scope.row.pregnancyResult)">-->
<!--            {{ scope.row.pregnancyResult }}-->
<!--          </el-tag>-->
<!--          <span v-else>-</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="胎数" align="center" prop="fetusCount" width="80">-->
<!--        <template #default="scope">-->
<!--          <span>{{ scope.row.fetusCount || '-' }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="孕检方式" align="center" prop="pregnancyWay" width="100">-->
<!--        <template #default="scope">-->
<!--          <span>{{ scope.row.pregnancyWay || '-' }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->
<!--      <el-table-column label="配种到孕检间隔(天)" align="center" prop="daysToPregnancyCheck" width="140">-->
<!--        <template #default="scope">-->
<!--          <span>{{ scope.row.daysToPregnancyCheck || '-' }}</span>-->
<!--        </template>-->
<!--      </el-table-column>-->

<!--      <el-table-column label="创建人" align="center" prop="createBy" width="100" />-->
<!--      <el-table-column label="所在牧场" align="center" prop="ranchName" width="120" />-->
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" fixed="right">-->
<!--        <template #default="scope">-->
<!--          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['Breeding_records:Breeding_records:edit']">修改</el-button>-->
<!--          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['Breeding_records:Breeding_records: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"-->
<!--        :page-sizes="[20,50,100,200, 500, 1000, 2000]"-->
<!--        @pagination="getList"-->
<!--    />-->

<!--    &lt;!&ndash; 添加或修改配种记录对话框 &ndash;&gt;-->
<!--    <el-dialog :title="title" v-model="open" width="800px" append-to-body>-->
<!--      <el-form ref="Breeding_recordsRef" :model="form" :rules="rules" label-width="120px">-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="母羊耳号" prop="eweManageTags">-->
<!--              <el-input v-model="form.eweManageTags" placeholder="请输入母羊耳号" @blur="getEweInfoAndPlan" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="公羊耳号" prop="ramManageTags">-->
<!--              <el-input v-model="form.ramManageTags" placeholder="请输入公羊耳号" @blur="getRamInfoByTags" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="配种方式" prop="breedType">-->
<!--              <el-select v-model="form.breedType" 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-option label="自然法请人工授精" value="5"></el-option>-->
<!--              </el-select>-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="技术员" prop="technician">-->
<!--              <el-input v-model="form.technician" placeholder="请输入技术员" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-row>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="耗精量" prop="breedDrugs">-->
<!--              <el-input v-model="form.breedDrugs" placeholder="请输入耗精量" />-->
<!--            </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>-->

<!--        &lt;!&ndash; 显示母羊信息区域 &ndash;&gt;-->
<!--        <el-row v-if="eweInfo">-->
<!--          <el-col :span="24">-->
<!--            <el-divider content-position="left">母羊信息</el-divider>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="品种">-->
<!--              <el-input v-model="eweInfo.variety" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="月龄">-->
<!--              <el-input v-model="eweInfo.month_age" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="胎次">-->
<!--              <el-input v-model="eweInfo.parity" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="繁育状态">-->
<!--              <el-input v-model="eweInfo.breed_status" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="当前羊舍">-->
<!--              <el-input v-model="eweInfo.sheepfold_name" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="是否性控">-->
<!--              <el-input :value="eweInfo.controlled === 1 ? '是' : '否'" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

<!--        &lt;!&ndash; 显示配种计划信息区域 &ndash;&gt;-->
<!--        <el-row v-if="breedPlan">-->
<!--          <el-col :span="24">-->
<!--            <el-divider content-position="left">配种计划信息</el-divider>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="计划公羊">-->
<!--              <el-input v-model="breedPlan.ram_manage_tags" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="12">-->
<!--            <el-form-item label="计划配种方式">-->
<!--              <el-input v-model="breedPlan.breed_type_name" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->

<!--        &lt;!&ndash; 显示孕检信息区域(如果已有孕检记录) &ndash;&gt;-->
<!--        <el-row v-if="form.pregnancyResult">-->
<!--          <el-col :span="24">-->
<!--            <el-divider content-position="left">孕检信息</el-divider>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="孕检日期">-->
<!--              <el-input :value="form.pregnancyCheckDate ? parseTime(form.pregnancyCheckDate, '{y}-{m}-{d}') : ''" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="孕检结果">-->
<!--              <el-input v-model="form.pregnancyResult" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="胎数">-->
<!--              <el-input v-model="form.fetusCount" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="孕检方式">-->
<!--              <el-input v-model="form.pregnancyWay" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="孕检技术员">-->
<!--              <el-input v-model="form.pregnancyTechnician" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--          <el-col :span="8">-->
<!--            <el-form-item label="配种到孕检间隔">-->
<!--              <el-input :value="form.daysToPregnancyCheck + '天'" readonly />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--      </el-form>-->
<!--      <template #footer>-->
<!--        <div class="dialog-footer">-->
<!--          <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--          <el-button @click="cancel">取 消</el-button>-->
<!--        </div>-->
<!--      </template>-->
<!--    </el-dialog>-->
<!--  </div>-->

<!--  <div class="dialog-footer">-->
<!--    <el-button type="primary" @click="submitForm">确 定</el-button>-->
<!--    <el-button @click="cancel">取 消</el-button>-->
<!--  </div>-->

<!--</template>-->

<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="母羊耳号" prop="eweManageTags">
        <el-input v-model="queryParams.eweManageTags" placeholder="请输入母羊耳号" clearable @keyup.enter="handleQuery"/>
      </el-form-item>
      <el-form-item label="冻精号" prop="frozenSemenNo">
        <el-input v-model="queryParams.frozenSemenNo" placeholder="请输入冻精号" clearable @keyup.enter="handleQuery"/>
      </el-form-item>
      <el-form-item label="配种方式" prop="breedType">
        <el-select v-model="queryParams.breedType" 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="5"></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="['Breeding_records:Breeding_records:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['Breeding_records:Breeding_records:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['Breeding_records:Breeding_records:export']">导出</el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="Breeding_recordsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="耳号" align="center" prop="eweManageTags" width="120" />
      <el-table-column label="品种" align="center" prop="eweVariety" width="100" />
      <el-table-column label="事件类型" align="center" width="100"><template #default>配种</template></el-table-column>
      <el-table-column label="配种日期" align="center" prop="createTime" width="160">
        <template #default="scope"><span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span></template>
      </el-table-column>
      <el-table-column label="配种公羊" align="center" prop="ramManageTags" width="120" />
      <el-table-column label="配种公羊品种" align="center" prop="ramVariety" width="120" />

      <el-table-column label="供体母羊" align="center" prop="donorEweNo" width="120" />
      <el-table-column label="供体母羊品种" align="center" prop="donorEweVariety" width="120" />
      <el-table-column label="供体公羊" align="center" prop="donorRamNo" width="120" />
      <el-table-column label="供体公羊品种" align="center" prop="donorRamVariety" width="120" />
      <el-table-column label="移胚数" align="center" prop="embryoCount" width="80" />

      <el-table-column label="配种方式" align="center" prop="breedType" width="140">
        <template #default="scope"><span>{{ getBreedTypeText(scope.row.breedType) }}</span></template>
      </el-table-column>
      <el-table-column label="配种子类型" align="center" prop="embryoSubType" width="140" />

      <el-table-column label="月龄" align="center" prop="eweMonthAge" width="80" />
      <el-table-column label="配种时羊只类别" align="center" prop="sheepType" width="120" />
      <el-table-column label="胎次" align="center" prop="eweParity" width="80" />
      <el-table-column label="配次" align="center" prop="matingCount" width="80" />
      <el-table-column label="发情后配种时间" align="center" prop="timeSincePlanning" width="100" />
      <el-table-column label="当前羊舍" align="center" prop="eweSheepfoldName" width="120" />
      <el-table-column label="技术员" align="center" prop="technician" width="100" />
      <el-table-column label="繁殖用药" align="center" prop="breedDrugs" width="100" />
      <el-table-column label="羊只备注" align="center" prop="eweComment" width="120" show-overflow-tooltip />
      <el-table-column label="繁育状态" align="center" prop="eweBreedStatus" width="100" />
      <el-table-column label="孕检日期" align="center" prop="pregnancyCheckDate" width="120" />
      <el-table-column label="孕检结果" align="center" prop="pregnancyResult" width="100" />
      <el-table-column label="预产日期" align="center" prop="expectedDate" width="120" />
      <el-table-column label="实产日期" align="center" prop="actualLambingDate" width="120" />

      <el-table-column label="配种时产后天数" align="center" prop="daysPostLambing" width="100" />
      <el-table-column label="配种时泌乳天数" align="center" prop="daysLactation" width="100" />
      <el-table-column label="配种时配后天数" align="center" prop="daysPostMating" width="100" />
      <el-table-column label="上次配种日期" align="center" prop="lastMatingDate" width="120" />

      <el-table-column label="冻精号" align="center" prop="frozenSemenNo" width="100" />
      <el-table-column label="是否性控" align="center" prop="eweControlled" width="80">
        <template #default="scope">{{ scope.row.eweControlled === 1 ? '是' : '否' }}</template>
      </el-table-column>
      <el-table-column label="耗精量" align="center" prop="spermConsumption" width="80" />
      <el-table-column label="创建人" align="center" prop="createBy" width="100" />
      <el-table-column label="创建日期" align="center" prop="createTime" width="160" />
      <el-table-column label="所在牧场" align="center" prop="ranchName" width="120" />
      <el-table-column label="备注" align="center" prop="comment" width="120" />

      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</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="800px" append-to-body>
      <el-form ref="Breeding_recordsRef" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="母羊耳号" prop="eweManageTags">
              <el-input v-model="form.eweManageTags" placeholder="请输入母羊耳号" @blur="getEweInfoAndPlan" />
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.breedType != 5">
            <el-form-item label="公羊耳号" prop="ramManageTags">
              <el-input v-model="form.ramManageTags" placeholder="请输入公羊耳号" @blur="getRamInfoByTags" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="配种日期" prop="createTime">
              <el-date-picker
                  v-model="form.createTime"
                  type="date"
                  value-format="YYYY-MM-DD"
                  placeholder="请选择配种日期"
                  style="width: 100%"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="配种方式" prop="breedType">
              <el-select v-model="form.breedType" placeholder="请选择" @change="handleBreedTypeChange">
                <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="5"></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="frozenSemenNo">
              <el-input v-model="form.frozenSemenNo" placeholder="请输入冻精号" />
            </el-form-item>
          </el-col>
        </el-row>

        <template v-if="form.breedType == 5">
          <el-divider content-position="left"><b style="color: #409EFF">胚胎移植手动录入</b></el-divider>

          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="供体母号" prop="donorEweNo">
                <el-input v-model="form.donorEweNo" placeholder="手动输入/自动同步" @blur="getDonorSheepInfo(form.donorEweNo, 'ewe')" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供体母品种">
                <el-input v-model="form.donorEweVariety" readonly placeholder="自动关联显示" style="background: #f5f7fa" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="供体公号" prop="donorRamNo">
                <el-input v-model="form.donorRamNo" placeholder="手动输入供体公羊" @blur="getDonorSheepInfo(form.donorRamNo, 'ram')" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="供体公品种">
                <el-input v-model="form.donorRamVariety" readonly placeholder="自动关联显示" style="background: #f5f7fa" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="12">
              <el-form-item label="胚胎类型" prop="embryoSubType">
                <el-select v-model="form.embryoSubType" placeholder="必选类型" style="width: 100%">
                  <el-option label="体内胚胎冻胚" value="体内胚胎冻胚" />
                  <el-option label="体内胚胎鲜胚" value="体内胚胎鲜胚" />
                  <el-option label="体外胚胎冻胚" value="体外胚胎冻胚" />
                  <el-option label="体外胚胎鲜胚" value="体外胚胎鲜胚" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="移胚数量" prop="embryoCount">
                <el-input-number v-model="form.embryoCount" :min="1" style="width: 100%" />
              </el-form-item>
            </el-col>
          </el-row>
        </template>

        <el-row>
          <el-col :span="12">
            <el-form-item label="技术员" prop="technician">
              <el-input v-model="form.technician" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="耗精量" prop="breedDrugs">
              <el-input v-model="form.breedDrugs" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup name="Breeding_records">
import {
  listBreeding_records,
  getBreeding_records,
  delBreeding_records,
  addBreeding_records,
  updateBreeding_records,
  getSheepInfoByTags,
  getLatestBreedPlanByEweTags
} from "@/api/Breeding_records/Breeding_records"

import { ref, computed, nextTick } from 'vue'
import { ArrowUp, ArrowDown, Plus, Delete } from '@element-plus/icons-vue'

// 响应式数据
const pasteInput = ref('')           // 批量粘贴输入框
const earNumberOptions = ref([])     // 耳号下拉选项
const earNumberLoading = ref(false)  // 耳号加载状态
const isExpanded = ref(false)        // 控制耳号展开/折叠状态
const defaultShowCount = 2           // 默认显示的耳号数量

// 计算属性：控制显示的耳号列表
const displayedEarNumbers = computed(() => {
  if (!queryParams.value.allEarNumbers || queryParams.value.allEarNumbers.length === 0) {
    return []
  }

  // 如果展开或总数<=2，显示全部；否则只显示前2个
  if (isExpanded.value || queryParams.value.allEarNumbers.length <= defaultShowCount) {
    return queryParams.value.allEarNumbers
  } else {
    return queryParams.value.allEarNumbers.slice(0, defaultShowCount)
  }
})
const {proxy} = getCurrentInstance()

const Breeding_recordsList = 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 eweInfo = ref(null)
const breedPlan = ref(null)

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    eweManageTags: null,
    ramManageTags: null,
    eweVariety: null,
    ramVariety: null,
    breedType: null,
    technician: null,
    createBy: null,
    createTime: null,
    pregnancyResult: null,
    isPregnancyChecked: null,
    // 添加排序参数
    orderByColumn: 'createTime',
    isAsc: 'desc'
  },
  rules: {
    eweManageTags: [
      {required: true, message: "母羊耳号不能为空", trigger: "blur"}
    ],
    ramManageTags: [
      {required: true, message: "公羊耳号不能为空", trigger: "blur"}
    ],
    technician: [
      {required: true, message: "技术员不能为空", trigger: "blur"}
    ],
    breedType: [
      {required: true, message: "配种方式不能为空", trigger: "change"}
    ],
    createTime: [{ required: true, message: "配种日期不能为空", trigger: "change" }],
    donorEweNo: [{ required: true, message: "供体母号不能为空", trigger: "blur" }],
    donorRamNo: [{ required: true, message: "供体公号不能为空", trigger: "blur" }],
    embryoSubType: [{ required: true, message: "请选择配种子类型", trigger: "change" }]
  },
  submitting: false
})

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




/** 获取配种方式文字显示 */
function getBreedTypeText(breedType) {
  if (breedType === 1) return '供体母羊配种'
  if (breedType === 2) return '同期发情人工授精'
  if (breedType === 3) return '本交'
  if (breedType === 4) return '自然发情人工授精'
  if (breedType === 5) return '胚胎移植'
  return '-'
}

/** * Handle Breed Type Change
 * If Embryo Transfer (5), try to fetch flush record info if Ewe Tag exists
 */
/** 切换配种方式触发 */
function handleBreedTypeChange(val) {
  // 同步母羊耳号
  if (form.value.eweManageTags) {
    form.value.donorEweNo = form.value.eweManageTags;
    getDonorSheepInfo(form.value.donorEweNo, 'ewe');
  }
  // 如果公羊号已有值，也查一下品种
  if (form.value.donorRamNo) {
    getDonorSheepInfo(form.value.donorRamNo, 'ram');
  } else {
    // 切换回其他类型时，清空移植专有字段
    form.value.donorEweNo = null;
    form.value.donorRamNo = null;
    form.value.donorEweVariety = null; // 仅用于页面展示
    form.value.donorRamVariety = null; // 仅用于页面展示
  }
}

/** 2. 抽取统一的供体信息查询方法 */
function getDonorSheepInfo(tag, type) {
  if (!tag) return;

  getSheepInfoByTags(tag).then(response => {
    if (response.data) {
      if (type === 'ewe') {
        // 这里的 donorEweVariety 只绑定在 form 或本地变量用于展示，不存入 insert 接口
        form.value.donorEweVariety = response.data.variety;
      } else if (type === 'ram') {
        form.value.donorRamVariety = response.data.variety;
      }
    } else {
      // 如果查不到，清空品种显示
      if (type === 'ewe') form.value.donorEweVariety = '未知品种';
      else form.value.donorRamVariety = '未知品种';
    }
  }).catch(() => {
    console.error("查询供体品种失败");
  });
}

/** 供体公羊耳号失去焦点时，关联品种 */
function getDonorRamInfo() {
  if (form.value.donorRamNo) {
    getSheepInfoByTags(form.value.donorRamNo).then(response => {
      if (response.data) {
        // 需求2：关联供体公羊品种
        form.value.donorRamVariety = response.data.variety;
      }
    });
  }
}
/** Overriding/Updating getEweInfoAndPlan to handle the Match data */
function getEweInfoAndPlan() {
  if (form.value.eweManageTags) {
    // 仅获取受体母羊的基础信息
    getSheepInfoByTags(form.value.eweManageTags).then(response => {
      if (response.data) {
        eweInfo.value = response.data;
        form.value.eweId = response.data.id;
      }
    });

    // 仅尝试匹配普通配种计划（如果是本交/人工授精等），胚胎移植不再自动匹配
    getLatestBreedPlanByEweTags(form.value.eweManageTags).then(response => {
      if (response.data && form.value.breedType != 5) {
        const plan = response.data;
        form.value.breedType = plan.breed_type || plan.breedType;
        form.value.ramManageTags = plan.ram_manage_tags;
      }
    });
  }
}
/** 获取孕检结果标签类型 */
function getPregnancyResultType(result) {
  if (result === '怀孕') return 'success'
  if (result === '空怀') return 'danger'
  if (result === '疑似怀孕') return 'warning'
  return 'info'
}

/** 查询配种记录列表 */
function getList() {
  loading.value = true
  listBreeding_records(queryParams.value).then(response => {
    Breeding_recordsList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 表格排序变化处理
function handleSortChange({column, prop, order}) {
  queryParams.value.orderByColumn = prop
  queryParams.value.isAsc = order === 'ascending' ? 'asc' : 'desc'
  getList()
}

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

// 表单重置
function reset() {
  form.value = {
    id: null,
    sheepId: null,
    ramId: null,
    eweId: null,
    eweManageTags: null,
    ramManageTags: null,
    technician: null,
    breedDrugs: null,
    breedType: null,
    comment: null,
    createBy: null,
    createTime: null,
    pregnancyCheckDate: null,
    pregnancyResult: null,
    pregnancyWay: null,
    fetusCount: null,
    pregnancyTechnician: null,
    pregnancyRemark: null,
    daysToPregnancyCheck: null
  }
  eweInfo.value = null
  breedPlan.value = null
  proxy.resetForm("Breeding_recordsRef")
}

/** 搜索按钮操作 */
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()
  form.value.createTime = proxy.parseTime(new Date(), '{y}-{m}-{d}')
  open.value = true
  title.value = "添加配种记录"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getBreeding_records(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改配种记录"

    // 如果有母羊耳号,加载母羊信息
    if (form.value.eweManageTags) {
      getEweInfoAndPlan()
    }
  })
}

// /** 根据母羊耳号获取羊只信息和配种计划信息 */
// function getEweInfoAndPlan() {
//   if (form.value.eweManageTags) {
//     // 获取母羊信息
//     getSheepInfoByTags(form.value.eweManageTags).then(response => {
//       if (response.data) {
//         eweInfo.value = response.data
//         form.value.eweId = response.data.id
//       } else {
//         proxy.$modal.msgError("未找到该母羊耳号对应的羊只信息")
//         eweInfo.value = null
//       }
//     }).catch(() => {
//       proxy.$modal.msgError("查询母羊信息失败")
//       eweInfo.value = null
//     })
//
//     // 获取配种计划信息(使用最新的获取方法)
//     getLatestBreedPlanByEweTags(form.value.eweManageTags).then(response => {
//       if (response.data) {
//         breedPlan.value = response.data
//         // 自动填充公羊耳号和配种方式(但允许用户修改)
//         if (!form.value.ramManageTags) {
//           form.value.ramManageTags = response.data.ram_manage_tags
//         }
//         if (!form.value.breedType) {
//           form.value.breedType = response.data.breed_type
//         }
//
//         proxy.$modal.msgSuccess("已自动匹配配种计划信息,可手动调整")
//       } else {
//         breedPlan.value = null
//         proxy.$modal.msgWarning("未找到该母羊的配种计划,请手动输入配种信息")
//       }
//     }).catch(() => {
//       proxy.$modal.msgWarning("查询配种计划失败,请手动输入配种信息")
//       breedPlan.value = null
//     })
//   }
// }

/** 根据公羊耳号获取羊只信息 */
function getRamInfoByTags() {
  if (form.value.ramManageTags) {
    getSheepInfoByTags(form.value.ramManageTags).then(response => {
      if (response.data) {
        form.value.ramId = response.data.id
      } else {
        proxy.$modal.msgError("未找到该公羊耳号对应的羊只信息")
      }
    }).catch(() => {
      proxy.$modal.msgError("查询公羊信息失败")
    })
  }
}

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

/** 提交按钮 */
/** 提交按钮 */
function submitForm() {
  proxy.$refs["Breeding_recordsRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateBreeding_records(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        }).catch(error => {
          console.error('修改失败:', error)
          proxy.$modal.msgError("修改失败，请查看控制台")
        })
      } else {
        addBreeding_records(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        }).catch(error => {
          console.error('新增失败:', error)
          proxy.$modal.msgError("新增失败，请查看控制台")
        })
      }
    }
  })
}

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

/** 导出按钮操作 */
function handleExport() {
  proxy.download('Breeding_records/Breeding_records/export', {
    ...queryParams.value
  }, `配种记录_${new Date().getTime()}.xlsx`)
}

// 页面初始化
onMounted(() => {
  getList()
})
</script>

<style scoped>
/* 样式保持不变 */
</style>