<template>
  <div class="app-container">
    <div class="operation">
      <el-select v-model="table.parammaps.pastureId" placeholder="牧场" class="filter-item" style="width: 120px;float:left;margin-right: 10px;">
        <el-option v-for="item in pastureList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-date-picker v-model="table.parammaps.inputDatetime" :clearable="false" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;margin-right: 10px;float: left;" @change="changeDate" />
      <el-button class="el-icon-arrow-left elIconArrowLeft" @click="handleBefore" />
      <el-button class="el-icon-arrow-right elIconArrowRight" @click="handleNext" />
      <el-select v-model="table.parammaps.search_type" placeholder="查询" class="filter-item" style="width: 120px;margin-right: 10px;">
        <el-option v-for="item in searchList" :key="item.value" :label="item.label" :value="item.value" />
      </el-select>

      <el-autocomplete v-if="table.parammaps.search_type == 0" v-model="table.parammaps.template_name" class="filter-item" :fetch-suggestions="formula_Search" value-key="name" placeholder="请输入配方名称" @select="handle_formulaSelect" >
        <template slot-scope="{ item }">
          <div>{{ item.name }}</div>
        </template>
      </el-autocomplete>
      <el-autocomplete v-else v-model="table.parammaps.barn_id" class="filter-item" :fetch-suggestions="fenceshed_Search" value-key="eqName" placeholder="请输入栏舍名称" @select="handle_fenceshedSelect">
        <template slot-scope="{ item }">
          <div>{{ item.eqName }}</div>
        </template>
      </el-autocomplete>
      <el-button class="successBorder" style="margin-left:10px;" @click="form_search">查询</el-button>
    </div>
    <div class="search" />
    <div class="table">
      <el-table
        :key="table.tableKey"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        :row-style="rowStyle"
        :cell-style="tableCellStyle"
        class="elTable table-fixed"
      >
        <el-table-column sortable label="配方模板/指标" min-width="98px" align="center">
          <template slot-scope="{row}">
            <a @click="clickFormulaTemplateIndex(row)">{{ row.tname }}</a>
          </template>
        </el-table-column>
        <el-table-column sortable label="牛头数" prop="ccount" min-width="58px" align="center" />
        <el-table-column label="干物质(kg)" align="center">
          <el-table-column sortable prop="dry" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.dry) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.dry) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="产奶净能(MJ)" align="center">
          <el-table-column sortable prop="nm" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.nm) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.nm) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="奶牛能量单位(NND)" align="center">
          <el-table-column sortable prop="nuint" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.nuint) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.nuint) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="粗蛋白(g)" align="center">
          <el-table-column prop="cp" label="配方量" min-width="58" align="center" />
          <el-table-column label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.cp) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.cp) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="磷(g)" align="center">
          <el-table-column sortable prop="p" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.p) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.p) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="产奶净能(MCal/DM)" align="center">
          <el-table-column sortable prop="nmd" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.nmd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.nmd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="粗蛋白(%DM)" align="center">
          <el-table-column sortable prop="cpd" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.cpd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.cpd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="脂肪(%DM)" align="center">
          <el-table-column sortable prop="fat" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.fat) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.fat) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="淀粉(%DM)" align="center">
          <el-table-column sortable prop="starch" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.starch) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.starch) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="NDF(%DM)" align="center">
          <el-table-column sortable prop="ndf" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.ndf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.ndf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="粗料中的NDF(%DM)" align="center">
          <el-table-column sortable prop="cndf" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.cndf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.cndf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="ADF(%DM)" align="center">
          <el-table-column sortable prop="adf" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.adf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.adf) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="钙(%DM)" align="center">
          <el-table-column sortable prop="cad" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.cad) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.cad) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="磷(%DM)" align="center">
          <el-table-column sortable prop="pd" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.pd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.pd) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column sortable label="精粗比(%)" align="center">
          <el-table-column sortable prop="jcrate" label="配方量" min-width="58" align="center" />
          <el-table-column sortable label="TMR料" min-width="65" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Hrate * scope.row.jcrate) | keepTreeNum }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable label="采食量" min-width="58" align="center">
            <template slot-scope="scope">
              <span>{{ (scope.row.Srate * scope.row.jcrate) | keepTreeNum }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="操作" align="center" width="70" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <el-button class="miniSuccess" icon="el-icon-search" @click="form_see(row)" />
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="table.total>0" :total="table.total" :page.sync="table.page" :limit.sync="table.page_size" @pagination="getList" />
    </div>

    <!-- 查看 -->
    <el-dialog :fullscreen="dialogFull" :destroy-on-close="true" class="dialogMinHeight" :visible.sync="see.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[see.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="app-see dialogMinHeight">
        <div class="tableSee">
          <el-table
            :key="see.table.tableKey"
            v-loading="see.table.listLoading"
            element-loading-text="给我一点时间"
            :data="see.table.list"
            border
            fit
            show-summary
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="tableCellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="栏舍/指标" min-width="100px" align="center">
              <template slot-scope="{row}">
                <a @click="clickFormulaHurdlesIndex(row)">{{ row.barname }}</a>
              </template>
            </el-table-column>
            <el-table-column label="牛头数" min-width="100px" align="center" prop="ccount" />
            <el-table-column label="干物质(kg)" min-width="130px" align="center">
              <el-table-column prop="dry-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="dry-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="dry-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="dry-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="产奶净能(M)" min-width="130px" align="center">
              <el-table-column prop="nm-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="nm-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="nm-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="nm-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="奶牛能量单位(NND)" min-width="130px" align="center">
              <el-table-column prop="nuint-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="nuint-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="nuint-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="nuint-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="粗蛋白(g)" min-width="130px" align="center">
              <el-table-column prop="cp-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="cp-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="cp-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="cp-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="磷(g)" min-width="130px" align="center">
              <el-table-column prop="p-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="p-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="p-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="p-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="产奶净能(MCal/DM)" min-width="130px" align="center">
              <el-table-column prop="nmd-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="nmd-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="nmd-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="nmd-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="粗蛋白(%DM)" min-width="130px" align="center">
              <el-table-column prop="cpd-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="cpd-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="cpd-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="cpd-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="脂肪(%DM)" min-width="130px" align="center">
              <el-table-column prop="fat-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="fat-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="fat-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="fat-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="淀粉(%DM)" min-width="130px" align="center">
              <el-table-column prop="starch-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="starch-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="starch-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="starch-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="NDF(%DM)" min-width="130px" align="center">
              <el-table-column prop="ndf-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="ndf-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="ndf-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="ndf-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="粗料中的NDF(%DM)" min-width="130px" align="center">
              <el-table-column prop="cndf-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="cndf-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="cndf-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="cndf-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="ADF(%DM)" min-width="130px" align="center">
              <el-table-column prop="adf-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="adf-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="adf-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="adf-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="钙(%DM)" min-width="130px" align="center">
              <el-table-column prop="cad-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="cad-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="cad-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="cad-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="磷(%DM)" min-width="130px" align="center">
              <el-table-column prop="pd-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="pd-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="pd-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="pd-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="(4.0)饲料转化效率(kg/DM)" min-width="130px" align="center">
              <el-table-column prop="trans4f-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="trans4f-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="trans4f-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="trans4f-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="(3.5)饲料转化效率(kg/DM)" min-width="130px" align="center">
              <el-table-column prop="trans35f-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="trans35f-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="trans35f-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="trans35f-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="精粗比(%)" min-width="130px" align="center">
              <el-table-column prop="jcrate-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="jcrate-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="jcrate-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="jcrate-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="日粮成本(元)" min-width="130px" align="center">
              <el-table-column prop="uprice-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="uprice-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="uprice-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="uprice-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="干物质成本(元/公斤)" min-width="130px" align="center">
              <el-table-column prop="upriced-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="upriced-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="upriced-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="upriced-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
            <el-table-column label="日公斤奶成本(元)" min-width="130px" align="center">
              <el-table-column prop="kprice-nur" label="奶牛需要" min-width="70" align="center" />
              <el-table-column prop="kprice-FT" label="配方量" min-width="58" align="center" />
              <el-table-column prop="kprice-H" label="TMR料" min-width="65" align="center" />
              <el-table-column prop="kprice-S" label="采食量" min-width="58" align="center" />
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose" style="right: 20px" @click="see.dialogFormVisible = false;$route.params.tname = '' ">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 配方详情 -->
    <el-dialog :fullscreen="dialogFull" :destroy-on-close="true" :visible.sync="details.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[details.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="details dialogMinHeight">
        <el-form ref="temp" :rules="details.rules" :model="details.temp" label-position="right" label-width="120px" style="width: 100%;margin-bottom:30px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="历史记录时间:" prop="maxDate">
                <el-date-picker v-model="details.temp.maxDate" :clearable="false" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date" placeholder="请选择历史记录时间" @change="changeMaxDate" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div class="table1">
          <div ref="templateDialog" class="templateDialog">
            <div class="recipeTemplateF">
              <p>配方模板表</p>
            </div>
          </div>
          <el-table
            :key="details.table1.tableKey"
            v-loading="details.table1.listLoading"
            element-loading-text="给我一点时间"
            :data="details.table1.list"
            border
            fit
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="序号" type="index" width="50" align="center" />
            <el-table-column label="配方名称" min-width="100px" align="center" prop="tname" />
            <el-table-column label="牲畜类别" min-width="100px" align="center" prop="ccname" />
            <el-table-column label="配方类型" min-width="100px" align="center" prop="fttype" />
            <el-table-column label="来源" min-width="100px" align="center" prop="source" />
            <el-table-column label="版本号" min-width="100px" align="center" prop="version" />
            <el-table-column label="版本时间" min-width="100px" align="center" prop="versiontime" />
          </el-table>
        </div>
        <div class="table2 detailDialog">
          <div class="recipeTemplateF">
            <p>配方详情表</p>
          </div>
          <el-table
            :key="details.table2.tableKey"
            v-loading="details.table2.listLoading"
            element-loading-text="给我一点时间"
            :data="details.table2.list"
            border
            fit
            show-summary
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="序号" type="index" width="50" align="center" />
            <el-table-column label="饲料组" min-width="100px" align="center" prop="feedgroup" />
            <el-table-column label="饲料名称" min-width="100px" align="center" prop="fname" />
            <el-table-column label="重量(KG)" min-width="100px" align="center" prop="fweight" />
            <el-table-column label="搅拌延时(min)" min-width="100px" align="center" prop="autosecond" />
            <el-table-column label="是否锁定牛头数比例" min-width="100" 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="100" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.sort }}</span>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="cancelClose" style="right: 20px" @click="details.dialogFormVisible = false;">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetDataByName, postJson } from '@/api/common'
import Cookies from 'js-cookie'
import Pagination from '@/components/Pagination'
import { parseTime } from '@/utils/index.js'
export default {
  name: 'FormulationEvaluation',
  components: { Pagination },
  filters: {
    keepTreeNum(value) {
      value = Number(value)
      return value.toFixed(3)
    }
  },
  data() {
    return {
      pastureList:JSON.parse(sessionStorage.pastureList), //牧场
      searchList: JSON.parse(sessionStorage.downlist).formulation_evaluation,  //查询
      formulaList: [],
      fenceHouseList: [],
      table: {
        page: 1,
        page_size: parseInt(Cookies.get('pageCount')),
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        parammaps: {
          pastureId: parseInt(Cookies.get('pastureId')),
          start_time: parseTime(new Date(), '{y}-{m}-{d}'),
          end_time: parseTime(new Date(), '{y}-{m}-{d}'),
          inputDatetime: [new Date(), new Date()],
          search_type: 0,
          template_id:'',
          template_name:'',
          barn_name:'',
          barn_id:''
        },
      },
      // =====
      dialogFull: false,


      see: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: {},
        rules: {},
        table: {
          tableKey: 0,
          list: [],
          total: 0,
          listLoading: true,
          getdataListParm: {
            name: 'judgenurFTReport',
            page: 1,
            offset: 1,
            pagecount: 0,
            returntype: 'Map',
            parammaps: {
              name: 'judgenurBarBmReport',
              name1: 'judgenurBarHSL'
            }
          }
        }
      },
      details: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: {
          maxDate: ''
        },
        rules: {},
        table1: {
          tableKey: 0,
          list: [],
          total: 0,
          listLoading: true,
          getdataListParm: {
            name: 'getFTListDateHis',
            page: 1,
            offset: 1,
            pagecount: 10,
            returntype: 'Map',
            parammaps: {
              pastureid: '',
              id: ''
            }
          }
        },
        table2: {
          tableKey: 0,
          list: [],
          total: 0,
          listLoading: true,
          getdataListParm: {
            name: 'getFTdetailListDate',
            page: 1,
            offset: 1,
            pagecount: 10,
            returntype: 'Map',
            parammaps: {
              pastureid: '',
              ftid: '',
              date: '',
              version: ''
            }
          }
        },
        maxDate: {
          getdataListParm: {
            name: 'getFTMaxDate',
            page: 1,
            offset: 1,
            pagecount: 10,
            returntype: 'Map',
            parammaps: {
              pastureid: ''
            }
          }
        }
      },
      textMap: {
        see: '',
        details: '配方详情'
      },
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },

  created() {
    if (this.$route.params.tname !== '' && this.$route.params.tname !== undefined && this.$route.params.start_time !== undefined && this.$route.params.end_time !== undefined) {
      console.log(this.table.parammaps.inputDatetime, 'this.table.parammaps.inputDatetime')
      this.table.parammaps.start_time = this.$route.params.start_time
      this.table.parammaps.end_time = this.$route.params.end_time
      this.textMap.see = '栏舍详情——' + this.$route.params.tname
      setTimeout(() => {
        this.dialogFull = false
        this.see.dialogStatus = 'see'
        this.see.dialogFormVisible = true
      }, 500)
      this.see.table.parammaps.ftid = this.$route.params.ftid
      this.see.table.parammaps.pastureid = this.$route.params.pastureid
      this.see.table.parammaps.start_time = this.table.parammaps.start_time
      this.see.table.parammaps.end_time = this.table.parammaps.end_time
      this.getListSee()
    }
    this.getList()
    // this.getfenceHouseList()
  },

  methods: {
    getList() {
      this.table.listLoading = true
      let page = this.table.page
      let page_size = this.table.page_size
      let url = '/api/v1/ops/feed_estimate/list' + '?page=' + page + '&page_size=' + page_size
      let data = {
        'api_name':'judgenurFTReport',
        'pasture_id':this.table.parammaps.pastureId,
        'start_time':this.table.parammaps.start_time,
        'end_time':this.table.parammaps.end_time,
        'search_type':this.table.parammaps.search_type
      }
      if(this.table.parammaps.template_id){
        data.template_id = this.table.parammaps.template_id
      }
      if(this.table.parammaps.barn_id){
        data.barn_id = this.table.parammaps.barn_id
      }
      postJson(url, data).then(response => {
        if (response.data.list !== null) {
          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
      }, 100)
    },
    form_search() {
      if(this.table.parammaps.search_type == '0'){
        this.table.parammaps.barid = ''
      }else{
        this.table.parammaps.templetid = ''
        console.log(this.table.parammaps.barid)
      }
      this.getList()
    },
    // 栏舍
    fenceshed_Search(){

    },
    handle_fenceshedSelect(){

    },
    // 配方
    formula_Search(queryString, cb){
      console.log(queryString,'====s')
      // this.table.parammaps.barn_id = queryString
      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":queryString
      }
      postJson(url, data).then(response => {
        if (response.code == 200) {
          this.formulaList = response.data.list
          var formulaList = this.formulaList;
          var results = queryString ? formulaList.filter(this.formulaFilter(queryString)) : formulaList;
          cb(results);
        }
      })
    },
    formulaFilter(queryString) {
      return (formulaList) => {
        return (formulaList.name.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },
    handle_formulaSelect(item){
      console.log(item);
      this.table.parammaps.template_id = item.id
    },

    getfenceHouseList(){
      let url = '/api/v1/ops/feed_formula/list' + '?page=' + 1 + '&page_size=' + page_size
      let data = {}
      data.name = 'getFeedTempletName'
      postJson(url, data).then(response => {
        if(response.data.list !== null){
          this.fenceHouseList = response.data.list
        }else{
          this.fenceHouseList = []
        }
      })
    },

    changeDate() {
      if (this.table.parammaps.inputDatetime !== '' && this.table.parammaps.inputDatetime !== null) {
        this.table.parammaps.start_time = parseTime(this.table.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.table.parammaps.end_time = parseTime(this.table.parammaps.inputDatetime[1], '{y}-{m}-{d}')
        this.getList()
      }
    },
    handleBefore() {
      if (this.table.parammaps.inputDatetime !== '' && this.table.parammaps.inputDatetime !== null) {
        var start = new Date(this.table.parammaps.inputDatetime[0].setDate(this.table.parammaps.inputDatetime[0].getDate() - 1))
        var stop = new Date(this.table.parammaps.inputDatetime[1].setDate(this.table.parammaps.inputDatetime[1].getDate() - 1))
        this.table.parammaps.inputDatetime.length = 0
        this.table.parammaps.inputDatetime.push(start, stop)
        this.$forceUpdate()
      }
      this.table.parammaps.start_time = parseTime(this.table.parammaps.inputDatetime[0], '{y}-{m}-{d}')
      this.table.parammaps.end_time = parseTime(this.table.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      this.getList()
    },
    handleNext() {
      if (this.table.parammaps.inputDatetime !== '' && this.table.parammaps.inputDatetime !== null) {
        var start2 = new Date(this.table.parammaps.inputDatetime[0].setDate(this.table.parammaps.inputDatetime[0].getDate() + 1))
        var stop2 = new Date(this.table.parammaps.inputDatetime[1].setDate(this.table.parammaps.inputDatetime[1].getDate() + 1))
        this.table.parammaps.inputDatetime.length = 0
        this.table.parammaps.inputDatetime.push(start2, stop2)
        this.$forceUpdate()
      }
      this.table.parammaps.start_time = parseTime(this.table.parammaps.inputDatetime[0], '{y}-{m}-{d}')
      this.table.parammaps.end_time = parseTime(this.table.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      this.getList()
    },
    tableCellStyle({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        return {
          textDecoration: 'underline'
        }
      }
      return {
        textDecoration: 'none'
      }
    },
    clickFormulaTemplateIndex(row) {
      console.log('点击了配方模板/指标')
      this.dialogFull = false
      this.details.dialogStatus = 'details'
      this.details.dialogFormVisible = true
      this.details.table1.getdataListParm.parammaps.pastureid = row.pastureid
      this.details.table1.getdataListParm.parammaps.id = row.ftid

      this.details.maxDate.getdataListParm.parammaps.pastureid = row.pastureid
      this.getMaxDate()
    },

    getMaxDate() {
      GetDataByName(this.details.maxDate.getdataListParm).then(response => {
        if (response.data.list !== null) {
          this.details.temp.maxDate = response.data.list[0].maxdate
        } else {
          this.details.temp.maxDate = ''
        }
        this.details.table1.getdataListParm.parammaps.date = this.details.temp.maxDate
        this.details.table2.getdataListParm.parammaps.date = this.details.temp.maxDate

        this.getListDetails1()
      })
    },
    changeMaxDate(item) {
      this.details.table1.getdataListParm.parammaps.date = this.details.temp.maxDate
      this.getListDetails1()
    },
    getListDetails1() {
      this.details.table1.listLoading = true
      GetDataByName(this.details.table1.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.details.table1.list = response.data.list
          this.details.table1.pageNum = response.data.pageNum
          this.details.table1.pageSize = response.data.pageSize
          this.details.table1.total = response.data.total

          this.details.table2.getdataListParm.parammaps.pastureid = this.details.table1.list[0].pastureid
          this.details.table2.getdataListParm.parammaps.ftid = this.details.table1.list[0].id
          this.details.table2.getdataListParm.parammaps.version = this.details.table1.list[0].version
          this.getListDetails2()
        } else {
          this.details.table1.list = []
          this.details.table2.list = []
          this.details.table1.pageNum = 0
          this.details.table1.pageSize = 0
          this.details.table1.total = 0
        }
        setTimeout(() => {
          this.details.table1.listLoading = false
        }, 100)
      })
    },
    getListDetails2() {
      this.details.table2.listLoading = true
      GetDataByName(this.details.table2.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.details.table2.list = response.data.list
          this.details.table2.pageNum = response.data.pageNum
          this.details.table2.pageSize = response.data.pageSize
          this.details.table2.total = response.data.total
        } else {
          this.details.table2.list = []
          this.details.table2.pageNum = 0
          this.details.table2.pageSize = 0
          this.details.table2.total = 0
        }
        setTimeout(() => {
          this.details.table2.listLoading = false
        }, 100)
      })
    },
    clickFormulaHurdlesIndex(row) {
      console.log('点击了栏舍/指标')
      this.$router.push('/formulationPlan/DhedFormula')
    },
    form_see(row) {
      console.log('查看', row)
      this.dialogFull = false
      this.textMap.see = '栏舍详情——' + row.tname
      this.see.dialogStatus = 'see'
      this.see.dialogFormVisible = true
      this.see.table.getdataListParm.parammaps.ftid = row.ftid
      this.see.table.getdataListParm.parammaps.pastureid = row.pastureid
      this.see.table.getdataListParm.parammaps.start_time = this.table.parammaps.start_time
      this.see.table.getdataListParm.parammaps.end_time = this.table.parammaps.end_time
      this.getListSee()
    },
    getListSee() {
      this.see.table.listLoading = true
      const url = 'authdata/GETNurJudgeRport'
      const data = this.see.table.getdataListParm
      postJson(url, data).then(response => {
        if (response.data !== null) {
          console.log('table数据', response.data)
          this.see.table.list = response.data
          this.see.table.pageNum = response.data.pageNum
          this.see.table.pageSize = response.data.pageSize
          this.see.table.total = response.data.total
        } else {
          this.see.table.list = []
          this.see.table.pageNum = 0
          this.see.table.pageSize = 0
          this.see.table.total = 0
        }
        setTimeout(() => {
          this.see.table.listLoading = false
        }, 100)
      })
    }

  }
}
</script>
<style lang="scss" scoped>
  .search {clear: both; }
  .table { margin-top: 10px; }
  .table2{margin-top: 20px;}
  .templateDialog{
     background: #fff;
     position: relative;
   }
  .detailDialog{
     background: #fff;
     position: relative;
   }
</style>
<style>
  .tableSee .el-table { overflow-x: auto; }
  .tableSee .el-table__header-wrapper,
  .tableSee .el-table__body-wrapper,
  .tableSee .el-table__footer-wrapper { overflow: visible; }
  .tableSee .el-table::after { position: relative; }
  .tableSee .el-table--scrollable-x .el-table__body-wrapper { overflow: visible; }
  .app-main{background: #fff;}
</style>
