<template>
  <div class="app-container">
    <div v-if="isPercentage" class="percentage" style="width: 210px;height: 90px;background: #fff;position: fixed;bottom: 0;left: 0;z-index: 9999999999999;">
      <h4 style="padding-left: 10px;line-height: 0;">导出进度：</h4>
      <el-progress style="padding-left: 10px;" :text-inside="true" :stroke-width="26" :percentage="percentage" />
    </div>
    <div class="filter-container">
      <el-select v-model="getdataListParm.parammaps.pastureName" placeholder="牧场" style="width: 140px;" class="filter-item" @change="changePastureName">
        <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.deptId" clearable placeholder="部门" class="filter-item" style="width:140px;">
        <el-option v-for="item in findAllDepart" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.feeType" placeholder="类型" style="width: 140px;" class="filter-item" clearable>
        <el-option v-for="item in getDictByName" :key="item.id" :label="item.label" :value="item.label" />
      </el-select>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
    </div>
    <div class="operation">
      <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
      <el-button v-waves class="filter-item" type="info" icon="el-icon-download" @click="handleDownloadTemp"> 模板 </el-button>
      <el-upload style="display: inline-block;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImportExcel" :on-success="handleImportExcelSuccess">
        <el-button v-waves class="filter-item" type="warning" icon="el-icon-upload2">导入</el-button>
      </el-upload>
      <el-button class="filter-item" style="margin-left: 10px;" type="success" icon="el-icon-edit" @click="handleDownload">导出</el-button>
    </div>
    <el-table
      :key="tableKey"
      v-loading="listLoading"
      element-loading-text="给我一点时间"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      :row-style="rowStyle"
      :cell-style="cellStyle"
      class="elTable"
      @sort-change="tableSort"
      :max-height="myHeight"
    >
      <el-table-column label="序号" align="center" type="index" width="50px">
        <template slot-scope="scope">
          <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="月份" prop="budgetMonth" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.budgetMonth }}</span>
        </template>
      </el-table-column>
      <el-table-column label="牧场" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.pastureName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="部门" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.deptName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="类型" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.feeType }}</span>
        </template>
      </el-table-column>
      <el-table-column label="预算" sortable="custom" prop="mymonthBudget" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.monthBudget }}</span>
        </template>
      </el-table-column>
      <el-table-column label="内控" sortable prop="mymonthLimit" min-width="150px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.monthLimit }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="230" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button type="primary" size="mini" @click="form_see(row)">查看</el-button>
          <el-button type="success" size="mini" @click="form_edit(row)">编辑</el-button>
          <el-button type="danger" size="mini" @click="form_delete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="get_table_data();tableSort()" />
    <!-- 弹出层新增or修改 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
      <el-form ref="createTemp" :rules="rules" :model="createTemp" label-position="right" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="牧场" prop="pastureId">
              <el-select v-model="createTemp.pastureId" placeholder="牧场" class="filter-item" style="width:100%" :disabled="dialogStatus==='see' || dialogStatus==='update'" @change="changePasture">
                <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="部门:" prop="deptId">
              <el-select v-model="createTemp.deptId" placeholder="部门" class="filter-item" style="width:100%" :disabled="dialogStatus==='see' || dialogStatus==='update'">
                <el-option v-for="item in createDepartList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="类型：" prop="feeType">
              <el-select v-model="createTemp.feeType" placeholder="类型" class="filter-item" style="width:100%" :disabled="dialogStatus==='see'||dialogStatus==='update'" @change="changeFeeType">
                <el-option v-for="item in getDictByName" :key="item.id" :label="item.label" :value="item.label" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="月份：" prop="budgetMonth">
              <div class="block">
                <el-date-picker v-model="createTemp.budgetMonth" type="month" placeholder="月份" format="yyyy-MM" value-format="yyyy-MM" style="width:100%" :disabled="dialogStatus==='see'||dialogStatus==='update'" />
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item prop="monthBudget">
              <span slot="label">{{ createTemp.unit }}</span>
              <el-input ref="monthBudget" v-model="createTemp.monthBudget" :disabled="dialogStatus==='see'" />
            </el-form-item>
          </el-col>
          <el-col :span="8" v-if="createTemp.feeType !== '饲养头数月预算'">
            <el-form-item prop="monthLimit">
              <span slot="label">{{ createTemp.unit2 }}</span>
              <el-input ref="monthLimit" v-model="createTemp.monthLimit" :disabled="dialogStatus==='see'" />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="8">
            <el-form-item label="饲养头日预算:" prop="cowSumBudgetMonth">
              <el-input ref="cowSumBudgetMonth" v-model="createTemp.cowSumBudgetMonth" :disabled="dialogStatus==='see'" />
            </el-form-item>
          </el-col>
        </el-row> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="dialogStatus==='create'" ref="createb" type="success" @click="add_dialog_save_again()">确认新增</el-button>
        <el-button v-if="dialogStatus==='create' || dialogStatus==='update'" type="primary" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">确认</el-button>
        <el-button @click="dialogFormVisible = false;get_table_data()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
require('script-loader!file-saver')
import { GetDataByName, GetDataByNames, PostDataByName, failproccess, GetAccount } from '@/api/common'
import waves from '@/directive/waves'
import { parseTime, sortChange, json2excel } from '@/utils/index.js'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import { MessageBox } from 'element-ui'
import { getToken } from '@/utils/auth'
import Cookies from 'js-cookie'
export default {
  name: 'Budget',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      myHeight:document.documentElement.clientHeight - 85- 200,
      // 校验规则
      rules: {
        pastureId: [{ required: true, message: '必填', trigger: 'blur' }],
        feeType: [{ required: true, message: '必填', trigger: 'blur' }],
        budgetMonth: [{ required: true, message: '必填', trigger: 'blur' }],
        deptId: [{ required: true, message: '必填', trigger: 'blur' }],

        monthBudget: [{ type: 'number', required: true, validator: (rule, value, callback) => {
          if (!value) {
            callback(new Error('不能为空'))
          }
          setTimeout(() => {
            const re = /(^[1-9](\d+)?(\.\d{1,3})?$)|(^\d\.\d{1,2}$)/
            const rsCheck = re.test(value)
            if (!rsCheck) {
              callback(new Error('请输入正数,且最多保留两位小数'))
            } else {
              callback()
            }
          }, 0)
        }, trigger: 'blur' }],
        // monthLimit: [{ type: 'number', required: true, validator: (rule, value, callback) => {
        //   if (!value) {
        //     callback(new Error('不能为空'))
        //   }
        //   setTimeout(() => {
        //     const re = /(^[1-9](\d+)?(\.\d{1,3})?$)|(^\d\.\d{1,2}$)/
        //     const rsCheck = re.test(value)
        //     if (!rsCheck) {
        //       callback(new Error('请输入正数,且最多保留两位小数'))
        //     } else {
        //       callback()
        //     }
        //   }, 0)
        // }, trigger: 'blur' }],
        cowSumBudgetMonth: [{ type: 'number', required: true, validator: (rule, value, callback) => {
          if (!value) {
            callback(new Error('不能为空'))
          }
          setTimeout(() => {
            const re = /^\d+$/
            const rsCheck = re.test(value)
            if (!rsCheck) {
              callback(new Error('请输入正数'))
            } else {
              callback()
            }
          }, 0)
        }, trigger: 'blur' }]
      },
      textMap: {
        update: '编辑',
        create: '新增',
        see: '查看详情'
      },
      edit: 0,
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      getDictByName: [],
      findAllPasture: [],
      findAllDepart: [],
      createDepartList: [],
      requestParams: [
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'getDictByName', offset: 0, pagecount: 0, params: ['其它成本'] }
        // { name: 'findAllDepart', offset: 0, pagecount: 0, params: [Cookies.get('pastureid')] }
      ],
      getDepartParam: {
        name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }
      },
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      getdataListParm: {
        name: 'getMonthbudgetlist',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureName: Cookies.get('pasturename'),
          feeType: '',
          deptId: ''
        }
      },
      dialogFormVisible: false,
      dialogStatus: '',
      createTemp: {
        pastureId: this.$store.state.user.pastureid,
        budgetMonth: '',
        feeType: '',
        monthBudget: '',
        monthLimit: '',
        cowSumBudgetMonth: '',
        deptId: '',
        unit: '预算：',
        unit2: '内控：'
      },
      requestParam: {},
      downloadParam: {},
      isPercentage: false,
      percentage: 1
    }
  },

  computed: {
    // 设置请求头
    headers() {
      return {
        // 设置token
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'uploadmonthbudget',
        importParams: '月份, 牧场,部门, 类型, 预算, 内控',
        sheetname: 'SheetJS'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      // process.env.VUE_APP_BASE_API是服务器的路径，也是axios的基本路径
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  created() {
    this.get_select_list()
  },

  methods: {
    tableSort(column) {
      sortChange(column, this.list)
    },
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.getDictByName = response.data.getDictByName.list
        this.findAllPasture = response.data.findAllPasture.list
        // this.findAllDepart = response.data.findAllDepart.list
        this.getDepartDownList()
        this.get_table_data()
      })
    },
    getDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.findAllDepart = response.data.list
      })
    },
    changePastureName(item) {
      this.getDepartParam.parammaps.pastureId = this.findAllPasture.find(obj => obj.name == item).id
      this.getdataListParm.parammaps.departName = ''
      this.getDepartDownList()
    },
    get_table_data() {
      this.listLoading = true
      GetDataByName(this.getdataListParm).then(response => {
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            console.log(this.getDictByName.find(obj => obj.label == response.data.list[i].feeType))
            if (this.getDictByName.find(obj => obj.label == response.data.list[i].feeType) !== undefined) {
              if (response.data.list[i].monthBudget !== undefined) {
                this.$set(response.data.list[i], 'mymonthBudget', parseFloat(response.data.list[i].monthBudget))
              }
              if (response.data.list[i].monthLimit !== undefined) {
                this.$set(response.data.list[i], 'mymonthLimit', parseFloat(response.data.list[i].monthLimit))
              }

              if (this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value !== '万元') {
                this.$set(response.data.list[i], 'monthBudget', response.data.list[i].monthBudget + '(' + this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value + ')')
              }

              this.$set(response.data.list[i], 'monthLimit', response.data.list[i].monthLimit + '(' + this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value + ')')
            } else {
              this.$set(response.data.list[i], 'mymonthBudget', parseFloat(response.data.list[i].monthBudget))
              this.$set(response.data.list[i], 'mymonthLimit', parseFloat(response.data.list[i].monthLimit))
              this.$set(response.data.list[i], 'monthBudget', response.data.list[i].monthBudget)
              this.$set(response.data.list[i], 'monthLimit', response.data.list[i].monthLimit)
            }
          }
          this.list = response.data.list
          this.pageNum = response.data.pageNum
          this.pageSize = response.data.pageSize
          if (response.data.total) {
            this.total = response.data.total
          }
        } else {
          this.list = []
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    form_search() {
      this.listLoading = true
      this.getdataListParm.offset = 1
      this.get_table_data()
    },
    resetCreateTemp() {
      this.createTemp.pastureId = this.$store.state.user.pastureid
      this.createTemp.budgetMonth = ''
      this.createTemp.feeType = ''
      this.createTemp.monthBudget = ''
      this.createTemp.monthLimit = ''
      this.createTemp.cowSumBudgetMonth = ''
      this.createTemp.deptId = ''
      this.createTemp.unit = '预算:'
      this.createTemp.unit2 = '内控:'
    },
    form_add() {
      this.resetCreateTemp()
      console.log(this.createTemp)
      this.edit = 1
      this.getDepartParam.parammaps.pastureId = this.createTemp.pastureId
      this.getCreateDepartDownList()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['createTemp'].clearValidate()
      })
    },
    changeFeeType(item) {
      this.createTemp.unit = '预算(' + this.getDictByName.find(obj => obj.label === item).value + '):'
      this.createTemp.unit2 = '内控(' + this.getDictByName.find(obj => obj.label === item).value + '):'
    },
    changePasture(item) {
      this.getDepartParam.parammaps.pastureId = item
      this.edit = 1
      this.getCreateDepartDownList()
    },
    add_dialog_save() {
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'insertMonthbudget'
          this.createTemp.cowSumBudgetMonth = parseInt(this.createTemp.cowSumBudgetMonth)
          if(this.createTemp.feeType == '饲养头数月预算'){
            this.createTemp.monthLimit = 0
          }
          if(this.createTemp.monthLimit == ''){
            this.createTemp.monthLimit = 0
          }
          this.requestParam.parammaps = this.createTemp
          PostDataByName(this.requestParam).then(response => {
            console.log('新增保存发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '新增成功',
                type: 'success',
                duration: 2000
              })
            } else {
              var pmonth = new RegExp('pmonth')
              if (pmonth.test(response.data)) {
                this.$notify({
                  title: '',
                  message: '该类型当前月份已存在',
                  type: 'warning',
                  duration: 2000
                })
              } else {
                failproccess(response, this.$notify)
              }
            }
          })
        }
      })
    },
    add_dialog_save_again() {
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'insertMonthbudget'
          this.createTemp.cowSumBudgetMonth = parseInt(this.createTemp.cowSumBudgetMonth)
          if(this.createTemp.feeType == '饲养头数月预算'){
            this.createTemp.monthLimit = 0
          }
          if(this.createTemp.monthLimit == ''){
            this.createTemp.monthLimit = 0
          }
          this.requestParam.parammaps = this.createTemp
          PostDataByName(this.requestParam).then(response => {
            console.log('新增保存发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              this.resetCreateTemp()
              this.$notify({ title: '成功', message: '新增成功', type: 'success', duration: 2000 })
            } else {
              var pmonth = new RegExp('pmonth')
              if (pmonth.test(response.data)) {
                this.$notify({ title: '', message: '该类型当前月份已存在', type: 'warning', duration: 2000 })
              } else {
                failproccess(response, this.$notify)
              }
            }
          })
        }
      })
    },
    form_edit(row) {
      this.edit = 0
      this.getDepartParam.parammaps.pastureId = row.pastureId
      this.getCreateDepartDownList()
      var unit = '预算(' + row.monthBudget.split('(')[1]
      var unit2 = '内控(' + row.monthLimit.split('(')[1]
      row.monthBudget = row.monthBudget.split('(')[0]
      row.monthLimit = row.monthLimit.split('(')[0]
      this.$set(row, 'unit', unit)
      this.$set(row, 'unit2', unit2)
      this.createTemp = Object.assign({}, row) // copy obj
      console.log(this.createTemp)

      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['createTemp'].clearValidate()
      })
    },
    edit_dialog_save() {
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'updateMonthbudget'
          this.createTemp.cowSumBudgetMonth = parseInt(this.createTemp.cowSumBudgetMonth)
          if(this.createTemp.feeType == '饲养头数月预算'){
            this.createTemp.monthLimit = 0
          }
          if(this.createTemp.monthLimit == ''){
            this.createTemp.monthLimit = 0
          }
          this.requestParam.parammaps = this.createTemp
          PostDataByName(this.requestParam).then(response => {
            console.log('新增保存发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
            } else {
              var pmonth = new RegExp('pmonth')
              if (pmonth.test(response.data)) {
                this.$notify({
                  title: '',
                  message: '该类型当前月份已存在',
                  type: 'warning',
                  duration: 2000
                })
              } else {
                failproccess(response, this.$notify)
              }
            }
          })
        }
      })
    },
    getCreateDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.createDepartList = response.data.list
      })
    },
    form_see(row) {
      var unit = '预算(' + row.monthBudget.split('(')[1]
      var unit2 = '内控(' + row.monthLimit.split('(')[1]
      row.monthBudget = row.monthBudget.split('(')[0]
      row.monthLimit = row.monthLimit.split('(')[0]
      this.$set(row, 'unit', unit)
      this.$set(row, 'unit2', unit2)
      this.createTemp = Object.assign({}, row)
      this.dialogStatus = 'see'
      this.dialogFormVisible = true
    },
    handleDownloadTemp() {
      this.requestParam.name = 'pStockDownTemp'
      GetDataByName(this.requestParam).then(response => {
        this.$nextTick(() => {
          import('@/vendor/Export2Excel').then(excel => {
            const list1 = response.data.list
            const tHeader = [
              '月份', '牧场', '部门', '类型', '预算', '内控'
            ]
            const filterVal = [
              '月份', '牧场', '部门', '类型', '预算', '内控'
            ]
            const data1 = this.formatJson(filterVal, list1)
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: '月预算模板',
              autoWidth: true,
              bookType: 'xlsx'
            })
          })
        })
      })
    },
    beforeImportExcel(file) {
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 10MB!')
      }
      return isLt2M
    },
    handleImportExcelSuccess(res, file) {
      this.get_table_data()
      if (res.msg === 'ok') {
        this.$message({
          title: '成功',
          message: '导入成功:' + res.data.success + '条!',
          type: 'success',
          duration: 2000
        })
        if (res.data.err_count > 0) {
          this.$notify({
            title: '失败',
            message: '导入失败:' + res.data.err_count + '条!',
            type: 'danger',
            duration: 2000
          })
           import('@/vendor/Export2Excel').then(excel => {
             const list1 = res.data.result
             const tHeader = ['月份', '牧场', '部门', '类型', '预算', '内控', '报错信息']
             const filterVal = ['月份', '牧场', '部门', '类型', '预算', '内控', 'error_msg']
             const data1 = this.formatJson(filterVal, list1)
             excel.export_json_to_excel({
               header: tHeader,
               data: data1,
               filename: '月预算报错信息',
               autoWidth: true,
               bookType: 'xlsx'
             })
           })
        }
      } else {
        this.$notify({
          title: '失败',
          message: '上传失败,文件格式错误',
          type: 'danger',
          duration: 2000
        })
      }
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    handleDownload() {
      console.log('点击了导出')
      this.$alert('月预算正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      this.isPercentage = true
      this.percentage = 1
      var timer = setInterval(() => {
        this.percentage += 5
        if (this.percentage > 95) {
          this.percentage = 99
          clearInterval(timer)
        }
        this.percentage = this.percentage
      }, 1000)
      this.downloadParam.name = 'getMonthbudgetlist'
      this.downloadParam.parammaps = this.getdataListParm.parammaps
      GetAccount(this.downloadParam).then(response => {
        if (response.data.list !== '') {
          for (let i = 0; i < response.data.list.length; i++) {
            if (this.getDictByName.find(obj => obj.label == response.data.list[i].feeType) == undefined) {
              this.$set(response.data.list[i], 'monthBudget', response.data.list[i].monthBudget)
              this.$set(response.data.list[i], 'monthLimit', response.data.list[i].monthLimit)
            } else {

              if (this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value !== '万元') {
                this.$set(response.data.list[i], 'monthBudget', response.data.list[i].monthBudget + '(' + this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value + ')')
              }


              this.$set(response.data.list[i], 'monthLimit', response.data.list[i].monthLimit + '(' + this.getDictByName.find(obj => obj.label == response.data.list[i].feeType).value + ')')
            }
          }
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        this.$nextTick(() => {
          const ExcelDatas = [
            {
              tHeader: ['月份', '牧场', '部门', '类型', '预算', '内控'],
              filterVal: ['budgetMonth', 'pastureName', 'deptName', 'feeType', 'monthBudget', 'monthLimit'],
              tableDatas: response.data.list,
              sheetName: '月预算'
            }
          ]
          json2excel(ExcelDatas, '月预算', true, 'xlsx')
        })
      })
    },
    form_delete(row) {
      MessageBox.confirm('是否删除此条信息?', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.requestParam.name = 'deleteMonthbudget'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps['id'] = row.id
          PostDataByName(this.requestParam).then(() => {
            this.get_table_data()
            this.dialogFormVisible = false
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    }
  }
}
</script>
<style lang="scss" scoped>
  .operation{margin-bottom: 10px;}
</style>
