 <template>
  <div class="app-container">
    <div class="operation">
   

      <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" style="float: left;" @click="handleCreate1">设置推料时间</el-button>
      <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" style="float: left;" @click="handleCreate2">设置允许误差时间</el-button>

      
     <el-button v-if="isRoleEdit" class="success" icon="el-icon-open" style="float: left;" @click="handleTakeEffect">启用</el-button>
      <el-button v-if="isRoleEdit" class="danger" icon="el-icon-turn-off" style="float: left;" @click="handleDisable">禁用</el-button>
      <el-button v-if="isRoleEdit" class="success" style="float: left;" @click="handleCheck">校验</el-button>
 
    </div>
 
    <div class="table">
      <el-table
        :key="table.tableKey"
        ref="table"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
        @header-click="headerClick"
        @cell-click="cellClick"
        @selection-change="handleSelect"
        @cell-dblclick="celldblclick"
      >
        <el-table-column type="selection" width="50" />
        <el-table-column :key="1" label="序号" align="center" type="index" width="50px" class-name="small-padding fixed-width" fixed="left" />
        <el-table-column label="栏舍名称" min-width="100px" align="center" class-name="small-padding fixed-width" fixed="left">
          <template slot-scope="scope">
        
            <span v-if="scope.row.NoEdit">{{ scope.row.barname }}</span>
            <el-input v-if="scope.row.Edit" v-model="scope.row.barname" style="width:95%;padding:10px 0;"   />
          </template>
        </el-table-column>
        <el-table-column :key="2" label="推料车名称" min-width="70px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.barname }}</span>
            <el-input v-if="scope.row.Edit" v-model="scope.row.barname" style="width:95%;padding:10px 0;"   />
          </template>
        </el-table-column>
        <el-table-column :key="3" label="推料车编号" min-width="90px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.ccount }}</span>
            <el-input v-if="scope.row.Edit" v-model="scope.row.ccount" style="width:95%;padding:10px 0;"   />
          </template>
        </el-table-column>
        <el-table-column :key="4" label="推料时间(每天)" min-width="85px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.ratio }}</span>
            <el-input v-if="scope.row.Edit" v-model="scope.row.ratio" step="0.01" type="number" style="width:95%;padding:10px 0;"   />
          </template>
        </el-table-column>
        <el-table-column :key="5" label="允许误差时间(分钟)" min-width="85px" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.NoEdit">{{ scope.row.ccountratio }}</span>
            <el-input v-if="scope.row.Edit" v-model="scope.row.ccountratio" type="number" style="width:95%;padding:10px 0;"   />
          </template>
        </el-table-column>

        <el-table-column label="操作" align="center" width="80" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <el-button v-if="row.isUpdate && isRoleEdit" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(row)" />
            <el-button v-if="row.isUpdateSave && isRoleEdit" :disabled="isokDisable" icon="el-icon-folder-checked" class="miniSuccess" @click="updateData(row)" />
            <span v-if="row.isUpdateSave && isRoleEdit" class="centerSpan">|</span>
            <el-button v-if="row.isUpdateSave && isRoleEdit" class="minCancel" icon="el-icon-close" @click="updateCancel(row)" />

            <el-button v-if="isRoleEdit" class="miniDanger" icon="el-icon-delete" @click="handleRowDelete(row)" />

          </template>
        </el-table-column>
      </el-table>
      <!-- <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" /> -->
    </div>
    


     <el-dialog :fullscreen="dialogFull" :visible.sync="create1.dialogFormVisible" :close-on-click-modal="false" width="50%">
      <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" />
            推料计划
          </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-add">
        <el-form ref="temp" :rules="create1.rules" :model="create1.temp" label-position="right" label-width="155px" style="width: 100%;margin:0 auto 50px">
        
          <el-row>
              <el-col :span="6">
                <el-form-item label="设置时间：" prop="useinbarid">
                   <el-time-picker
                    v-model="timevalue1"
                    :picker-options="{ selectableRange: '00:00:00 - 23:59:59' }"
                     value-format="HH:mm"
                     @change="change_time1" format="HH:mm"
                    placeholder="任意时间点">
                  </el-time-picker>
                </el-form-item>
              </el-col>

          </el-row>
           <el-row>
               <el-tag v-for="tag in timetags1" :key="tag.name" closable @close="tag_close1(tag)" type="success">{{tag}}</el-tag>

            </el-row>

        
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="create1.dialogFormVisible = false;getList()">关闭</el-button>
          <el-button class="save"  @click="handleCreate1">确认</el-button>
        </div>
      </div>
    </el-dialog>


    <el-dialog :fullscreen="dialogFull" :visible.sync="create2.dialogFormVisible" :close-on-click-modal="false" width="50%">
      <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" />
            允许误差时间
          </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-add">
        <el-form ref="temp" :rules="create2.rules" :model="create2.temp" label-position="right" label-width="155px" style="width: 100%;margin:0 auto 50px">
        
          <el-row>
              <el-col :span="6">
              <el-form-item label="允许误差时间(分钟)：" prop="time">
                <el-input ref="time" v-model="create2.temp.time" class="filter-item" placeholder="请输入" type="text" />
              </el-form-item>
            </el-col>

          </el-row>
           

        
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="create2.dialogFormVisible = false;getList()">关闭</el-button>
          <el-button class="save"  @click="handleCreate2">确认</el-button>
        </div>
      </div>
    </el-dialog>


   <!-- 校验 -->
    <el-dialog title="提示" :destroy-on-close="true" :visible.sync="check.dialogFormVisible" :close-on-click-modal="false" width="30%">
      <div class="check">
        <p v-if="check.temp.isDistribution == '0'">当前有栏舍未分配，建议及时进行分配，未分配栏舍如下：</p>
        <p v-else>已分配完：当前栏舍已分配完善</p>
        {{ check.temp.bnames }}
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button class="save" @click="check.dialogFormVisible=false;">确认</el-button>
      </div>
    </el-dialog>
    
 
    
  </div>
</template>

<script>
import { GetDataByName, postJson, GetDataByNames, compareSort, ExecDataByConfig, failproccess, PostDataByName, formatNum, checkButtons } from '@/api/common'
import Pagination from '@/components/Pagination'
import Pagination2 from '@/components/Pagination2'
import { parseTime, json2excel, handleTableSpan, handleObjectSpanMethod } from '@/utils/index.js'
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
import axios from 'axios'
import { getToken } from '@/utils/auth'
 
export default {
  inject: ['reload'],
  name: 'PushMaterialPlan',
  components: { Pagination, Pagination2 },
  data() {
    return {


      table: {
        getdataListParm: {
          name: 'getFPList',
          page: 1,
          offset: 1,
          // pagecount: parseInt(Cookies.get('pageCount')),
          pagecount: '',
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            enable: '',
            barid: '',
            tname: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        temp: {},
  
 
      },


      create1: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { pastureid: Cookies.get('pastureid'), fname: ''},
        rules: {
          // fname: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          // fclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          // feedcode: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
        }
      },

      create2: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: { pastureid: Cookies.get('pastureid'), time: ''},
        rules: {
          // fname: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          // fclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          // feedcode: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
        }
      },

      check: {
        dialogFormVisible: false,
        dialogStatus: '',
        getCheckParm: {
          name: 'checkRemainplan',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        },
        temp: {
          bnames: '',
          isDistribution: ''
        }
      },





      timevalue1: new Date(2022, 9, 10, 18, 40),
      timetags1: [],




      dialogFull: false,
      isRoleEdit: [],
      headerList: [],
      pickerMinDate: '',
 
   
      rules: {
        cowclassid: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
      },
      
      selectList: [],
   
   
       

      requestParam: {},
      download: {
        getdataListParm: {
          name: 'getFPList',
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            enable: ''
          }
        },
        list: []
      },
      spanObj: {},
      mergekeys: ['barname', 'sumweight'],
      isShowDialog: false,
      isokDisable: false,
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      myHeight: document.documentElement.clientHeight - 85 - 140,
      oldRowList:{},


      



    }
  },
  computed: {
    
    
  },
  created() {
    this.getButtons()
    this.getList()
   
  },

  methods: {
    getButtons() {
      const Edit = 'DhedFormula'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit
    },

    getTimeList() {
      GetDataByName(this.getTimeListParm).then(response => {
        if (response.data.list !== null) {
          this.timeList = response.data.list
        } else {
          this.timeList = []
        }
      })
    },
     

     // 新增
    handleCreate1() {
      console.log('点击了新增')
      this.resetTemp1()
      this.dialogFull = false
      this.create1.dialogStatus = 'create'
      this.create1.dialogFormVisible = true
    },
     resetTemp1() {
      this.create1.temp = { pastureid: Cookies.get('pastureid'), 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'sort': "", 'ftid': '', 'ftname': '', 'tmrcode': '', 'tmrid': '', 'times': '', 'lppcode': '', 'lppid': '', 'rtime': '', barid: '', 'treatmethod': '', 'useinbar': '', 'useinbarid': '' }
    },

    handleCreate2() {
      console.log('点击了新增')
      this.resetTemp2()
      this.dialogFull = false
      this.create2.dialogStatus = 'create'
      this.create2.dialogFormVisible = true
    },
     resetTemp2() {
      this.create2.temp = { pastureid: Cookies.get('pastureid'), 'myId': (new Date()).valueOf(), 'Edit': true, 'NoEdit': false, 'isCreate': true, 'isUpdate': false, 'isUpdateSave': false, 'enable': 1, 'sort': "", 'ftid': '', 'ftname': '', 'tmrcode': '', 'tmrid': '', 'times': '', 'lppcode': '', 'lppid': '', 'rtime': '', barid: '', 'treatmethod': '', 'useinbar': '', 'useinbarid': '' }
    },



 
    
    getList() {
      this.table.listLoading = true
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          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], 'isUpdate', true) // 编辑操作
            this.$set(response.data.list[i], 'isUpdateSave', false) // 编辑保存
          }
          // console.log(response.data.list, sumr)
      
          this.table.list = response.data.list
          console.log(this.table.list, 'this.table.list')
          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
          this.table.total = response.data.total
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },
    handleSearch() {
      this.getList()
    },


    change_time1(tag){
      console.log("tag", tag)
        console.log("timetags1", this.timetags1)
  
     this.timetags1.push(tag)

    },




    tag_close1(tag){
        console.log("tag", tag)
        console.log("timetags1", this.timetags1)
        this.timetags1.splice(this.timetags1.indexOf(tag), 1);
    },




    // 校验
    handleCheck() {
      console.log('点击了校验')
      this.check.dialogStatus = 'check'
      this.check.dialogFormVisible = true
      this.getCheckList()
    },
    getCheckList() {
      GetDataByName(this.check.getCheckParm).then(response => {
        if (response.data.list[0].bnames !== undefined) {
          this.check.temp.isDistribution = 0
          this.check.temp.bnames = response.data.list[0].bnames
        } else {
          this.check.temp = {}
          this.check.temp.isDistribution = 1
        }
      })
    },

    handleTakeEffect() {
      if (this.selectList.length == 0) {
        this.$message({ type: 'error', message: '请选择车次信息', duration: 2000 })
      } else {
        MessageBox.confirm('当前选中' + this.selectList.length + '条信息，是否生效?', {
          confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
        }).then(() => {
          for (let i = 0; i < this.selectList.length; i++) {
            // this.$set(this.selectList[i], 'enable', '1')
            this.selectList[i].enable = 1
          }
          console.log('生效', this.selectList)
          this.requestParam.common = { 'returnmap': '0' }
          this.requestParam.data = []
          this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
          this.requestParam.data[0].children = []
          this.requestParam.data[0].children[0] = { 'name': 'updateRemainplanEnable', 'type': 'e', 'parammaps': {
            enable: '@insertSpotList.enable',
            id: '@insertSpotList.id',
            pastureid: '@insertSpotList.pastureid'
          }}
          ExecDataByConfig(this.requestParam).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()
            }
          })
        })
      }
    },
    handleDisable() {
      if (this.selectList.length == 0) {
        this.$message({ type: 'error', message: '请选择车次信息', duration: 2000 })
      } else {
        MessageBox.confirm('当前选中' + this.selectList.length + '条信息，是否禁用?', {
          confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
        }).then(() => {
          for (let i = 0; i < this.selectList.length; i++) {
            // this.$set(this.selectList[i], 'enable', '1')
            this.selectList[i].enable = 0
          }
          console.log('禁用', this.selectList)
          this.requestParam.common = { 'returnmap': '0' }
          this.requestParam.data = []
          this.requestParam.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.selectList }}
          this.requestParam.data[0].children = []
          this.requestParam.data[0].children[0] = { 'name': 'updateRemainplanEnable', 'type': 'e', 'parammaps': {
            enable: '@insertSpotList.enable',
            id: '@insertSpotList.id',
            pastureid: '@insertSpotList.pastureid'
          }}
          ExecDataByConfig(this.requestParam).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()
            }
          })
        })
      }
    },






    renderHeader(h, { column, $index }) { // h即为cerateElement的简写，具体可看vue官方文档
      return h(
        'div',
        [
          h('span', column.label),
          h('i', {
            class: 'el-icon-unlock',
            ref: 'el-icon-unlock',
            style: 'margin-left:5px;'
          })
        ]
      )
    },

    headerClick(column, event) {
      console.log(column, event)
      this.headerList.push(event)
      for (let i = 0; i < this.table.list.length; i++) {
          if (this.table.list[i].Edit == true) {
            if (event.target.outerHTML == '<i class="el-icon-unlock" style="margin-left: 5px;"></i>') {
              event.target.className = 'el-icon-lock'
              this.$set(this.table.list[i], 'isTwoWeight', true) // 锁住不可编辑
            } else if (event.target.outerHTML == '<i class="el-icon-lock" style="margin-left: 5px;"></i>') {
              event.target.className = 'el-icon-unlock'
              this.$set(this.table.list[i], 'isTwoWeight', false) // 解锁可编辑
            }
          }
        }
    },
 
 
 
     
    
   
    celldblclick(row, column, cell, event) {
      console.log(row, '=====')
      this.handleUpdate(row)
    },
    // 编辑
    handleUpdate(row) {
      console.log(row)
      this.oldRowList = {...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
        }
      }
      // 编辑true,不可编辑false
      row.Edit = true
      row.NoEdit = false
      // 编辑false,编辑保存true
      row.isUpdate = false
      row.isUpdateSave = true
      row.ftid = String(row.ftid)
      if (row.ptsfid == '-1') {
        row.ptsfid = ''
      }
      row.ptsfid = String(row.ptsfid)
      // dryweight
      this.table.temp.ftid = row.ftid
      this.table.temp.ftname = row.ftname
      this.table.temp.ptsfid = row.ptsfid
      this.table.temp.ptsfname = row.ptsfname
    },
    updateData(row) {
      
      var arr = []
      for (let i = 1; i <= this.table.RWLength; i++) {
        var obj = {}
        obj['times'] = i
        obj['pastureid'] = row.pastureid
        obj['barid'] = row.barid
        obj['cowcount'] = row.ccount
        obj['ccountradio'] = row.ccountradio
        obj['ptid'] = row.ftid
        if (row.ptsfid !== '') {
          obj['ptsid'] = row.ptsfid
        } else {
          obj['ptsid'] = '-1'
        }
        obj['weight'] = row['w' + i]
        if(row['bw' + i] == ""){
          obj['supplement'] = 0
        }else{
          obj['supplement'] = row['bw' + i]
        }
        obj['tratio'] = Math.round(row['r' + i])
        obj['todaysupplement'] = row.todaysupplement
        obj['todayweight'] = row.todayweight
        arr.push(obj)
      }
      if (this.table.isPtsfname == 0) {
        row.ptsfid = '-1'
        row.ptsfname = ''
      } else {
        if (row.ptsfid == '') {
          row.ptsfid = '-1'
          row.ptsfname = ''
        }
      }
      if (row.supplyweight == '') {
        row.supplyweight = '0'
      }
      if (this.table.isPtsfname == false) {
        row.supplyweight = '0'
      }
      console.log(row, '============')
      this.$set(row, 'ratio', Math.floor(parseFloat(row.ratio) * 100) / 100)
      this.$set(row, 'ccountratio', Math.floor(parseFloat(row.ccountratio) * 100) / 100)
      row.ccountratio = String(row.ccountratio)
      row.sumr = Math.round(row.sumr)
      // for(let i=0;i<arr.length;i++){
      //   if(arr[i].tratio == undefined ||arr[i].tratio =='' || arr[i].tratio == null){
      //     arr[i].tratio = 0
      //   }
      // }
      this.table.rwList = arr
      console.log('点击了编辑保存', row)
      this.table.temp.pastureid = row.pastureid
      this.table.temp.id = row.id
      this.table.temp.barname = row.barname
      this.table.temp.barid = row.barid
      this.table.temp.ccount = row.ccount
      this.table.temp.ratio = row.ratio
      this.table.temp.ccountratio = row.ccountratio
      this.table.temp.ftid = row.ftid
      this.table.temp.ftname = row.ftname
      this.table.temp.ptsfid = row.ptsfid
      this.table.temp.ptsfname = row.ptsfname
      this.table.temp.ftweight = row.ftweight
      this.table.temp.supplyweight = row.supplyweight
      this.table.temp.feedweight = row.feedweight
      this.table.temp.owner = row.owner
      this.table.temp.sumr = row.sumr
      
      console.log(row, '===========')
      this.table.temp.softccount = row.softccount
   

      var obj = {}
      obj.pastureid = row.pastureid
      obj.id = row.id
      obj.data = []
       
       
 
      if (this.table.temp.ccount === '') {
        this.$message({ type: 'error', message: '实际牛头数不能为空', duration: 2000 })
        return false
      }
     
      const positiveInteger = /^[0-9]\d*$/
      if (!positiveInteger.test(parseFloat(this.table.temp.ccount))) {
        this.$message({
          type: 'error',
          message: '实际牛头数请输入正整数',
          duration: 2000
        })
        return false
      }
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      // this.requestParam.parammaps = this.table.temp
      this.requestParam.common = {
        'returnmap': '0'
      }
      this.requestParam.data = []
      this.requestParam.data[0] = { 'name': 'updateBigFP', 'type': 'e', 'parammaps': {
        pastureid: row.pastureid,
        id: row.id,
        barname: row.barname,
        barid: row.barid,
        softccount: row.softccount,
        ccount: row.ccount,
        ratio: row.ratio,
        ccountratio: row.ccountratio,
        ftid: row.ftid,
        ftname: row.ftname,
        ptsfid: row.ptsfid,
        ptsfname: row.ptsfname,
        ftweight: row.ftweight,
        supplyweight: row.supplyweight,
        feedweight: row.feedweight,
        owner: row.owner,
        sumr: row.sumr
      }}
      this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.table.rwList }}
      this.requestParam.data[1].children = []
      this.requestParam.data[1].children[0] = { 'name': 'updateBigFPDetail', 'type': 'e', 'parammaps': {
        pastureid: '@insertSpotList.pastureid',
        barname: row.barname,
        barid: '@insertSpotList.barid',
        times: '@insertSpotList.times',
        tratio: '@insertSpotList.tratio',
        weight: '@insertSpotList.weight',
        cowcount: '@insertSpotList.cowcount',
        ccountradio: row.ccountratio,
        ptid: '@insertSpotList.ptid',
        ptsid: '@insertSpotList.ptsid',
        supplement: '@insertSpotList.supplement',
        feedweight: row.feedweight,
        supplyweight: row.supplyweight,
        ratio: row.ratio
      }}
      this.requestParam.data[2] = { 'name': 'updateLPPbyFPChange', 'type': 'e', 'parammaps': {
        pastureid: row.pastureid,
        fpid: row.id
      }}
      ExecDataByConfig(this.requestParam).then(response => {
        console.log('编辑保存发送参数', this.requestParam)
        if (response.msg === 'fail') {
          this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
        } else {
          if(obj.data.length>0){
            const url = 'authdata/fpdetail/edit'
            const data = obj
            postJson(url, data).then(response => {
              if(response.msg !== 'fail'){
                this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
              }
            })
          }else{
            this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
          }
          this.getList()
          for (let i = 0; i < this.headerList.length; i++) {
            if (this.headerList[i].target.className == 'el-icon-lock') {
              this.headerList[i].target.className = 'el-icon-unlock'
              this.$set(this.headerList[i].target, 'className', 'el-icon-unlock')
            }
          }
        }
      })
    },
    updateCancel(row) {
      console.log('点击了编辑取消')
      // 编辑false,不可编辑true
      row.Edit = false
      row.NoEdit = true
      // 编辑true,编辑保存false
      row.isUpdate = true
      row.isUpdateSave = false
      // this.reload()
      for (let i = 0; i < this.headerList.length; i++) {
        if (this.headerList[i].target.className == 'el-icon-lock') {
          this.headerList[i].target.className = 'el-icon-unlock'
          this.$set(this.headerList[i].target, 'className', 'el-icon-unlock')
        }
      }
      console.log(this.table.getdataListParm.offset)
      this.table.getdataListParm.offset = this.table.getdataListParm.offset
      this.getList()
      // this.$router.push('/formulationPlan/dhedFormula')
    },
    cellClick(row, column, event) {
      console.log(column)
    },
    handleSelect(val) {
      console.log('勾选数据', val)
      this.selectList = val
    },
    
    tableRowClassName({ row }) {
      // console.log(row)
      if (row.isColor == '0') {
        return 'red-row'
      } else {
        return ''
      }
    },
  
   
    
    // 删除
    handleRowDelete(row) {
      console.log('点击了行内删除')
      MessageBox.confirm('是否确认删除此信息?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.selectList = []
        this.requestParam.name = 'deleteDungsieve'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.pastureid = row.pastureid
        this.requestParam.parammaps.id = row.id
        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.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },
  
  
    // 应用
    handleApplication() {
      console.log('点击了应用')
      MessageBox.confirm('是否确认将' + this.history.getdataListParm.parammaps.date + '的数据应用到当前?', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam.name = 'applyFPdate'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.pastureid = Cookies.get('pastureid')
        this.requestParam.parammaps.date = this.history.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.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消应用' })
      })
    },
    
 
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
 
    blurBw(row) {
      console.log(row)
    },
    focusBw(row) {
      console.log(row)
    }
  }
}
</script>
<style lang="scss" scoped>
  .search {
    clear: both;
  }

  .table {
    margin-top: 10px;
  }
</style>
<style lang="scss">
  .red-row{
    background: #fde2e2 !important;
  }
</style>
