<template>
  <div ref="appContainer" class="app-container">
    <div ref="myContainer" class="myContainer">
      <!-- 配方模板表 -->
      <div ref="template" class="template">
        <div class="recipeTemplate">
          <p>配方模板表</p>
        </div>
        <div class="search">
          <el-select v-model="table.parammaps.cattle_category_id" filterable placeholder="牲畜类别" class="filter-item" clearable>
            <el-option v-for="item in livestockTypeList" :key="item.value" :label="item.label" :value="item.label" />
          </el-select>
          <el-select v-model="table.parammaps.formula_type_id" filterable placeholder="配方类型" class="filter-item" style="width: 120px;" clearable>
            <el-option v-for="item in formulaTypeList" :key="item.value" :label="item.label" :value="item.label" />
          </el-select>
          <el-select v-model="table.parammaps.data_source_id" filterable placeholder="来源" class="filter-item" style="width: 120px;" clearable>
            <el-option v-for="item in sourceList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <el-select v-model="table.parammaps.is_show" filterable placeholder="是否启用" class="filter-item" style="width: 120px;" clearable>
            <el-option v-for="item in enableList" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <div ref="selectInput" class="filter-item selectInput">
            <el-input v-model="table.parammaps.all" type="text" placeholder="请点击选择搜索条件" class="Input" />
            <i v-if="arrowDown" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
            <i v-if="arrowUp" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
            <ul v-if="arrowUp" class="selectUl">
              <li><a>配方名称</a><el-input v-model="table.parammaps.name" clearable style="width: 245px;" /></li>
              <li><a>备注</a><el-input v-model="table.parammaps.remarks" clearable style="width: 245px;" /></li>
              <li />
              <li>
                <div style="float: right;">
                  <el-button class="downminCancel" @click="arrowUp=false;arrowDown=true;">取消</el-button>
                  <el-button class="miniPrimary" @click="handleSearch1">搜索</el-button>
                </div>
              </li>
            </ul>
          </div>
          <el-button class="successBorder" @click="handleSearch1">查询</el-button>
          <el-button class="successBorder" @click="handleRefresh1">重置</el-button>
        </div>
        <div class="operation">
          <el-button v-if="isAdd1" class="success" icon="el-icon-plus" @click="handleCreate1">新增</el-button>
          <el-upload style="float: right;" action="#" :http-request="httpRequest" :show-file-list="false" :on-change="handleChange" :before-upload="beforeAvatarUpload" multiple accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
            <el-button v-if="isImport1" class="import" icon="el-icon-download" style="float: right;">导入</el-button>
          </el-upload>
          <el-dropdown style="float: right;margin-right: 10px;">
            <el-button v-if="isExport1" class="export" icon="el-icon-upload2">导出</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
              <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button class="export" style="float: right;" @click="handleDistributeFormula">下发配方</el-button>
        </div>
        <div ref="table" class="table">
          <el-table
            :key="table.tableKey"
            v-loading="table.listLoading"
            element-loading-text="给我一点时间"
            :data="table.list"
            border
            fit
            highlight-current-row
            style="width: 98%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
            :height="myheight1"
            @row-click="table1RowClick"
            @selection-change="handleSelectionChange"
          >
            <el-table-column type="selection" align="center" width="50" />
            <el-table-column label="序号" align="center" type="index" width="50px" />
            <el-table-column label="配方名称" min-width="90px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.NoEdit">{{ scope.row.name }}</span>
                <el-input v-if="scope.row.Edit" v-model.trim="scope.row.name" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:98%;padding:10px 0;" />
              </template>
            </el-table-column>
            <el-table-column label="配方编码" min-width="130px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.NoEdit">{{ scope.row.encode_number }}</span>
                <el-input v-if="scope.row.Edit" v-model.trim="scope.row.encode_number" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" disabled maxlength="32" style="width:98%;padding:10px 0;" />
              </template>
            </el-table-column>
            <el-table-column label="配方颜色" min-width="70px" align="center">
              <template slot-scope="scope">
                <el-color-picker v-model="scope.row.colour" size="mini" :predefine="predefineColors" style="vertical-align: middle;" :disabled="scope.row.NoEdit" />
              </template>
            </el-table-column>
            <el-table-column label="牲畜类别" min-width="130px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.NoEdit">{{ scope.row.cattle_category_name }}</span>
                <el-select v-if="scope.row.Edit" v-model="scope.row.cattle_category_id" filterable placeholder="牲畜类别" class="filter-item" style="width:95%;padding:10px 0;" @change="changeLivestockType1">
                  <el-option v-for="item in livestockTypeList" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="配方类型" min-width="130px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.NoEdit">{{ scope.row.formula_type_name }}</span>
                <el-select v-if="scope.row.Edit && scope.row.isCreate == true" v-model="scope.row.formula_type_id" filterable placeholder="配方类型" class="filter-item" style="width:95%;padding:10px 0;" @change="changeFormulaType1">
                  <el-option v-for="item in formulaTypeList" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
                <el-select v-if="scope.row.Edit && scope.row.isUpdateSave == true" v-model="scope.row.formula_type_id" disabled filterable placeholder="配方类型" class="filter-item" style="width:95%;padding:10px 0;" @change="changeFormulaType1">
                  <el-option v-for="item in formulaTypeList" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="来源" min-width="90px" align="center" prop="data_source_name" />
            <el-table-column label="备注" min-width="90px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.NoEdit">{{ scope.row.remarks }}</span>
                <el-input v-if="scope.row.Edit" v-model="scope.row.remarks" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="255" style="width:95%;padding:10px 0;" />
              </template>
            </el-table-column>
            <el-table-column label="版本号" min-width="90px" align="center" prop="version">
              <template slot-scope="scope">
                <span>{{ scope.row.version }}</span>
                <!-- <span @click="clickNew(scope.row)" class="new">NEW</span> -->
              </template>
            </el-table-column>
            <el-table-column label="使用牧场" min-width="90px" align="center" prop="pasture_name"/>
            <el-table-column label="是否启用" min-width="90px" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.is_show" :disabled="scope.row.NoEdit==true && !isEnable" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" @change="handleEnableChange1(scope.$index, scope.row,'show')" />
              </template>
            </el-table-column>
            <el-table-column label="是否可修改" min-width="90px" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.is_modify" :disabled="scope.row.NoEdit==true && !isModify1" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" @change="handleEnableChange1(scope.$index, scope.row,'modify')" />
              </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width" fixed="right">
              <template slot-scope="{row}">
                <el-button v-if="row.NoEdit && isUsageOverview" icon="el-icon-tickets" class="miniSuccess" @click="handleRowUsageOverview(row)" />
                <span v-if="row.NoEdit && isRoleEdit && isUsageOverview" icon="el-icon-data-line" class="centerSpan">|</span>
                <el-button v-if="row.isCreate && isAdd1" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData1(row)" />
                <span v-if="row.isCreate && isAdd1" class="centerSpan">|</span>
                <el-button v-if="row.isCreate && isAdd1" class="minCancel" icon="el-icon-close" @click="createCancel1(row)" />

                <el-button v-if="row.isUpdate && isEdit1" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate1(row)" />
                <span v-if="row.isUpdate && isEdit1 && isDelete1" class="centerSpan">|</span>

                <el-button v-if="row.isUpdate && isDelete1" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete1(row)" />

                <el-button v-if="row.isUpdateSave && isEdit1" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData1(row)" />
                <span v-if="row.isUpdateSave && isEdit1" class="centerSpan">|</span>
                <el-button v-if="row.isUpdateSave && isEdit1" class="minCancel" icon="el-icon-close" @click="updateCancel1(row)" />

                <span v-if="row.NoEdit && isEdit1" icon="el-icon-data-line" class="centerSpan">|</span>
                <el-button v-if="row.NoEdit && isFormulaEvaluation" icon="el-icon-data-line" class="miniSuccess" @click="handleFormulationEvaluation(row)" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <span v-if="table.listLoading == false" style="margin-right: 30px;margin-top: 10px;margin-bottom: 10px;font-size: 14px;">共{{ table.total }}条</span>
      </div>
      <!-- 配方详情表 -->
      <div v-if="isDetail" ref="detail" class="detail">
        <el-row :gutter="20">
          <el-col :span="8">
            <div class="search">
              <el-select v-model="table3.parammaps.pasture_id" style="width:100px;" filterable placeholder="牧场" class="filter-item" clearable>
                <el-option v-for="item in pastureList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
              <el-date-picker v-model="table3.parammaps.inputDatetime" :clearable="false" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
              <el-button class="successBorder" @click="handleSearch3">查询</el-button>
            </div>
            <div class="table">
              <el-timeline>
                <el-timeline-item v-for="(item, index) in table3.list" color="#009A69" :key="index" :timestamp="item.timestamp">
                  <span style="font-size:14px;">{{item.pasture_name}}</span><br/>
                  <span style="font-size:12px;">{{item.modify_time}}</span><br/>
                  <span style="font-size:12px;">{{item.modify_detail}}</span>
                </el-timeline-item>
              </el-timeline>
            </div>
          </el-col>
          <el-col :span="16">
          <div class="recipeTemplate">
            <p>配方详情表</p>
          </div>
          <div class="operation" style="margin-bottom: 10px;">
            <el-button v-if="isRoleEdit" style="float: left;" icon="el-icon-plus" class="success" @click="handleCreate2">新增</el-button>
            <el-button v-if="isRoleEdit" style="float: left;" icon="el-icon-delete" class="danger" @click="form_delete2">删除</el-button>
            <el-button v-if="isRoleEdit" style="float: left;" class="success" icon="el-icon-takeaway-box" @click="handleSyntheticPremix">合成预混料</el-button>
            <el-button v-if="isOrder && isRoleEdit" icon="el-icon-sort" style="float: left;" class="success" @click="handleChangeOrder">更改顺序</el-button>
            <div v-else style="float: left;margin-left: 10px;">
              <el-button  icon="el-icon-folder-checked" class="success" @click="saveChangeOrder">保存</el-button>
              <el-button  icon="el-icon-close" class="sortCancel" @click="cancelChangeOrder">取消</el-button>
            </div>
            <el-button class="hide" @click="handleCloseTable2">隐藏</el-button>
            <el-button v-if="isEnlarge" class="hide2" @click="handleEnlarge">放大</el-button>
            <el-button v-else class="hide2" @click="handleNarrow">缩小</el-button>
          </div>
          <div class="search">
            <div ref="selectInput2" class="filter-item selectInput" style="margin: 0 10px;">
              <el-input v-model="table2.parammaps.all" type="text" name="" value="" placeholder="请点击选择搜索条件" class="Input" />
              <i v-if="arrowDown2" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
              <i v-if="arrowUp2" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
              <ul v-if="arrowUp2" class="selectUl">
                <li>
                  <a style="width: 130px;">饲料名称</a>
                  <el-select v-model="table2.parammaps.forage_name" filterable clearable placeholder="" style="width:190px;">
                    <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.name" />
                  </el-select>
                </li>
                <li><a style="width: 130px;">饲料组名称</a><el-input v-model="table2.parammaps.forage_group_name" style="width: 190px;" /></li>
                <li><a style="width: 130px;">重量</a><el-input v-model="table2.parammaps.weight" style="width: 190px;" /></li>
                <li>
                  <a style="width: 130px;">搅拌延时</a>
                  <el-select v-model="table2.parammaps.stir_delay" filterable placeholder="" style="width:190px;" clearable>
                    <el-option v-for="item in mixingDelayList" :key="item.id" :label="item.name" :value="item.name" />
                  </el-select>
                </li>
                <li>
                  <a style="width: 130px;">是否锁定牛头数比例</a>
                  <el-select v-model="table2.parammaps.is_lock_cow_count_ratio" placeholder="" style="width:190px;" clearable>
                    <el-option v-for="item in lockBullsList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </li>
                <li><a style="width: 130px;">顺序</a><el-input v-model="table2.parammaps.sort" style="width: 190px;" /></li>
                <li>
                  <div style="float: right;">
                    <el-button class="downminCancel" @click="arrowUp2=false;arrowDown2=true;">取消</el-button>
                    <el-button class="miniPrimary" @click="form_search2">搜索</el-button>
                  </div>
                </li>
              </ul>
            </div>
            <el-button class="successBorder" @click="form_search2">查询</el-button>
            <el-button class="successBorder" @click="handleRefresh2">重置</el-button>
          </div>
          <div v-if="isEnlarge" class="table2">
            <el-table
              id="table2"
              ref="table2"
              :key="table2.tableKey"
              v-loading="table2.listLoading"
              element-loading-text="给我一点时间"
              :data="table2.list"
              border
              fit
              highlight-current-row
              style="width: 98%;"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable"
              row-key="id"
              show-summary
              :max-height="220"
              :summary-method="getSummaries"
              @selection-change="handleSelectionChange2"
              @cell-dblclick="celldblclick"
            >
              <el-table-column type="selection" width="50" />
              <el-table-column label="序号" align="center" type="index" width="50px" />
              <el-table-column label="饲料组" min-width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.groupNoEdit">{{ scope.row.forage_group_name }}</span>
                  <el-input v-if="scope.row.groupEdit" v-model="scope.row.forage_group_name" :disabled="scope.row.isGroupDisabled" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
                </template>
              </el-table-column>
              <el-table-column label="饲料名称" min-width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.forage_name }}</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.forage_id" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;" @change="(value)=> {changeFname(value, scope.row)}">
                    <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="重量（KG）" prop="fweight" width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.weight }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.weight" placeholder="重量" step="0.0001" type="number" style="width:95%;padding:10px 0;" />
                </template>
              </el-table-column>
              <el-table-column label="搅拌延时（min）" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.stir_delay }}</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.stir_delay" filterable placeholder="搅拌延时" class="filter-item" style="width:95%;padding:10px 0;">
                    <el-option v-for="item in mixingDelayList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="允许延时偏差(min)" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.allow_error }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.allow_error" step="0.01" type="number" style="width:95%;padding:10px 0;" min-number="0" />
                </template>
              </el-table-column>
              <el-table-column v-if="lockCount.isLockCount" label="是否锁定牛头数比例" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit && scope.row.islockcount == '0'">否</span>
                  <span v-if="scope.row.NoEdit && scope.row.islockcount == '1'">是</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.islockcount" placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
                    <el-option v-for="item in lockBullsList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="顺序" min-width="70px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.sort }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.sort" step="0.01" type="number" style="width:95%;padding:10px 0;" min-number="0" @blur="blurSort(scope.row)" />
                </template>
              </el-table-column>
              <el-table-column label="是否可修改" min-width="90px" align="center">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.is_modify" :disabled="scope.row.NoEdit==true && !isModify2" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" @change="handleEnableChange2(scope.$index, scope.row,'modify')" />
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="{row}">
                  <el-button v-if="row.isCreate && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData2(row)" />
                  <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" icon="el-icon-close" @click="createCancel2(row)" />
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate2(row)" />
                  <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete2(row)" />
                  <el-button v-if="row.isUpdateSave && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData2(row)" />
                  <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel2(row)" />
                  <span v-if="parseInt(row.preftid)>0 && row.isUpdateSave==false && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="parseInt(row.preftid)>0 && row.isUpdateSave==false && isRoleEdit" icon="el-icon-connection" class="miniSuccess" @click="handleSplitPremix(row)" />
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div v-else class="table2">
            <el-table
              id="table2"
              ref="mytable2"
              :key="table2.tableKey"
              v-loading="table2.listLoading"
              element-loading-text="给我一点时间"
              :data="table2.list"
              border
              fit
              highlight-current-row
              style="width: 98%;"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable"
              row-key="id"
              show-summary
              :max-height="enlargeHeight"
              :summary-method="getSummaries"
              @selection-change="handleSelectionChange2"
              @cell-dblclick="celldblclick"
            >
              <el-table-column type="selection" width="50" />
              <el-table-column label="序号" align="center" type="index" width="50px" />
              <el-table-column label="饲料组" min-width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.groupNoEdit">{{ scope.row.forage_group_name }}</span>
                  <el-input v-if="scope.row.groupEdit" v-model="scope.row.forage_group_name" :disabled="scope.row.isGroupDisabled" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" />
                </template>
              </el-table-column>
              <el-table-column label="饲料名称" min-width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.forage_name }}</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.forage_id" filterable placeholder="" class="filter-item" style="width:95%;padding:10px 0;" @change="(value)=> {changeFname(value, scope.row)}">
                    <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="重量（KG）" prop="fweight" width="120px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.weight }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.weight" placeholder="重量" step="0.0001" type="number" style="width:95%;padding:10px 0;" />
                </template>
              </el-table-column>
              <el-table-column label="搅拌延时（min）" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.stir_delay }}</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.stir_delay" filterable placeholder="搅拌延时" class="filter-item" style="width:95%;padding:10px 0;">
                    <el-option v-for="item in mixingDelayList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="允许延时偏差(min)" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.allow_error }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.allow_error" step="0.01" type="number" style="width:95%;padding:10px 0;" min-number="0" />
                </template>
              </el-table-column>
              <el-table-column v-if="lockCount.isLockCount" label="是否锁定牛头数比例" min-width="80px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit && scope.row.islockcount == '0'">否</span>
                  <span v-if="scope.row.NoEdit && scope.row.islockcount == '1'">是</span>
                  <el-select v-if="scope.row.Edit" v-model="scope.row.islockcount" placeholder="" class="filter-item" style="width:95%;padding:10px 0;">
                    <el-option v-for="item in lockBullsList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column label="顺序" min-width="70px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.NoEdit">{{ scope.row.sort }}</span>
                  <el-input v-if="scope.row.Edit" v-model="scope.row.sort" step="0.01" type="number" style="width:95%;padding:10px 0;" min-number="0" @blur="blurSort(scope.row)"/>
                </template>
              </el-table-column>
              <el-table-column label="是否可修改" min-width="90px" align="center">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.is_modify" :disabled="scope.row.NoEdit==true && !isModify2" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" @change="handleEnableChange2(scope.$index, scope.row,'modify')" />
                </template>
              </el-table-column>
              <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
                <template slot-scope="{row}">
                  <el-button v-if="row.isCreate && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="createData2(row)" />
                  <span v-if="row.isCreate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isCreate && isRoleEdit" class="minCancel" icon="el-icon-close" @click="createCancel2(row)" />
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate2(row)" />
                  <span v-if="row.isUpdate && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdate && isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete2(row)" />
                  <el-button v-if="row.isUpdateSave && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData2(row)" />
                  <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel2(row)" />
                  <span v-if="parseInt(row.preftid)>0 && row.isUpdateSave==false && isRoleEdit" class="centerSpan">|</span>
                  <el-button v-if="parseInt(row.preftid)>0 && row.isUpdateSave==false && isRoleEdit" icon="el-icon-connection" class="miniSuccess" @click="handleSplitPremix(row)" />
                </template>
              </el-table-column>
            </el-table>
          </div>
        </el-col>
      </el-row>
      </div>
    </div>
    <!-- 下发配方 -->
    <el-dialog :fullscreen="dialogFull" :destroy-on-close="true" :visible.sync="distributeFormula.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
            {{ textMap[distributeFormula.dialogStatus] }}
          </span>
          <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
            <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
            <svg-icon v-else icon-class="fullscreen" />
          </div>
        </div>
      </template>
      <div class="dialogMinHeight" style="overflow-y: auto;margin-bottom: 0px;overflow-x: hidden;">
        <div ref="distributeFormulaDialog" class="distributeFormulaDialog">
          <div class="search">
            <el-input v-model="distributeFormula.table.parammaps.name" placeholder="请输入牧场名称搜索" style="width: 245px;" />
            <el-button class="successBorder" @click="handleDistributeFormulaSearch" style="margin-left:10px;">查询</el-button>
            <el-button class="successBorder" @click="handleDistributeFormulaRefresh" style="margin-left:10px;">重置</el-button>
          </div>
          <div class="table">
            <el-table
              :key="distributeFormula.table.tableKey"
              v-loading="distributeFormula.table.listLoading"
              element-loading-text="给我一点时间"
              :data="distributeFormula.table.list"
              border
              fit
              highlight-current-row
              style="width: 98%;"
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              @selection-change="handleSelectionDistributeFormula">
            >
              <el-table-column type="selection" width="55" />
              <el-table-column label="序号" align="center" type="index" width="50px" />
              <el-table-column label="牧场名称" min-width="130px" align="center" prop="name" />
              <el-table-column label="负责人姓名" min-width="90px" align="center" prop="manager_user" />
              <el-table-column label="手机号" min-width="90px" align="center" prop="manager_phone" />
              <el-table-column label="牧场地址" min-width="90px" align="center" prop="address" />
            </el-table>
          </div>
        </div>
      </div>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="distributeFormula.dialogFormVisible = false; ">关闭</el-button>
          <el-button class="save" :disabled="isokDisable || distributeFormula.selectionList.length == 0" @click="distributeFormulaData()">确认</el-button>
        </div>
    </el-dialog>
    <!-- 配方模板表 -->
    <el-dialog :fullscreen="dialogFull" :destroy-on-close="true" :visible.sync="template.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
            {{ textMap[template.dialogStatus] }}
          </span>
          <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
            <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
            <svg-icon v-else icon-class="fullscreen" />
          </div>
        </div>
      </template>
      <div class="dialogMinHeight" style="overflow-y: auto;margin-bottom: 0px;overflow-x: hidden;">
        <div ref="templateDialog" class="templateDialog">
          <div class="recipeTemplate">
            <p>配方模板表</p>
          </div>
          <div class="operation1">
            <el-date-picker v-model="template.table.getdataListParm.parammaps.date" type="date" placeholder="请选择历史记录时间" :clearable="false" style="width: 180px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="changeDate" />
            <!-- <el-button class="successBorder" @click="handleApplication">应用</el-button> -->
          </div>

          <div class="search">
            <el-select v-model="template.table.getdataListParm.parammaps.ccname" placeholder="牲畜类别" class="filter-item" clearable>
              <el-option v-for="item in livestockTypeList" :key="item.value" :label="item.label" :value="item.label" />
            </el-select>
            <el-select v-model="template.table.getdataListParm.parammaps.fttype" placeholder="配方类型" class="filter-item" style="width: 120px;" clearable>
              <el-option v-for="item in formulaTypeList" :key="item.value" :label="item.label" :value="item.label" />
            </el-select>
            <el-select v-model="template.table.getdataListParm.parammaps.enable" placeholder="是否启用" class="filter-item" style="margin-left:10px;width: 120px;" clearable>
              <el-option v-for="item in enableList" :key="item.id" :label="item.name" :value="item.id" />
            </el-select>
            <div ref="selectInput" class="filter-item selectInput">
              <el-input type="text" name="" value="" placeholder="请点击选择搜索条件" class="Input" />
              <i v-if="arrowDown" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
              <i v-if="arrowUp" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
              <ul v-if="arrowUp" class="selectUl">
                <li><a>配方名称</a><el-input v-model="template.table.getdataListParm.parammaps.tname" style="width: 245px;" /></li>
                <li><a>备注</a><el-input v-model="template.table.getdataListParm.parammaps.remark" style="width: 245px;" /></li>
                <li><a>来源</a><el-input v-model="template.table.getdataListParm.parammaps.source" style="width: 245px;" /></li>
                <li>
                  <div style="float: right;">
                    <el-button class="downminCancel" @click="arrowUp=false;arrowDown=true;">取消</el-button>
                    <el-button class="miniPrimary" @click="handleDialogSearch">搜索</el-button>
                  </div>
                </li>
              </ul>
            </div>
            <el-button class="successBorder" @click="handleDialogSearch" style="margin-left:10px;">查询</el-button>
            <el-button class="successBorder" @click="handleDialogRefresh" style="margin-left:10px;">重置</el-button>
          </div>

          <div class="table">
            <el-table
              :key="template.table.tableKey"
              v-loading="template.table.listLoading"
              element-loading-text="给我一点时间"
              :data="template.table.list"
              border
              fit
              highlight-current-row
              style="width: 98%;"
              :row-style="rowStyle"
              :height="myheight2"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              @row-click="tableRowClickDialog"
            >
              <el-table-column v-if="template.dialogStatus == 'RecipeRecord'" label="序号" align="center" type="index" width="50px" />
              <el-table-column v-else label="序号" align="center" type="index" width="50px">
                <template slot-scope="scope">
                  <span>{{ scope.$index + (template.table.pageNum-1) * template.table.pageSize + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column label="配方名称" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.tname }}</span>
                </template>
              </el-table-column>
              <el-table-column label="配方编码" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.tcode }}</span>
                </template>
              </el-table-column>
              <el-table-column label="配方颜色" min-width="110px" align="center">
                <template slot-scope="scope">
                  <el-color-picker v-model="scope.row.tcolor" size="mini" :predefine="predefineColors" style="vertical-align: middle;" />
                </template>
              </el-table-column>
              <el-table-column label="牲畜类别" min-width="110px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.ccname }}</span>
                </template>
              </el-table-column>
              <el-table-column label="配方类型" min-width="110px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.fttype }}</span>
                </template>
              </el-table-column>
              <el-table-column label="来源" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.source }}</span>
                </template>
              </el-table-column>
              <el-table-column label="备注" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.remark }}</span>
                </template>
              </el-table-column>
              <el-table-column label="版本号" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.version }}</span>
                </template>
              </el-table-column>
              <el-table-column label="版本时间" min-width="90px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.versiontime }}</span>
                </template>
              </el-table-column>
              <el-table-column label="是否启用" min-width="90px" align="center">
                <template slot-scope="scope">
                  <el-switch v-model="scope.row.enable" disabled active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" />
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>

        <div v-if="isDetailDialog" id="detailDialog2" ref="detailDialog2" class="detailDialog" style="margin-top: 30px;height: 200px;overflow-y: auto;overflow-x: hidden;">
          <div class="recipeTemplate">
            <p>配方详情表</p>
          </div>
          <div class="operation" >
            <div ref="selectInput2" class="filter-item selectInput">
              <el-input type="text" name="" value="" placeholder="请点击选择搜索条件" class="Input" />
              <i v-if="arrowDown2" icon="el-icon-arrow-down" class="el-icon-arrow-down" />
              <i v-if="arrowUp2" icon="el-icon-arrow-up" class="el-icon-arrow-up" />
              <ul v-if="arrowUp2" class="selectUl">
                <li>
                  <a style="width: 130px;">饲料名称</a>
                  <el-select v-model="template.table2.getdataListParm.parammaps.fname" filterable placeholder="" style="width:245px;">
                    <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.name" />
                  </el-select>
                </li>
                <li><a style="width: 130px;">饲料组名称</a><el-input v-model="template.table2.getdataListParm.parammaps.feedgroup" style="width: 245px;" /></li>
                <li><a style="width: 130px;">重量</a><el-input v-model="template.table2.getdataListParm.parammaps.fweight" style="width: 245px;" /></li>
                <li>
                  <a style="width: 130px;">搅拌延时</a>
                  <el-select v-model="template.table2.getdataListParm.parammaps.autosecondname" filterable placeholder="" style="width:245px;">
                    <el-option v-for="item in mixingDelayList" :key="item.id" :label="item.name" :value="item.name" />
                  </el-select>
                </li>
                <li>
                  <a style="width: 130px;">是否锁定牛头数比例</a>
                  <el-select v-model="template.table2.getdataListParm.parammaps.islockcount" placeholder="" style="width:245px;">
                    <el-option v-for="item in lockBullsList" :key="item.id" :label="item.name" :value="item.id" />
                  </el-select>
                </li>
                <li><a style="width: 130px;">顺序</a><el-input v-model="template.table2.getdataListParm.parammaps.sort" style="width: 245px;" /></li>
                <li>
                  <div style="float: right;">
                    <el-button class="downminCancel" @click="arrowUp2=false;arrowDown2=true;">取消</el-button>
                    <el-button class="miniPrimary" @click="handleDialogSearch2">搜索</el-button>
                  </div>
                </li>
              </ul>
            </div>
            <el-button class="successBorder" @click="handleDialogSearch2">查询</el-button>
            <el-button class="successBorder" @click="handleDialogRefresh2">重置</el-button>
            <el-button class="hide" @click="handleDialogCloseTable2">隐藏</el-button>
          </div>

          <div class="table2">
            <el-table
              id="templateTable2"
              :key="template.table2.tableKey"
              v-loading="template.table2.listLoading"
              element-loading-text="给我一点时间"
              :data="template.table2.list"
              border
              fit
              highlight-current-row
              style="width: 98%;"
              :summary-method="getTemplateTable2Summaries"
              show-summary
              :row-style="rowStyle"
              :cell-style="cellStyle"
              class="elTable table-fixed"
              row-key="id"
            >
              <el-table-column label="饲料组" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.feedgroup }}</span>
                </template>
              </el-table-column>
              <el-table-column label="饲料名称" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.fname }}</span>
                </template>
              </el-table-column>
              <el-table-column label="重量（KG）" prop="fweight" min-width="200px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.fweight }}</span>
                </template>
              </el-table-column>
              <el-table-column label="搅拌延时（min）" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.autosecondname }}</span>
                </template>
              </el-table-column>
              <el-table-column label="是否锁定牛头数比例" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span v-if="scope.row.islockcount == '0'">否</span>
                  <span v-if="scope.row.islockcount == '1'">是</span>
                </template>
              </el-table-column>
              <el-table-column label="顺序" min-width="130px" align="center">
                <template slot-scope="scope">
                  <span>{{ scope.row.sort }}</span>
                </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelClose cancelClose1" @click="template.dialogFormVisible = false; ">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 合成预混料 -->
    <el-dialog :fullscreen="dialogFull" :destroy-on-close="true" :visible.sync="detail.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <template slot="title">
        <div class="avue-crud__dialog__header">
          <span class="el-dialog__title">
            <span style="display:inline-block;width:3px;height:20px;margin-right:5px; float: left;margin-top:2px" />
            {{ textMap[detail.dialogStatus] }}
          </span>
          <div class="avue-crud__dialog__menu" @click="dialogFull? dialogFull=false: dialogFull=true">
            <svg-icon v-if="dialogFull" icon-class="exit-fullscreen" />
            <svg-icon v-else icon-class="fullscreen" />
          </div>
        </div>
      </template>
      <div class="detailDialog">
        <h2>饲料</h2>
        <div class="table1">
          <el-table
            :key="detail.tableKey"
            v-loading="detail.listLoading"
            element-loading-text="给我一点时间"
            :data="detail.list"
            fit
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
            show-summary
          >
            <el-table-column label="序号" align="center" type="index" width="50px" />
            <el-table-column label="饲料名称" min-width="130px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.forage_name }}</span>
              </template>
            </el-table-column>
            <el-table-column prop="weight" label="重量（KG）" />
            <el-table-column label="搅拌延时（min）" min-width="110px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.stir_delay }}</span>
              </template>
            </el-table-column>
            <el-table-column v-if="lockCount.isLockCount" label="是否锁定牛头数比例" min-width="130px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.islockcount == '0'">否</span>
                <span v-if="scope.row.islockcount == '1'">是</span>
              </template>
            </el-table-column>
            <el-table-column label="顺序" min-width="110px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.sort }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <h2>合成预混料</h2>
        <div class="table2" style="margin-bottom: 50px;">
          <el-table
            :key="detail.tableKey2"
            v-loading="detail.listLoading2"
            element-loading-text="给我一点时间"
            :data="detail.list2"
            border
            fit
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="配方名称" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.name" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" :disabled="detail.disabled" />
              </template>
            </el-table-column>
            <el-table-column label="配方颜色" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-color-picker v-model="scope.row.colour" size="mini" :predefine="predefineColors" style="vertical-align: middle;" :disabled="detail.disabled" />
              </template>
            </el-table-column>
            <el-table-column label="牲畜类别" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-select v-model="scope.row.cattle_category_id" placeholder="选择牲畜父类" class="filter-item" style="width:95%;padding:10px 0;" :disabled="detail.disabled" @change="changeLivestockType2">
                  <el-option v-for="item in livestockTypeList" :key="item.value" :label="item.label" :value="item.value" />
                </el-select>
              </template>
            </el-table-column>
            <el-table-column label="配方类型" min-width="110px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.formula_type_name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="来源" min-width="110px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.data_source_name }}</span>
              </template>
            </el-table-column>
            <el-table-column label="备注" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.remarks" type="textarea" :autosize="{ minRows: 1.3, maxRows: 4}" maxlength="32" style="width:95%;padding:10px 0;" :disabled="detail.disabled" />
              </template>
            </el-table-column>
            <el-table-column label="是否启用" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-switch v-model="scope.row.is_show" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="2" :disabled="detail.disabled" />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="detail.dialogFormVisible = false; ">关闭</el-button>
          <el-button class="save" :disabled="isokDisable" @click="syntheticPremixData()">确认</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 历史记录 -->
    <el-dialog :title="textMap[historyRecord.dialogStatus]" :destroy-on-close="true" :visible.sync="historyRecord.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="historyRecord">
        <keep-alive>
          <component :is="historyRecord.myComponent" ref="historyRecord" />
        </keep-alive>
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose1" @click="historyRecord.dialogFormVisible = false; ">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 行内配方记录 -->
    <el-dialog :title="textMap[usageOverview.dialogStatus]" :destroy-on-close="true" :visible.sync="usageOverview.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="usageOverview">
        <div class="search">
          <el-date-picker ref="inputDatetime" v-model="usageOverview.getdataListParm.parammaps.inputDatetime" class="filter-item inputDatetime" type="daterange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
          <el-button class="successBorder" @click="handleRowUsageOverviewSearch">查询</el-button>
        </div>
        <div class="table">
          <el-table
            :key="usageOverview.tableKey"
            v-loading="usageOverview.listLoading"
            element-loading-text="给我一点时间"
            :data="usageOverview.list"
            border
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="序号" align="center" width="50px" type="index" />
            <!-- <el-table-column label="序号" width="60px" align="center" prop="sort" /> -->
            <el-table-column label="牧场名称" min-width="100px" align="center" prop="pasture_name" />
            <el-table-column label="混料准确率（%）" min-width="100px" align="center" prop="mixed_fodder_accurate_ratio" />
            <el-table-column label="混料正确率（%）" min-width="100px" align="center" prop="mixed_fodder_correct_ratio" />
            <el-table-column label="撒料准确率（%）" min-width="100px" align="center" prop="sprinkle_fodder_accurate_ratio" />
            <el-table-column label="撒料正确率（%）" min-width="100px" align="center" prop="sprinkle_fodder_correct_ratio" />
            <el-table-column label="搅拌时间(分钟)" min-width="100px" align="center" prop="add_feed_time" />
            <el-table-column label="搅拌延时(分钟)" min-width="100px" align="center" prop="sprinkle_time" />
            <el-table-column label="撒料时间(分钟)" min-width="100px" align="center" prop="stir_time" />
            <el-table-column label="最近修改配方时间" min-width="100px" align="center" prop="last_edit_time" />
            <!-- <el-table-column label="下发时间" min-width="100px" align="center" prop="datetime1" /> -->
            <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width" fixed="right">
              <template slot-scope="{row}">
                <a class="correcting" size="mini" style="width: 80px;" @click="handle_feedingefficiency(row)">饲喂效率</a>
                <span v-if="isCanceldistributingformula" icon="el-icon-data-line" class="centerSpan">|</span>
                <a  v-if="isCanceldistributingformula" class="correcting" size="mini" style="width: 80px;" @click="handle_canceldistributingformula(row)">取消下发配方</a>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose1" @click="usageOverview.dialogFormVisible = false; ">关闭</el-button>
      </div>
    </el-dialog>


    <el-dialog :title="textMap[feedingEfficiency.dialogStatus]" :destroy-on-close="true" :visible.sync="feedingEfficiency.dialogFormVisible" :close-on-click-modal="false" width="50%">
    <div class="content">
      <div><span class="title">实际牛头数</span><span class="num">{{feedingEfficiency.data.actual_number_of_cattle}}</span></div>
      <div><span class="title">应混料量(kg)</span><span class="num">{{feedingEfficiency.data.amount_to_be_mixed}}</span></div>
      <div><span class="title">实际混料量(kg)</span><span class="num">{{feedingEfficiency.data.actual_mixed_volume}}</span></div>
      <div><span class="title">撒料量(kg)</span><span class="num">{{feedingEfficiency.data.sprinkle_volume}}</span></div>
      <div><span class="title">转投剩料量(kg)</span><span class="num">{{feedingEfficiency.data.leftover_material}}</span></div>
      <div><span class="title">今日剩料量(kg)</span><span class="num">{{feedingEfficiency.data.today_leftovers}}</span></div>
      <div><span class="title">剩料率(%)</span><span class="num">{{feedingEfficiency.data.leftover_rate}}</span></div>
      <div><span class="title">TMR干物质(%)</span><span class="num">{{feedingEfficiency.data.tmr_dry_matter}}</span></div>
      <div><span class="title">配方干物质采食量(kg/头)</span><span class="num">{{feedingEfficiency.data.formulated_dry_matter_intake}}</span></div>
      <div><span class="title">实际干物质采食量(kg/头)</span><span class="num">{{feedingEfficiency.data.actual_dry_matter_intake}}</span></div>
      <div><span class="title">采食率(%)</span><span class="num">{{feedingEfficiency.data.food_intake_rate}}</span></div>
      <div><span class="title">配方成本(元/头)</span><span class="num">{{feedingEfficiency.data.cost_of_formulation}}</span></div>
      <div><span class="title">实际成本(元/头)</span><span class="num">{{feedingEfficiency.data.actual_cost}}</span></div>
      <div><span class="title">产奶量(kg/头)</span><span class="num">{{feedingEfficiency.data.milk_yield}}</span></div>
      <div><span class="title">饲料转化率(%)</span><span class="num">{{feedingEfficiency.data.feed_conversion_ratio}}</span></div>
      <div><span class="title">公斤奶饲料成本</span><span class="num">{{feedingEfficiency.data.feed_costs}}</span></div>
    </div>
    <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose1" @click="feedingEfficiency.dialogFormVisible = false; ">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { postJson,getJson,delJson,exportFile,GetDataByName, GetDataByNames, PostDataByName, failproccess, checkButtons, ExecDataByConfig, formatNum } from '@/api/common'
import Sortable from 'sortablejs'
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
import { json2excel } from '@/utils/index.js'
import axios from 'axios'
import { getToken } from '@/utils/auth'
import { parseTime } from '@/utils/index.js'
import Pagination from '@/components/Pagination'
import localDownloadUtil from "@/utils/localDownloadUtil.js";
export default {
  name: 'RecipeTemplate',
  components: { Pagination },
  data() {
    return {
      isAdd1:'',isEdit1:'',isImport1:'',isExport1:'',isDelete1:'',isFormulaEvaluation:'',isUsageOverview:'',isCanceldistributingformula:'',isModify1:'',isEnable1:'',isModify2:'',
      predefineColors: [
        '#E57373', '#F06292', '#BA68C8', '#9575CD', '#7986CB', '#64B5F6', '#4FC3F7', '#4DD0E1', '#4DB6AC', '#81C784', '#AED581', '#DCE775', '#FFF176', '#FFD54F', '#FFB74D', '#FF8A65', '#A1887F', '#E0E0E0', '#90A4AE'
      ],
      livestockTypeList:JSON.parse(sessionStorage.downlist).cattle_parent_category, // 牲畜类别
      formulaTypeList: JSON.parse(sessionStorage.downlist).formula_type,  // 配方类型
      enableList: JSON.parse(sessionStorage.downlist).is_show, // 是否启用
      sourceList: JSON.parse(sessionStorage.downlist).forage_source,   //来源
      pastureList:JSON.parse(sessionStorage.pastureList), //牧场
      table: {
        page: 1,
        page_size: parseInt(Cookies.get('pageCount')),
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: false,
        parammaps: {
          cattle_category_id: '',formula_type_id:'',data_source_id:'',is_show:'',name:'',remarks:''
        },
        temp: {}
      },
      isokDisable: false,
      dataForm:{
        name: "",
        file: null,
      },
      table2: {
        // getDryweightParm: {
        //   name: 'getFTdryweight',
        //   page: 1,
        //   offset: 1,
        //   pagecount: 10,
        //   returntype: 'Map',
        //   parammaps: {
        //     pastureid: '',
        //     ftid: ''
        //   }
        // },
        // dryweight: '',

        parammaps: {
          pastureid: parseInt(Cookies.get('pastureId')),
          id:'',
          fname: '',
          feedgroup: '',
          fweight: '',
          autosecondname: '',
          islockcount: '',
          sort: ''
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: false,
        temp: {},
      },
      mixingDelayList: [{ id: '0', name: '0' }, { id: '1', name: '1' }, { id: '2', name: '2' }, { id: '3', name: '3' }, { id: '4', name: '4' }, { id: '5', name: '5' }, { id: '6', name: '6' }, { id: '7', name: '7' }, { id: '8', name: '8' }, { id: '9', name: '9' }, { id: '10', name: '10' }, { id: '11', name: '11' }, { id: '12', name: '12' }, { id: '13', name: '13' }, { id: '14', name: '14' }, { id: '15', name: '15' }], // 搅拌延时
      table3: {
        page: 1,
        page_size: parseInt(Cookies.get('pageCount')),
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        parammaps: {
          name:'',inputDatetime:[],end_time:'',start_time:'',pasture_id:parseInt(Cookies.get('pastureId'))
        },
        temp: {}
      },
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      myheight1: document.documentElement.clientHeight - 265,
      distributeFormula:{
        dialogFormVisible: false,
        dialogStatus: '',
        table: {
          parammaps: {
            name:''
          },
          tableKey: 0,
          total: 0,
          listLoading: true,
          list: []
        },
        selectionList:[]
      },
      dialogFull: false,
      textMap: {
        distributeFormula: '选择牧场',
        usageOverviewTxt:'使用概况',
        feedingEfficiencyTxt:'饲喂效率'
      },
      // ==============================

      isRoleEdit: [],

      requestParams: [
        { name: 'getDictByName', offset: 0, pagecount: 0, params: ['牲畜父类'] },
        { name: 'getDictByName2', offset: 0, pagecount: 0, params: ['配方类型'] },
        { name: 'getFeedAndPre', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
      ],
      lockBullsList: [{ id: '0', name: '否' }, { id: '1', name: '是' }], // 是否锁定牛头数比例


      feedNameList: [], // 饲料名称
      selectHistoryTimeList: [{ id: 0, name: '2020-06-10' }, { id: 1, name: '2020-06-11' }, { id: 2, name: '2020-06-12' }, { id: 3, name: '2020-06-13' }], // 请选择历史记录时间
      arrowDown: true,
      arrowUp: false,
      ispastureuse: Cookies.get('ispastureuse'),

      lockCount: {
        getdataListParm: {
          name: 'getSysoptEnable',
          page: 1,
          offset: 1,
          pagecount: 30,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            inforname: 'isLockCount'
          }
        },
        isLockCount: false // 是否显示是否锁定牛头数比例
      },
      isDetail: false,
      arrowDown2: true,
      arrowUp2: false,
      // table2: {
      //   getDryweightParm: {
      //     name: 'getFTdryweight',
      //     page: 1,
      //     offset: 1,
      //     pagecount: 10,
      //     returntype: 'Map',
      //     parammaps: {
      //       pastureid: '',
      //       ftid: ''
      //     }
      //   },
      //   dryweight: '',
      //   getdataListParm: {
      //     name: 'getFTdetailList',
      //     page: 1,
      //     offset: 1,
      //     pagecount: '',
      //     returntype: 'Map',
      //     parammaps: {
      //       pastureid: Cookies.get('pastureid'),
      //       fname: '',
      //       feedgroup: '',
      //       fweight: '',
      //       autosecondname: '',
      //       islockcount: '',
      //       sort: ''
      //     }
      //   },
      //   tableKey: 0,
      //   list: [],
      //   total: 0,
      //   listLoading: false,
      //   temp: {},
      //   updateList: {}
      // },
      isDetailDialog: false,
      template: {
        dialogFormVisible: false,
        dialogStatus: '',
        table: {
          getdataListParm: {
            name: 'getFTListDate',
            page: 1,
            offset: 1,
            pagecount: '',
            returntype: 'Map',
            parammaps: {
              pastureid: Cookies.get('pastureid'),
              tname: '',
              ccid: '',
              ccname: '',
              fttype: '',
              remark: '',
              enable: '',
              date: '',
              source: ''
            }
          },
          tableKey: 0,
          total: 0,
          listLoading: true,
          list: []
        },
        table2: {
          getdataListParm: {
            name: 'getFTdetailListDate',
            page: 1,
            offset: 1,
            pagecount: 10,
            returntype: 'Map',
            parammaps: {
              pastureid: Cookies.get('pastureid'),
              fname: '',
              fweight: '',
              islockcount: '',
              sort: '',
              feedgroup: '',
              autosecondname: ''
            }
          },
          tableKey: 0,
          total: 0,
          listLoading: true,
          list: []
        },
        // 历史日期
        getdataDateParm: {
          name: 'getFTMaxDate',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        }
      },

      isOrder: true,
      detail: {
        dialogFormVisible: false,
        dialogStatus: '',
        tableKey: 0,
        total: 0,
        listLoading: true,
        list: [],
        tableKey2: 0,
        total2: 0,
        listLoading2: false,
        list2: [{ tname: '', tcolor: '#ccc', ccid: '', fttype: '预混配方', fttypeid: '2', source: '自定义', remark: '', 'enable': 1 }],
        getdataListParm: {
          name: 'getFTDetailCompare',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {}
        },
        list3: [],
        disabled: false,
        getdataListParm2: {
          name: 'getFTCompare',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {}
        }
      },
      selectList: [],
      selectList2: [],
      // textMap: {
      //   RecipeRecord: '配方记录',
      //   SyntheticPremix: '合成预混料',
      //   historyRecord: '历史记录',
      //   detail: '饲料详情',
      //   rowRecipeRecordTxt: '配方修改记录'
      // },

      requestParam: {},
      requestParam2: {},
      requestParam3:{},
      download: {
        getdataListParm: {
          name: 'getFTList',
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            tname: '',
            ccid: '',
            ccname: '',
            fttypeid: '',
            fttype: '',
            remark: '',
            enable: ''
          }
        },
        list: []
      },
      historyRecord: {
        dialogStatus: '',
        dialogFormVisible: false
      },

      dropState: false,
      myheight2: 0,
      height: 0,
      usageOverview: {
        dialogStatus: '',
        dialogFormVisible: false,
        getdataListParm: {
          name: 'getFitHistory1', 'name1': 'getFitHistory2', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
          parammaps: { inputDatetime: [new Date(), new Date()], pastureid: '', fitid: '' }
        },
        tableKey: 0, total: 0, listLoading: true, list: []
      },
      feedingEfficiency:{
        dialogStatus: '',
        dialogFormVisible: false,
        data:{}
      },
      isEnlarge: true,
      // enlargeHeight: document.documentElement.clientHeight - 85 - 165 + 50,
      enlargeHeight: document.documentElement.clientHeight - 85 - 165 + 50,
      getTcodeParm: {
        name: 'getTcode', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
        parammaps: { pastureid: '', fttypeid: '' }
      },
    }
  },

  mounted() {
    document.addEventListener('click', (e) => {
      if (this.$refs.selectInput !== undefined) {
        if (!this.$refs.selectInput.contains(e.target)) {
          this.arrowDown = true
          this.arrowUp = false
        } else {
          this.arrowDown = false
          this.arrowUp = true
        }
      }
      if (this.$refs.selectInput2 !== undefined) {
        if (!this.$refs.selectInput2.contains(e.target)) {
          this.arrowDown2 = true
          this.arrowUp2 = false
        } else {
          this.arrowDown2 = false
          this.arrowUp2 = true
        }
      }
    })
  },
  created() {
    this.getList()
    this.getButton()
    // this.getDownList()
    // this.getIsLockCount()
  },
  methods: {
    getButton(){
      const add = 'recipe:recipeList:add'
      this.isAdd1 = checkButtons(add)
      const edit = 'recipe:recipeList:edit'
      this.isEdit1 = checkButtons(edit)
      const _import = 'recipe:recipeList:import'
      this.isImport1 = checkButtons(_import)
      const _export = 'recipe:recipeList:export'
      this.isExport1 = checkButtons(_export)
      const del = 'recipe:recipeList:delete'
      this.isDelete1 = checkButtons(del)
      const formulaEvaluation = 'recipe:recipeList:formulaEvaluation'
      this.isFormulaEvaluation = checkButtons(formulaEvaluation)
      const usageOverview = 'recipe:recipeList:usageOverview'
      this.isUsageOverview = checkButtons(usageOverview)
      const canceldistributingformula = 'recipe:recipeList:canceldistributingformula'
      this.isCanceldistributingformula = checkButtons(canceldistributingformula)

      const enable = 'recipe:recipeList:enable'
      this.isEnable = checkButtons(enable)
      const modify1 = 'recipe:recipeList:modify'
      this.isModify1 = checkButtons(modify1)
      const modify2 = 'recipe:recipeList:modify2'
      this.isModify2 = checkButtons(modify2)

    },
    // -------------------模板-----------------------------
    getList() {
      this.table.listLoading = true
      let page = this.table.page
      let page_size = this.table.page_size
      let url = '/api/v1/ops/feed_formula/list' + '?page=' + page + '&page_size=' + page_size
      let data = {
        "name":this.table.parammaps.name,
        "remarks":this.table.parammaps.remarks
      }
      if(this.table.parammaps.cattle_category_id !== ''){
        data.cattle_category_id = this.table.parammaps.cattle_category_id
      }
      if(this.table.parammaps.formula_type_id !== ''){
        data.formula_type_id = this.table.parammaps.formula_type_id
      }
      if(this.table.parammaps.data_source_id !== ''){
        data.data_source_id = this.table.parammaps.data_source_id
      }
      if(this.table.parammaps.is_show !== ''){
        data.is_show = this.table.parammaps.is_show
      }
      postJson(url, data).then(response => {
        if (response.code == 200) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(response.data.list[i], 'Edit', false) // 编辑
            this.$set(response.data.list[i], 'NoEdit', true) // 不可编辑/输入
            this.$set(response.data.list[i], 'isCreate', false) // 新增操作
            this.$set(response.data.list[i], 'isUpdate', true) // 编辑操作
            this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
          }
          this.table.list = response.data.list
          this.table.total = response.data.total
          this.table.pageNum = response.data.page
          this.table.pageSize = response.data.page_size
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 1000)
      })
    },
    handleSearch1() {
      console.log('点击了查询')
      this.table.page = 1
      this.getList()
      this.arrowDown = true
      this.arrowUp = false
    },
    handleRefresh1() {
      console.log('点击了重置')
      this.table.page = 1
      this.table.parammaps.cattle_category_id = ''
      this.table.parammaps.formula_type_id = ''
      this.table.parammaps.data_source_id = ''
      this.table.parammaps.is_show = ''
      this.table.parammaps.name = ''
      this.table.parammaps.remarks = ''
      this.getList()
    },
    // 模板新增
    handleCreate1() {
      // 编辑true/不可编辑false
      // 新增操true,编辑false，编辑保存false
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit === true) {
          this.$message({ type: 'error', message: '当前内容未保存，请点击取消或保存继续进行操作', duration: 2000 })
          return false
        }
      }
      this.table.list.unshift({
        'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false,
        'name': '', 'encode_number': '', 'colour': '#ccc',
        'cattle_category_id': '', 'cattle_category_name': '',
        'formula_type_id': '', 'formula_type_name': '',
        'data_source_id':2,'data_source_name': '用户自定义',
        'remarks': '','is_show': 1 ,'is_modify':1
      })
      this.table.temp = this.table.list[0]
      this.get_encodenumber()
    },
    get_encodenumber(){
      let url = 'api/v1/ops/feed_formula/encode_number'
      let data = ''
      getJson(url, data).then(response => {
        this.table.temp.encode_number = response.data.encode_number
      })
    },
    // 牲畜类别
    changeLivestockType1(item) {
      this.table.temp.cattle_category_name = this.livestockTypeList.find(obj => obj.value == item).label
    },
    // 配方类型
    changeFormulaType1(item) {
      this.table.temp.formula_type_name = this.formulaTypeList.find(obj => obj.value == item).label
    },
    handleEnableChange1(index,row,type){
      let edit_type = ''
      let is_show = ''
      if(type == 'show'){
        edit_type = 1
        is_show = row.is_show
      }else{
        edit_type = 2
        is_show = row.is_modify
      }
      let url = '/api/v1/ops/feed_formula/is_modify_show'
      let data = {
        "feed_formula_id":row.id,
        "is_show":is_show,
        'edit_type':edit_type
      }
      postJson(url,data).then(response => {
        if(response.code == 200){
          this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
          this.getList()
        }
      })
    },
    createData1(row) {
      this.table.temp.name = row.name
      this.table.temp.encode_number = row.encode_number
      this.table.temp.colour = row.colour
      this.table.temp.cattle_category_id = row.cattle_category_id
      this.table.temp.cattle_category_name = row.cattle_category_name
      this.table.temp.formula_type_id = row.formula_type_id
      this.table.temp.formula_type_name = row.formula_type_name
      this.table.temp.is_show = row.is_show
      this.table.temp.is_modify = row.is_modify
      this.table.temp.data_source_id = row.data_source_id
      this.table.temp.data_source_name = row.data_source_name
      this.table.temp.remarks = row.remarks

      if (this.table.temp.name == '' && this.table.temp.cattle_category_id == '' && this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '配方名称/牲畜类别/配方类型不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.cattle_category_id == '' && this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '牲畜类别/配方类型不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.name == '') {
        this.$message({ type: 'error', message: '配方名称不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.cattle_category_id == '') {
        this.$message({ type: 'error', message: '牲畜类别不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '配方类型不能为空', duration: 2000 })
        return false
      }
      const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
      if (pattern.test(this.table.temp.encode_number)) {
        this.$message({ type: 'error', message: '配方编码不可输入特殊字符', duration: 2000 })
        return false
      }
      console.log(this.table.temp)
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      let url = '/api/v1/ops/feed_formula/add'
      let data = {
        "name": this.table.temp.name,
        "encode_number": this.table.temp.encode_number,
        "colour": this.table.temp.colour,
        "cattle_category_id": this.table.temp.cattle_category_id,
        "cattle_category_name": this.table.temp.cattle_category_name,
        "formula_type_id": this.table.temp.formula_type_id,
        "formula_type_name": this.table.temp.formula_type_name,
        "data_source_id": this.table.temp.data_source_id,
        "data_source_name": this.table.temp.data_source_name,
        "remarks": this.table.temp.remarks,
        "is_show": this.table.temp.is_show,
        "is_modify": this.table.temp.is_modify,
      }
      if(this.table.temp.remarks !== ''){
        data.remarks = this.table.temp.remarks
      }
      postJson(url, data).then(response => {
        if(response.code == 200){
          this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
          this.getList()
        }
      })
    },
    createCancel1(row) {
      for (let i = 0; i < this.table.list.length; i++) {
        if (row.myId === this.table.list[i].myId) {
          var listIndex = this.table.list.indexOf(this.table.list[i])
        }
        if (listIndex > -1) {
          this.table.list.splice(listIndex, 1)
          return
        }
      }
    },
    // 模板编辑
    handleUpdate1(row) {
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit == true) {
          this.$message({ type: 'error', message: '当前内容未保存，请点击取消或保存继续进行操作', duration: 2000 })
          return false
        }
      }
      this.table.temp = Object.assign({}, row)
      // 编辑true,不可编辑false
      row.Edit = true
      row.NoEdit = false
      // 新增false,编辑false,编辑保存true
      row.isCreate = false
      row.isUpdate = false
      row.isUpdateSave = true
    },
    updateData1(row) {
      this.table.temp.name = row.name
      this.table.temp.encode_number = row.encode_number
      this.table.temp.colour = row.colour
      this.table.temp.cattle_category_id = row.cattle_category_id
      this.table.temp.cattle_category_name = row.cattle_category_name
      this.table.temp.formula_type_id = row.formula_type_id
      this.table.temp.formula_type_name = row.formula_type_name
      this.table.temp.is_show = row.is_show
      this.table.temp.is_modify = row.is_modify
      this.table.temp.data_source_id = row.data_source_id
      this.table.temp.data_source_name = row.data_source_name
      this.table.temp.remarks = row.remarks

      if (this.table.temp.name == '' && this.table.temp.cattle_category_id == '' && this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '配方名称/牲畜类别/配方类型不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.cattle_category_id == '' && this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '牲畜类别/配方类型不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.name == '') {
        this.$message({ type: 'error', message: '配方名称不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.cattle_category_id == '') {
        this.$message({ type: 'error', message: '牲畜类别不能为空', duration: 2000 })
        return false
      } else if (this.table.temp.formula_type_id == '') {
        this.$message({ type: 'error', message: '配方类型不能为空', duration: 2000 })
        return false
      }
      const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
      if (pattern.test(this.table.temp.encode_number)) {
        this.$message({ type: 'error', message: '配方编码不可输入特殊字符', duration: 2000 })
        return false
      }
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      let url = '/api/v1/ops/feed_formula/edit'
      let data = {
        "name": this.table.temp.name,
        "encode_number": this.table.temp.encode_number,
        "colour": this.table.temp.colour,
        "cattle_category_id": this.table.temp.cattle_category_id,
        "cattle_category_name": this.table.temp.cattle_category_name,
        "formula_type_id": this.table.temp.formula_type_id,
        "formula_type_name": this.table.temp.formula_type_name,
        "data_source_id": this.table.temp.data_source_id,
        "data_source_name": this.table.temp.data_source_name,
        "remarks": this.table.temp.remarks,
        "is_show": this.table.temp.is_show,
        "is_modify": this.table.temp.is_modify,
        'id':this.table.temp.id
      }
      if(this.table.temp.remarks !== ''){
        data.remarks = this.table.temp.remarks
      }
      postJson(url, data).then(response => {
        if(response.code == 200){
          this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
          this.getList()
        }
      })
    },
    updateCancel1(row) {
      console.log('点击了编辑取消')
      // 编辑false,不可编辑true
      row.Edit = false
      row.NoEdit = true
      // 新增false,编辑 true,编辑保存false
      row.isCreate = false
      row.isUpdate = true
      row.isUpdateSave = false
      this.getList()
    },
    handleRowDelete1(row){
      MessageBox.confirm('确定删除吗?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        let url = 'api/v1/ops/feed_formula/delete/'
        let data = row.id
        delJson(url, data).then(response => {
          if (response.code == 200) {
            this.$notify({
              title: '',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            this.getList()
          }
        })
      })
    },
    handleExport(item) {
      if (item == 1) {
        console.log('导出模板')
        let url = 'api/v1/ops/feed_formula/excel_template'
        let data = {name:''}
        exportFile(url, data).then(response => {
          let xlxsname = '配方列表模板' + parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}') + '.xlsx'
          localDownloadUtil.blobDownloads(response,xlxsname)
        })
      } else {
        console.log('导出数据')
        let url = 'api/v1/ops/feed_formula/excel_export'
        let data = {name:''}
        exportFile(url, data).then(response => {
          let xlxsname = '配方列表' + parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}') + '.xlsx'
          localDownloadUtil.blobDownloads(response,xlxsname)
        })
      }
    },
    handleImport(){
      let url = 'api/v1/ops/forage/excel_import'
      let data = {name:''}
      importFile(url, data).then(response => {

      })
    },
    //验证文件类型
    beforeAvatarUpload(file) {
      console.log(file);
      const isXls = file.type === "application/vnd.ms-excel" ? true : file.type === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ? true : false;
      if (!isXls) {
        alert("上传的文件只能是xls以及xlsx格式!");
      }
      return isXls;
    },
    // 判断文件个数
    handleChange(file, fileList) {
      if (fileList.length >= 2) {
        return;
      }
      if (fileList.length === 1) {
        this.hasFile = true;
      }
      this.dataForm.file = file;
    },
    // 导入
    httpRequest(param) {
      let formData = new FormData();
      formData.append('file', this.dataForm.file.raw);
      let url = 'api/v1/ops/forage/excel_import';
      let data = formData
      console.log(param.file);
      axios({
        method: 'POST',
        url: process.env.VUE_APP_BASE_API + url,
        data: data,
        headers: {
          'Authorization': 'Bearer ' + getToken(),
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if(res.data.code == 200){
          this.$notify({ title: '成功', message:'操作成功', type: 'success', duration: 2000 })
          this.getList()
        }
      }).catch((e) => {
        console.log(e);
      });
    },


    // 下发配方
    handleDistributeFormula(){
      if(this.selectList.length>0){
        this.distributeFormula.dialogStatus = 'distributeFormula'
        this.distributeFormula.dialogFormVisible = true
        this.dialogFull = false
        this.getPastureList()
      }else{
        this.$message({ type: 'error', message: '请先选择配方', duration: 2000 })
      }
    },
    getPastureList(){
      this.distributeFormula.table.listLoading = true
      let page = 1
      let page_size = 0
      let url = 'api/v1/ops/pasture/list' + '?page=' + page + '&page_size=' + page_size
      let data = {
        "name":this.distributeFormula.table.parammaps.name
      }
      postJson(url, data).then(response => {
        if (response.code == 200) {
          this.distributeFormula.table.list = response.data.list
        } else {
          this.distributeFormula.table.list = []
        }
        setTimeout(() => {
          this.distributeFormula.table.listLoading = false
        }, 1000)
      })
    },
    handleDistributeFormulaSearch(){
      this.getPastureList()
    },
    handleDistributeFormulaRefresh(){
      this.distributeFormula.table.parammaps.name = ''
    },
    handleSelectionDistributeFormula(item){
      this.distributeFormula.selectionList = item
      console.log(this.distributeFormula.selectionList)
    },
    distributeFormulaData(){
      let feed_formula_ids = []
      let pasture_ids = []
      this.distributeFormula.selectionList.forEach((item)=>{
        pasture_ids.push(item.id)
      })
      this.selectList.forEach((item)=>{
        feed_formula_ids.push(item.id)
      })
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      let url = '/api/v1/ops/feed_formula/distribute'
      let data = {
        feed_formula_ids:feed_formula_ids,
        pasture_ids:pasture_ids
      }
      postJson(url, data).then(response => {
        if(response.code == 200){
          this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
          this.distributeFormula.dialogFormVisible = false
          this.getList()
        }
      })
    },
    // 模板行点击
    table1RowClick(row, column, event) {
      for (let i = 0; i < this.table.list.length; i++) {
        if (this.table.list[i].Edit == true) {
          return false
        }
      }
      if (this.isOrder == false) {
        this.$message({ type: 'error', message: '请保存或取消当前更改顺序操作', duration: 2000 })
      } else {
        if (column.label !== '操作' && column.label !== '是否启用' && column.label !== '是否可修改' && column.label !== '版本号') {
          this.isDetail = true // 点击行显示详情
          this.myheight1 = document.documentElement.clientHeight - 85 - 265 - 185
          console.log(row,'====')
          this.table2.parammaps.id = row.id
          this.table2.parammaps.formula_type_id = row.formula_type_id
          this.table3.parammaps.id = row.id
          this.getList2()
          this.getList3()
          this.getFeedNameList()
        }
      }
    },
    getFeedNameList(){
      let page = 0
      let page_size = 0
      let url = 'api/v1/ops/feed_formula/forage_list' + '?page=' + page + '&page_size=' + page_size
      // let url = 'api/v1/ops/forage/list' + '?page=' + page + '&page_size=' + page_size
      let data = ''
      getJson(url, data).then(response => {
        if (response.code == 200) {
          this.feedNameList = response.data.list
        } else {
          this.feedNameList = []
        }
      })
    },
    // 详情
    getList2(item) {
      this.table2.listLoading = true
      let url = ''
      let data = {}
      if(item == 'search'){
        url = 'api/v1/ops/feed_formula/feed/search'
        data.feed_formula_id = this.table2.parammaps.id
        data.forage_name = this.table2.parammaps.forage_name
        data.forage_group_name = this.table2.parammaps.forage_group_name
        if(this.table2.parammaps.weight){
          data.weight = this.table2.parammaps.weight
        }
        if(this.table2.parammaps.is_lock_cow_count_ratio){
          data.is_lock_cow_count_ratio = this.table2.parammaps.is_lock_cow_count_ratio
        }
        if(this.table2.parammaps.sort){
          data.sort = this.table2.parammaps.sort
        }
      }else{
        url = 'api/v1/ops/feed_formula/feed_detail/list'
        data.feed_formula_id = this.table2.parammaps.id
      }
      postJson(url, data).then(response => {
        if (response.data) {
          for (let i = 0; i < response.data.length; i++) {
            this.$set(response.data[i], 'Edit', false) // 编辑
            this.$set(response.data[i], 'NoEdit', true) // 不可编辑/输入
            this.$set(response.data[i], 'groupEdit', false) // 饲料组编辑
            this.$set(response.data[i], 'isGroupDisabled', false) // 饲料组编辑禁止编辑
            this.$set(response.data[i], 'groupNoEdit', true) // 饲料组不可编辑
            this.$set(response.data[i], 'isCreate', false) // 新增操作
            this.$set(response.data[i], 'isUpdate', true) // 编辑操作
            this.$set(response.data[i], 'isUpdateSave', false) // 编辑保存
          }
          // this.table2.getDryweightParm.parammaps = this.table2.getdataListParm.parammaps
          // this.getDryWeight()
          this.table2.list = response.data
          console.log('table2数据', this.table2.list)
          this.table2.total = response.data.total
        } else {
          this.table2.list = []
        }
        setTimeout(() => {
          this.table2.listLoading = false
        }, 100)
      })
    },
    form_search2() {
      console.log('点击了查询')
      this.arrowDown2 = true
      this.arrowUp2 = false
      this.table2.offset = 1
      this.table2.parammaps.all = ''
      var obj = {}
      obj.fname = this.table2.parammaps.fname
      obj.feedgroup = this.table2.parammaps.feedgroup
      obj.fweight = this.table2.parammaps.fweight
      obj.autosecondname = this.table2.parammaps.autosecondname
      if (this.table2.parammaps.islockcount !== '') {
        if (this.table2.parammaps.islockcount == 0) {
          this.table2.parammaps.islockcount = '否'
        } else {
          this.table2.parammaps.islockcount = '是'
        }
      }
      obj.islockcount = this.table2.parammaps.islockcount
      obj.sort = this.table2.parammaps.sort
      Object.getOwnPropertyNames(obj).forEach((key) => {
        console.log(key, obj[key])
        if (obj[key] !== '') {
          this.table2.parammaps.all += obj[key] + '/'
        }
      })
      if (this.table2.parammaps.all.charAt(this.table2.parammaps.all.length - 1) == '/') {
        this.table2.parammaps.all = this.table2.parammaps.all.slice(0, this.table2.parammaps.all.length - 1)
      }
      this.getList2('search')
    },
    handleRefresh2() {
      console.log('点击了重置')
      this.table2.parammaps.forage_name = ''
      this.table2.parammaps.forage_group_name = ''
      this.table2.parammaps.weight = ''
      this.table2.parammaps.allow_error = ''
      this.table2.parammaps.islockcount = '0'
      this.table2.parammaps.sort = ''
      this.table2.parammaps.all = ''
      this.table2.offset = 1
      this.getList2('search')
    },
    changeFname(item, row) {
      console.log(item, row)
      this.table2.temp.forage_name = this.feedNameList.find(obj => obj.id == item).name
      row.forage_name = this.feedNameList.find(obj => obj.id == item).name
      if (this.feedNameList.find(obj => obj.id == item).ispreft == '0') {
        this.table2.temp.preftid = '0'
      } else {
        this.table2.temp.preftid = item
      }
      if (row.sort == '') {
        row.forage_group_name = this.table2.temp.forage_name
      } else {
        if (row.isCreate == true) { // 新增状态下
          for (let i = 1; i < this.table2.list.length; i++) {
            if (this.table2.list[i].sort == row.sort) {
              console.log(this.table2.list[i])
              row.forage_group_name = this.table2.list[i].forage_group_name
              break
            } else {
              row.forage_group_name = this.table2.temp.forage_name
            }
          }
        } else if (row.isUpdateSave == true) { // 编辑状态下
          var Arr = []
          for (let i = 0; i < this.table2.list.length; i++) {
            Arr.push(this.table2.list[i].sort)
          }
          var Count = 0
          for (let i = 0; i < Arr.length; i++) {
            if (Arr[i] == row.sort) {
              Count++
            }
          }
          for (let i = 0; i < this.table2.list.length; i++) {
            if (Count > 1) {
              row.forage_group_name = this.table2.list[i].forage_group_name
              console.log(this.table2.list[i].forage_group_name)
              break
            } else if (Count == 1) {
              row.forage_group_name = this.table2.temp.forage_name
              console.log(222, this.table2.temp.forage_name)
            }
          }
        }
      }
    },
    // 详情新增
    handleCreate2() {
      console.log('点击了详情新增', this.table2.list)
      // 编辑true/不可编辑false
      // 新增操true,编辑false，编辑保存false
      for (let i = 0; i < this.table2.list.length; i++) {
        if (this.table2.list[i].Edit === true) {
          this.$message({ type: 'error', message: '当前内容未保存，请点击取消或保存继续进行操作', duration: 2000 })
          return false
        }
      }
      if (this.table2.list.length == 0) {
        var mysort = 0
      } else {
        var mysort = parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1
      }
      this.table2.list.unshift({ 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'groupEdit': false, 'groupNoEdit': true, 'is_modify': 1, 'forage_group_name': '', 'forage_id': '', 'forage_name': '', 'weight': '', 'stir_delay': '0','allow_error':0,'islockcount': '0', 'sort': mysort })
      console.log(this.table2.list)
    },
    createData2(row) {
      console.log('点击了详情新增保存1', row)
      this.table2.temp.pastureid = Cookies.get('pastureid')
      this.table2.temp.forage_id = row.forage_id
      this.table2.temp.forage_name = this.table2.temp.forage_name
      this.table2.temp.weight = row.weight
      this.table2.temp.islockcount = row.islockcount
      this.table2.temp.sort = row.sort
      this.table2.temp.forage_group_name = row.forage_group_name
      this.table2.temp.preftid = this.table2.temp.preftid
      this.table2.temp.stir_delay = row.stir_delay
      this.table2.temp.allow_error = row.allow_error
      this.table2.temp.is_modify = row.is_modify
      if (this.table2.temp.forage_id === '' && this.table2.temp.weight === '' && this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '饲料名称/重量/搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.weight === '' && this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '重量/搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      }else if (this.table2.temp.forage_id === '') {
        this.$message({ type: 'error', message: '饲料名称不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.fweight === '') {
        this.$message({ type: 'error', message: '重量不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.stir_delay === '') {
        this.$message({ type: 'error', message: '搅拌延时不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '允许延时偏差不能为空', duration: 2000 })
        return false
      }
      if(parseFloat(this.table2.temp.allow_error) > parseFloat(this.table2.temp.stir_delay)){
        this.$message({ type: 'error', message: '允许延时偏差不可超出搅拌延时', duration: 2000 })
        return false
      }
      if (this.table2.temp.sort !== '') {
        this.table2.temp.sort = this.table2.temp.sort
      } else {
        console.log(this.table2.list.length)
        if (this.table2.list.length == 1) {
          this.table2.temp.sort = 1
        } else {
          this.table2.temp.sort = parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1
          row.sort = parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1
        }
      }
      if (this.table2.parammaps.formula_type_id == 2) {
        if (parseInt(this.table2.temp.preftid) > 0) {
          this.$message({ type: 'error', message: '饲料名称不能选择预混配方', duration: 2000 })
          return false
        }
      }
      // 校验顺序是否>=0
      var ruleSort = /^\d+$/
      if (!ruleSort.test(this.table2.temp.sort)) {
        this.$message({ type: 'error', message: '饲料顺序不可为负数或小数', duration: 2000 })
        return false
      }
      // 检验重量>0
      this.table2.temp.weight = formatNum(this.table2.temp.weight, 4) // 根据默认参数设置小数位数
      row.weight = formatNum(row.weight, 4)
      if (this.table2.temp.weight == 0) {
        this.$message({ type: 'error', message: '重量请输入正数，最多保留四位小数', duration: 2000 })
        return false
      }
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      let dateTime = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      const url = 'api/v1/ops/feed_formula/feed/add'
      const data = {
        'feed_formula_id':this.table2.parammaps.id,
        'list':[
          {
            "feed_formula_id": this.table2.parammaps.id,
            "forage_id": this.table2.temp.forage_id,
            "forage_name": this.table2.temp.forage_name,
            "forage_group_name": this.table2.temp.forage_group_name,
            "sort": parseFloat(this.table2.temp.sort),
            "is_modify": this.table2.temp.is_modify
          }
        ]
      }
      if(this.table2.temp.weight){
        this.$set(data.list[0],'weight',parseFloat(this.table2.temp.weight))
      }
      if(this.table2.temp.stir_delay){
        this.$set(data.list[0],'stir_delay',parseFloat(this.table2.temp.stir_delay))
      }
      if(this.table2.temp.allow_error){
        this.$set(data.list[0],'allow_error',parseFloat(this.table2.temp.allow_error))
      }
      postJson(url, data).then(response => {
        if (response.msg !== 'fail') {
          this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
          this.getList2()
        } else {
          this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },
    createCancel2(row) {
      console.log('点击了详情新增取消')
      for (let i = 0; i < this.table2.list.length; i++) {
        if (row.myId === this.table2.list[i].myId) {
          var listIndex = this.table2.list.indexOf(this.table2.list[i])
        }
        if (listIndex > -1) {
          this.table2.list.splice(listIndex, 1)
          return
        }
      }
      this.getDialogList()
    },
    // 行拖拽
    rowDrop() {
      const tbody = document.querySelector('#table2 .el-table__body-wrapper tbody')
      const that = this
      var sortable = Sortable.create(tbody, {
        disabled: that.dropState,
        onChoose({ newIndex, oldIndex }) {
          console.log(that.isOrder, 'that.isOrder == false')
          console.log(that.dropState, 'that.dropState')
          if (that.dropState == true || that.isOrder == true) {
            sortable.destroy()
          }
        },
        onEnd({ newIndex, oldIndex }) {
          const currRow = that.table2.list.splice(oldIndex, 1)[0]
          that.table2.list.splice(newIndex, 0, currRow)
          console.log('索引', newIndex)
          console.log('拖动数据', currRow)
          console.log('上', that.table2.list[newIndex - 1])
          console.log('下', that.table2.list[newIndex + 1])
          if (that.table2.list[newIndex - 1] === undefined) { // 拖动至最上方无值 // 顺序等于0，其他+1 // 饲料组等于饲料名称
            for (let i = 0; i < that.table2.list.length; i++) {
              that.table2.list[i].sort = parseInt(that.table2.list[i].sort) + 1 // 其他的顺序＋1
            }
            currRow.sort = 0
            currRow.feedgroup = currRow.fname
            console.log('拖动至最上方无值')
          } else if (currRow.sort == that.table2.list[newIndex - 1].sort) { // 拖动值顺序等于上值顺序
            currRow.sort = that.table2.list[newIndex - 1].sort
            console.log('拖动值顺序等于上值顺序')
          } else if (that.table2.list[newIndex + 1] == undefined) { // 拖动至最下方无值 // 顺序等于上方顺序+1 // 饲料组等于饲料名称
            currRow.sort = parseInt(that.table2.list[newIndex - 1].sort) + 1
            currRow.feedgroup = currRow.fname
            console.log('拖动至最下方无值')
          } else if (currRow.sort == that.table2.list[newIndex + 1].sort) { // 拖动值顺序等于下值顺序
            currRow.sort == that.table2.list[newIndex + 1].sort
            console.log('拖动值顺序等于下值顺序')
          } else if (that.table2.list[newIndex - 1].sort == that.table2.list[newIndex + 1].sort) { // 拖动至上下顺序一致，顺序/饲料组与上下保持一致
            currRow.sort = that.table2.list[newIndex - 1].sort
            currRow.feedgroup = that.table2.list[newIndex - 1].feedgroup
            console.log('拖动至上下顺序一致')
          } else if (that.table2.list[newIndex - 1].sort !== undefined && that.table2.list[newIndex + 1].sort !== undefined) { // 拖动至上下都有值
            console.log('上下')
            if (parseInt(that.table2.list[newIndex - 1].sort) + 1 == that.table2.list[newIndex + 1].sort) {
              console.log(newIndex)
              for (let i = newIndex; i < that.table2.list.length; i++) {
                that.table2.list[i].sort = parseInt(that.table2.list[i].sort) + 1
              }
            }
            currRow.sort = parseInt(that.table2.list[newIndex - 1].sort) + 1
            currRow.feedgroup = currRow.fname
            console.log(that.table2.list[newIndex + 1].sort)
          }
        }
      })
      console.log(sortable.option('disabled'))
    },
    handleChangeOrder() {
      this.isOrder = false
      this.rowDrop()
    },
    saveChangeOrder() {
      // 保存顺序
      console.log(this.table2.list)
      let list = []
      for(let i=0;i<this.table2.list.length;i++){
        let obj = {
          feed_formula_id:this.table2.list[i].feed_formula_id,
          id:this.table2.list[i].id,
          forage_id:this.table2.list[i].forage_id,
          forage_name:this.table2.list[i].forage_name,
          forage_group_name:this.table2.list[i].forage_group_name,
          weight:this.table2.list[i].weight,
          stir_delay:this.table2.list[i].stir_delay,
          allow_error:this.table2.list[i].allow_error,
          sort:this.table2.list[i].sort,
          is_modify: this.table2.list[i].is_modify
        }
        list.push(obj)
      }
      let url = 'api/v1/ops/feed_formula/feed/sort'
      const data = {
        'feed_formula_id':this.table2.parammaps.id,
        'list':list
      }
      postJson(url, data).then(response => {
        if (response.msg === 'fail') {
          this.$notify({ title: '顺序切换失败', message: response.data, type: 'warning', duration: 2000 })
        } else {
          this.$notify({ title: '', message: '顺序切换成功', type: 'success', duration: 2000 })
          this.getList2()
          this.isOrder = true
        }
      })
    },
    cancelChangeOrder() {
      // 取消顺序
      this.getList2()
      this.isOrder = true
    },
    // 详情编辑
    handleUpdate2(row) {
      console.log('详情编辑', row)
      this.dropState = true
      row.isGroupDisabled = false
      row.islockcount = String(row.islockcount)
      this.table2.temp.forage_name = row.forage_name
      this.table2.temp.preftid = row.preftid
      const rowArr = []
      for (let i = 0; i < this.table2.list.length; i++) {
        if (this.table2.list[i].Edit == true) {
          this.$message({ type: 'error', message: '当前内容未保存，请点击取消或保存继续进行操作', duration: 2000 })
          return false
        }
        rowArr.push(this.table2.list[i].sort)
      }
      var count = 0
      for (let i = 0; i < rowArr.length; i++) {
        if (rowArr[i] == row.sort) {
          count++
        }
      }
      // 判断是否有相同顺序，如果没有饲料组不可编辑，若有饲料组可编辑
      if (count == 1) {
        // 饲料组编辑false，不可编辑true
        row.groupEdit = false
        row.groupNoEdit = true
        // 编辑true,不可编辑false
        row.Edit = true
        row.NoEdit = false
        // 新增false,编辑false,编辑保存true
        row.isCreate = false
        row.isUpdate = false
        row.isUpdateSave = true
      } else if (count > 1) {
        // 饲料组编辑true，不可编辑false
        row.groupEdit = true
        row.groupNoEdit = false
        // 编辑true,不可编辑false
        row.Edit = true
        row.NoEdit = false
        // 新增false,编辑false,编辑保存true
        row.isCreate = false
        row.isUpdate = false
        row.isUpdateSave = true
        return false
      }
      if(row.stir_delay == undefined){
        row.stir_delay = ''
        this.$set(row,'stir_delay','')
      }
      if(row.allow_error == undefined){
        row.allow_error = ''
        this.$set(row,'allow_error','')
      }
      console.log('详情编辑', row)
      this.table2.updateList = Object.assign({}, row)
    },
    updateData2(row) {
      console.log('点击了详情编辑保存', row)
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.table2.temp.pastureid = Cookies.get('pastureid')
      this.table2.temp.forage_id = row.forage_id
      this.table2.temp.forage_name = this.table2.temp.forage_name
      this.table2.temp.weight = row.weight
      this.table2.temp.islockcount = row.islockcount
      this.table2.temp.sort = row.sort
      this.table2.temp.id = row.id
      this.table2.temp.forage_group_name = row.forage_group_name
      this.table2.temp.preftid = this.table2.temp.preftid
      this.table2.temp.stir_delay = row.stir_delay
      this.table2.temp.allow_error = row.allow_error
      if (this.table2.temp.forage_id === '' && this.table2.temp.weight === '' && this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '饲料名称/重量/搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.weight === '' && this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '重量/搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.stir_delay === '' && this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '搅拌延时/允许延时偏差不能为空', duration: 2000 })
        return false
      }else if (this.table2.temp.forage_id === '') {
        this.$message({ type: 'error', message: '饲料名称不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.fweight === '') {
        this.$message({ type: 'error', message: '重量不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.stir_delay === '') {
        this.$message({ type: 'error', message: '搅拌延时不能为空', duration: 2000 })
        return false
      } else if (this.table2.temp.allow_error === '') {
        this.$message({ type: 'error', message: '允许延时偏差不能为空', duration: 2000 })
        return false
      }
      if(parseFloat(this.table2.temp.allow_error) > parseFloat(this.table2.temp.stir_delay)){
        this.$message({ type: 'error', message: '允许延时偏差不可超出搅拌延时', duration: 2000 })
        return false
      }
      if (this.table2.temp.sort !== '') {
        this.table2.temp.sort = this.table2.temp.sort
      } else {
        console.log(this.table2.list.length)
        if (this.table2.list.length == 1) {
          this.table2.temp.sort = 1
        } else {
          this.table2.temp.sort = parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1
          row.sort = parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1
        }
      }
      if (this.table2.parammaps.formula_type_id == 2) {
        if (parseInt(this.table2.temp.preftid) > 0) {
          this.$message({ type: 'error', message: '饲料名称不能选择预混配方', duration: 2000 })
          return false
        }
      }
      // 校验顺序是否>=0
      var ruleSort = /^\d+$/
      if (!ruleSort.test(this.table2.temp.sort)) {
        this.$message({ type: 'error', message: '饲料顺序不可为负数或小数', duration: 2000 })
        return false
      }
      // 检验重量>0
      this.table2.temp.weight = formatNum(this.table2.temp.weight, 4) // 根据默认参数设置小数位数
      row.weight = formatNum(row.weight, 4)
      if (this.table2.temp.weight == 0) {
        this.$message({ type: 'error', message: '重量请输入正数，最多保留四位小数', duration: 2000 })
        return false
      }
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      let dateTime = parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}')
      const url = 'api/v1/ops/feed_formula/feed/edit'
      const data = {
        "feed_formula_id": this.table2.parammaps.id,
        "id":this.table2.temp.id,
        "forage_id": this.table2.temp.forage_id,
        "forage_name": this.table2.temp.forage_name,
        "forage_group_name": this.table2.temp.forage_group_name,
        "sort": parseFloat(this.table2.temp.sort),
        "weight": parseFloat(this.table2.temp.weight),
        "stir_delay": parseFloat(this.table2.temp.stir_delay),
        "allow_error": parseFloat(this.table2.temp.allow_error),
        "is_modify": this.table2.temp.is_modify
      }
      postJson(url, data).then(response => {
        if (response.msg !== 'fail') {
          this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
          this.getList2()
        } else {
          this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },
    updateCancel2(row) {
      console.log('点击了详情编辑取消')
      // 饲料组编辑false，不可编辑true
      row.groupEdit = false
      row.groupNoEdit = true
      // 编辑false,不可编辑true
      row.Edit = false
      row.NoEdit = true
      // 新增false,编辑true,编辑保存false
      row.isCreate = false
      row.isUpdate = true
      row.isUpdateSave = false
      this.getList2()
      this.dropState = false
    },
    blurSort(row) {
      if (row.isCreate == true) {
        if (row.sort !== '') {
          for (let i = 1; i < this.table2.list.length; i++) {
            if (this.table2.list[i].sort == parseInt(row.sort)) {
              row.forage_group_name = this.table2.list[i].forage_group_name
              return false
            } else {
              row.forage_group_name = row.forage_name
            }
          }
        } else {
          row.forage_group_name = row.forage_name
        }
      } else if (row.isUpdateSave == true) {
        if (row.sort !== '') {
          for (let i = 0; i < this.table2.list.length; i++) {
            if (this.table2.list[i].sort == row.sort) {
              console.log('失去焦点，行内顺序与表格某顺序相同时', this.table2.list[i])
              if (this.table2.list[i].id !== row.id) {
                row.isGroupDisabled = true
                row.forage_group_name = this.table2.list[i].forage_group_name
                break
              }
            } else {
              console.log('失去焦点，行内顺序与表格某顺序不相同时')
              row.isGroupDisabled = true
              row.forage_group_name = row.forage_name
            }
          }
        } else {
          row.forage_group_name = row.forage_name
        }
      }
    },
    // 详情删除
    handleRowDelete2(row) {
      console.log('点击了行内删除')
      MessageBox.confirm('是否确认删除此信息?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        const url = 'api/v1/ops/feed_formula/feed/delete'
        const data = {
          "feed_formula_id": row.feed_formula_id,
          "list": [
            {
              "feed_formula_id": row.feed_formula_id,
              "id": row.id,
              "forage_id":row.forage_id,
              "forage_name": row.forage_name,
              "forage_group_name": row.forage_group_name,
              "weight":row.weight,
              "stir_delay":row.stir_delay,
              "allow_error": row.allow_error,
              "sort": row.sort,
            }
          ]
        }
        postJson(url, data).then(response => {
          if (response.msg !== 'fail') {
            this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
            this.getList2()
          } else {
            this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
          }
        })

      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },
    form_delete2() {
      console.log('点击了删除')
      if (this.selectList2.length == 0) {
        this.$message({ type: 'error', message: '请选择配方详情', duration: 2000 })
      } else {
        MessageBox.confirm('是否确认删除此信息?', {
          confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
        }).then(() => {
          let list = []
          for(let i=0;i<this.selectList2.length;i++){
            let obj = {
              'feed_formula_id':this.selectList2[i].feed_formula_id,
              'id':this.selectList2[i].id,
              'forage_id':this.selectList2[i].forage_id,
              'forage_name':this.selectList2[i].forage_name,
              'forage_group_name':this.selectList2[i].forage_group_name,
              'weight':this.selectList2[i].weight,
              'stir_delay':this.selectList2[i].stir_delay,
              'allow_error':this.selectList2[i].allow_error,
              'sort':this.selectList2[i].sort
            }
            list.push(obj)
          }
          const url = 'api/v1/ops/feed_formula/feed/delete'
          const data = {
            "feed_formula_id": this.table2.parammaps.id,
            "list": list
          }
          postJson(url, data).then(response => {
            if (response.msg !== 'fail') {
              this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
              this.getList2()
            } else {
              this.$notify({ title: '删除失败', message: response.data, type: 'warning', duration: 2000 })
            }
          })
        })
      }
    },
    handleSelectionChange2(val) {
      console.log('勾选数据', val)
      this.selectList2 = val
    },
    celldblclick(row, column, cell, event) {
      this.handleUpdate2(row)
    },
    handleEnableChange2(index,row){
      let url = 'api/v1/ops/feed_formula/feed/is_modify'
      let data = {
        "feed_formula_id":row.feed_formula_id,
        "is_modify":row.is_modify,
        'id':row.id,
      }
      postJson(url,data).then(response => {
        if(response.code == 200){
          this.$notify({ title: '成功', message: '成功', type: 'success', duration: 2000 })
          this.getList2()
        }
      })
    },
    // 合成预混料
    handleSyntheticPremix() {
      console.log('点击了合成预混料', this.selectList2)
      this.dialogFull = false
      // if (this.table2.getdataListParm.parammaps.fttypeid == 2) {
      //   this.$message({ type: 'error', message: '预混配方不可合成预混料', duration: 2000 })
      //   return false
      // } else {
        if (this.selectList2.length > 1) {
          for (let i = 0; i < this.selectList2.length; i++) {
            if (parseInt(this.selectList2[i].preftid) > 0) {
              this.$message({ type: 'error', message: '不可选择预混料', duration: 2000 })
              return false
            }
          }

          if (this.selectList2[0].splitftpreid !== undefined) {
            this.detail.getdataListParm.parammaps.ftid = this.selectList2[0].splitftpreid
            this.detail.getdataListParm.parammaps.pastureid = this.selectList2[0].pastureid
            GetDataByName(this.detail.getdataListParm).then(response => {
              if (response.data.list !== null) { // 不为空时得到比对数据
                this.detail.list3 = response.data.list
                const sortList = [] // 声明排序数组
                var fweightSum = 0 // 总重量
                for (let i = 0; i < this.selectList2.length; i++) {
                  const obj = {}
                  obj.fid = this.selectList2[i].fid
                  obj.fweight = this.selectList2[i].fweight
                  fweightSum = fweightSum + parseFloat(this.selectList2[i].fweight)
                  sortList.push(obj)
                }
                // 排序
                sortList.sort(function(a, b) {
                  return a.fid.localeCompare(b.fid)
                })
                var a = 0
                if (this.detail.list3.length == sortList.length) {
                  for (let i = 0; i < this.detail.list3.length; i++) {
                    if (this.detail.list3[i].fid == sortList[i].fid && (this.detail.list3[i].fweight / this.detail.list3[i].sumWeight).toFixed(3) == (sortList[i].fweight / fweightSum).toFixed(3)) {
                      a++
                    }
                  }
                  if (a == this.detail.list3.length) { // 如果相等，则该配方为原预混配方
                    this.detail.getdataListParm2.parammaps.ftid = this.selectList2[0].splitftpreid
                    this.detail.getdataListParm2.parammaps.pastureid = this.selectList2[0].pastureid
                    GetDataByName(this.detail.getdataListParm2).then(response => {
                      if (response.data.list !== null) {
                        this.detail.dialogStatus = 'SyntheticPremix'
                        this.detail.dialogFormVisible = true
                        this.detail.list = this.selectList2
                        this.detail.list2 = response.data.list
                        this.detail.disabled = true
                        setTimeout(() => {
                          this.detail.listLoading = false
                        }, 100)
                      } else {
                        this.detail.list2 = []
                      }
                    })
                  } else {
                    this.detail.dialogStatus = 'SyntheticPremix'
                    this.detail.dialogFormVisible = true
                    this.detail.list = this.selectList2
                    this.detail.disabled = false
                    this.detail.list2 = [{ name: '', colour: '#ccc', cattle_category_id: '',cattle_category_name:'', formula_type_name: '预混配方', formula_type_id: '2',data_source_id:1, data_source_name: '自定义', remarks: '', 'is_show': 1 }]
                    setTimeout(() => {
                      this.detail.listLoading = false
                    }, 100)
                  }
                } else {
                  this.detail.dialogStatus = 'SyntheticPremix'
                  this.detail.dialogFormVisible = true
                  this.detail.list = this.selectList2
                  this.detail.disabled = false
                  this.detail.list2 = [{ name: '', colour: '#ccc', cattle_category_id: '', cattle_category_name:'',formula_type_name: '预混配方', formula_type_id: '2', data_source_id:1,data_source_name: '自定义', remarks: '', 'is_show': 1 }]
                  setTimeout(() => {
                    this.detail.listLoading = false
                  }, 100)
                }
              } else {
                this.detail.list3 = []
                this.detail.dialogStatus = 'SyntheticPremix'
                this.detail.dialogFormVisible = true
                this.detail.list = this.selectList2
                this.detail.disabled = false
                this.detail.list2 = [{ name: '', colour: '#ccc', cattle_category_id: '', cattle_category_name:'',formula_type_name: '预混配方', formula_type_id: '2', data_source_id:1,data_source_name: '自定义', remarks: '', 'is_show': 1 }]
                setTimeout(() => {
                  this.detail.listLoading = false
                }, 100)
              }
            })
          } else {
            this.detail.dialogStatus = 'SyntheticPremix'
            this.detail.dialogFormVisible = true
            this.detail.list = this.selectList2
            this.detail.disabled = false
            this.detail.list2 = [{ name: '', colour: '#ccc', cattle_category_id: '', cattle_category_name:'',formula_type_name: '预混配方', formula_type_id: '2', data_source_id:1,data_source_name: '自定义', remarks: '', 'is_show': 1 }]
            setTimeout(() => {
              this.detail.listLoading = false
            }, 100)
          }
        } else {
          this.$message({ type: 'error', message: '请选择俩条及以上饲料进行合成', duration: 2000 })
          return false
        }
      // }
    },
    // 畜生类别
    changeLivestockType2(item) {
      this.detail.list2[0].cattle_category_name = this.livestockTypeList.find(obj => obj.value === item).label
    },
    syntheticPremixData() {
      console.log('点击了合成预混料确认')
      if (this.detail.disabled == true) { // 原预混料
        let sumFweight = 0
        for (let i = 0; i < this.detail.list.length; i++) {
          sumFweight += parseFloat(this.detail.list[i].fweight)
        }
        sumFweight = sumFweight.toFixed(3)
        this.isokDisable = true
        setTimeout(() => {
          this.isokDisable = false
        }, 1000)
        this.requestParam.common = { 'returnmap': '0' }
        this.requestParam.data = []
        this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.detail.list }}
        this.requestParam.data[0].children = []
        this.requestParam.data[0].children[0] = { 'name': 'deleteFTdetail', 'type': 'e', 'parammaps': {
          pastureid: '@insertSpotList.pastureid',
          id: '@insertSpotList.id'
        }}
        this.requestParam.data[1] = { 'name': 'insertSpotList2', 'resultmaps': { 'list': this.detail.list2 }}
        this.requestParam.data[1].children = []
        this.requestParam.data[1].children[0] = { 'name': 'insertFTdetail', 'type': 'e', 'parammaps': {
          pastureid: Cookies.get('pastureid'),
          ftid: this.table2.getdataListParm.parammaps.ftid,
          fid: this.detail.list2[0].id,
          fname: '@insertSpotList2.tname',
          fweight: sumFweight,
          islockcount: '0',
          sort: parseInt(this.table2.list[this.table2.list.length - 1].sort) + 1,
          feedgroup: '@insertSpotList2.tname',
          preftid: this.detail.list2[0].id,
          autosecond: this.detail.list[0].autosecond
        }}
        ExecDataByConfig(this.requestParam).then(response => {
          console.log('合成预混料保存发送参数', this.requestParam)
          if (response.msg === 'fail') {
            const tname = new RegExp("key 'tname'")
            if (tname.test(response.data)) {
              this.$message({ type: 'error', message: '预混配方已存在，不可重复生成', duration: 2000 })
            } else {
              this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
            }
          } else {
            this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
            this.detail.dialogFormVisible = false
            this.getList2()
            this.getDownList()
          }
        })
      } else { // 现生成预混料
        if (this.detail.list2[0].name == '' && this.detail.list2[0].cattle_category_id == '') {
          this.$message({ type: 'error', message: '配方名称/牲畜类别/不能为空', duration: 2000 })
          return false
        } else if (this.detail.list2[0].name == '') {
          this.$message({ type: 'error', message: '配方名称不能为空', duration: 2000 })
          return false
        } else if (this.detail.list2[0].cattle_category_id == '') {
          this.$message({ type: 'error', message: '牲畜类别不能为空', duration: 2000 })
          return false
        }
        const pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？]")
        if (pattern.test(this.detail.list2[0].name)) {
          this.$message({ type: 'error', message: '配方名称不可输入特殊字符', duration: 2000 })
          return false
        }
        let sumFweight = 0
        for (let i = 0; i < this.detail.list.length; i++) {
          sumFweight += parseFloat(this.detail.list[i].weight)
        }
        sumFweight = sumFweight.toFixed(3)
        console.log(sumFweight)
        this.isokDisable = true
        setTimeout(() => {
          this.isokDisable = false
        }, 1000)
        if (this.detail.list2[0].colour == null) {
          this.detail.list2[0].colour = '#CCCCCC'
        }
        let feed_list = []
        for(let i=0;i<this.detail.list.length;i++){
          let obj = {
            "feed_formula_id":this.detail.list[i].feed_formula_id,
            "forage_id":this.detail.list[i].forage_id,
            "forage_name": this.detail.list[i].forage_name,
            "forage_group_name": this.detail.list[i].forage_group_name,
            "weight": this.detail.list[i].weight,
            "sort": this.detail.list[i].sort
          }
          if(this.detail.list[i].stir_delay){
            obj.stir_delay = this.detail.list[i].stir_delay
          }
          if(this.detail.list[i].allow_error){
            obj.allow_error = this.detail.list[i].allow_error
          }
          feed_list.push(obj)
        }
        let url = 'api/v1/ops/feed_formula/feed/mixed'
        let data = {
          "name": this.detail.list2[0].name,
          "colour": this.detail.list2[0].colour,
          "cattle_category_id": parseFloat(this.detail.list2[0].cattle_category_id),
          "cattle_category_name": this.detail.list2[0].cattle_category_name,
          "formula_type_id": parseFloat(this.detail.list2[0].formula_type_id),
          "formula_type_name": this.detail.list2[0].formula_type_name,
          "data_source_id": parseFloat(this.detail.list2[0].data_source_id),
          "remarks": this.detail.list2[0].remarks,
          "feed_formula_id":feed_list[0].feed_formula_id,
          "feed_list": feed_list
        }
        postJson(url,data).then(response => {
          console.log('合成预混料保存发送参数', this.requestParam)
          if (response.msg === 'fail') {
            const tname = new RegExp("key 'tname'")
            if (tname.test(response.data)) {
              this.$message({ type: 'error', message: '预混配方已存在，不可重复生成', duration: 2000 })
            } else {
              this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
            }
          } else {
            this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
            this.detail.dialogFormVisible = false
            this.getList2()
            this.getDownList()
          }
        })
      }
    },
    getList3(){
      this.table3.listLoading = true
      let url = '/api/v1/ops/feed_formula/edit_record/list'
      let data = {
        "pasture_id":this.table3.parammaps.pasture_id,
        'feed_formula_id':this.table3.parammaps.id,
        'feed_formula_id':65
      }
      if(this.table3.parammaps.inputDatetime !== null && this.table3.parammaps.inputDatetime.length > 0){
        data.start_time = parseTime(this.table3.parammaps.inputDatetime[0],'{y}-{m}-{d}')
        data.end_time = parseTime(this.table3.parammaps.inputDatetime[1],'{y}-{m}-{d}')
      }
      postJson(url, data).then(response => {
        if (response.code == 200) {
          this.table3.list = response.data.list
          this.table3.total = response.data.total
        } else {
          this.table3.list = []
        }
        setTimeout(() => {
          this.table3.listLoading = false
        }, 1000)
      })
    },
    handleSearch3(){
      this.getList3()
    },


    // =================================

    getSummaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        if (column.property !== undefined) {
          // 加了prop属性的el-table-column 才能找到column.property
          const values = data.map(item => Number(item[column.property]))
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr)
              if (!isNaN(value)) {
                return prev + curr // 多行相加
              } else {
                return prev
              }
            }, 0)
            sums[index] = sums[index].toFixed(4) + '(干物质量：' + this.table2.dryweight + ')'
          } else {
            sums[index] = ''
          }
        }
      })
      // console.log(sums, 'sums[index]')
      return sums
    },
    getDryWeight() {
      GetDataByName(this.table2.getDryweightParm).then(response => {
        console.log('干物质数据', response.data.list)
        if (response.data.list[0].dryweight !== undefined) {
          this.table2.dryweight = response.data.list[0].dryweight
        } else {
          this.table2.dryweight = ''
        }
      })
    },
    getTemplateTable2Summaries(param) {
      const { columns, data } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          // 后台待发
          sums[index] += '(干物质量：' + this.template.table2.getdataListParm.parammaps.dryweight + ')'
        } else {
          sums[index] = ''
        }
      })
      return sums
    },





    handleSelectionChange(val) {
      console.log('勾选数据', val)
      this.selectList = val
    },


    // 配方记录
    handleRecipeRecord() {
      console.log('点击了配方记录')
      this.template.dialogStatus = 'RecipeRecord'
      this.dialogFull = false
      this.template.dialogFormVisible = true
      this.template.table.getdataListParm.parammaps.ccname = ''
      this.template.table.getdataListParm.parammaps.fttype = ''
      this.template.table.getdataListParm.parammaps.enable = ''
      this.template.table.getdataListParm.parammaps.tname = ''
      this.template.table.getdataListParm.parammaps.remark = ''
      this.template.table.getdataListParm.parammaps.source = ''
      this.template.table.getdataListParm.offset = 1
      this.getDateList()
      this.isDetailDialog = false
      this.myheight2 = document.documentElement.clientHeight - 85 - 265
    },
    // 历史时间
    getDateList() {
      GetDataByName(this.template.getdataDateParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.template.table.getdataListParm.parammaps.date = response.data.list[0].maxdate
          this.getTemplateDialogList()
        } else {
          this.template.table.getdataListParm.parammaps.date = ''
        }
      })
    },
    // 配方记录-模板
    getTemplateDialogList() {
      this.template.table.listLoading = true
      GetDataByName(this.template.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.template.table.list = response.data.list
          this.template.table.pageNum = response.data.pageNum
          this.template.table.pageSize = response.data.pageSize
          this.template.table.total = response.data.total
        } else {
          this.template.table.list = []
          this.template.table2.list = []
        }
        setTimeout(() => {
          this.template.table.listLoading = false
        }, 100)
      })
    },
    handleDialogSearch() {
      this.template.table.getdataListParm.offset = 1
      this.getTemplateDialogList()
      this.arrowDown = true
      this.arrowUp = false
    },
    handleDialogRefresh() {
      this.template.table.getdataListParm.parammaps.ccname = ''
      this.template.table.getdataListParm.parammaps.fttype = ''
      this.template.table.getdataListParm.parammaps.enable = ''
      this.template.table.getdataListParm.parammaps.tname = ''
      this.template.table.getdataListParm.parammaps.remark = ''
      this.template.table.getdataListParm.parammaps.source = ''
      this.template.table.getdataListParm.offset = 1
      this.getTemplateDialogList()
    },

    // 配方记录-模板行点击
    tableRowClickDialog(row, column, event) {
      console.log('配方记录-模板行点击')
      this.isDetailDialog = true
      this.template.table2.getdataListParm.parammaps.date = this.template.table.getdataListParm.parammaps.date
      this.template.table2.getdataListParm.parammaps.version = row.version
      this.template.table2.getdataListParm.parammaps.ftid = row.id
      this.template.table2.getdataListParm.parammaps.dryweight = row.dryweight
      this.myheight2 = document.documentElement.clientHeight - 85 - 265 - 185
      this.getDialogList()
      this.getDownList()
    },

    getDialogList() {
      this.template.table2.listLoading = true
      GetDataByName(this.template.table2.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.template.table2.list = response.data.list
          this.template.table2.pageNum = response.data.pageNum
          this.template.table2.pageSize = response.data.pageSize
          this.template.table2.total = response.data.total
        } else {
          this.template.table2.list = []
        }
        this.$nextTick(function() {
          document.querySelector('#detailDialog2').scrollIntoView()
          // window.scrollTo({
          //   'top': this.$refs.detailDialog2.clientHeight
          // })
        })
        setTimeout(() => {
          this.template.table2.listLoading = false
        }, 100)
      })
    },
    handleDialogSearch2() {
      console.log('点击了查询')
      this.arrowDown2 = true
      this.arrowUp2 = false
      this.template.table2.getdataListParm.offset = 1
      this.getDialogList2()
    },
    handleDialogRefresh2() {
      console.log('点击了重置')
      this.template.table2.getdataListParm.parammaps.fname = ''
      this.template.table2.getdataListParm.parammaps.feedgroup = ''
      this.template.table2.getdataListParm.parammaps.fweight = ''
      this.template.table2.getdataListParm.parammaps.autosecondname = ''
      this.template.table2.getdataListParm.parammaps.islockcount = '0'
      this.template.table2.getdataListParm.parammaps.sort = ''
      this.template.table2.getdataListParm.offset = 1
      this.getDialogList2()
    },
    getDialogList2() {
      this.template.table2.listLoading = true
      GetDataByName(this.template.table2.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.template.table2.list = response.data.list
          this.template.table2.pageNum = response.data.pageNum
          this.template.table2.pageSize = response.data.pageSize
          this.template.table2.total = response.data.total
        } else {
          this.template.table2.list = []
        }
        this.$nextTick(function() {
          window.scrollTo({
            'top': this.$refs.templateDialog.clientHeight
          })
        })
        setTimeout(() => {
          this.template.table2.listLoading = false
        }, 100)
      })
    },

    changeDate() {
      this.getTemplateDialogList()
    },
    // 应用
    handleApplication() {
      console.log('点击了应用')
      MessageBox.confirm('是否确认将' + this.template.table.getdataListParm.parammaps.date + '的数据应用到当前?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam.name = 'applyFTdate'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.pastureid = Cookies.get('pastureid')
        this.requestParam.parammaps.date = this.template.table.getdataListParm.parammaps.date
        PostDataByName(this.requestParam).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
            this.getTemplateDialogList()
            this.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消应用' })
      })
    },

    handleCloseTable2() {
      this.isDetail = false
      this.myheight1 = ''
      this.isEnlarge = true
    },
    handleDialogCloseTable2() {
      this.isDetailDialog = false
      this.myheight2 = document.documentElement.clientHeight - 85 - 265
    },
    // -------------------详情-----------------------------
    // 获取是否显示是否锁定牛头数
    getIsLockCount() {
      GetDataByName(this.lockCount.getdataListParm).then(response => {
        console.log(response.data.list)
        if (response.data.list[0].inforvalue == 0) {
          this.lockCount.isLockCount = false
        } else {
          this.lockCount.isLockCount = true
        }
      })
    },













    // 拆分预混料
    handleSplitPremix(row) {
      console.log('点击了拆分预混料')
      MessageBox.confirm('是否确认拆分当前预混料?', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.requestParam.name = 'splitFTpre'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.ftid = this.table2.getdataListParm.parammaps.ftid
        this.requestParam.parammaps.preftid = row.preftid
        this.requestParam.parammaps.ftdid = row.id
        this.requestParam.parammaps.pastureid = row.pastureid
        this.requestParam.parammaps.feedgroup = row.feedgroup
        this.requestParam.parammaps.sort = row.sort
        this.requestParam.parammaps.fweight = row.fweight
        PostDataByName(this.requestParam).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
            this.getList2()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },



    handleFormulationEvaluation(row) {
      console.log(row)
      // this.$router.push({ path: '/statisticalAnalysis/FormulationEvaluation', query: { tname: row.tname }})
      this.$router.push({
        name: 'FormulationEvaluation',
        params: {
          tname: row.name,
          ftid: row.id,
          pastureid: row.pastureid,
          startTime: parseTime(new Date(), '{y}-{m}-{d}'),
          inputDatetime: [new Date('startTime'), new Date('startTime')], // 日期后台待传
          stopTime: parseTime(new Date(), '{y}-{m}-{d}')
        }
      })
    },
    // 使用概况
    handleRowUsageOverview(row) {
      console.log(row)
      this.usageOverview.temp = Object.assign({}, row)
      this.usageOverview.dialogFormVisible = true
      this.textMap.usageOverviewTxt = row.name + '配方使用概况'
      this.usageOverview.dialogStatus = 'usageOverviewTxt'
      this.usageOverview.getdataListParm.parammaps.pastureid = row.pastureid
      this.usageOverview.getdataListParm.parammaps.fitid = row.id
      this.usageOverview.getdataListParm.parammaps.inputDatetime = [new Date(), new Date()]
      this.getRowUsageOverviewList()
    },
    getRowUsageOverviewList() {
      this.usageOverview.listLoading = false
      this.usageOverview.getdataListParm.parammaps.fitid = this.usageOverview.temp.id
      if (this.usageOverview.getdataListParm.parammaps.inputDatetime == null) {
        this.usageOverview.getdataListParm.parammaps.inputDatetime = ''
        this.usageOverview.getdataListParm.parammaps.startTime = ''
        this.usageOverview.getdataListParm.parammaps.stopTime = ''
      } else {
        this.usageOverview.getdataListParm.parammaps.startTime = parseTime(this.usageOverview.getdataListParm.parammaps.inputDatetime[0],'{y}-{m}-{d}')
        this.usageOverview.getdataListParm.parammaps.stopTime = parseTime(this.usageOverview.getdataListParm.parammaps.inputDatetime[1],'{y}-{m}-{d}')
      }
      const url = 'api/v1/ops/feed_formula/usage'
      const data = {
        'feed_formula_id':this.usageOverview.temp.id,
        'start_time':this.usageOverview.getdataListParm.parammaps.startTime,
        'end_time':this.usageOverview.getdataListParm.parammaps.stopTime
      }
      postJson(url, data).then(response => {
        if (response.data !== null) {
          // for (let i = 0; i < response.data.list.length; i++) {
          //   if (response.data.list[i].arrList == null) {
          //     this.$set(response.data.list[i], 'arrList', [])
          //   }
          // }
          this.usageOverview.list = response.data
          this.usageOverview.pageNum = response.data.pageNum
          this.usageOverview.pageSize = response.data.pageSize
          // this.usageOverview.total = response.data.total
        } else {
          this.usageOverview.list = []
          this.usageOverview.total = 0
        }
        console.log(response.data, 'response.data')
        setTimeout(() => {
          this.usageOverview.listLoading = false
        }, 100)
      })
    },
    handleRowUsageOverviewSearch() {
      this.getRowUsageOverviewList()
    },
    handle_feedingefficiency(row){
      console.log(row,'====')
      this.feedingEfficiency.temp = Object.assign({}, row)
      this.textMap.feedingEfficiencyTxt = row.pasture_name
      this.feedingEfficiency.dialogStatus = 'feedingEfficiencyTxt'
      this.getFeedingEfficiencyList()
    },
    getFeedingEfficiencyList(){
      const url = 'api/v1/ops/feed_efficiency/statistics?page='+0+'&page_size='+0
      const data = {
        'api_name':'getFeedEfficiencyFT',
        'start_time':this.usageOverview.getdataListParm.parammaps.startTime,
        'end_time':this.usageOverview.getdataListParm.parammaps.stopTime,
        'feed_formula_id':this.usageOverview.temp.id,
        'pasture_id':[this.feedingEfficiency.temp.pasture_id]
        // 'pasture_id':[0]
      }
      postJson(url, data).then(response => {
        if(response.data.list){
          let list = response.data.list
          let dataValue = Object.values(list)
          this.feedingEfficiency.data= dataValue[0]
          this.feedingEfficiency.dialogFormVisible = true
        }else{
          this.feedingEfficiency.data= {}
          this.feedingEfficiency.dialogFormVisible = true
        }
      })
    },
    handle_canceldistributingformula(row){
      MessageBox.confirm('取消后该牧场将无法继续使用该配方，确认取消吗？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        const url = '/api/v1/ops/feed_formula/cancel/distribute'
        const data = {
          pasture_ids:[row.pasture_id],
          feed_formula_ids:[this.usageOverview.temp.id]
        }
        postJson(url, data).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.$notify({ title: '', message: '成功', type: 'success', duration: 2000 })
            // this.getList()
          }
        })
      })
    },
    handleEnlarge() {
      var height = (document.documentElement.clientHeight - 165 + 50).toString() + 'px'
      // var height = (document.documentElement.clientHeight - 165 + 80).toString() + 'px'
      // var height2 = '-' + (document.documentElement.clientHeight - 400).toString() + 'px'
      var height2 = '-' + (this.$refs.template.offsetHeight).toString() + 'px'
      // console.log(this.$refs.detail.offsetHeight)
      // console.log(height2, 'height2')
      this.isEnlarge = false
      this.$refs.detail.style.top = height2
      this.$refs.detail.style.height = height
      this.$refs.appContainer.style.height = height
      this.$refs.table2.style.height = 0
      this.$refs.myContainer.style.posiiton = 'relative'
      this.$refs.detail.style.posiiton = 'absolute'
    },
    handleNarrow() {
      this.isEnlarge = true
      this.$refs.detail.style.top = 0
      this.$refs.detail.style.height = '300px'
      this.$refs.myContainer.style.posiiton = ''
      this.$refs.detail.style.posiiton = ''
      this.$refs.detail.style.zIndex = ''
    },
    handleTakeEffect() {
      if (this.selectList.length == 0) {
        this.$message({ type: 'error', message: '请选择车次信息', duration: 2000 })
      } else {
        MessageBox.confirm('当前选中' + this.selectList.length + '条信息，是否生效?', {
          confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
        }).then(() => {
          let ids = []
          for (let i = 0; i < this.selectList.length; i++) {
            ids.push(this.selectList[i].id)
          }
          var data = {}
          data.parammaps = {}
          data.parammaps.enable = 1
          data.parammaps.id = ids.toString()
          var url = 'authdata/feedtemplet/enable'
          postJson(url,data).then(response => {
            console.log('生效保存发送参数', data)
            if (response.msg === 'fail') {
              this.$notify({ title: '生效失败', message: response.data, type: 'warning', duration: 2000 })
            } else {
              this.$notify({ title: '', message: '生效成功', type: 'success', duration: 2000 })
              this.getList()
            }
          })
        })
      }
    },
    handleDisable() {
      if (this.selectList.length == 0) {
        this.$message({ type: 'error', message: '请选择车次信息', duration: 2000 })
      } else {
        MessageBox.confirm('当前选中' + this.selectList.length + '条信息，是否禁用?', {
          confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
        }).then(() => {
          let ids = []
          for (let i = 0; i < this.selectList.length; i++) {
            ids.push(this.selectList[i].id)
          }
          var data = {}
          data.parammaps = {}
          data.parammaps.enable = 0
          data.parammaps.id = ids.toString()
          console.log('禁用', data)
          var url = 'authdata/feedtemplet/enable'
          postJson(url,data).then(response => {
            console.log('禁用保存发送参数', this.requestParam)
            if (response.msg === 'fail') {
              this.$notify({ title: '禁用失败', message: response.data, type: 'warning', duration: 2000 })
            } else {
              this.$notify({ title: '', message: '禁用成功', type: 'success', duration: 2000 })
              this.getList()
            }
          })
        })
      }
    },
    // clickNew(row){
    //   console.log('new',row)
    // }
  }
}
</script>
<style lang="scss" scoped>
  // .search{margin-top:10px;height: 40px;}
  // .operation{height: 50px;}
  .table{margin-top:5px;}
  .table2{margin-top:10px;}
  $width:350px;
  $left:325px;
  .selectInput{
    position: relative;
    display: inline-block;
    .Input{width: $width;position: relative;}
    .el-icon-arrow-down{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
    .el-icon-arrow-up{width: 30px;height: 30px;position: absolute;left: $left;top:10px;color:#C0C4CC;}
    .selectUl{
      height:220px;overflow-y: auto;z-index: 111;width: $width;background: #fff;border: 1px solid #E4E7ED;box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);margin: -1px 0 0 0;padding: 6px 0; margin: 0;box-sizing: border-box;position: absolute;
      li{
        list-style: none;font-size: 14px; padding: 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #606266; height: 50px; line-height: 50px; box-sizing: border-box; cursor: pointer;
        a{float:left;width: 80px;}
        a:hover{color: rgba(0, 204, 102, 0.71); font-weight: 700;}
      }
    }
  }
  .template{
    background: #fff;
    position: relative;
  }
  .app-container{background: #fff;}
  .detail{
    background: #fff;
    overflow-y: hidden;
    overflow-x: hidden;
    // position: fixed;
    // bottom: 0;
    // right:0;
    z-index: 3;
    // width: calc(100% - 210px);
    position: relative;
  }
  .hide2{float: right;right:0;}
  .templateDialog{
    background: #fff;
    position: relative;
  }
 .detailDialog{
    background: #fff;
    position: relative;
  }
  .hide{float: right;margin-right: 60px;}
  .content div{
    text-align: center;
    line-height: 30px;
    border-bottom: 1px solid #eee;
  }
  .content div .title{
    width:250px;text-align: right;display: inline-block;margin-right: 10px;
  }
  .item {
    margin-top: 10px;
    margin-right: 40px;
  }
  .new{
    background: #01BE80;
    padding: 5px 5px;
    margin-left: 5px;
    border-radius: 8px;
    color:#fff;
    cursor: pointer;
  }
 </style>
 <style>
  .el-color-dropdown__main-wrapper{display: none !important;}
  .el-color-dropdown__value{display: none !important;}
  .el-color-dropdown__btns .el-button--text{display: none !important;}
 </style>
