<template>
  <div class="app-container" style="width: 90%;">
    <div class="el-icon-info" style="font-size: 30px;float: right;color: #009C69;" @click="handleDescription" />
    <el-form ref="createTemp" :rules="rules" :model="createTemp" label-position="right" label-width="270px" style="margin-top: 40px;margin-bottom:30px;">
      <el-row>
        <el-col :span="12">
          <el-form-item label="计划准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model.number="createTemp.remainOptRate" type="number" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="配方准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="牛群准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="车次准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="混料自动跳转准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="混料手动跳转准确率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="泌乳牛采食量平均值偏差预警值（kg）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="泌乳牛产奶量平均值偏差预警值（kg）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="撒料时间偏差预警值（min）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="超出平均混料时间预警值（min）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="超出平均转化率预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="超出平均公斤奶饲料成本（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="牛栏剩料率超出预警值（%）：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="库存预警天数：" prop="remainOptRate">
            <el-input ref="remainOptRate" v-model="createTemp.remainOptRate" :disabled="isRoleEdit==false" class="filter-item" placeholder="剩料分配占比原混料" type="text" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer" style="bottom: 10px;">
      <el-button v-if="isRoleEdit" class="save" :disabled="isokDisable" @click="handleSave">{{$t('formulationEvaluation.save')}}</el-button>
      <el-button v-if="isRoleEdit" class="warning" :disabled="isokDisable" @click="handleRecovery">恢复默认</el-button>
    </div>
    <el-dialog :title="textMap[description.dialogStatus]" :destroy-on-close="true" :visible.sync="description.dialogFormVisible" :close-on-click-modal="false" width="70%">
      <div class="app-description dialogMinHeight">
        <div class="content">
          1、计划准确率预警值：计划准确率低于此预警值则统计在统计报告中。
          <br>
          2、配方准确率预警值：配方准确率低于此预警值则统计在统计报告中。
          <br>
          3、牛群准确率预警值：牛群准确率低于此预警值则统计在统计报告中。
          <br>
          4、车次准确率预警值：车次准确率低于此预警值则统计在统计报告中。
          <br>
          5、混料自动跳转准确率预警值：混料自动跳转准确率低于此预警值则统计在统计报告中。
          <br>
          6、混料手动跳转准确率预警值：混料手动跳转准确率低于此预警值则统计在统计报告中。
          <br>
          7、泌乳牛采食量平均值偏差预警值：泌乳牛采食量平均值偏差高于此预警值则统计在统计报告中。
          <br>
          8、泌乳牛产奶量平均值偏差预警值：泌乳牛产奶量平均值偏差高于此预警值则统计在统计报告中。
          <br>
          9、撒料时间偏差预警值：撒料时间偏差高于此预警值则统计在统计报告中。
          <br>
          10、超出平均混料时间预警值：平均混料时间高于此预警值则统计在统计报告中。
          <br>
          11、超出平均转化率预警值：平均转换率高于此预警值则统计在统计报告中。
          <br>
          12、超出平均公斤奶饲料成本：平均公斤奶饲料成本高于此预警值则统计在统计报告中。
          <br>
          13、牛栏剩料率超出预警值：牛栏剩料率高于此预警值则统计在统计报告中。
          <br>
          14、库存预警天数：库存预警模块根据设置天数进行统计。限制正整数。
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelClose" @click="description.dialogFormVisible = false; ">{{$t('common.closed')}}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { GetDataByName, PostDataByName, GetDataByNames, failproccess, checkButtons, ExecDataByConfig } from '@/api/common'
import Cookies from 'js-cookie'
import { MessageBox } from 'element-ui'
export default {
  name: 'DefaultParameter',
  data() {
    return {
      isRoleEdit: [],
      planBeforeDayList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否可取前一天计划
      planNextDayList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否可取后一天计划
      isSupplementList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否启用补料
      isLeftoverMaterialList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否启用剩料
      decimalPlacesList: [{ id: '0', name: '整数' }, { id: '1', name: '一位小数' }, { id: '2', name: '两位小数' }, { id: '3', name: '三位小数' }], // 日计划报表小数点位数
      isLockBullsList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 启用饲料锁定牛头数
      disposalList: [], // 剩料处理选项
      waterConditioningList: [{ id: '0', name: '青贮' }, { id: '1', name: '总日粮饲喂量' }, { id: '2', name: '不处理' }], // 水分调节选项
      priceCalculationList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否启用库存管理
      numberList: [{ id: '0', name: '1' }, { id: '1', name: '2' }, { id: '2', name: '3' }, { id: '3', name: '4' }], // 班次数量
      feedontractList: [{ id: '1', name: '是' }, { id: '0', name: '否' }], // 是否启用饲料合同
      leftoverMaterialList: [{ id: '0', name: '顶额分配' }, { id: '1', name: '剩料分配' }],
      requestParams: [
        { name: 'getRemainFeedList', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
      ],
      getdataListParm: {
        name: 'getysoptList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureid: Cookies.get('pastureid')
        }
      },
      tableKey: 0,
      listLoading: true,
      createTemp: {},
      rules: {},
      isokDisable: false,
      description: {
        dialogFormVisible: false,
        dialogStatus: ''
      },
      textMap: {
        description: '参数说明'
      },
      requestParam: {}

    }
  },
  created() {
    this.getList()
    this.getButtons()
    this.getDownList()
  },

  methods: {

    getButtons() {
      const Edit = 'DefaultParameter'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit
    },
    getDownList() {
      GetDataByNames(this.requestParams).then(response => {
        this.disposalList = response.data.getRemainFeedList.list
      })
    },
    getList() {
      this.listLoading = true
      GetDataByName(this.getdataListParm).then(response => {
        console.log('table1数据', response.data.list)
        if (response.data.list !== null) {
          this.createTemp = response.data.list[0]
        } else {
          this.list = []
        }
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    handleSave() {
      console.log('点击了保存')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.requestParam.common = { 'returnmap': '0' }
      this.requestParam.data = []
      this.requestParam.data[0] = { 'name': 'updatesysopt', 'type': 'e', 'parammaps': {
        pastureid: this.createTemp.pastureid,
        isGetLastPlan: this.createTemp.isGetLastPlan,
        isGetNextPlan: this.createTemp.isGetNextPlan,
        isEnableSupplyFeed: this.createTemp.isEnableSupplyFeed,
        isEnableRemainFeed: this.createTemp.isEnableRemainFeed,
        reportDigit: this.createTemp.reportDigit,
        isLockCount: this.createTemp.isLockCount,
        remainOpt: this.createTemp.remainOpt,
        waterOpt: this.createTemp.waterOpt,
        overweightWarnRate: this.createTemp.overweightWarnRate,
        overweightBanRate: this.createTemp.overweightBanRate,
        repertoryWarn: this.createTemp.repertoryWarn,
        isfeedstorage: this.createTemp.isfeedstorage,
        times: this.createTemp.times,
        isEnableContract: this.createTemp.isEnableContract,
        remainOptDis: this.createTemp.remainOptDis,
        remainOptRate: this.createTemp.remainOptRate
      }}
      this.requestParam.data[1] = { 'name': 'updateFPbyFTChangeALL', 'type': 'e', 'parammaps': {
        pastureid: this.createTemp.pastureid
      }}

      ExecDataByConfig(this.requestParam).then(response => {
        console.log('保存发送参数', this.requestParam)
        if (response.msg !== 'fail') {
          this.$notify({ title: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), type: 'success', duration: 2000 })
          this.getList()
        } else {
          this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
        }
      })
    },
    handleRecovery() {
      console.log('点击了恢复默认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      MessageBox.confirm('是否确认恢复默认设置?', {
        confirmButtonText: this.$t('common.confirm'), confirmButtonText: this.$t('common.cancel'), type: 'warning'
      }).then(() => {
        this.requestParam.common = { 'returnmap': '0' }
        this.requestParam.data = []
        this.requestParam.data[0] = { 'name': 'updatesysoptinit', 'type': 'e', 'parammaps': {
          pastureid: this.createTemp.pastureid
        }}
        this.requestParam.data[1] = { 'name': 'updateFPbyFTChangeALL', 'type': 'e', 'parammaps': {
          pastureid: this.createTemp.pastureid
        }}

        ExecDataByConfig(this.requestParam).then(response => {
          console.log('保存发送参数', this.requestParam)
          if (response.msg !== 'fail') {
            this.$notify({ title: this.$t('common.succes'), message: this.$t('driver.saveSuccess'), type: 'success', duration: 2000 })
            this.getList()
          } else {
            this.$notify({ title: this.$t('driver.saveFail'), message: response.data, type: 'warning', duration: 2000 })
          }
        })
      })
    },
    handleDescription() {
      this.description.dialogStatus = 'description'
      this.description.dialogFormVisible = true
    }
  }
}
</script>
<style lang="scss" scoped>
  .app-description{
    display:flex; justify-content: center; align-items: center;font-size: 14px;line-height: 28px;
    .content{
      display:flex;
    }
  }
</style>
