<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:120px" class="filter-item">
        <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-input v-model="getdataListParm.parammaps.partCode" placeholder="备件编号" style="width: 160px;" class="filter-item" />
      <el-input v-model="getdataListParm.parammaps.partName" placeholder="备件名称" style="width: 140px;" class="filter-item" />
      <el-input v-model="getdataListParm.parammaps.specification" placeholder="规格" style="width: 140px;" class="filter-item" />
      <el-autocomplete v-model="getdataListParm.parammaps.providerName" value-key="providerName" class="inline-input" :fetch-suggestions="providerSearch" placeholder="供应商" style="width:150px;top:-3px;" @select="handleSelectProvider" />
      <el-autocomplete v-model="getdataListParm.parammaps.brandName" value-key="brandName" class="inline-input" :fetch-suggestions="brandSearch" placeholder="品牌" style="width:150px;top:-3px;" @select="handleSelectBrand" />
      <el-input v-model="getdataListParm.parammaps.location" placeholder="库位" style="width: 160px;" class="filter-item" />
      <el-input v-model="getdataListParm.parammaps.contractCode" placeholder="合同编号" style="width: 140px;" class="filter-item" />
      <el-select v-model="getdataListParm.parammaps.statue" clearable placeholder="合同状态" class="filter-item" style="width: 120px;">
        <el-option v-for="item in statues" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.isZeroStock" clearable placeholder="零库存" class="filter-item" style="width: 120px;">
        <el-option v-for="item in isZeroStocks" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.warnings" clearable placeholder="预警信息" class="filter-item" style="width: 120px;">
        <el-option v-for="item in warnings" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.reportery" placeholder="全部库存" class="filter-item" style="width: 120px;">
        <el-option v-for="item in customList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <tree-select
        class="typeSelect"
        :height="150"
        :width="250"
        size="small"
        clearable
        :data="parentDept"
        :disabled="false"
        :placeholder="placeholder"
        style="display:inline-block;"
        :default-props="defaultProps"
        :node-key="nodeKey"
        :checked-keys="defaultCheckedKeys"
        @popoverHide="popoverHide"
      />
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
      <div>
        <el-button v-if="isCustomTemplate" v-waves class="filter-item" type="info" icon="el-icon-tickets" @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-if="isCustomImport" v-waves class="filter-item" type="warning" icon="el-icon-download" @click="form_searchClear">导入</el-button>
        </el-upload>
        <el-button v-if="isCustomExport" v-waves class="filter-item" type="success" icon="el-icon-upload2" @click="handleDownload">导出</el-button>
      </div>
    </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"
      :cell-class-name="tableCellClassName"
      @cell-click="cellClick"
      @sort-change="tableSort1"
    >
      <!-- table表格 -->
      <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 label="供应商" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.providerName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备件编号" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.partCode }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备件名称" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.partName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备件规格" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.specification }}</span>
        </template>
      </el-table-column>
      <el-table-column label="计量单位" min-width="90px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.unit }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品牌" min-width="60px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.brand }}</span>
        </template>
      </el-table-column>
      <el-table-column label="单价" sortable prop="price" min-width="60px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.price }}</span>
        </template>
      </el-table-column>
      <el-table-column label="当前库存" sortable prop="reportery" min-width="100px" align="center">
        <template slot-scope="{row}">
          <span v-if="row.minRepertory !== '' && parseFloat(row.reportery) < parseFloat(row.minRepertory)" style="background:red;display:block;line-height: 45px;color:#fff;">{{ row.reportery }}</span>
          <span v-else-if="row.maxRepertory !== '' && parseFloat(row.reportery) > parseFloat(row.maxRepertory)" style="background:green;display:block;line-height: 45px;color:#fff;">{{ row.reportery }}</span>
          <span v-else>{{ row.reportery }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最高库存" sortable prop="maxRepertory" min-width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.maxRepertory }}</span>
        </template>
      </el-table-column>
      <el-table-column label="最低库存" sortable prop="minRepertory" min-width="100px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.minRepertory }}</span>
        </template>
      </el-table-column>
      <el-table-column label="库位" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.location }}</span>
        </template>
      </el-table-column>
      <el-table-column label="牧场" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.pastureName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同编号" min-width="130px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.contractCode }}</span>
        </template>
      </el-table-column>
      <el-table-column label="零库存" min-width="110px" align="center" :formatter="isZeroStock" />
      <el-table-column label="合同状态" min-width="110px" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.statue }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200px" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button v-if="isCustomSee" type="primary" size="mini" @click="form_see(row)">查看</el-button>
          <el-button type="success" style="width:70px" size="mini" @click="handleChange(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="getList" />
    <!-- 卡片 -->
    <el-dialog :title="textMap[dialogStatusCard]" :visible.sync="dialogFormVisibleCard" :close-on-click-modal="false" style="width:100%;">
      <div class="app-contentcard" style="width:90%;margin:0 auto">
        <div class="card">
          <el-tabs v-model="activeName">
            <el-tab-pane label="基础信息" name="first">
              <el-form
                ref="seeTemp"
                :rules="rules"
                :model="seeTemp"
                label-position="right"
                label-width="95px"
              >
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="备件编号:" prop="partCode">
                      <span>{{ seeTemp.partCode }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="备件名称:" prop="partName">
                      <span>{{ seeTemp.partName }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="备件规格：" prop="specification">
                      <span>{{ seeTemp.specification }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="供应商：" prop="providerName">
                      <span>{{ seeTemp.providerName }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="品牌：" prop="brand">
                      <span>{{ seeTemp.brand }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="计量单位：" prop="providerId">
                      <span>{{ seeTemp.unit }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="单价：" prop="providerId">
                      <span>{{ seeTemp.price }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="牧场：" prop="pastureName">
                      <span>{{ seeTemp.pastureName }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="当前库存：" prop="reportery">
                      <span>{{ seeTemp.reportery }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="最高库存：" prop="maxRepertory">
                      <span>{{ seeTemp.maxRepertory }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="最低库存：" prop="minRepertory">
                      <span>{{ seeTemp.minRepertory }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="库位：" prop="location">
                      <span>{{ seeTemp.location }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="7">
                    <el-form-item label="合同编号：" prop="partCode">
                      <span>{{ seeTemp.contractCode }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="合同状态：" prop="statue">
                      <span>{{ seeTemp.statue }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="5">
                    <el-form-item label="零库存：" prop="isZeroStock">
                      <span>{{ seeTemp.isZeroStock }}</span>
                    </el-form-item>
                  </el-col>
                  <el-col :span="7">
                    <el-form-item label="备注：" prop="note">
                      <span>{{ seeTemp.note }}</span>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-form>
            </el-tab-pane>
            <el-tab-pane label="入库记录" name="second">
              <div class="filter-container">
                <el-input v-model="getdataListParmStorage.parammaps.laidCode" placeholder="入库单号" style="width: 140px;" class="filter-item" />
                <el-date-picker ref="inputDatetime" v-model="getdataListParmStorage.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchStorage">搜索</el-button>
              </div>
              <el-table
                :key="tableKey"
                v-loading="listLoadingStorage"
                element-loading-text="给我一点时间"
                :data="listStorage"
                border
                fit
                highlight-current-row
                style="width: 100%;"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable"
                :cell-class-name="tableCellClassName"
                @cell-click="cellClick"
                @sort-change="tableSort2"
              >
                <el-table-column label="序号" width="100px" align="center" type="index">
                  <template slot-scope="scope">
                    <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="入库单号" prop="laidCode" min-width="110px" align="center" />
                <el-table-column sortable label="入库日期" prop="createTime" min-width="60px" align="center" />
                <el-table-column label="入库数量" sortable prop="storageAmount" min-width="60px" align="center" />
                <el-table-column label="单价" sortable prop="price" min-width="60px" align="center" />
                <el-table-column label="总价" sortable prop="sumPrice" min-width="60px" align="center" />
              </el-table>
              <pagination v-show="total>0" :total="totalStorage" :page.sync="getdataListParmStorage.offset" :limit.sync="getdataListParmStorage.pagecount" @pagination="getCardStorage" />
            </el-tab-pane>
            <el-tab-pane label="出库记录" name="third">
              <div class="filter-container">
                <el-input v-model="getdataListParmDelivery.parammaps.useForm" placeholder="出库单号" style="width: 140px;" class="filter-item" />
                <el-select v-model="getdataListParmDelivery.parammaps.departmentId" clearable placeholder="领用部门" class="filter-item" style="width: 120px;">
                  <el-option v-for="item in findAllDepart" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
                <el-input v-model="getdataListParmDelivery.parammaps.eqCode" placeholder="关联设备编号" style="width: 140px;" class="filter-item" />
                <el-input v-model="getdataListParmDelivery.parammaps.eqName" placeholder="关联设备名称" style="width: 140px;" class="filter-item" />
                <el-date-picker ref="inputDatetime2" v-model="getdataListParmDelivery.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchDelivery">搜索</el-button>
              </div>
              <el-table
                :key="tableKey"
                v-loading="listLoadingDelivery"
                element-loading-text="给我一点时间"
                :data="listDelivery"
                border
                fit
                highlight-current-row
                style="width: 100%;"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable"
                :cell-class-name="tableCellClassName"
                @cell-click="cellClick"
                @sort-change="tableSort2"
              >
                <el-table-column label="序号" width="100px" align="center" type="index">
                  <template slot-scope="scope">
                    <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="出库单号" prop="useForm" min-width="60px" align="center" />
                <el-table-column label="出库日期" sortable prop="createTime" min-width="60px" align="center" />
                <el-table-column label="领用部门" prop="departmentName" min-width="60px" align="center" />
                <el-table-column label="关联设备编号" prop="eqCode" min-width="60px" align="center" />
                <el-table-column label="关联设备名称" prop="eqName" min-width="60px" align="center" />
                <el-table-column label="出库数量" sortable prop="checkoutNumber" min-width="60px" align="center" />
                <el-table-column label="单价" sortable prop="price" min-width="60px" align="center" />
                <el-table-column label="总价" sortable prop="sumPrice" min-width="60px" align="center" />
              </el-table>
              <pagination v-show="total>0" :total="totalDelivery" :page.sync="getdataListParmDelivery.offset" :limit.sync="getdataListParmDelivery.pagecount" @pagination="getCardDelivery" />
            </el-tab-pane>
            <el-tab-pane label="退库记录" name="fouth">
              <div class="filter-container">
                <el-input v-model="getdataListParmCancelling.parammaps.useForm" placeholder="退库单号" style="width: 140px;" class="filter-item" />
                <el-date-picker ref="inputDatetime3" v-model="getdataListParmCancelling.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchCancelling">搜索</el-button>
              </div>
              <el-table
                :key="tableKey"
                v-loading="listLoadingCancelling"
                element-loading-text="给我一点时间"
                :data="listCancelling"
                border
                fit
                highlight-current-row
                style="width: 100%;"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable"
                :cell-class-name="tableCellClassName"
                @cell-click="cellClick"
                @sort-change="tableSort2"
              >
                <el-table-column label="序号" width="100px" align="center" type="index">
                  <template slot-scope="scope">
                    <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="退库单号" prop="useForm" min-width="60px" align="center" />
                <el-table-column label="退库日期" sortable prop="createTime" min-width="60px" align="center" />
                <el-table-column label="退库人" prop="empname" min-width="60px" align="center" />
                <el-table-column label="退库数量" sortable prop="quitNumber" min-width="60px" align="center" />
                <el-table-column label="单价" sortable prop="price" min-width="60px" align="center" />
                <el-table-column label="总价" sortable prop="sumPrice" min-width="60px" align="center" />
                <el-table-column label="退库原因" prop="note" min-width="60px" align="center" />
              </el-table>
              <pagination v-show="total>0" :total="totalCancelling" :page.sync="getdataListParmCancelling.offset" :limit.sync="getdataListParmCancelling.pagecount" @pagination="getCardCancelling" />
            </el-tab-pane>
            <el-tab-pane label="退货记录" name="fifth">
              <div class="filter-container">
                <el-input v-model="getdataListParmRefund.parammaps.useForm" placeholder="退货单号" style="width: 140px;" class="filter-item" />
                <el-date-picker ref="inputDatetime4" v-model="getdataListParmRefund.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchRefund">搜索</el-button>
              </div>
              <el-table
                :key="tableKey"
                v-loading="listLoadingRefund"
                element-loading-text="给我一点时间"
                :data="listRefund"
                border
                fit
                highlight-current-row
                style="width: 100%;"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable"
                :cell-class-name="tableCellClassName"
                @cell-click="cellClick"
                @sort-change="tableSort2"
              >
                <el-table-column label="序号" width="100px" align="center" type="index">
                  <template slot-scope="scope">
                    <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="退货单号" prop="useForm" min-width="60px" align="center" />
                <el-table-column label="退货日期" sortable prop="createTime" min-width="60px" align="center" />
                <el-table-column label="退货人" prop="empname" min-width="60px" align="center" />
                <el-table-column label="退货数量" sortable prop="refundNumber" min-width="60px" align="center" />
                <el-table-column label="单价" sortable prop="price" min-width="60px" align="center" />
                <el-table-column label="总价" sortable prop="sumPrice" min-width="60px" align="center" />
                <el-table-column label="退货原因" sortable prop="note" min-width="60px" align="center" />
              </el-table>
              <pagination v-show="total>0" :total="totalRefund" :page.sync="getdataListParmRefund.offset" :limit.sync="getdataListParmRefund.pagecount" @pagination="getCardRefund" />
            </el-tab-pane>
            <el-tab-pane label="盘点记录" name="sixth">
              <div class="filter-container">
                <el-input v-model="getdataListParmRecord.parammaps.oddCode" placeholder="盘点单号" style="width: 140px;" class="filter-item" />
                <el-date-picker ref="inputDatetime5" v-model="getdataListParmRecord.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
                <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_searchRecord">搜索</el-button>
              </div>
              <el-table
                :key="tableKey"
                v-loading="listLoadingRecord"
                element-loading-text="给我一点时间"
                :data="listRecord"
                border
                fit
                highlight-current-row
                style="width: 100%;"
                :row-style="rowStyle"
                :cell-style="cellStyle"
                class="elTable"
                :cell-class-name="tableCellClassName"
                @cell-click="cellClick"
                @sort-change="tableSort2"
              >
                <el-table-column label="序号" width="100px" align="center" type="index">
                  <template slot-scope="scope">
                    <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
                  </template>
                </el-table-column>
                <el-table-column label="盘点单号" prop="oddCode" min-width="60px" align="center" />
                <el-table-column label="盘点日期" sortable prop="createTime" min-width="60px" align="center" />
                <el-table-column label="盘点人" prop="empname" min-width="60px" align="center" />
                <el-table-column label="盘点数量" sortable prop="checkAmount" min-width="60px" align="center" />
                <el-table-column label="差值" sortable prop="repertory" min-width="60px" align="center" />
              </el-table>
              <pagination v-show="total>0" :total="totalRefund" :page.sync="getdataListParmRecord.offset" :limit.sync="getdataListParmRecord.pagecount" @pagination="getCardRecord" />
            </el-tab-pane>
          </el-tabs>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;bottom:10px">
        <el-button @click="dialogFormVisibleCard = false">关闭</el-button>
      </div>
    </el-dialog>
    <!-- 库位变更 -->
    <el-dialog :title="textMap[dialogStatus_change]" :visible.sync="dialogFormVisible_change" :close-on-click-modal="false" style="width:80%;margin:0 auto;">
      <div class="app-change">
        <el-form ref="changeTemp" :rules="rules" :model="changeTemp" label-position="right" label-width="95px">
          <el-row>
            <el-col :span="14">
              <el-form-item label="当前库位:" prop="location">
                <span>{{ changeTemp.location }}</span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="14">
              <el-form-item label="变更库位:" prop="warehoseCode">
                <el-autocomplete
                  v-model="changeTemp.warehoseCode"
                  value-key="warehoseCode"
                  class="inline-input"
                  :fetch-suggestions="getWarehoseCode"
                  placeholder="请输入库位"
                  style="width:100%"
                  @focus="handleFocusWarehoseCode"
                  @blur="handleBlurWarehoseCode"
                  @select="handleSelectWarehoseCode"
                />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" :disabled="isokDisable" @click="changeData()">保存并关闭</el-button>
          <el-button @click="dialogFormVisible_change = false;getList();">取消并关闭</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 错误提示 -->
    <el-dialog :title="textMap[dialogStatusErro]" :visible.sync="dialogFormVisibleErro" :close-on-click-modal="false">
      <div class="app-erro">
        <el-table
          :key="tableKey"
          v-loading="listLoadingErro"
          element-loading-text="给我一点时间"
          :data="listErro"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
        >
          <!-- table表格 -->
          <el-table-column label="序号" align="center" type="index" min-width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="错误信息" min-width="110px" align="center">
            <template slot-scope="scope">
              <span><b>错误行：</b>{{ scope.row.input }}</span><br><span><b>错误信息：</b>{{ scope.row.error_msg }}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>

  </div>
</template>

<script>
// 引入
import { GetDataByName, GetDataByNames, PostDataByName, checkButtons, getRecuData, failproccess, transData, GetAccount } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import { parseTime, sortChange } from '@/utils/index.js'
// eslint-disable-next-line no-unused-vars
import { validateEMail } from '@/utils/validate.js'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import TreeSelect from '@/components/TreeSelect'
import Cookies from 'js-cookie'
import { getToken } from '@/utils/auth'
export default {
  name: 'Custom',
  components: { Pagination, TreeSelect },
  directives: { waves },
  data() {
    return {
      disabled: true,
      activeName: 'first',
      color: '#409EFF',
      // 新增
      // 导入
      // 卡片
      tableKey: 0,

      total: 0,
      listLoading: true,
      listLoadingErro: true,
      listErro: [],
      getRecuListParm: {
        name: 'getStockTypeList',
        idname: 'id',
        params: [-1]
      },
      temp: {
        categoryId: '',
        stockNumber: '',
        categoryName: '',
        assTypeId: '',
        stockName: '',
        specification: '',
        note: '',
        providerName: '',
        unit: '',
        price: '',
        repertory: '',
        minRepertory: '',
        maxRepertory: '',
        pastureId: '',
        purpose: '',
        record: ''
      },
      dialogFormVisible: false,
      dialogFormVisibleCard: false,
      dialogStatusCard: '',

      dialogFormVisible_change: false,
      dialogStatus_change: '',
      changeTemp: {},
      getWarehoseCodeParm: {
        name: 'getWarehouseListByProvider',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureId: '',
          providerId: ''
        }
      },
      changeParam: {
        name: 'changePRlocation',
        parammaps: {}
      },
      isokDisable: false,
      searchBtnVisible: true,
      dialogFormVisibleErro: false,
      dialogStatusErro: '',
      // 校验规则
      rules: {
        warehoseCode: [{ required: true, message: '必填', trigger: 'blur' }]
        // stockName: [{ required: true, message: '必填', trigger: 'blur' }],
        // specification: [{ required: true, message: '必填', trigger: 'blur' }],
        // providerId: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      // eslint-disable-next-line no-undef
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      parentClass: [],

      Classid: '',
      selectionIndex: [],

      // 3.卡片-退库记录
      totalCancelling: 0,
      listCancelling: [],
      listLoadingCancelling: true,
      getdataListParmCancelling: {
        name: 'getPartquitRecord',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          useForm: '',
          inputDatetime: ''
        }
      },
      // 4.卡片-退货记录
      totalRefund: 0,
      listRefund: [],
      listLoadingRefund: true,
      getdataListParmRefund: {
        name: 'getPartrefundRecord',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          useForm: '',
          inputDatetime: ''
        }
      },
      // 4.卡片-退货记录
      totalRecord: 0,
      listRecord: [],
      listLoadingRecord: true,
      getdataListParmRecord: {
        name: 'getCheckpartRecord',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          oddCode: '',
          inputDatetime: ''
        }
      },
      // getdataListParmBeforeUploading: {
      //   name: 'getStockPastureList',
      //   page: 0,
      //   offset: 0,
      //   pagecount: 10,
      //   returntype: 'Map',
      //   parammaps: {
      //     pastureId: Cookies.get('pastureid')
      //   }
      // },
      // ------------------------------------------
      customList: [{ id: 0, name: '全部库存' }, { id: 1, name: '库存不为零' }],
      isCustomTemplate: [], isCustomImport: [], isCustomExport: [], isCustomSee: [],
      findAllProvider: [],
      findAllAssetType: [],
      findAllPasture: [],
      findAllDepart: [],
      findAllEmploye: [],
      getDictByNameYuJing: [],
      findAllCategory: [],
      requestParams: [
        { name: 'findAllProviderByCt', offset: 0, pagecount: 0, parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllAssetType', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllCategory', offset: 0, pagecount: 0, params: [] }
      ],
      requestBrand: {
        name: 'getBrandList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {}
      },
      requestProvider: {
        name: 'getProviderList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {}
      },
      warnings: [{ id: '1', name: '高' }, { id: '2', name: '低' }, { id: '3', name: '正常' }],
      isZeroStocks: [{ id: '0', name: '否' }, { id: '1', name: '是' }],
      statues: [{ id: '1', name: '正常' }, { id: '2', name: '已过期' }, { id: '3', name: '终止' }],
      getdataListParm: {
        name: 'getStockPastureList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureName: Cookies.get('pasturename'),
          partCode: '',
          partName: '',
          providerName: this.$route.query.providerName,
          brandName: '',
          contractCode: '',
          statue: '',
          isZeroStock: '',
          warnings: '',
          reportery: 1,
          specification: '',
          location: ''
        }
      },
      list: [],
      requestParam: {
        name: 'getStockPastureList',
        offset: 0,
        pagecount: 0,
        parammaps: {
          pastureName: Cookies.get('pasturename')
        }
      },
      downList: [],
      textMap: {
        card: '查看详情',
        create: '新增',
        update: '编辑',
        erro: '导入错误信息',
        change: '库位变更'
      },
      seeTemp: {},
      // 1.卡片-入库记录
      totalStorage: 0,
      listStorage: [],
      listLoadingStorage: true,
      getdataListParmStorage: {
        name: 'getPartLaidRecord',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          partCode: '',
          laidCode: '',
          inputDatetime: '',
          startTime: '',
          stopTime: ''
        }
      },
      // 2.卡片-出库记录
      totalDelivery: 0,
      listDelivery: [],
      listLoadingDelivery: true,
      getdataListParmDelivery: {
        name: 'getPartUseRecord',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          useForm: '',
          departmentId: '',
          inputDatetime: '',
          startTime: '',
          stopTime: '',
          eqCode: '',
          eqName: ''
        }
      },
      buttons: [],
      isPercentage: false,
      percentage: 1,
      getDeptListParm: { name: 'getpart_classList' },
      parentDept: [],
      defaultProps: {
        children: 'children',
        label: 'partClassNameCode'
      },
      nodeKey: 'id',
      defaultCheckedKeys: [],
      placeholder: '请选择备件类别'
    }
  },
  computed: {
    // 设置请求头
    headers() {
      return {
        // 设置token
        // eslint-disable-next-line no-undef
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'insertRepertory',
        importParams: '牧场,物料编码,品名,规格型号,品牌,计量单位,库存数量,单价,库位,供应商',
        sheetname: 'SheetJS'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      // process.env.VUE_APP_BASE_API是服务器的路径，也是axios的基本路径
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  created() {
    this.getTypeList()
    this.get_select_list()
    this.getDownClassList()
    this.getList()

    // this.getDownLoadList()
    const that = this
    GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
      that.buttons = response.data.list
      that.get_auto_buttons()
    })
  },

  methods: {
    tableSort1(column) {
      sortChange(column, this.list)
    },
    tableSort2(column) {
      if (this.activeName == 'second') {
        sortChange(column, this.listStorage)
      } else if (this.activeName == 'third') {
        sortChange(column, this.listDelivery)
      } else if (this.activeName == 'fouth') {
        sortChange(column, this.listCancelling)
      } else if (this.activeName == 'fifth') {
        sortChange(column, this.listRefund)
      } else if (this.activeName == 'sixth') {
        sortChange(column, this.listRecord)
      }
    },
    get_auto_buttons() {
      const CustomTemplate = 'customs:custom:template'
      const isCustomTemplate = checkButtons(this.$store.state.user.buttons, CustomTemplate)
      this.isCustomTemplate = isCustomTemplate

      const CustomImport = 'customs:custom:import'
      const isCustomImport = checkButtons(this.$store.state.user.buttons, CustomImport)
      this.isCustomImport = isCustomImport

      const CustomExport = 'customs:custom:export'
      const isCustomExport = checkButtons(this.$store.state.user.buttons, CustomExport)
      this.isCustomExport = isCustomExport

      // 查看
      const CustomSee = 'customs:custom:see'
      const isCustomSee = checkButtons(this.$store.state.user.buttons, CustomSee)
      this.isCustomSee = isCustomSee
    },
    getTypeList() {
      // this.listLoading = true
      this.getDeptListParm.parammaps = this.deptform
      GetDataByName(this.getDeptListParm).then(response => {
        this.listType = response.data
        if (response.data.list !== null) {
          this.listType = transData(response.data.list, 'id', 'pid', 'children')
          console.log(this.listType)
        }
        this.parentDept = this.listType
      })
    },
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllProvider = response.data.findAllProviderByCt.list
        this.findAllAssetType = response.data.findAllAssetType.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllDepart = response.data.findAllDepart.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.findAllCategory = response.data.findAllCategory.list
      })
    },
    getList() {
      this.listLoading = true
      console.log(this.$route.query.providerName)
      if (this.$route.query.pastureName !== undefined) {
        this.getdataListParm.parammaps.pastureName = this.$route.query.pastureName
      }
      GetDataByName(this.getdataListParm).then(response => {
		if(response.data.list !== null){
			console.log('table数据', response.data.list)
			for (let i = 0; i < response.data.list.length; i++) {
			  if (response.data.list[i].price !== undefined) {
			    this.$set(response.data.list[i], 'price', parseFloat(response.data.list[i].price))
			  }
			  if (response.data.list[i].reportery !== undefined) {
			    this.$set(response.data.list[i], 'reportery', parseFloat(response.data.list[i].reportery))
			  }
			  if (response.data.list[i].maxRepertory !== undefined) {
			    this.$set(response.data.list[i], 'maxRepertory', parseFloat(response.data.list[i].maxRepertory))
			  }
			  if (response.data.list[i].minRepertory !== undefined) {
			    this.$set(response.data.list[i], 'minRepertory', parseFloat(response.data.list[i].minRepertory))
			  }
			}
			this.list = response.data.list
			this.pageNum = response.data.pageNum
			this.pageSize = response.data.pageSize
		}else{
			this.list = []
			this.pageNum = 0
			this.pageSize = 0
		}
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      })
    },
    isZeroStock: function(cellValue) {
      // console.log(cellValue.isZeroStock)
      if (cellValue.isZeroStock == 0) {
        return '否'
      } else if (cellValue.isZeroStock == 1) {
        return '是'
      }
    },
    form_see(row) {
      this.defaultCheckedKeys = [this.temp.categoryId]
      this.dialogStatusCard = 'card'
      this.activeName = 'first'
      this.seeTemp = Object.assign({}, row) // copy obj
      if (this.seeTemp.isZeroStock == 0) {
        this.seeTemp.isZeroStock = '否'
      } else {
        this.seeTemp.isZeroStock = '是'
      }

      console.log('查看基础信息data', this.seeTemp)
      // 入库记录
      this.getdataListParmStorage.parammaps.pastureId = row.pastureId
      this.getdataListParmStorage.parammaps.partCode = row.partCode
      this.getdataListParmStorage.parammaps.contractId = row.contractId
      // this.getdataListParmStorage.parammaps.laidCode = row.laidCode
      this.getCardStorage()
      // 出库记录
      this.getdataListParmDelivery.parammaps.pastureId = row.pastureId
      this.getdataListParmDelivery.parammaps.contractId = row.contractId
      this.getdataListParmDelivery.parammaps.partCode = row.partCode
      this.getCardDelivery()
      // 退库记录
      this.getdataListParmCancelling.parammaps.pastureId = row.pastureId
      this.getdataListParmCancelling.parammaps.partCode = row.partCode
      this.getdataListParmCancelling.parammaps.contractId = row.contractId
      this.getCardCancelling()
      // 退货记录
      this.getdataListParmRefund.parammaps.pastureId = row.pastureId
      this.getdataListParmRefund.parammaps.partCode = row.partCode
      this.getdataListParmRefund.parammaps.contractId = row.contractId
      this.getCardRefund()
      this.dialogFormVisibleCard = true
      // 盘点记录
      this.getdataListParmRecord.parammaps.pastureId = row.pastureId
      this.getdataListParmRecord.parammaps.partCode = row.partCode
      this.getdataListParmRecord.parammaps.contractId = row.contractId
      this.getCardRecord()
      this.dialogFormVisibleCard = true
      // this.$nextTick(() => {
      //   this.$refs['temp'].clearValidate()
      // })
    },
    handleChange(row) {
      console.log(row)
      this.changeTemp = Object.assign(row, {})
      this.$set(this.changeTemp, 'warehoseId', '')
      this.$set(this.changeTemp, 'warehoseCode', '')
      this.dialogStatus_change = 'change'
      this.dialogFormVisible_change = true
    },
    getWarehoseCode(queryString, cb) {
      console.log('领用单号模糊查询输入值', queryString)
      this.getWarehoseCodeParm.parammaps['pastureId'] = Cookies.get('pastureid')
      this.getWarehoseCodeParm.parammaps['providerId'] = this.changeTemp.providerId
      this.getWarehoseCodeParm.parammaps['warehoseCode'] = queryString
      GetDataByName(this.getWarehoseCodeParm).then(response => {
        console.log('库位模糊查询搜索data', response.data.list)
        cb(response.data.list)
      })
    },
    handleFocusWarehoseCode() {
      this.changeTemp.warehoseId = ''
      this.changeTemp.warehoseCode = ''
    },
    handleSelectWarehoseCode(item) {
      console.log(item, '---------')
      this.$set(this.changeTemp, 'warehoseId', item.id)
      this.$set(this.changeTemp, 'warehoseCode', item.warehoseCode)
    },
    handleBlurWarehoseCode() {
      if (this.changeTemp.warehoseId == '') {
        this.changeTemp.warehoseId = ''
        this.changeTemp.warehoseCode = ''
      }
    },
    changeData() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['changeTemp'].validate(valid => {
        if (valid) {
          this.changeParam.parammaps.id = this.changeTemp.id
          this.changeParam.parammaps.warehoseCode = this.changeTemp.warehoseCode
          this.changeParam.parammaps.warehoseId = this.changeTemp.warehoseId
          PostDataByName(this.changeParam).then(response => {
            console.log(response)
            if (response.msg !== 'fail') {
              this.getList()
              this.dialogFormVisible_change = false
              this.$notify({
                title: '成功',
                message: '保存成功-',
                type: 'success',
                duration: 2000
              })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      })
    },
    brandSearch(queryString, cb) {
      console.log('品牌模糊查询输入值', queryString)
      this.requestBrand.parammaps['brandName'] = queryString
      GetDataByName(this.requestBrand).then(response => {
        console.log('品牌模糊查询搜索data', response.data.list)
        cb(response.data.list)
      })
    },
    handleSelectBrand(item) {
      console.log('品牌模糊查询选中值', item)
    },
    providerSearch(queryString, cb) {
      console.log('供应商模糊查询输入值', queryString)
      this.requestProvider.parammaps['providerName'] = queryString
      GetDataByName(this.requestProvider).then(response => {
        console.log('供应商模糊查询搜索data', response.data.list)
        cb(response.data.list)
      })
    },
    handleSelectProvider(item) {
      console.log('供应商模糊查询选中值', item)
    },
    form_search() {
      this.listLoading = true
      this.getdataListParm.offset = 1
      this.getdataListParm.pastureName = Cookies.get('pasturename')
      this.getList()
    },
    form_searchClear() {
      this.listLoading = true
      this.beforeUploading()
    },
    beforeUploading() {
      PostDataByName(this.getdataListParmBeforeUploading).then(response => {
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      })
    },
    handleDownload() {
      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.requestParam.name = 'getStockPastureList'
      this.requestParam.parammaps.pastureName = this.getdataListParm.parammaps.pastureName
      this.requestParam.parammaps.partCode = this.getdataListParm.parammaps.partCode
      this.requestParam.parammaps.partName = this.getdataListParm.parammaps.partName
      this.requestParam.parammaps.providerName = this.getdataListParm.parammaps.providerName
      this.requestParam.parammaps.brandName = this.getdataListParm.parammaps.brandName
      this.requestParam.parammaps.contractCode = this.getdataListParm.parammaps.contractCode
      this.requestParam.parammaps.statue = this.getdataListParm.parammaps.statue
      this.requestParam.parammaps.isZeroStock = this.getdataListParm.parammaps.isZeroStock
      this.requestParam.parammaps.warnings = this.getdataListParm.parammaps.warnings
      this.requestParam.parammaps.reportery = this.getdataListParm.parammaps.reportery
      this.requestParam.parammaps.specification = this.getdataListParm.parammaps.specification
      GetAccount(this.requestParam).then(response => {
        this.$nextTick(() => {
          import('@/vendor/Export2Excel').then(excel => {
            console.log(response.data.list)

            response.data.list.forEach(function(item,index){
              if(item.isZeroStock == 0){
                item.isZeroStock = "否"
              } else {
                item.isZeroStock = "是"
              }
            })
            const list1 = response.data.list

            console.log(response.data.list)

            if (response.data.list !== '') {
              this.percentage = 99
              setTimeout(() => {
                this.isPercentage = false
              }, 2000)
            }
            // const list1 = this.downList
            const tHeader = [
              '牧场', '备件名称', '备件编号', '规格', '供应商', '单位', '品牌', '单价', '库存', '最小库存', '最大库存', '位置', '状态', '合同状态', '零库存']
            const filterVal = [
              'pastureName', 'partName', 'partCode', 'specification', 'providerName', 'unit', 'brand', 'price', 'reportery', 'minRepertory', 'maxRepertory', 'location', 'statue', 'isZeroStock']
            const data1 = this.formatJsonTemp(filterVal, list1)
       
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: '备件库存信息',
              autoWidth: true,
              bookType: 'xlsx'
            })
          })
        })
      })
    },

    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    // -----------------------------------
    // 供应商模糊查询

    createFilter(queryString) {
      return returnValue => {
        return (
          returnValue.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0
        )
      }
    },
    handleSelect(item) {
      this.temp.providerId = item.id
      this.temp.providerName = item.name
    },
    // 1-1: table&搜索

    tableCellClassName({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex
      column.index = columnIndex
    },
    cellClick(row, column, cell, event) {
      // console.log('cell',cell)
      console.log('行索引', row.index)
      console.log('列索引', column.index)
      // console.log('event',event)
    },
    selected(select) {
      // this.batchCancelId = []
      this.selectionIndex = []
      this.selectionIndex.push(3, 4, 5)
      // console.log(this.selectionIndex)
    },

    popoverHide(checkedIds, checkedData) {
      console.log(checkedIds, checkedData)
      if (checkedIds !== null) {
        if (checkedData.childrens == 0) {
          // this.defaultCheckedKeys = checkedIds
        } else {
          this.defaultCheckedKeys = []
          this.$message({ type: 'warning', message: '请选择详细备件类别' })
        }
      }
      this.$forceUpdate()
      // this.temp.categoryId = checkedIds
      // this.temp.stockNumber = checkedData.checkNumber
      // console.log(checkedIds, checkedData.checkNumber)
    },
    getDownClassList() {
      getRecuData(this.getRecuListParm).then(response => {
        this.parentClass = response.data
      })
    },

    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },
    form_reset() {
      // 格式化日期
      parseTime(new Date(), '{y}-{m}-{d}')
      this.defaultCheckedKeys = []
    },
    // 导出模板
    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.formatJsonTemp(filterVal, list1)
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: '备件库存模板',
              autoWidth: true,
              bookType: 'xlsx'
            })
          })
        })
      })
    },
    formatJsonTemp(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    beforeImportExcel(file) {
      /*   const isExcel =
        file.type ===
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' */
      const isLt2M = file.size / 1024 / 1024 < 6
      /*  if (!isExcel) {
        this.$message.error(
          '上传文件必须是Xlsx格式!建议先导出，再修改导出文件再导入！'
        )
      }*/
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 6MB!')
      }
      return isLt2M
    },
    handleImportExcelSuccess(res, file) {
      if (res.msg === 'ok') {
        this.$message({
          title: '成功',
          message: '导入成功:' + res.data.success + '条!',
          type: 'success',
          duration: 2000
        })
        if (res.data.err_count > 0) {
          this.dialogFormVisibleErro = true
          this.dialogStatusErro = 'erro'
          this.listErro = res.data.result
          setTimeout(() => {
            this.listLoadingErro = false
          }, 100)
          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
        })
      }
    },
    // 1.卡片-入库记录
    getCardStorage() {
      this.listLoadingStorage = true
      if (this.$refs['inputDatetime'] !== undefined && this.$refs['inputDatetime'].value !== null) {
        this.getdataListParmStorage.parammaps.startTime = this.$refs['inputDatetime'].value[0]
        this.getdataListParmStorage.parammaps.stopTime = this.$refs['inputDatetime'].value[1]
      } else {
        this.getdataListParmStorage.parammaps.startTime = ''
        this.getdataListParmStorage.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParmStorage).then(response => {
        this.listStorage = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalStorage = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingStorage = false
        }, 100)
      })
    },
    form_searchStorage() {
      this.listLoadingStorage = true
      if (this.getdataListParmStorage.parammaps.inputDatetime === null) {
        this.getdataListParmStorage.parammaps.inputDatetime = ''
      }
      this.getdataListParmStorage.offset = 1
      this.getCardStorage()
    },
    // 2.卡片-出库记录
    getCardDelivery() {
      this.listLoadingDelivery = true
      if (this.$refs['inputDatetime2'] !== undefined && this.$refs['inputDatetime2'].value !== null) {
        this.getdataListParmDelivery.parammaps.startTime = this.$refs['inputDatetime2'].value[0]
        this.getdataListParmDelivery.parammaps.stopTime = this.$refs['inputDatetime2'].value[1]
      } else {
        this.getdataListParmDelivery.parammaps.startTime = ''
        this.getdataListParmDelivery.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParmDelivery).then(response => {
        this.listDelivery = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalDelivery = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingDelivery = false
        }, 100)
      })
    },
    form_searchDelivery() {
      this.listLoadingDelivery = true
      this.getdataListParmDelivery.offset = 1
      this.getCardDelivery()
    },
    // 3.卡片-退库记录
    getCardCancelling() {
      this.listLoadingCancelling = true

      if (this.$refs['inputDatetime3'] !== undefined && this.$refs['inputDatetime3'].value !== null) {
        this.getdataListParmCancelling.parammaps.startTime = this.$refs['inputDatetime3'].value[0]
        this.getdataListParmCancelling.parammaps.stopTime = this.$refs['inputDatetime3'].value[1]
      } else {
        this.getdataListParmCancelling.parammaps.startTime = ''
        this.getdataListParmCancelling.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParmCancelling).then(response => {
        this.listCancelling = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalCancelling = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingCancelling = false
        }, 100)
      })
    },
    form_searchCancelling() {
      this.listLoadingCancelling = true
      this.getdataListParmCancelling.offset = 1
      this.getCardCancelling()
    },
    // 4.卡片-退货记录
    getCardRefund() {
      this.listLoadingRefund = true
      if (this.$refs['inputDatetime4'] !== undefined && this.$refs['inputDatetime4'].value !== null) {
        this.getdataListParmRefund.parammaps.startTime = this.$refs['inputDatetime4'].value[0]
        this.getdataListParmRefund.parammaps.stopTime = this.$refs['inputDatetime4'].value[1]
      } else {
        this.getdataListParmRefund.parammaps.startTime = ''
        this.getdataListParmRefund.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParmRefund).then(response => {
        this.listRefund = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalRefund = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingRefund = false
        }, 100)
      })
    },
    form_searchRefund() {
      this.listLoadingRefund = true
      this.getdataListParmRefund.offset = 1
      this.getCardRefund()
    },
    // 5.卡片-盘点记录
    getCardRecord() {
      this.listLoadingRecord = true
      if (this.$refs['inputDatetime5'] !== undefined && this.$refs['inputDatetime5'].value !== null) {
        this.getdataListParmRecord.parammaps.startTime = this.$refs['inputDatetime5'].value[0]
        this.getdataListParmRecord.parammaps.stopTime = this.$refs['inputDatetime5'].value[1]
      } else {
        this.getdataListParmRecord.parammaps.startTime = ''
        this.getdataListParmRecord.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParmRecord).then(response => {
        this.listRecord = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.totalRecord = response.data.total
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingRecord = false
        }, 100)
      })
    },
    form_searchRecord() {
      this.listLoadingRefund = true
      this.getdataListParmRecord.offset = 1
      this.getCardRecord()
    }

  }
}
</script>
