<template>
  <!-- 102 -->
   <div>
 
 
     <el-card class="box-card">
       <!-- 搜索区域 -->
       <div class="search-bx1">
           <el-input v-model="searchData.calf_code" placeholder="犊牛编号"  style="width: 180px;" class="g-mr20 g-mb20" clearable />
 
           <el-input v-model="searchData.barn_number" placeholder="栏舍身份ID"  style="width: 180px;" class="g-mr20" clearable />
           <el-input v-model="searchData.barn_name" placeholder="栏舍"  style="width: 180px;" class="g-mr20" clearable />
           <!-- <el-input v-model="searchData.mother_code" placeholder="母号"  style="width: 180px;" class="g-mr20" clearable /> -->
          
           <el-select v-model="searchData.status" filterable placeholder="健康状态" class="g-mr20" style="width: 180px;" clearable>
             <el-option v-for="item in healthList" :key="item.id" :label="item.value" :value="item.id" />
           </el-select>
 
           <el-select v-model="searchData.calf_category_id" filterable placeholder="犊牛类型" class="g-mr20" style="width: 180px;" clearable>
             <el-option v-for="item in calfTypeList" :key="item.id" :label="item.name" :value="item.id" />
           </el-select>
 
           <el-select v-model="searchData.genders" filterable placeholder="性别" class="g-mr20" style="width: 180px;" clearable>
             <el-option v-for="item in sexList" :key="item.id" :label="item.value" :value="item.id" />
           </el-select>
 
           <!-- <el-input-number v-model="searchData.min_daily_weight_gain" style="width:120px;" :controls="false" placeholder="日均增重" />
           <span style="margin:0px 8px;">至</span>
           <el-input-number v-model="searchData.max_daily_weight_gain" style="width:120px;" class="g-mr20" :controls="false" placeholder="日均增重" /> -->
 
           <el-input-number v-model="searchData.min_daily_age" style="width:120px;" :controls="false" placeholder="日龄" />
           <span style="margin:0px 8px;">至</span>
           <el-input-number v-model="searchData.max_daily_age" style="width:120px;" class="g-mr20" :controls="false" placeholder="日龄" />
 
 
           <el-button type="primary"   @click="form_search">搜索</el-button>
           <el-button type="primary"   @click="form_clear">重置</el-button>
           <el-button type="primary"  v-if="isButtonEdit" @click="form_add">添加</el-button>
            <!-- <el-button type="primary"   @click="form_export">导出</el-button> -->
       </div>
 
  
       <!-- 表格 -->
       <el-table   key="0"  :data="tableList"  v-loading="tableLoading" element-loading-text="给我一点时间"    border fit>
         <el-table-column label="序号"  width="50px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.id }}</span>
           </template>
         </el-table-column>
         <el-table-column label="犊牛编号" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.calf_code }}</span>
           </template>
           <template slot-scope="scope">
             <span  style = "color:#409EFF; cursor: pointer;" @click="click_cowcode(scope.row)">{{ scope.row.calf_code }}</span>
           </template>
         </el-table-column>
        
         <el-table-column label="耳号" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.ear_number }}</span>
           </template>
         </el-table-column>
         <el-table-column label="栏舍身份ID" min-width="150px" align="center">
             <template slot-scope="scope">
               <span>{{ scope.row.barn_number }}</span>
             </template>
           </el-table-column>
         <el-table-column label="栏舍" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.barn_name }}</span>
           </template>
         </el-table-column>
         <el-table-column label="犊牛类型" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.calf_category_name }}</span>
           </template>
         </el-table-column>
         <el-table-column label="出生日期" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.birth_date_format }}</span>
           </template>
         </el-table-column>
         <el-table-column label="性别" min-width="150px" align="center">
           <template slot-scope="scope">
             <span v-if="scope.row.genders == 1">公</span>
             <span v-if="scope.row.genders == 2">母</span>
             <span v-else> </span>
           </template>
         </el-table-column>
         <el-table-column label="日龄" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.daily_age }}</span>
           </template>
         </el-table-column>
         <el-table-column label="出生体重(KG)" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.birth_weight }}</span>
           </template>
         </el-table-column>
         <el-table-column label="当前体重(KG)" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.current_weight }}</span>
           </template>
         </el-table-column>
         <el-table-column label="日均增重(KG)" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.daily_weight_gain }}</span>
           </template>
         </el-table-column>
         <el-table-column label="母号" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.mother_code }}</span>
           </template>
         </el-table-column>
         <el-table-column label="建档日期" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.created_at_format }}</span>
           </template>
         </el-table-column>
         <el-table-column label="出栏日期" min-width="150px" align="center">
           <template slot-scope="scope">
             <span>{{ scope.row.leave_barn_date_format }}</span>
           </template>
         </el-table-column>
         <el-table-column label="状态" min-width="150px" align="center">
           <template slot-scope="scope">
             <span v-if="scope.row.status == 1" style="color:#67c23a;font-weight:bold">健康</span>
             <span v-if="scope.row.status == 2" style="color:#ff9100;font-weight:bold">疾病</span>
             <span v-if="scope.row.status == 3" style="color:#dec40d;font-weight:bold">出栏</span>
             <span v-if="scope.row.status == 4" style="color:#ff0000;font-weight:bold">死亡</span>
             <span v-if="scope.row.status == 5" style="color:#fa00ff;font-weight:bold">淘汰</span>
           </template>
         </el-table-column>
 
         <el-table-column label="操作" align="center" width="300" class-name="small-padding fixed-width" fixed="right">
           <template slot-scope="scope">
              <!-- 修改按钮 -->
              <el-button type="primary" size="mini" icon="el-icon-edit"  v-if="isButtonEdit" @click="form_edit(scope.row)">编辑</el-button>
 
              <el-button type="primary" size="mini" icon="el-icon-edit"  v-if="isButtonEdit" @click="form_event(scope.row)">事件记录</el-button>
              <!-- 删除按钮 -->
              <el-button type="danger" size="mini" icon="el-icon-delete"  v-if="isButtonEdit"  @click="form_delete(scope.row)">删除</el-button>
           </template>
         </el-table-column>
       </el-table>
 
       <!-- 分页区域 -->
       <el-pagination  @size-change="change_size_page"  @current-change="change_current_page"  :current-page="searchData.page" :page-sizes="[1,5,10,20,30,50]"  :page-size="searchData.page_size" layout="total, prev, pager, next" :total="searchData.total"/>
     </el-card>
 
 
     <!-- 弹窗 新增or修改 -->
     <el-dialog  :title="addFormTxt[addFormStatus]" :visible.sync="addFormShow" @close="add_dialog_close" width="50%">
       <div class="">
         <el-form  ref="addFormRef"  :rules="addFormRules"  :model="addForm"  label-position="right" label-width="140px"  style="width:50%;margin:0 auto 50px">
             <el-form-item label="栏舍：" prop="barn_id">
               <el-select  v-model="addForm.barn_id" filterable placeholder="请选择"   style="width: 100%;" >
                 <el-option v-for="item in cowshedList" :key="item.id" :label="item.name" :value="item.id" />
               </el-select>
             </el-form-item> 
             <el-form-item label="犊牛编号：" prop="calf_code">
                 <el-input   v-model="addForm.calf_code"  placeholder=""   :disabled="addFormStatus=='edit'"></el-input>  
             </el-form-item>
             <el-form-item label="耳号：" prop="ear_number">
                 <el-input   v-model="addForm.ear_number"  placeholder=""   :disabled="addFormStatus=='edit'"></el-input>  
             </el-form-item>
 
             
 
             <el-form-item label="犊牛类型：" prop="calf_category_id">
               <el-select  v-model="addForm.calf_category_id" filterable placeholder="请选择"   style="width: 100%;" >
                 <el-option v-for="item in calfTypeList" :key="item.id" :label="item.name" :value="item.id" />
               </el-select>
             </el-form-item> 
             
             <el-form-item label="出生日期：" prop="birth_date_format">
               <el-date-picker v-model="addForm.birth_date_format" type="datetime" placeholder="选择日期"   style="width: 100%;" :clearable="false"   />
             </el-form-item>
             <el-form-item label="性别：" prop="genders">
               <el-select  v-model="addForm.genders" filterable placeholder="请选择"   style="width: 100%;" >
                 <el-option v-for="item in sexList" :key="item.id" :label="item.value" :value="item.id" />
               </el-select>
             </el-form-item> 
             <el-form-item label="出生体重(KG)：" prop="birth_weight">
                 <el-input   v-model="addForm.birth_weight"    ></el-input>  
             </el-form-item>      
             <el-form-item label="当前体重(KG)：" prop="current_weight">
                 <el-input   v-model="addForm.current_weight"    ></el-input>  
             </el-form-item>     
             <el-form-item label="母号：" prop="mother_code">
                 <el-input   v-model="addForm.mother_code"    ></el-input>  
             </el-form-item>
             <el-form-item label="备注：" prop="remark">
               <el-input  v-model="addForm.remark" type="textarea" maxlength="200"   :rows="3"  />
             </el-form-item>
 
           
             
         </el-form>
         <div slot="footer" class="dialog-footer">
           <el-button type="primary" @click="addFormStatus==='create'?add_dialog_save():edit_dialog_save()">确认</el-button>
           <el-button @click="addFormShow = false">关闭</el-button>
         </div>
       </div>
     </el-dialog>
 
 
     <!-- 弹窗 牛只信息  -->
     <el-dialog   title="牛只信息" :visible.sync="eventFormShow" @close="event_dialog_close" width="50%">
       <div class="">
         <el-form  ref="eventFormRef"  :rules="eventFormRules"  :model="eventForm"  label-position="right" label-width="170px"  style="width:50%;margin:0 auto 50px">
              
 
             <el-row>
               
                 <el-form-item label="牛号：" prop="calf_code">
                   <el-input ref="calf_code" v-model="eventForm.calf_code"    disabled />
                 </el-form-item> 
             
                 <el-form-item label="犊牛类型：" prop="calf_category_name">
                   <el-input ref="calf_category_name" v-model="eventForm.calf_category_name"    disabled />
                 </el-form-item> 
           
                 <el-form-item label="事件类型：" prop="event_kind">
                   <el-select ref="event_kind" v-model="eventForm.event_kind" filterable placeholder="请选择"  style="width: 100%;"    >
                     <el-option v-for="item in eventNameList" :key="item.id" :label="item.name" :value="item.id"  />
                   </el-select>
                 </el-form-item>
    
             </el-row>
 
              <!-- 1 称重 2 饲喂 3 粪便情况 4 测量体温 5 测量心跳 6 测量呼吸 7 疾病 8 病愈 9 去角 10 去副乳 11 转栏 12 出栏 13 死亡 -->
              <!-- 称重 -->
             <el-row   v-if="eventForm.event_kind == 1" >
                <el-form-item label="体重：" prop="weight">
                   <el-input ref="weight" v-model="eventForm.weight"   />
                 </el-form-item> 
             </el-row>
             <!-- 饲喂 -->
             <el-row   v-if="eventForm.event_kind == 2">
                 <el-form-item label="一班进食量：" prop="first_class_food_number"  >
                   <el-input ref="first_class_food_number" v-model="eventForm.first_class_food_number"   />
                 </el-form-item> 
                 <el-form-item label="二班进食量：" prop="second_class_food_number" v-if="class_num == 2 || class_num == 3 || class_num == 4">
                   <el-input ref="second_class_food_number" v-model="eventForm.second_class_food_number"   />
                 </el-form-item> 
                 <el-form-item label="三班进食量：" prop="third_class_food_number" v-if="class_num == 3 || class_num == 4 ">
                   <el-input ref="third_class_food_number" v-model="eventForm.third_class_food_number"  />
                 </el-form-item> 
                 <el-form-item label="四班进食量：" prop="fourth_class_food_number" v-if="class_num == 4">
                   <el-input ref="fourth_class_food_number" v-model="eventForm.fourth_class_food_number"  />
                 </el-form-item> 
             </el-row>
             <!-- 粪便情况 -->
             <el-row   v-if="eventForm.event_kind == 3">
                 <el-form-item label="粪便评分：" prop="fecal_score">
                   <el-select ref="fecal_score" v-model="eventForm.fecal_score" filterable placeholder="请选择"  style="width: 100%;"  >
                     <el-option v-for="item in scoreNameList" :key="item.id" :label="item.name" :value="item.id" />
                   </el-select>
                 </el-form-item>
             </el-row>
             <!-- 测量体温 -->
             <el-row   v-if="eventForm.event_kind == 4" >
                <el-form-item label="体温(℃)：" prop="temp">
                   <el-input ref="temp" v-model="eventForm.temp"   />
                 </el-form-item> 
             </el-row>
             <!-- 测量心跳 -->
             <el-row   v-if="eventForm.event_kind == 5" >
                <el-form-item label="心跳频率(次/分钟)：" prop="heartbeat">
                   <el-input ref="heartbeat" v-model="eventForm.heartbeat"   />
                 </el-form-item> 
             </el-row>
             <!-- 测量呼吸 -->
             <el-row   v-if="eventForm.event_kind == 6" >
                <el-form-item label="呼吸频率(次/分钟)：" prop="breathe">
                   <el-input ref="breathe" v-model="eventForm.breathe"   />
                 </el-form-item> 
             </el-row>
             <!-- 疾病 -->
             <el-row   v-if="eventForm.event_kind == 7" >
                <el-form-item label="疾病名称：" prop="diseased_type">
                   <el-select ref="diseased_type" v-model="eventForm.diseased_type" filterable placeholder="请选择"  style="width: 100%;"  >
                     <el-option v-for="item in diseaseNameList" :key="item.id" :label="item.name" :value="item.id" />
                   </el-select>
                 </el-form-item>
                 <el-form-item label="用药：" prop="medication">
                   <el-input ref="medication" v-model="eventForm.medication"   />
                 </el-form-item> 
             </el-row>
             <!-- 转投栏舍 -->
             <el-row   v-if="eventForm.event_kind == 11" >
                 <el-form-item label="原栏舍：" prop="original_barn_name">
                   <el-input ref="original_barn_name" v-model="eventForm.original_barn_name"   disabled/>
                 </el-form-item> 
                 <el-form-item label="转投栏舍：" prop="new_barn_id">
                   <el-select ref="new_barn_id" v-model="eventForm.new_barn_id" filterable placeholder="请选择"  style="width: 100%;"  @change = "change_cowshed" >
                     <el-option v-for="item in cowshedList" :key="item.id" :label="item.name" :value="item.id" />
                   </el-select>
                 </el-form-item>
             </el-row>
             <!-- 死亡 -->
             <el-row   v-if="eventForm.event_kind == 13" >
                <el-form-item label="死亡原因：" prop="reason">
                   <el-input ref="reason" v-model="eventForm.reason"   />
                 </el-form-item> 
             </el-row>
 
             <el-row  >
                 <el-form-item label="备注：" prop="remark">
                   <el-input ref="remark" v-model="eventForm.remark"   />
                 </el-form-item>
             </el-row>
 
  
            
             
         </el-form>
         <div slot="footer" class="dialog-footer">
           <el-button type="primary" @click="event_dialog_save()">确认</el-button>
           <el-button @click="eventFormShow = false">关闭</el-button>
         </div>
       </div>
     </el-dialog>
  
  
      <!-- 牛只详情 -->
      <el-dialog  title="牛只详情" :visible.sync="cowcodeFormShow" top="10px"  @close="cowcode_dialog_close" width="95%" :append-to-body="true" :close-on-click-modal="false" >
        <div class=" ">
          <CowcodeDetail :cowcode-data="cowcodeData"  />
       
          <div slot="footer" class="dialog-footer">
            <el-button   @click="cowcodeFormShow = false;get_table_data()">关闭</el-button>
          </div>

           
        </div>
      </el-dialog>

   </div>
 
 
 </template> 
 
 <script>
 import {  ajaxDataGet, ajaxDataPost, ajaxDataPut, ajaxDataDelete, checkButtons} from '@/api/common'
 import { parseTime, json2excel } from '@/utils/index.js'
 import CowcodeDetail from '@/componentView/CowcodeDetail.vue'

 export default {
  components: {  CowcodeDetail},
   data() {
 
  
     
  
   
     return {
 
  
 
       //接口 - 获取 - 表格
       url_get_table:'/api/v1/ops/calf/list',
       //接口 - 新增 - 表格
       url_add_table:'/api/v1/ops/calf/add',  
       //接口 - 修改 - 表格
       url_edit_table:'/api/v1/ops/calf/update', 
       //接口 - 删除 - 表格
       url_delete_table:'/api/v1/ops/calf/delete', 
 
 
        //接口 - 新增事件 - 表格
        url_add_event_table:'/api/v1/ops/event/add',  
       
       //接口 - 下拉框 列表 
       url_get_select1:'/api/v1/ops/calf_feed/enum/list',
 
       //接口 - 下拉框 列表 栏舍组
       url_get_select2:'/api/v1/ops/barn_group/list?page=1&page_size=1000',
 
       
 
       //获取 - 表格数据 - 参数
       searchData:{
         calf_code: "",
         barn_name: "",
         barn_number: "",
         barn_id:undefined,
         mother_code: "",
         calf_category_id:undefined,
         genders: undefined,
         status: undefined,
         min_daily_weight_gain: undefined,
         max_daily_weight_gain: undefined,
         min_daily_age: undefined,
         max_daily_age: undefined,
         page: 1,  //页码
         page_size: 10,   //每页数量
         total:0,  //总页数
         pastureId: ""
       },
       tableLoading: false,
       //表格内容
       tableList:[
         //  { username:"admin", id:100, date:'2023-12-01',email:'测试信息1123',roleList:[2,3] },
         // { username:"epans", id:200, date:'2023-12-01',email:'测试信息1123',roleList:[] },
         // { username:"derek", id:300, date:'2023-12-01',email:'测试信息1123' },
         // { username:"admin", id:100, date:'2023-12-01',email:'测试信息1123' },
         // { username:"epans", id:200, date:'2023-12-01',email:'测试信息1123' },
         // { username:"derek", id:300, date:'2023-12-01',email:'测试信息1123' },
         // { username:"admin", id:100, date:'2023-12-01',email:'测试信息1123' },
         // { username:"epans", id:200, date:'2023-12-01',email:'测试信息1123' },
         // { username:"derek", id:300, date:'2023-12-01',email:'测试信息1123' },
         // { username:"admin", id:100, date:'2023-12-01',email:'测试信息1123' },
         // { username:"epans", id:200, date:'2023-12-01',email:'测试信息1123' },
         // { username:"derek", id:300, date:'2023-12-01',email:'测试信息1123' },
       ],
 
 
       //栏舍状态
       statusList:[
         {id: 1, value: '正常'},
         {id: 2, value: '空栏'},
         {id: 3, value: '损坏'},
       ],
 
     
 
       //犊牛类型
       calfTypeList:[
          
       ],
 
        //  下拉框 - 犊牛 
        cowNameList: [
     
       ], 
 
       sexList:[
         {id: 1, value: '公'},
         {id: 2, value: '母'},
       ],
 
       healthList:[
         {id: 1, value: '健康'},
         {id: 2, value: '疾病'},
         {id: 3, value: '出栏'},
         {id: 4, value: '死亡'},
         {id: 5, value: '淘汰'},
       ],
 
 
 
 
        //  下拉框 - 事件类型 
        eventNameList: [
         {id: 1, name: "称重"}, 
         {id: 2, name: "饲喂"}, 
         {id: 3, name: "粪便情况"},
         {id: 4, name: "测量体温"},
         {id: 5, name: "测量心跳"},
         {id: 6, name: "测量呼吸"},
         {id: 7, name: "疾病"},
         {id: 8, name: "痊愈"},
         {id: 9, name: "去角"},
         {id: 10, name: "去副乳"},
         {id: 11, name: "转投栏舍"},
         {id: 12, name: "出栏"},
         {id: 13, name: "死亡"},
       ], 
 
 
       //  下拉框 - 粪便评分 
       scoreNameList: [
         {id: 5, name: "5分"}, 
         {id: 4, name: "4分"}, 
         {id: 3, name: "3分"},
         {id: 2, name: "2分"},
         {id: 1, name: "1分"},
       ], 
 
       //  下拉框 - 疾病 
       diseaseNameList: [
         // {id: 1, name: "腹泻"}, 
         // {id: 2, name: "便秘"}, 
         // {id: 3, name: "下痢"},
         // {id: 4, name: "脐炎"},
         // {id: 5, name: "肺炎"},
         // {id: 6, name: "软瘫衰弱"}
       ], 
 
       //  下拉框 - 栏舍
       cowshedList: [
         // {id: "栏舍组1", name: "栏舍组1"}, 
         // {id: "栏舍组2", name: "栏舍组2"}, 
         // {id: "栏舍组3", name: "栏舍组3"}
       ], 
       class_num:4,
 
 
  
 
       addFormShow:false,
       addFormStatus: '',
       addFormTxt: {  edit: '修改',  create: '新增' },
       addForm:{
         barn_id:undefined,ear_number:'',calf_code:'',calf_category_id:undefined, id:undefined, birth_date_format: parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}'),genders:undefined, birth_weight:undefined, current_weight:undefined, mother_code:'',remark:'',
       },
 
       addFormRules:{
         barn_id: [ { required: true, message: '栏舍必选', trigger: 'change' },  ],
         calf_code: [ { required: true, message: '犊牛编号必填', trigger: 'blur' },  ],
         // ear_number: [ { required: true, message: '耳号必填', trigger: 'blur' },  ],
         calf_category_id: [ { required: true, message: '犊牛类型必选', trigger: 'change' },  ],
         birth_date_format: [ { required: true, message: '出生日期必填', trigger: 'blur' },  ],
         genders: [ { required: true, message: '性别必选', trigger: 'change' },  ],
         birth_weight: [ { required: true, message: '出生体重必填', trigger: 'blur' },  ],
         current_weight: [ { required: true, message: '当前体重必填', trigger: 'blur' },  ],
         mother_code: [ { required: true, message: '母号必填', trigger: 'blur' },  ],
 
       },
       //按钮权限
       isButtonEdit:false,
 
 
 
       eventFormShow:false,
       eventForm:{
         calf_code:'',id:'' ,event_kind:undefined,medication:'',remark:''
       },
       eventFormRules:{
       
 
       },


      //牛只详情组件
      cowcodeData:{ id:"" },
      cowcodeFormShow:false,
 
 
      
        
     }
   },
   created(){
       //获取按钮权限
       const isButtonEdit = checkButtons(this.$store.state.buttonsList, "牛只信息编辑")
       this.isButtonEdit = isButtonEdit
       console.log('this.isButtonEdit==========',this.isButtonEdit)
      
 
       //获取下拉框
       this.get_select_list1()
 
       //表格 - 初始化 
       this.get_table_data()
 
 
  
      
 
     
   },
   methods:{
 
   
     
     //获取 下拉框
     get_select_list1(){
         var me = this
          
 
 
         ajaxDataPost('/api/v1/ops/base_setting/calf_type/list?page=1&page_size=1000', {name:"" }).then(e => {
             console.log("穿梭框1：",e)
 
             //打印请求成功结果
             if(e.data.list == null || e.data.list == undefined ||e.data.list.length == 0   ){
               me.calfTypeList = []
             } else {
               me.calfTypeList = e.data.list
             }
 
         })
 
 
 
 
         ajaxDataPost('/api/v1/ops/barn/list?page=1&page_size=1000', {name:"",barn_group_name:"",status:undefined}).then(e => {
             console.log("栏舍：",e)
 
             //打印请求成功结果
             if(e.data.list == null || e.data.list == undefined ||e.data.list.length == 0   ){
               me.cowshedList = []
             } else {
               me.cowshedList = e.data.list
             }
 
         })
 
 
 
         
 
 
         ajaxDataPost('/api/v1/ops/calf/list?page=1&page_size=10000', {}).then(e => {
           console.log("牛只下拉框：",e)
 
           if(e.code == 200 ){
             me.cowNameList = e.data.list
            
           } else {
             me.cowNameList = []
           }
         })
 
 
         ajaxDataPost('/api/v1/ops/base_setting/category_table/list?page=1&page_size=10000', {category_type:3}).then(e => {
           console.log("疾病下拉框：",e)
 
           if(e.code == 200 ){
             me.diseaseNameList = e.data.list
            
           } else {
             me.diseaseNameList = []
           }
         })
 
 
         
  
 
       // 班次数量下拉框
       ajaxDataGet('/api/v1/ops/calf_feed/enum/list').then(e => {
         console.log(e)
         if(e.code === 200){
           var class_num = e.data.class_list.length
         } else {
           var class_num = 4
         }
         console.log("class_num========",class_num)
         me.class_num = class_num
       })
 
 
     
     },
 
     
     //获取 表格
     get_table_data() {
  
      var me = this
 
      me.tableLoading = true
      console.log("searchData======>", me.searchData)
 
      if( me.searchData.status == ""){
         me.searchData.status = undefined
       }
       
       if( me.searchData.calf_category_id == ""){
         me.searchData.calf_category_id = undefined
       }
       if( me.searchData.genders == ""){
         me.searchData.genders = undefined
       }
 
       var send_url = me.url_get_table + '?page=' + me.searchData.page +  '&page_size=' + me.searchData.page_size
 
       ajaxDataPost(send_url,  me.searchData).then(e => {
         console.log("表格请求结果：",e)
           //打印请求成功结果
           if(e.code == 200 ){
             me.tableList = e.data.list
             me.searchData.total = e.data.total;	// 总数
             me.searchData.page = e.data.page;	//页码
             me.searchData.page_size = e.data.page_size;	//每页数量
            
           } else {
             me.$message({ type: 'error', message: '请求表格列表失败！' + e.msg, duration: 2000 })
           }
 
           setTimeout(() => {
             me.tableLoading = false
           }, 100)
   
         })
 
        
     },
     //搜索 查询表格
     form_search(){
       var me = this
       console.log('请求表格列表searchData',me.searchData)
       me.get_table_data()
 
     },
 
     //重置 表格
     form_clear(){
       var me = this
       me.searchData.calf_code = ""
       me.searchData.barn_name = ""
       me.searchData.mother_code = ""
       me.searchData.barn_number = ""
       me.searchData.calf_category_id = undefined
       me.searchData.genders = undefined
       me.searchData.status = undefined
       me.searchData.min_daily_weight_gain = undefined
       me.searchData.max_daily_weight_gain = undefined
       me.searchData.min_daily_age = undefined
       me.searchData.max_daily_age = undefined
 
       me.searchData.page = 1
       me.searchData.page_size = 10
 
      
 
 
       me.get_table_data()
     },
 
     //监听 page_size 改变的事件
     change_size_page(item){
       console.log(item)
      // this.searchData.page_size = item
       //  this.getUserList()
     },
 
     //监听 page 改变的事件
     change_current_page(item){
       console.log(item)
        this.searchData.page = item
        this.get_table_data()
     },
 
     //清空弹窗表单信息
     reset_form(){
       this.addForm.calf_code = ''
       this.addForm.ear_number = ''
       this.addForm.name = ''
       this.addForm.barn_id = undefined
       this.addForm.barn_number = ''
 
         
       this.addForm.calf_category_id = undefined
       this.addForm.id = undefined
       this.addForm.genders = undefined
       this.addForm.birth_weight = undefined
       this.addForm.current_weight = undefined
       this.addForm.mother_code = ''
       this.addForm.remark = ''
  
       this.addForm.birth_date_format = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
 
 
     
        
     },
 
     //新增
     form_add() {
       this.reset_form()
       this.addFormStatus = 'create'
       this.addFormShow = true
       this.$nextTick(() => {
         this.$refs['addFormRef'].clearValidate()
       })
     },
 
     //编辑
     form_edit(row) {
       this.reset_form()
       console.log('行内容row=========', row)
       //编辑行内容赋值
       this.addForm = Object.assign({}, row)  
 
       if(row.genders == 0){
         this.addForm.genders = undefined
       }
       this.addFormStatus = 'edit'
       this.addFormShow = true
       this.$nextTick(() => {
         this.$refs['addFormRef'].clearValidate()
       })
     },
 
 
     //新增关闭
     add_dialog_close(){
        //内容重置
        this.$refs['addFormRef'].resetFields()
     },
 
     //新增 保存
     add_dialog_save() {
       var me = this
       this.$refs['addFormRef'].validate(valid => {
         //验证成功
         if (valid) {
           //发起请求
           var send_data = {
               "barn_id": me.addForm.barn_id,
               "calf_code": me.addForm.calf_code,
               "ear_number": me.addForm.ear_number,
               
               "calf_category_id": me.addForm.calf_category_id,
               "birth_weight": parseFloat(me.addForm.birth_weight) ,
               "genders": me.addForm.genders,
               "current_weight":parseFloat(me.addForm.current_weight) ,
               "mother_code": me.addForm.mother_code,
               "remark": me.addForm.remark,
               // "birth_date":parseTime(me.addForm.birth_date_format, '{y}-{m}-{d} {h}:{i}:{s}'), 
               "birth_date_format":parseTime(me.addForm.birth_date_format, '{y}-{m}-{d} {h}:{i}:{s}'), 
 
           }
 
  
  
 
 
           console.log("弹窗参数：", send_data)
 
           //关闭弹窗
           // me.addFormShow = false
          //加载 - 发送新增保存
            ajaxDataPost(me.url_add_table, send_data).then(e => {
                 console.log("新增结果：",e)
                 //打印请求成功结果
                 if(e.code == 200  ){
                   me.$message({ type: 'success', message: '新增成功！'  , duration: 2000 })
                   //关闭弹窗
                   me.addFormShow = false
                   me.get_table_data()
                 } else {
                   me.$message({ type: 'error', message: '新增失败！' + e.msg, duration: 2000 })
                 }
             })
          
         }
       })
     },
     //编辑 保存
     edit_dialog_save(){
       var me = this
       this.$refs['addFormRef'].validate(valid => {
         //验证成功
         if (valid) {
           //发起请求
           var send_data = {
     
               "id": me.addForm.id,
               "barn_id": me.addForm.barn_id,
               "calf_code": me.addForm.calf_code,
               "ear_number": me.addForm.ear_number,
               "calf_category_id": me.addForm.calf_category_id,
               "birth_weight": parseFloat(me.addForm.birth_weight) ,
               "genders": me.addForm.genders,
               "current_weight":parseFloat(me.addForm.current_weight) ,
               "mother_code": me.addForm.mother_code,
               "remark": me.addForm.remark,
               // "birth_date":parseTime(me.addForm.birth_date_format, '{y}-{m}-{d} {h}:{i}:{s}'), 
               "birth_date_format":parseTime(me.addForm.birth_date_format, '{y}-{m}-{d} {h}:{i}:{s}'), 
           }
 
           // var name = this.barnGroupList.find(obj => obj.id == me.addForm.barn_group_id).name
           // console.log(name)
 
            // 编辑保存
           console.log("弹窗参数：", send_data)
 
           //关闭弹窗
           // me.addFormShow = false
          //加载 - 发送新增保存
          ajaxDataPut(me.url_edit_table, send_data).then(e => {
                 console.log("编辑结果：",e)
                 //打印请求成功结果
                 if(e.code == 200  ){
                   me.$message({ type: 'success', message: '编辑成功！'  , duration: 2000 })
                   //关闭弹窗
                   me.addFormShow = false
                   me.get_table_data()
                 } else {
                   me.$message({ type: 'error', message: '编辑失败！' + e.msg, duration: 2000 })
                 }
             })
          
         }
       })
     },
 
 
     //删除
     form_delete(row) {
       var me = this
 
        me.$confirm('是否删除此条内容?', '提示', {
           confirmButtonText: '确定',
           cancelButtonText: '取消',
           type: 'warning'
         }).then(() => {
             console.log("删除的ID参数：", row.id)
             //加载 - 发送新增保存
             ajaxDataDelete(me.url_delete_table + '/' +row.id, {}).then(e => {
                 console.log("编辑结果：",e)
                 //打印请求成功结果
                 if(e.code == 200  ){
                   me.$message({ type: 'success',  message: '删除成功!'  });
                   me.get_table_data()
                 } else {
                   me.$message({ type: 'error', message: '删除失败！' + e.msg, duration: 2000 })
                 }
             })
 
         
  
           
         }).catch(() => {
           me.$message({
             type: 'info',
             message: '已取消删除'
           });          
         });
 
 
        
     },
 
     //事件编辑
     form_event(row) {
       console.log('行内容row=========', row)
       //编辑行内容赋值
       this.eventForm = Object.assign({}, row)  
      if(row.message && row.message !== ""){
         var messageTxt = JSON.parse(row.message)
         //编辑行内容赋值
         this.eventForm  = Object.assign({}, row ,messageTxt)  
       } else {
         this.eventForm  = Object.assign({}, row)  
       }
  
       this.eventFormShow = true
       this.$nextTick(() => {
         this.$refs['eventFormRef'].clearValidate()
       })
     },
 
 
     //事件关闭
     event_dialog_close(){
        //内容重置
        this.$refs['eventFormRef'].resetFields()
        this.eventFormShow = false
     },
 
     //事件 保存
     event_dialog_save() {
       var me = this
       this.$refs['eventFormRef'].validate(valid => {
         //验证成功
         if (valid) {
           //发起请求
            
           var send_data = {
               "calf_code": me.eventForm.calf_code,
               "calf_category_id":  me.eventForm.calf_category_id,
               "calf_category_name": me.eventForm.calf_category_name,
               "event_kind":me.eventForm.event_kind,
               "remark": me.eventForm.remark,
               "source": 2,
               "message": "",
           }
           console.log("弹窗参数：", send_data)
 
           // event_kind 1 称重 2 饲喂 3 粪便情况 4 测量体温 5 测量心跳 6 测量呼吸 7 疾病 8 病愈 9 去角 10 去副乳 11 转栏 12 出栏 13 死亡
           var event_kind = me.eventForm.event_kind
           if(event_kind == 1){
             var messageTxt = {
               "weight":  parseFloat(me.eventForm.weight)
             }
             send_data.message = JSON.stringify(messageTxt)
           }
           if(event_kind == 2){
             var messageTxt = {
               "first_class_food_number":  parseFloat(me.eventForm.first_class_food_number),
               "second_class_food_number":  parseFloat(me.eventForm.second_class_food_number),
               "third_class_food_number":  parseFloat(me.eventForm.third_class_food_number),
               "fourth_class_food_number":  parseFloat(me.eventForm.fourth_class_food_number),
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 3){
             var messageTxt = {
               "fecal_score":  me.eventForm.fecal_score  
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 4){
             var messageTxt = {
               "temp":   parseFloat(me.eventForm.temp)
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 5){
             var messageTxt = {
               "heartbeat":  parseFloat(me.eventForm.heartbeat)
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 6){
             var messageTxt = {
               "breathe":  parseFloat(me.eventForm.breathe)
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 7){
             var messageTxt = {
               "diseased_type":  me.eventForm.diseased_type,
               "medication":  me.eventForm.medication,
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           if(event_kind == 11){
             var messageTxt = {
               "original_barn_id":   parseFloat(me.eventForm.original_barn_id),
               "original_barn_name":  me.eventForm.original_barn_name,
               "new_barn_id":   parseFloat(me.eventForm.new_barn_id),
               "new_barn_string":  me.eventForm.new_barn_string,
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
           
           if(event_kind == 13){
             var messageTxt = {
               "reason":  me.eventForm.reason
             }
             send_data.message = JSON.stringify(messageTxt)
           }
 
       
  
 
           //关闭弹窗
           // me.addFormShow = false
          //加载 - 发送新增保存
            ajaxDataPost(me.url_add_event_table, send_data).then(e => {
                 console.log("新增结果：",e)
                 //打印请求成功结果
                 if(e.code == 200  ){
                   me.$message({ type: 'success', message: '新增成功！'  , duration: 2000 })
                   //关闭弹窗
                   me.eventFormShow = false
                   me.get_table_data()
                 } else {
                   me.$message({ type: 'error', message: '新增失败！' + e.msg, duration: 2000 })
                 }
             })
          
         }
       })
     },
 
 
     
 
     //查看牛号信息
     click_cowcode(row) {
       console.log('查看牛号信息卡片', row)
       this.cowcodeData =  Object.assign({}, row)  
       this.cowcodeFormShow = true
     },

     cowcode_dialog_close(){
       this.cowcodeFormShow = false
      },
 
     form_export() {
     //获取请求表格数据的参数
     //this.download.getdataListParm.parammaps = this.tableObj.getdataListParm.parammaps
     //请求表格
     // GetDataByName(this.download.getdataListParm).then(response => {
     //     if (response.data.list !== null) {
     //       this.download.list = response.data.list
     //     } else {
     //       this.download.list = []
     //     }
     //     var excelDatas = [
     //       {
     //         tHeader: ['表头1', '表头2', '表头3', '表头4',],
     //         filterVal: ['title1', 'title2', 'title3', 'title4'],
     //         tableDatas: this.download.list,
     //         sheetName: 'Sheet1'
     //       }
     //     ]
     //     json2excel(excelDatas, '表格大标题', true, 'xlsx')
     // })
 
     var excelDatas = [
         {
             tHeader: ['表头1', '表头2', '表头3', '表头4',],
             filterVal: ['title1', 'title2', 'title3', 'title4'],
             tableDatas: [ 
                 {title1: "内容1",title2: "内容2",title3: "内容3",title4: "内容4"},
                 {title1: "内容11",title2: "内容22",title3: "内容32",title4: "内容44"},
                 {title1: "内容111",title2: "内容222",title3: "内容333",title4: "内容444"},
             ],
             sheetName: 'Sheet1'
         }
     ]
     json2excel(excelDatas, '表格大标题', true, 'xlsx')
 }
 
      
 
   }
 }
 </script>
 <!-- 加了scoped，则是仅在此组件里生效 -->
 <style scoped>
 
 </style>
 