<template>
  <div class="app-container">
    <div class="search">
      <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime filter-item" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
      <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.getdataListParm.parammaps.feedid" filterable placeholder="饲料名称" class="filter-item" style="width: 150px;" clearable>
        <el-option v-for="item in feedNameList" :key="item.id" :label="item.fname" :value="item.id" />
      </el-select>
      <el-select v-model="table.getdataListParm.parammaps.providerid" placeholder="供应商" class="filter-item" style="width: 150px;" clearable>
        <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
      </el-select>
      <el-select v-model="table.getdataListParm.parammaps.islaid" placeholder="是否入库" class="filter-item" style="width: 150px;" clearable>
        <el-option v-for="item in islaidList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-button class="successBorder" @click="form_search">查询</el-button>
      <el-button class="successBorder" @click="handleRefresh">重置</el-button>
    </div>
    <div class="operation">
      <el-button v-if="isRoleEdit" class="success" icon="el-icon-plus" @click="handleCreate">新增入库单</el-button>
      <el-upload style="float: right;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImport" :on-success="handleImportSuccess">
        <el-button v-if="isRoleEdit" class="import" icon="el-icon-download" style="float: right;">导入</el-button>
      </el-upload>
      <el-dropdown style="float: right;margin-right: 10px;">
        <el-button class="export" icon="el-icon-upload2">导出</el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="handleExport(1)">导出模板</el-dropdown-item>
          <el-dropdown-item @click.native="handleExport(2)">导出数据</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
    <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="cellStyle"
        class="elTable table-fixed"
        :max-height="myHeight"
      >
        <el-table-column label="序号" align="center" type="index" width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入库日期" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.laiddate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="饲料名称" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.feedname }}</span>
          </template>
        </el-table-column>
        <el-table-column label="供应商" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.providername }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入库重量(kg)" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.operateweight }}</span>
          </template>
        </el-table-column>
        <el-table-column label="总价(元)" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sumprice }}</span>
          </template>
        </el-table-column>
        <el-table-column label="批号" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.pcpde }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.remark }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入库状态" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.islaid }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createemp }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建日期" min-width="90px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.createdate }}</span>
          </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 class="miniSuccess" icon="el-icon-search" @click="form_see(row)" />
            <el-button v-if="row.islaid == '否'" class="miniSuccess" icon="el-icon-edit-outline" @click="handleUpdate(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" :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" v-if='create.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[create.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-add">
        <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 100%;margin:0 auto">
          <el-row>
            <el-col :span="24">
              <h3 style="width: 160px;text-align: right;">基础信息</h3>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库日期:" prop="laiddate">
                <el-date-picker v-model="create.createTemp.laiddate" :disabled="create.dialogStatus=='see'" class="filter-item" type="date" placeholder="入库日期" :clearable="false" :picker-options="create.pickerOptions1" format="yyyy-MM-dd" value-format="yyyy-MM-dd" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="送货单编号:" prop="wagonnumber">
                <el-input ref="wagonnumber" v-model="create.createTemp.wagonnumber" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="送货单编号" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="饲料名称:" prop="feedname">
                <el-autocomplete
                  v-model="create.createTemp.feedname"
                  value-key="fname"
                  class="inline-input"
                  :fetch-suggestions="feedNameSearch"
                  placeholder="请选择饲料名称"
                  style="width:98%"
                  :disabled="create.dialogStatus=='see' || create.dialogStatus=='update'"
                  @select="handleSelectFeedName"
                  @blur="blurFeedName"
                >
                  <template slot-scope="{ item }">
                    <span>{{ item.fname }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库重量(kg):" prop="operateweight">
                <el-input ref="operateweight" v-model.trim="create.createTemp.operateweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurOperateweight" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供应商:" prop="providerid">
                <el-input v-if="create.dialogStatus=='see'" ref="providername" v-model.trim="create.createTemp.providername" disabled class="filter-item" placeholder="请选择供应商" />
                <el-select v-else v-model="create.createTemp.providerid" clearable placeholder="请选择供应商" :disabled="create.dialogStatus=='see'" class="filter-item" style="width: 100%" @change="changeSupplier">
                  <el-option v-for="item in supplierList" :key="item.id" :label="item.providerName" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="合同编号:" prop="contractcode">
                <el-select v-model="create.createTemp.contractcode" clearable placeholder="请选择合同编号" :disabled="create.dialogStatus=='see'" class="filter-item" style="width: 100%" @change="changeContractNo">
                  <el-option v-for="item in contractNoList" :key="item.id" :label="item.contractcodeCat" :value="item.contractcode" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <h3 style="width: 160px;text-align: right;">价格信息</h3>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="单价(元):" prop="pricenew">
                <el-input ref="pricenew" v-model="create.createTemp.pricenew" :disabled="create.createTemp.contractcode !=='' || create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurPricenew" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="总价(元):" prop="sumprice">
                <el-input ref="sumprice" v-model="create.createTemp.sumprice" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurSumprice" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <h3 style="width: 160px;text-align: right;">饲料信息</h3>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="毛重(kg):" prop="grossweight">
                <el-input ref="grossweight" v-model.trim="create.createTemp.grossweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurGrossweight" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="皮重(kg):" prop="tareweight">
                <el-input ref="tareweight" v-model.trim="create.createTemp.tareweight" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="最多两位小数" type="number" :step="0.01" @blur="blurTareweight" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="许可证号:" prop="licence">
                <el-input ref="licence" v-model="create.createTemp.licence" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="许可证号" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="批号:" prop="pcpde">
                <el-input ref="pcpde" v-model="create.createTemp.pcpde" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="批号" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <h3 style="width: 160px;text-align: right;">操作信息</h3>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="创建人:" prop="createemp">
                <el-input ref="createemp" v-model="create.createTemp.createemp" class="filter-item" placeholder="创建人" type="text" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建日期:" prop="createdate">
                <el-date-picker v-model="create.createTemp.createdate" class="filter-item" type="date" placeholder="创建日期" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="备注:" prop="remark">
                <el-input ref="remark" v-model="create.createTemp.remark" :disabled="create.dialogStatus=='see'" class="filter-item" placeholder="1-255字符" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button v-if="create.dialogStatus == 'see' " class="cancelClose cancelClose1" @click="create.dialogFormVisible = false;getList(); ">关闭</el-button>
          <el-button v-if="create.dialogStatus !== 'see' " class="cancelClose" @click="create.dialogFormVisible = false;getList(); ">关闭</el-button>
          <el-button v-if="create.dialogStatus !== 'see' " class="save" :disabled="isokDisable" @click="create.dialogStatus==='create'?createData():updateData()">确认</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 初始化库存 -->
    <el-dialog :fullscreen="dialogFull" :visible.sync="initial.dialogFormVisible" :close-on-click-modal="false" width="80%" height="55%">
      <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[initial.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-add" style="height: 100%;margin: 0 auto 60px;">
        <div class="operation">
          <el-button style="float: left;margin-bottom:10px;" class="success" @click="handleInitialExport">模板下载</el-button>
          <el-upload style="float: left;margin-left: 10px;margin-bottom:10px;" action="" :auto-upload="false" accept=".xlsx, .xls" :show-file-list="false" :on-change="handleInitialImport">
            <el-button class="success" icon="el-icon-download">导入</el-button>
          </el-upload>
        </div>
        <div class="table">
          <el-table
            :key="initial.tableKey"
            v-loading="initial.listLoading"
            element-loading-text="给我一点时间"
            :data="initial.list"
            border
            fit
            highlight-current-row
            style="width: 100%;"
            :row-style="rowStyle"
            :cell-style="cellStyle"
            class="elTable table-fixed"
          >
            <el-table-column label="序号" align="center" type="index" width="50px" />
            <el-table-column label="饲料名称" min-width="130px" align="center">
              <template slot-scope="scope">
                <span>{{ scope.row.fname }}</span>
              </template>
            </el-table-column>
            <el-table-column label="库存重量" min-width="130px" align="center">
              <template slot-scope="scope">
                <el-input v-model="scope.row.stockweight" placeholder="最多两位小数" type="number" :step="0.01" style="width:95%;padding:10px 0;" />
              </template>
            </el-table-column>
          </el-table>
          <div slot="footer" class="dialog-footer">
            <el-button class="cancelClose" @click="initial.dialogFormVisible = false; ">关闭</el-button>
            <el-button class="save" :disabled="isokDisable" @click="initialData()">确认</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { GetDataByName, GetDataByNames, checkButtons, ExecDataByConfig, failproccess, formatNum } from '@/api/common'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
import { json2excel, parseTime } from '@/utils/index.js'
import axios from 'axios'
import { getToken } from '@/utils/auth'
import xlsx from 'xlsx'
import { upload } from '@/utils/index.js'
export default {
  name: 'Warehousing',
  components: { Pagination },
  data() {
    return {
      dialogFull: false,
      feedNameList: [], // 饲料名称
      feedNameAddList: [], // 饲料名称新增
      supplierList: [], // 供应商
      contractNoList: [], // 合同编号
      islaidList: [ { id: 0, name: '未入库' },{ id: 1, name: '已入库' }], // 是否入库
      requestParams: [
        { name: 'getFeedListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }},
        { name: 'getProviderListEnable', offset: 0, pagecount: 0, parammaps: { pastureid: Cookies.get('pastureid') }}
      ],
      table: {
        getdataListParm: {
          name: 'getFeedlaidList',
          page: 1,
          offset: 1,
          pagecount: parseInt(Cookies.get('pageCount')),
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            inputDatetime: '',
            startTime: '',
            stopTime: '',
            feedid: '',
            islaid: '',
            providerid: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true
      },
      create: {
        dialogFormVisible: false,
        dialogStatus: '',
        pickerOptions1: {
          disabledDate(time) {
            return time.getTime() > Date.now()// 当天之前的时间可选
          }
        },
        createTemp: {
          laiddate: '', feedid: '', feedname: '', operateweight: '', providerid: '', providername: '', startweight: '', priceold: '', contractcode: '', pricenew: '', sumprice: '', grossweight: '', tareweight: '', licence: '', pcpde: '', createemp: '', createdate: '', remark: '', 'wagonnumber': ''
        },
        rules: {
          laiddate: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          operateweight: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }],
          feedname: [{ type: 'string', required: true, message: '必填', trigger: 'change' }],
          pricenew: [{ type: 'string', required: true, message: '必填', trigger: 'blur' }]
        },
        getdataListParm: {
          name: 'getBigContractListEnable',
          offset: 0,
          pagecount: '',
          parammaps: { pastureid: Cookies.get('pastureid') }
        },
        getfeedNameParm: {
          name: 'getFeedListEnableV2',
          offset: 0,
          pagecount: '',
          parammaps: { pastureid: Cookies.get('pastureid') }
        }
      },
      initial: {
        dialogFormVisible: false,
        dialogStatus: '',
        rules: {},
        getdataListParm: {
          name: 'getinitFeed',
          page: 1,
          offset: 1,
          pagecount: 6,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true,
        character: {
          fname: {
            text: '饲料名称',
            type: String
          },
          stockweight: {
            text: '库存重量',
            type: String
          }
        }
      },
      textMap: {
        create: '新增入库单',
        update: '编辑入库单',
        see: '查看入库单',
        initial: '初始化库存'
      },
      requestParam: {},
      download: {
        getdataListParm: {
          name: 'getFeedlaidList',
          page: 1,
          offset: 1,
          pagecount: 0,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            inputDatetime: '',
            startTime: '',
            stopTime: '',
            feedid: '',
            islaid: '',
            providerid: ''
          }
        },
        list: []
      },
      isokDisable: false,
      isRoleEdit: [],
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      myHeight:document.documentElement.clientHeight - 85- 150 - 45
    }
  },
  computed: {
    // 设置请求头
    headers() {
      return {
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'checkFeed,checkProviderRK,checkcontractcode,checkcontractcodePrice,insertFeedlaidUpload,insertFeedstorageLaidUpload',
        importParams: '入库日期,送货单编号,饲料名称,供应商,合同编号,入库重量（kg）,单价（元）,总价（元）,毛重(kg),皮重(kg),许可证号,批号,创建人,备注',
        sheetname: 'Sheet1',
        // 登录牧场
        pastureid: Cookies.get('pastureid'),
        // 日期参数
        dateParams: '入库日期',
        // 必填参数
        requiredParams: '入库日期,饲料名称,入库重量（kg）,单价（元）',
        // 为数值的参数
        numParams: '入库重量（kg）,单价（元）,总价（元）,毛重(kg),皮重(kg)'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  created() {
    this.getButtons()
    this.getDownList()
    this.getList()
  },

  methods: {

    getButtons() {
      const Edit = 'Warehousing'
      const isRoleEdit = checkButtons(JSON.parse(sessionStorage.getItem('buttons')), Edit)
      this.isRoleEdit = isRoleEdit
    },
    getDownList() {
      GetDataByNames(this.requestParams).then(response => {
        this.feedNameList = response.data.getFeedListEnable.list
        this.supplierList = response.data.getProviderListEnable.list
      })
    },
    handleBefore() {
      if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
        var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() - 1))
        var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() - 1))
        this.table.getdataListParm.parammaps.inputDatetime.length = 0
        this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
        this.$forceUpdate()
      }
    },
    handleNext() {
      if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
        var start = new Date(this.table.getdataListParm.parammaps.inputDatetime[0].setDate(this.table.getdataListParm.parammaps.inputDatetime[0].getDate() + 1))
        var stop = new Date(this.table.getdataListParm.parammaps.inputDatetime[1].setDate(this.table.getdataListParm.parammaps.inputDatetime[1].getDate() + 1))
        this.table.getdataListParm.parammaps.inputDatetime.length = 0
        this.table.getdataListParm.parammaps.inputDatetime.push(start, stop)
        this.$forceUpdate()
      }
    },
    getList() {
      this.table.listLoading = true
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.table.list = response.data.list
          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
        } else {
          this.table.list = []
        }
        this.table.total = response.data.total
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },
    form_search() {
      // console.log('点击了查询')
      if (this.table.getdataListParm.parammaps.inputDatetime !== '' && this.table.getdataListParm.parammaps.inputDatetime !== null) {
        this.table.getdataListParm.parammaps.startTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
        this.table.getdataListParm.parammaps.stopTime = parseTime(this.table.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
      } else {
        this.table.getdataListParm.parammaps.inputDatetime = ''
        this.table.getdataListParm.parammaps.startTime = ''
        this.table.getdataListParm.parammaps.stopTime = ''
      }
      this.table.getdataListParm.offset = 1
      this.getList()
    },
    handleRefresh() {
      console.log('点击了重置')
      this.table.getdataListParm.parammaps.inputDatetime = ''
      this.table.getdataListParm.parammaps.startTime = ''
      this.table.getdataListParm.parammaps.stopTime = ''
      this.table.getdataListParm.parammaps.feedid = ''
      this.table.getdataListParm.parammaps.islaid = ''
      this.table.getdataListParm.parammaps.providerid = ''
      this.table.getdataListParm.offset = 1
      this.getList()
    },

    resetCreateTemp() {
      this.create.createTemp = {
        pastureid: Cookies.get('pastureid'), laiddate: parseTime(new Date(), '{y}-{m}-{d}'), feedid: '', feedname: '', operateweight: '', providerid: '', providername: '', startweight: '', priceold: '', contractcode: '', pricenew: '', sumprice: '', grossweight: '', tareweight: '', licence: '', pcpde: '', createemp: Cookies.get('employename'), createdate: parseTime(new Date(), '{y}-{m}-{d}'), remark: '', 'wagonnumber': ''
      }
      this.contractNoList = []
    },
    // 供应商
    changeSupplier(item) {
      console.log(item)
      if (item !== '') {
        this.create.createTemp.providername = this.supplierList.find(obj => obj.id == item).providerName
      } else {
        this.create.createTemp.providername = ''
        this.create.createTemp.contractcode = ''
        this.create.createTemp.pricenew = ''
        this.create.createTemp.sumprice = ''
        this.contractNoList = []
      }
      if (this.create.createTemp.feedid !== '' && this.create.createTemp.providerid !== '') {
        this.getContractNoList()
      }
    },
    // 合同编号
    changeContractNo(item) {
      if (item !== '') {
        this.create.createTemp.pricenew = this.contractNoList.find(obj => obj.contractcode == item).price
      } else {
        this.create.createTemp.pricenew = ''
      }
      if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
        this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
        this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
      }
    },
    getContractNoList() {
      this.create.getdataListParm.parammaps.feedid = this.create.createTemp.feedid
      this.create.getdataListParm.parammaps.providerid = this.create.createTemp.providerid
      GetDataByName(this.create.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.contractNoList = response.data.list
          this.create.createTemp.contractcode = ''
          this.create.createTemp.pricenew = ''
          this.create.createTemp.sumprice = ''
        } else {
          this.contractNoList = []
          this.create.createTemp.contractcode = ''
          this.create.createTemp.pricenew = ''
          this.create.createTemp.sumprice = ''
        }
      })
    },
    feedNameSearch(queryString, cb) {
      this.create.getfeedNameParm.parammaps['fname'] = queryString
      GetDataByName(this.create.getfeedNameParm).then(response => {
        console.log('模糊查询搜索data', response.data.list)
        if (response.data.list == null) {
          cb([])
        } else {
          cb(response.data.list)
        }
      })
    },
    handleSelectFeedName(item) {
      console.log('模糊查询选中值', item)
      this.create.createTemp.feedname = item.fname
      this.create.createTemp.feedid = item.id
      this.create.createTemp.startweight = item.stockweight
      this.create.createTemp.priceold = item.price
      this.create.createTemp.providerid = ''
      this.create.createTemp.providername = ''
      this.create.createTemp.contractcode = ''
      this.create.createTemp.pricenew = ''
      this.create.createTemp.sumprice = ''
      if (this.create.createTemp.feedid !== '' && this.create.createTemp.providerid !== '') {
        this.getContractNoList()
      }
    },
    blurFeedName() {
      this.create.createTemp.feedname = ''
      this.create.createTemp.feedid = ''
      this.create.createTemp.startweight = ''
      this.create.createTemp.priceold = ''
      this.create.createTemp.providerid = ''
      this.create.createTemp.providername = ''
      this.create.createTemp.contractcode = ''
      this.create.createTemp.pricenew = ''
      this.create.createTemp.sumprice = ''
    },
    // 入库重量
    blurOperateweight() {
      // 毛重grossweight皮重tareweight入库重量operateweight
      if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
        this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.operateweight), 2)
      }
      if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
        if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
          this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
          this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
        }
      }
      if (this.create.createTemp.tareweight !== '' && this.create.createTemp.grossweight !== '') {
        if (this.create.createTemp.operateweight == '') {
          this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
        }
        if (parseFloat(this.create.createTemp.tareweight) > parseFloat(this.create.createTemp.grossweight)) {
          this.create.createTemp.tareweight = formatNum(this.create.createTemp.grossweight, 2)
          this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
        }
      }
      if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
        this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
        this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
      } else {
        this.create.createTemp.sumprice = ''
      }
    },
    // 毛重
    blurGrossweight() {
      // 毛重grossweight皮重tareweight入库重量operateweight
      if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
        this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.operateweight), 2)
      }

      if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
        if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
          this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
          this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
        }
      }
      if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
        this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
        this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
      } else {
        this.create.createTemp.sumprice = ''
      }
    },
    // 皮重
    blurTareweight() {
      // 毛重grossweight皮重tareweight入库重量operateweight
      if (this.create.createTemp.operateweight !== '' && this.create.createTemp.tareweight !== '') {
        this.create.createTemp.grossweight = formatNum(parseFloat(this.create.createTemp.tareweight) + parseFloat(this.create.createTemp.operateweight), 2)
      }
      if (this.create.createTemp.grossweight !== '' && this.create.createTemp.operateweight !== '') {
        if (parseFloat(this.create.createTemp.operateweight) > parseFloat(this.create.createTemp.grossweight)) {
          this.create.createTemp.grossweight = formatNum(this.create.createTemp.operateweight, 2)
          this.create.createTemp.tareweight = formatNum(parseFloat(this.create.createTemp.operateweight) - parseFloat(this.create.createTemp.operateweight), 2)
        }
      }
      if (this.create.createTemp.tareweight !== '' && this.create.createTemp.grossweight !== '') {
        if (parseFloat(this.create.createTemp.tareweight) > parseFloat(this.create.createTemp.grossweight)) {
          this.create.createTemp.tareweight = formatNum(this.create.createTemp.grossweight, 2)
          this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
        } else {
          this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.grossweight) - parseFloat(this.create.createTemp.tareweight), 2)
        }
      }
      if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
        this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
        this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
      } else {
        this.create.createTemp.sumprice = ''
      }
    },
    // 单价
    blurPricenew() {
      if (this.create.createTemp.operateweight !== '' && this.create.createTemp.pricenew !== '') {
        this.create.createTemp.sumprice = parseFloat(this.create.createTemp.operateweight) * parseFloat(this.create.createTemp.pricenew)
        this.create.createTemp.sumprice = formatNum(this.create.createTemp.sumprice, 2)
      } else {
        this.create.createTemp.sumprice = ''
      }
    },
    // 总价
    blurSumprice() {
      if (this.create.createTemp.sumprice !== '' && this.create.createTemp.pricenew !== '') {
        this.create.createTemp.operateweight = formatNum(parseFloat(this.create.createTemp.sumprice) / parseFloat(this.create.createTemp.pricenew), 2)
      } else {
        this.create.createTemp.operateweight = ''
      }
    },
    handleCreate() {
      console.log('点击了新增入库单')
      this.dialogFull = false
      this.create.dialogStatus = 'create'
      this.create.dialogFormVisible = true
      this.$nextTick(() => {
        this.resetCreateTemp()
        this.$refs.createTemp.resetFields()
      })
    },

   
    createData() {
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          if (this.create.createTemp.operateweight == '' && this.create.createTemp.grossweight == '') {
            this.$message({ type: 'error', message: '请输入入库重量或毛重', duration: 2000 })
            return false
          }
          if (this.create.createTemp.sumprice.length > 15) {
            this.$message({ type: 'error', message: '数值过大请重新输入', duration: 2000 })
          }
          const keepTwoNum = /^\d+(\.\d{1,2})?$/
          // 入库重量
          if (this.create.createTemp.operateweight !== '') {
            if (this.create.createTemp.operateweight == 0) {
              this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.operateweight))) {
                this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 单价
          if (this.create.createTemp.pricenew == 0) {
            this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
            return false
          } else {
            if (!keepTwoNum.test(parseFloat(this.create.createTemp.pricenew))) {
              this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
              return false
            }
          }
          // 总价
          if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
            if (this.create.createTemp.sumprice == 0) {
              this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.sumprice))) {
                this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 毛重
          if (this.create.createTemp.grossweight !== '') {
            if (this.create.createTemp.grossweight == 0) {
              this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.grossweight))) {
                this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 皮重
          if (this.create.createTemp.tareweight !== '') {
            if (this.create.createTemp.tareweight == 0) {
              this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.tareweight))) {
                this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }

          MessageBox.confirm('是否确认保存当前内容', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
          }).then(() => {
            this.isokDisable = true
            setTimeout(() => {
              this.isokDisable = false
            }, 1000)
            this.requestParam.common = { 'returnmap': '0' }
            this.requestParam.data = []
            this.requestParam.data[0] = { 'name': 'insertFeedlaid', 'type': 'e', 'parammaps': {
              'pastureid': this.create.createTemp.pastureid,
              'laiddate': this.create.createTemp.laiddate,
              'feedid': this.create.createTemp.feedid,
              'feedname': this.create.createTemp.feedname,
              'providerid': this.create.createTemp.providerid,
              'providername': this.create.createTemp.providername,
              'contractcode': this.create.createTemp.contractcode,
              'operateweight': this.create.createTemp.operateweight,
              'grossweight': this.create.createTemp.grossweight,
              'tareweight': this.create.createTemp.tareweight,
              'sumprice': this.create.createTemp.sumprice,
              'licence': this.create.createTemp.licence,
              'pcpde': this.create.createTemp.pcpde,
              'remark': this.create.createTemp.remark,
              'createdate': this.create.createTemp.createdate,
              'createemp': this.create.createTemp.createemp,
              'startweight': this.create.createTemp.startweight,
              'priceold': this.create.createTemp.priceold,
              'pricenew': this.create.createTemp.pricenew,
              'wagonnumber': this.create.createTemp.wagonnumber
            }}
            if (this.create.createTemp.operateweight !== '' && parseFloat(this.create.createTemp.operateweight) > 0) {
              this.requestParam.data[1] = { 'name': 'insertFeedstorageLaid', 'type': 'e', 'parammaps': {
                'operateweight': this.create.createTemp.operateweight,
                'pastureid': this.create.createTemp.pastureid,
                'feedid': this.create.createTemp.feedid,
                'fname': this.create.createTemp.fname,
                'pcpde': this.create.createTemp.pcpde,
                'stockweight': this.create.createTemp.startweight,
                'price': this.create.createTemp.pricenew
              }}
            }
            console.log('点击了新增入库单保存', this.requestParam)
            ExecDataByConfig(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.create.dialogFormVisible = false
                this.getList()
              }
            })
          })
        }
      })
    },
    handleUpdate(row) {
      console.log('点击了编辑')
      this.$nextTick(() => {
        this.$refs.createTemp.resetFields()
      })
      this.dialogFull = false
      this.create.dialogStatus = 'update'
      this.create.dialogFormVisible = true
      row.feedid = String(row.feedid)
      if (row.providerid == -1) {
        row.providerid = ''
        row.providername = ''
      }
      this.create.createTemp = Object.assign({}, row)
    },
    updateData() {
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          if (this.create.createTemp.operateweight == '' && this.create.createTemp.grossweight == '') {
            this.$message({ type: 'error', message: '请输入入库重量或毛重', duration: 2000 })
            return false
          }
          if (this.create.createTemp.sumprice.length > 15) {
            this.$message({ type: 'error', message: '数值过大请重新输入', duration: 2000 })
          }
          const keepTwoNum = /^\d+(\.\d{1,2})?$/
          // 入库重量
          if (this.create.createTemp.operateweight !== '') {
            if (this.create.createTemp.operateweight == 0) {
              this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.operateweight))) {
                this.$message({ type: 'error', message: '入库重量请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 单价
          if (this.create.createTemp.pricenew == 0) {
            this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
            return false
          } else {
            if (!keepTwoNum.test(parseFloat(this.create.createTemp.pricenew))) {
              this.$message({ type: 'error', message: '单价请输入自然数并保留两位小数', duration: 2000 })
              return false
            }
          }
          // 总价
          if (this.create.createTemp.pricenew !== '' && this.create.createTemp.operateweight !== '') {
            if (this.create.createTemp.sumprice == 0) {
              this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.sumprice))) {
                this.$message({ type: 'error', message: '总价请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 毛重
          if (this.create.createTemp.grossweight !== '') {
            if (this.create.createTemp.grossweight == 0) {
              this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.grossweight))) {
                this.$message({ type: 'error', message: '毛重请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          // 皮重
          if (this.create.createTemp.tareweight !== '') {
            if (this.create.createTemp.tareweight == 0) {
              this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
              return false
            } else {
              if (!keepTwoNum.test(parseFloat(this.create.createTemp.tareweight))) {
                this.$message({ type: 'error', message: '皮重请输入自然数并保留两位小数', duration: 2000 })
                return false
              }
            }
          }
          MessageBox.confirm('是否确认保存当前内容', { confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
          }).then(() => {
            this.isokDisable = true
            setTimeout(() => {
              this.isokDisable = false
            }, 1000)
            this.requestParam.common = { 'returnmap': '0' }
            this.requestParam.data = []
            this.requestParam.data[0] = { 'name': 'updateFeedlaid', 'type': 'e', 'parammaps': {
              'pastureid': this.create.createTemp.pastureid,
              'id': this.create.createTemp.id,
              'laiddate': this.create.createTemp.laiddate,
              'feedid': this.create.createTemp.feedid,
              'feedname': this.create.createTemp.feedname,
              'providerid': this.create.createTemp.providerid,
              'providername': this.create.createTemp.providername,
              'contractcode': this.create.createTemp.contractcode,
              'operateweight': this.create.createTemp.operateweight,
              'grossweight': this.create.createTemp.grossweight,
              'tareweight': this.create.createTemp.tareweight,
              'sumprice': this.create.createTemp.sumprice,
              'licence': this.create.createTemp.licence,
              'pcpde': this.create.createTemp.pcpde,
              'remark': this.create.createTemp.remark,
              'createdate': this.create.createTemp.createdate,
              'createemp': this.create.createTemp.createemp,
              'startweight': this.create.createTemp.startweight,
              'priceold': this.create.createTemp.priceold,
              'pricenew': this.create.createTemp.pricenew,
              'wagonnumber': this.create.createTemp.wagonnumber
            }}
            if (this.create.createTemp.operateweight !== '' && parseFloat(this.create.createTemp.operateweight) > 0) {
              this.requestParam.data[1] = { 'name': 'insertFeedstorageLaid', 'type': 'e', 'parammaps': {
                'operateweight': this.create.createTemp.operateweight,
                'pastureid': this.create.createTemp.pastureid,
                'feedid': this.create.createTemp.feedid,
                'fname': this.create.createTemp.fname,
                'pcpde': this.create.createTemp.pcpde,
                'stockweight': this.create.createTemp.startweight,
                'price': this.create.createTemp.pricenew
              }}
            }
            console.log('点击了新增入库单保存', this.requestParam)
            ExecDataByConfig(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.create.dialogFormVisible = false
                this.getList()
              }
            })
          })
        }
      })
    },
    form_see(row) {
      console.log('点击了查看')
      this.$nextTick(() => {
        this.$refs.createTemp.resetFields()
      })
      this.dialogFull = false
      this.create.dialogStatus = 'see'
      this.create.dialogFormVisible = true
      if (row.providerid == -1) {
        row.providerid = ''
        row.providername = ''
      }
      this.create.createTemp = Object.assign({}, row)
    },

    handleInitial() {
      console.log('点击了初始化库存')
      this.dialogFull = false
      this.initial.dialogStatus = 'initial'
      this.initial.dialogFormVisible = true
      this.getInitialList()
    },
    getInitialList() {
      this.initial.listLoading = true
      GetDataByName(this.initial.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.initial.list = response.data.list
          this.initial.pageNum = response.data.pageNum
          this.initial.pageSize = response.data.pageSize
          this.initial.total = response.data.total
        } else {
          this.initial.list = []
        }
        setTimeout(() => {
          this.initial.listLoading = false
        }, 100)
      })
    },
    handleInitialExport() {
      console.log('点击了初始化库存导出')

      const ExcelDatas = [
        {
          tHeader: ['饲料名称', '库存重量'],
          filterVal: ['fname', 'stockweight'],
          tableDatas: this.initial.list,
          sheetName: '初始化库存'
        }
      ]
      json2excel(ExcelDatas, '初始化库存', true, 'xlsx')
    },
    async handleInitialImport(eve) {
      const file = eve.raw
      if (!file) return
      let reader = await upload(file)
      const worker = xlsx.read(reader, { type: 'binary' })
      // 将返回的数据转换为json对象的数据
      reader = xlsx.utils.sheet_to_json(worker.Sheets[worker.SheetNames[0]])
      console.log(reader)
      const arr = []
      reader.forEach(item => {
        const obj = {}
        for (const key in this.initial.character) {
          if (!this.initial.character.hasOwnProperty(key)) break
          let v = this.initial.character[key]
          const text = v.text
          const type = v.type
          v = item[text] || ''
          type === 'string' ? (v = String(v)) : null
          type === 'number' ? (v = Number(v)) : null
          obj[key] = v
        }
        arr.push(obj)
      })
      console.log('导入处理后数据', arr)
      var sum = 0
      for (let i = 0; i < this.initial.list.length; i++) {
        for (let j = 0; j < arr.length; j++) {
          if (this.initial.list[i].fname == arr[j].fname) {
            this.initial.list[i].stockweight = arr[j].stockweight
            sum++
            arr.splice(j, 1)
          }
        }
      }
      console.log(arr)
      for (let i = 0; i < arr.length; i++) {
        this.$set(arr[i], 'msg', '饲料名称与系统不匹配')
      }
      console.log(sum)
      this.$message({ title: '成功', message: '导入成功:' + sum + '条!', type: 'success', duration: 2000 })
      this.$notify({ title: '失败', message: '导入失败:' + arr.length + '条!', type: 'danger', duration: 2000 })
      if (arr.length > 0) {
        const ExcelDatas1 = [
          {
            tHeader: ['饲料名称', '库存重量', '报错信息'],
            filterVal: ['fname', 'stockweight', 'msg'],
            tableDatas: arr,
            sheetName: 'ExcelDatas1'
          }
        ]
        json2excel(ExcelDatas1, '初始化库存报错信息', true, 'xlsx')
      }
    },
    initialData() {
      console.log('点击了初始化库存保存')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      var rulesStockweight = /^\d+(\.\d{1,2})?$/
      for (let i = 0; i < this.initial.list.length; i++) {
        if (!rulesStockweight.test(parseFloat(this.initial.list[i].stockweight))) {
          this.$message({ type: 'warning', message: '库存重量不可小于0，且保留俩位小数', duration: 2000 })
          return false
        }
      }
      this.requestParam.common = { 'returnmap': '0' }
      this.requestParam.data = []
      this.requestParam.data[0] = { 'name': 'clearFS', 'type': 'e', 'parammaps': {
        'pastureid': Cookies.get('pastureid')
      }}
      this.requestParam.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.initial.list }}
      this.requestParam.data[1].children = []
      this.requestParam.data[1].children[0] = { 'name': 'insertFeedstorage', 'type': 'e', 'parammaps': {
        pastureid: '@insertSpotList.pastureid',
        feedid: '@insertSpotList.feedid',
        fname: '@insertSpotList.fname',
        pcpde: '@insertSpotList.pcpde',
        stockweight: '@insertSpotList.stockweight',
        price: '@insertSpotList.price'
      }}
      ExecDataByConfig(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.create.dialogFormVisible = false
          this.getList()
        }
      })
    },
    // 导出
    handleExport(item) {
      if (item == 1) {
        console.log('点击了导出模板')
        const requestParam = this.requestParam
        const url = process.env.VUE_APP_BASE_API + 'file/导入导出模板/库存管理/入库导入模板.xlsx' // 请求下载文件的地址
        console.log(url)
        axios({
          method: 'GET',
          url: url,
          data: requestParam,
          headers: { token: getToken(), optname: 'insertcustomdoc' },
          responseType: 'blob'
        }).then(res => {
          if (!res) return
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
          const blob = new Blob([res.data], {
            type: 'application/octet-stream;charset=utf-8'
          })
          const url = window.URL.createObjectURL(blob)
          const aLink = document.createElement('a')
          aLink.style.display = 'none'
          aLink.href = url
          const docname = '入库管理导入模板.xlsx'
          aLink.setAttribute('download', docname) // 下载的文件
          document.body.appendChild(aLink)
          aLink.click()
          document.body.removeChild(aLink)
          window.URL.revokeObjectURL(url)
        })
      } else {
        console.log('点击了导出数据')
        this.download.getdataListParm.parammaps = this.table.getdataListParm.parammaps
        if (this.download.getdataListParm.parammaps.inputDatetime !== '' && this.download.getdataListParm.parammaps.inputDatetime !== null) {
          this.download.getdataListParm.parammaps.startTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[0], '{y}-{m}-{d}')
          this.download.getdataListParm.parammaps.stopTime = parseTime(this.download.getdataListParm.parammaps.inputDatetime[1], '{y}-{m}-{d}')
        } else {
          this.download.getdataListParm.parammaps.inputDatetime = ''
          this.download.getdataListParm.parammaps.startTime = ''
          this.download.getdataListParm.parammaps.stopTime = ''
        }
        GetDataByName(this.download.getdataListParm).then(response => {
          if (response.data.list !== null) {
            this.download.list = response.data.list
          } else {
            this.download.list = []
          }
          var excelDatas = [
            {
              tHeader: ['入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量（kg）', '单价（元）', '总价', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注'],
              filterVal: ['laiddate', 'wagonnumber', 'feedname', 'providername', 'contractcode', 'operateweight', 'pricenew', 'sumprice', 'grossweight', 'tareweight', 'licence', 'pcpde', 'createemp', 'createdate', 'remark'],
              tableDatas: this.download.list,
              sheetName: 'Sheet1'
            }
          ]
          json2excel(excelDatas, '入库管理', true, 'xlsx')
        })
      }
    },

    beforeImport(file) {
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 2MB!')
      }
      return isLt2M
    },
    handleImportSuccess(res, file) {
      this.getList()
      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 = [
               '入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量（kg）', '单价（元）', '总价（元）', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注', '错误信息'
             ]
             const filterVal = [
               '入库日期', '送货单编号', '饲料名称', '供应商', '合同编号', '入库重量（kg）', '单价（元）', '总价（元）', '毛重(kg)', '皮重(kg)', '许可证号', '批号', '创建人', '创建日期', '备注', '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]
          }
        })
      )
    }
  }
}
</script>
