<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>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="备件入库" name="first">
        <div class="filter-container">
          <el-select v-model="getdataListParm.parammaps.pastureName" style="width: 140px;" placeholder="牧场" 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.laidCode" placeholder="入库单号" style="width: 200px;" class="filter-item" />
          <el-date-picker ref="inputDatetime" v-model="getdataListParm.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-select v-model="getdataListParm.parammaps.laidType" clearable placeholder="入库方式" class="filter-item" style="width: 120px;">
            <el-option v-for="item in laidTypes" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
          <!-- <el-select v-model="getdataListParm.parammaps.easStatus" style="width: 150px;" clearable placeholder="EAS同步状态" class="filter-item">
            <el-option v-for="item in easStatus.easStatusList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select> -->
          <el-select v-model="getdataListParm.parammaps.sapStatus" style="width: 150px;" clearable placeholder="SAP上传状态" class="filter-item">
            <el-option v-for="item in easStatus.sapStatusList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
          <el-select v-model="getdataListParm.parammaps.purchase_type" clearable style="width: 140px;" placeholder="申购状态" class="filter-item">
            <el-option v-for="item in subscriptionStatusList" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
          <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
          <div>
            <el-button v-if="isStorageAdd" class="filter-item" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
            <!-- <el-button v-if="isStorageTemplate" 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="isStorageImport" v-waves class="filter-item" type="warning" icon="el-icon-download">导入</el-button>
            </el-upload>
            <el-button v-if="isStorageExport" class="filter-item" style="margin-left: 10px;" type="success" icon="el-icon-upload2" @click="handleDownload">导出</el-button>
            <!-- <el-button v-if="isStorageExportEAS" class="filter-item" style="margin-left: 10px;" type="danger" icon="el-icon-upload2" @click="handleDownloadEas1">导出EAS</el-button> -->
            <!-- <el-button v-if="isEasSynchronization" class="filter-item" type="primary" style="float: right;" @click="handleEAS">EAS同步</el-button> -->

            <el-button v-if="isStorageSap"  class="filter-item" style="margin-left: 10px;" type="success" icon="el-icon-upload2" @click="sapUpload">SAP上传</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 table-fixed"
          @selection-change="change_table_selection"
          @current-change="handleCurrentChange"
          :max-height="myHeight"
        >
        <el-table-column type="selection" :selectable="checkboxInit" align="center" width="50" />

          <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="入库单号" align="center" min-width="110px">
            <template slot-scope="scope">
              <span>{{ scope.row.laidCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="牧场" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.pastureName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="供应商" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="备件种类数" sortable prop="partKind" align="center" min-width="110px">
            <template slot-scope="scope">
              <span>{{ scope.row.partKind }}</span>
            </template>
          </el-table-column>
          <el-table-column label="入库方式" align="center" min-width="110px" :formatter="laidType" />>
          <el-table-column label="录入人" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.empname }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="入库日期" sortable prop="creatTime" min-width="110px" align="center" />
          <!-- <el-table-column label="EAS同步状态" min-width="120px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.easStatus }}</span>
            </template>
          </el-table-column> -->
          <el-table-column  prop="ProofCode" label="sap编码" min-width="80px" align="center">
              <template slot-scope="scope">
                <span>{{scope.row.ProofCode}}</span>
              </template>
            </el-table-column>
          <el-table-column   prop="ProofCode" label="sap上传状态" min-width="80px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.ProofCode">已上传</span>
                <span v-else>未上传</span>

              </template>
            </el-table-column>
            <el-table-column   prop="sterilisation" label="冲销状态" min-width="80px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.sterilisation == 1">已冲销</span>
                <span v-else>未冲销</span>
              </template>
            </el-table-column>
            <el-table-column label="申购状态" min-width="80px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.purchase_type == 1">暂估</span>
                <span v-else-if="scope.row.purchase_type == 3">赠品</span>
                <span v-else>正常</span>
              </template>
            </el-table-column>
          <el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <el-button v-if="isStorageSee" type="primary" size="mini" @click="form_see(row)">查看</el-button>
              <!-- <el-button v-if="isStorageSee" type="success" size="mini" @click="form_edit(row)">编辑</el-button> -->
              <el-button v-if="isStorageDelete && row.laidType !== 2" style="display:inline-block" type="danger" size="mini" @click="handleDelate(row)">删除</el-button>
              <el-button v-else style="display:none" type="danger" size="mini" @click="handleDelate(row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total>0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="get_table_data" />
      </el-tab-pane>
      <el-tab-pane label="入库记录" name="second">
        <div class="filter-container">
          <el-select v-model="getdataListParm2.parammaps.pastureName" style="width: 140px;" placeholder="牧场" 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="getdataListParm2.parammaps.laidCode" placeholder="入库单号" style="width: 200px;" class="filter-item" />
          <el-input v-model="getdataListParm2.parammaps.partCode" placeholder="备件编号" style="width: 200px;" class="filter-item" />
          <el-input v-model="getdataListParm2.parammaps.partName" placeholder="备件名称" style="width: 200px;" class="filter-item" />
          <el-select v-model="getdataListParm2.parammaps.providerId" filterable clearable style="width: 140px;" placeholder="供应商" class="filter-item">
            <el-option v-for="item in findAllProvider2" :key="item.id" :label="item.name" :value="item.id" />
          </el-select>
          <el-date-picker ref="inputDatetime2" v-model="getdataListParm2.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_search2">搜索</el-button>
        </div>
        <el-table
          :key="tableKey2"
          v-loading="listLoading2"
          element-loading-text="给我一点时间"
          :data="list2"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable table-fixed"
          @sort-change="tableSort"
          :max-height="myHeight"
        >
          <el-table-column label="序号" align="center" type="index" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNum2-1) * pageSize2 + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="牧场" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.pastureName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="入库单号" align="center" min-width="150px">
            <template slot-scope="scope">
              <span>{{ scope.row.laidCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件编号" min-width="150px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" align="center" min-width="150px">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="备件品牌" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.brandName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" align="center" min-width="100px">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="库位" align="center" min-width="130px">
            <template slot-scope="scope">
              <span>{{ scope.row.warehoseCode }}</span>
            </template>
          </el-table-column>
          <el-table-column sortable prop="storageAmount" label="入库数量" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.storageAmount }}</span><br>
            </template>
          </el-table-column>
          <el-table-column sortable prop="price" label="单价" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span><br>
            </template>
          </el-table-column>
          <el-table-column sortable prop="sumPrice" label="总价" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.sumPrice }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="录入人" align="center" min-width="90px">
            <template slot-scope="scope">
              <span>{{ scope.row.empname }}</span>
            </template>
          </el-table-column>
          <el-table-column label="入库日期" sortable prop="creatTime" min-width="120px" align="center" />
        </el-table>
        <pagination v-show="total2>0" :total="total2" :page.sync="getdataListParm2.offset" :limit.sync="getdataListParm2.pagecount" @pagination="get_table_data2" />
      </el-tab-pane>
    </el-tabs>
    <!-- 弹出层新增or修改 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="app-add">
        <el-form
          ref="storage"
          :model="storage"
          :rules="rules"
          label-position="right"
          label-width="100px"
          style="width: 90%;margin:0 auto;"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库单号：" prop="laidCode">
                <el-input ref="laidCode" v-model="storage.laidCode" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="牧场：" prop="pastureId">
                <el-select v-model="storage.pastureId" placeholder="牧场" class="filter-item" style="width:100%">
                  <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="employeId">
                <el-select v-model="storage.employeId" placeholder="录入人" class="filter-item" style="width:100%">
                  <el-option v-for="item in findAllEmploye" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库方式:" prop="laidType">
                <el-radio-group v-model="storage.laidType" @change="changeStorageType">
                  <el-radio v-if="isStorageMethod1" v-model="storage.laidType" :label="0" :disabled="dialogStatus==='update'">采购入库</el-radio>
                  <el-radio v-if="isStorageMethod2" v-model="storage.laidType" :label="1" :disabled="dialogStatus==='update'">手动入库</el-radio>
                  <el-radio v-if="isStorageMethod3" v-model="storage.laidType" :label="2" :disabled="dialogStatus==='update'">调拨入库</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col v-if="isProvider" :span="8">
              <el-form-item label="供应商" prop="providerId">
                <el-select v-model="storage.providerId" filterable placeholder="请选择供应商" :disabled="dialogStatus==='update'" style="width:100%" @change="changeProvider">
                  <el-option v-for="item in findAllProvider" :key="item.id" clearable :label="item.name" :value="item.id" :disabled="dialogStatus==='update'" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="入库日期：" prop="storageTime">
                <el-date-picker v-model="storage.storageTime" :picker-options="pickerOptions" type="date" placeholder="入库日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row v-if="No1">
            <el-col :span="10">
              <el-form-item label="采购单号：" prop="buyeCode">
                <el-autocomplete ref="buyeCode" v-model="storage.buyeCode" value-key="name" class="inline-input" :fetch-suggestions="buyeCodeSearch" placeholder="请输入采购单号" style="width:550px" @select="handleSelectBuyeCode">
                  <template slot-scope="{ item }">
                    <span>{{ item.buyeCode }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="No2">
            <el-col :span="16">
              <el-form-item label="备件：" prop="partCode">
                <el-autocomplete
                  v-model="orderPart.partCode"
                  value-key="name"
                  class="inline-input"
                  :fetch-suggestions="sparePartSearch"
                  placeholder="请输入备件编号或备件名称或备件规格"
                  style="width:100%"
                  @select="handleSelectSparePart"
                >
                  <template slot-scope="{ item }">
                    <b>备件编号：</b><div class="name" style="display: inline;">{{ item.partCode }}</div>&nbsp;
                    |  &nbsp;<b>备件名称：</b><span class="addr">{{ item.partName }}</span>&nbsp;
                    |  &nbsp;<b>备件规格：</b><span class="addr">{{ item.specification }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="No3">
            <el-col :span="10">
              <el-form-item label="调拨单号：" prop="applyCode">
                <el-autocomplete v-model="storage.applyCode" value-key="name" class="inline-input" :fetch-suggestions="allocationSearch" placeholder="请输入调拨单号" style="width:550px" @select="handleSelectAllocation">
                  <template slot-scope="{ item }">
                    <b>调拨单号：</b><div class="name" style="display: inline;">{{ item.applyCode }}</div>&nbsp;
                    |  &nbsp;<b>调出牧场：</b><span class="addr">{{ item.pastureName }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <h5 style="float:right;margin-top:10px;margin-left:10px;">总金额：{{ TotalAmount }}</h5>
        <el-button v-if="storage.laidType == '0'" style="float:right;" type="danger" size="mini" @click="handleEmptySpareParts()">删除空备件</el-button>
        <el-table
          :key="tableKey"
          v-loading="listLoading"
          element-loading-text="给我一点时间"
          :data="listAdd"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:30px"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable table-fixed"
        >
          <!-- table表格 -->
          <el-table-column type="index" label="序号" align="center" width="50px" />
          <el-table-column :key="1" label="备件编号" min-width="90px" prop="partCode" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column :key="2" label="备件名称" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column :key="3" label="备件规格" prop="specification" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column :key="4" label="备件图片" prop="specifications" align="center" min-width="60">
            <template slot-scope="scope">
              <el-popover placement="right" title="" trigger="hover">
                <img v-if="scope.row.picpath !== ''" :src="scope.row.picpath">
                <img v-if="scope.row.picpath !== ''" slot="reference" :src="scope.row.picpath" :alt="scope.row.srcpath" style="height: 100px;width:100px;">
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column :key="5" label="备件品牌" prop="brand" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.brand }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="isWarehoseCodeAllo" :key="6" label="供应商" prop="brand" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span>
            </template>
          </el-table-column>
          <el-table-column :key="7" label="计量单位" prop="unit" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="isWarehoseCode" :key="8" label="库位" prop="warehoseCode" align="center" min-width="150">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.warehoseCode"
                class="inline-input"
                :fetch-suggestions="querySearchWarehoseCode"
                value-key="warehoseCode"
                placeholder="库位"
                @select="(value)=>
                {handleSelectWarehoseCode(value, scope.row)}"
                @blur="(value)=>{blurWarehoseCode(value, scope.row)}"
              />
            </template>
          </el-table-column>
          <el-table-column v-if="isWarehoseCodeAllo" :key="9" label="库位" prop="warehoseCode" align="center" min-width="150">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.warehoseCode"
                class="inline-input"
                :fetch-suggestions="querySearchWarehoseCodeAllo"
                value-key="warehoseCode"
                placeholder="库位"
                @select="(value)=>
                {handleSelectWarehoseCodeAllo(value, scope.row)}"
                @blur="(value)=>{blurWarehoseCodeAllo(value, scope.row)}"
              />
            </template>
          </el-table-column>
          <el-table-column v-if="No1" :key="10" label="采购数量" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.amount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" :key="11" label="已入库数量" prop="receiveAmount" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ scope.row.receiveAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" :key="12" valign="middle" label="本次入库数量" min-width="90px" align="center">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="reportery">
                  <el-input ref="reportery1" v-model="scope.row.reportery" style="margin-top:15px" @blur="blurReportery" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column v-if="No2" :key="13" label="本次入库数量" valign="middle" min-width="90px" align="center">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="reportery">
                  <el-input ref="reportery" v-model="scope.row.reportery" style="margin-top:15px" @blur="blurReportery" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column v-if="No3" :key="14" ref="price" valign="middle" label="调拨数量" prop="price" align="center" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.amount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No3" :key="15" ref="price" valign="middle" label="入库数量" prop="price" align="center" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.amount }}</span>
            </template>
          </el-table-column>
          <el-table-column :key="16" label="单价" prop="price" align="center" min-width="100">
            <template slot-scope="scope">
              <span  >{{ scope.row.price }}</span>
              <!-- <el-form v-if="isPriceInput" :model="scope.row" :rules="rules">
                <el-form-item prop="price">
                   <el-input ref="price" v-model="scope.row.price" :disabled="storage.laidType == 0" style="margin-top:15px" />
                  <el-input ref="price" v-model="scope.row.price" style="margin-top:15px" />
                </el-form-item>
              </el-form> -->
            </template>
          </el-table-column>
          <el-table-column v-if="isSumPrice" :key="17" ref="sumPrice" label="总价" prop="sumPrice" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ (scope.row.sumPrice = scope.row.price * parseFloat(scope.row.reportery)) | keepTwoNum }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No3" :key="18" ref="sumPrice" label="总价" prop="sumPrice" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ scope.row.sumPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="isDel" label="操作" align="center" width="100" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <a class="del" @click="partDelete(row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
        <el-form
          ref="temp"
          :rules="rules"
          :model="temp"
          label-position="right"
          label-width="100px"
          style="width: 800px; margin-left:50px;"
        />
        <div slot="footer" class="dialog-footer" style="bottom:10px">
          <el-button type="primary" :disabled="isokDisable" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">保存并关闭</el-button>
          <el-button @click="dialogFormVisible = false;get_table_data()">取消并关闭</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 查看-->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible_See" :close-on-click-modal="false" width="90%">
      <div class="app-see">
        <el-form ref="seeTemp" :rules="rules" :model="seeTemp" label-position="right" label-width="100px" style="width: 90%;margin:0 auto;">
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库单号：" prop="laidCode">
                <el-input ref="laidCode" v-model="seeTemp.laidCode" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="牧场：" prop="pastureName">
                <el-input ref="pastureName" v-model="seeTemp.pastureName" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="employeId">
                <el-input ref="empname" v-model="seeTemp.empname" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库方式:" prop="laidType">
                <el-radio-group v-model="seeTemp.laidType">
                  <el-radio v-model="seeTemp.laidType" :label="0" disabled>采购入库</el-radio>
                  <el-radio v-model="seeTemp.laidType" :label="1" disabled>手动入库</el-radio>
                  <el-radio v-model="seeTemp.laidType" :label="2" disabled>调拨入库</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col v-if="isProvider" :span="8">
              <el-form-item label="供应商:" prop="providerName">
                <el-input ref="providerName" v-model="seeTemp.providerName" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="入库日期：" prop="seeTemp">
                <el-input ref="storageTime" v-model="seeTemp.creatTime" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col v-if="No1" :span="8">
              <el-form-item label="采购单号：" prop="purchaseId">
                <el-input ref="purchaseId" v-model="seeTemp.purchaseId" disabled />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <h5 style="float:right;">总金额：{{ TotalAmount }}</h5>
        <el-table
          :key="tableKey"
          v-loading="listLoadingSee"
          element-loading-text="给我一点时间"
          :data="listSee"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:30px"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable table-fixed"
          @sort-change="tableSort"
        >
          <el-table-column type="index" label="序号" align="center" width="50px" />
          <el-table-column label="备件编号" min-width="80px" prop="partCode" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" prop="specification" align="center" min-width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件图片" prop="specifications" align="center" min-width="110px">
            <template slot-scope="scope">
              <el-popover placement="right" title="" trigger="hover">
                <img v-if="scope.row.picpath !== ''" :src="scope.row.picpath">
                <img v-if="scope.row.picpath !== ''" slot="reference" :src="scope.row.picpath" :alt="scope.row.srcpath" style="height: 100px;width:100px;">
              </el-popover>
            </template>
          </el-table-column>
          <el-table-column label="备件品牌" prop="brandName" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.brandName }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="isWarehoseCodeAllo" label="供应商" prop="brandName" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" prop="unit" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库位" prop="warehoseCode" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.warehoseCode }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" sortable prop="buyAmount" label="采购数量" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.buyAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" sortable label="已入库数量" prop="receivedAmount" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ scope.row.receivedAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" :key="5" sortable prop="storageAmount" label="本次入库数量" min-width="70px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.storageAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No2" :key="6" sortable prop="storageAmount" label="本次入库数量" min-width="70px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.storageAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No3" :key="7" ref="price" sortable prop="storageAmount" valign="middle" label="调拨数量" align="center" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.storageAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No3" :key="8" ref="price" sortable prop="storageAmount" valign="middle" label="入库数量" align="center" min-width="100">
            <template slot-scope="scope">
              <span>{{ scope.row.storageAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column :key="9" sortable label="单价" prop="price" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
              <!-- <el-input v-model="scope.row.price" style="margin-top:15px" disabled /> -->
            </template>
          </el-table-column>
          <el-table-column :key="10" sortable label="总价" prop="sumPrice" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.sumPrice }}</span>
            </template>
          </el-table-column>

          <el-table-column  :key="11"  prop="dflag" label="冲销状态" min-width="80px" align="center">
              <template slot-scope="scope">
                <span v-if="scope.row.dflag == 1">已冲销</span>
                <span v-else>未冲销</span>
              </template>
            </el-table-column>
        </el-table>

        <el-form
          ref="temp"
          :rules="rules"
          :model="temp"
          label-position="right"
          label-width="100px"
          style="width: 800px; margin-left:50px;"
        />
        <div slot="footer" class="dialog-footer" style="margin-bottom:-25px;">
          <el-button @click="dialogFormVisible_See = false">关闭</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- EAS同步 -->
    <el-dialog :title="textMap[easStatus.dialogStatus]" :visible.sync="easStatus.dialogFormVisible" :close-on-click-modal="false" width="80%">
      <div class="easStatus">
        <el-table
          :key="easStatus.tableKey"
          v-loading="easStatus.listLoading"
          element-loading-text="给我一点时间"
          :data="easStatus.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">
            <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" prop="laidCode" />
          <el-table-column label="牧场" min-width="110px" align="center" prop="pastureName" />
          <el-table-column label="供应商" min-width="110px" align="center" prop="providerName" />
          <el-table-column label="录入人" min-width="110px" align="center" prop="empName" />
          <el-table-column label="入库日期" min-width="110px" align="center" prop="createTime" />
          <el-table-column label="失败原因" min-width="110px" align="center" prop="failReason" />
          <el-table-column label="操作" align="center" width="300px" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <el-button v-if="isManualSynchronization" type="primary" size="mini" style="width:70px;" @click="handleManual(row)">手动同步</el-button>
              <el-button v-if="isCloseSynchronization" type="danger" size="mini" style="width:70px;" @click="handleClose(row)">关闭同步</el-button>
              <el-button v-if="isIgnoreSynchronization" type="danger" size="mini" style="width:70px;" @click="handleIgnore(row)">忽略同步</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="easStatus.total>0" :total="easStatus.total" :page.sync="easStatus.getdataListParm.offset" :limit.sync="easStatus.getdataListParm.pagecount" @pagination="get_table_dataEasStatusLst" />
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button @click="easStatus.dialogFormVisible = false;get_table_data()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
// eslint-disable-next-line no-unused-vars
import { GetDataByName, GetDataByNames, PostDataByName, ExecDataByConfig, checkButtons, GetAccount, EasSync,SapLaid } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import { parseTime, sortChange, json2excel } 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 { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
import { getToken } from '@/utils/auth'
export default {
  name: 'Storage',
  components: { Pagination },
  directives: { waves },
  filters: {
    keepTwoNum(value) {
      value = Number(value)
      return value.toFixed(3)
    }
  },
  data() {
    return {
      myHeight:document.documentElement.clientHeight - 85- 250,
      isSap:1,
      isSrm:1,
      selectList: [],
      currentRow:{},
      orderAAA: {},
      temp: {},

      // 校验规则

      isStorageSap:[],

      // --------------------------------------
      isStorageAdd: [], isStorageTemplate: [], isStorageImport: [], isStorageExport: [], isStorageExportEAS: [], isStorageSee: [], isStorageDelete: [], isStorageMethod1: [], isStorageMethod2: [], isStorageMethod3: [],
      isEasSynchronization: [], isManualSynchronization: [], isCloseSynchronization: [], isIgnoreSynchronization: [],
      rules: {
        providerId: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      laidTypes: [{ id: '0', name: '采购入库' }, { id: '1', name: '手动入库' }, { id: '2', name: '调拨入库' }],
      findAllProvider: [],
      findAllProvider2: [],
      findAllPasture: [],
      findAllEmploye: [],
      getDictByName: [],
      requestParams: [
        { name: 'findAllProviderByCt', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'getDictByName', offset: 0, pagecount: 0, params: ['资产状态'] },
        { name: 'findAllProvider', offset: 0, pagecount: 0, params: [] }
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()// 当天之前的时间可选
        }
      },
      subscriptionStatusList:[{id:0,name:'正常'},{id:1,name:'暂估'},{id:3,name:'赠品'}],//申购状态
      dialogFormVisible: false,
      dialogFormVisible_See: false,
      dialogStatus: '',
      textMap: {
        see: '查看详情',
        update: '编辑',
        create: '新增',
        easStatus: 'EAS同步—同步失败数据'
      },
      No1: true,
      No2: false,
      No3: false,
      isProvider: true,
      isDel: true,
      isWarehoseCode: true,
      isWarehoseCodeAllo: false,
      isSumPrice: true,
      requestAllocation: {
        name: 'getTransferCodeRK',
        returntype: 'Map',
        parammaps: {
          applyCode: '',
          pastureId: this.$store.state.user.pastureid
        }
      },
      getAllocationListParm: {
        name: 'getPartTransferbybigid',
        returntype: 'Map',
        parammaps: {}
      },
      disabled: false,
      isokDisable: false,
      tableKey: 0,
      total: 0,
      listLoading: true,
      list: [],
      getdataListParm: {
        name: 'getBigStockLaidList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          laidNumber: '',
          inputDatetime: '',
          pastureName: Cookies.get('pasturename'),
          easStatus: '',
          sapStatus:'',
          purchase_type:''
        }
      },
      activeName: 'first',
      tableKey2: 0,
      listLoading2: true,
      total2: 0,
      list2: [],
      getdataListParm2: {
        name: 'getPartlaideDetailList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          inputDatetime: '',
          laidCode: '',
          stopTime: '',
          startTime: '',
          partCode: '',
          partName: '',
          providerId: '',
          pastureName: Cookies.get('pasturename')
        }
      },
      requestParam: {
        name: 'downloadPartlaideList',
        parammaps: {
          pastureName: Cookies.get('pasturename'),
          inputDatetime: ''
        }
      },
      downList: [],
      listLoadingSee: true,
      listSee: [],
      totalSee: 0,
      seeTemp: {},
      getdataListSee: {
        name: 'getpartLaidListBybig',
        returntype: 'Map',
        parammaps: {}
      },
      getParmCreateNumber: {
        name: 'autoCreatCode',
        page: 0,
        offset: 0,
        pagecount: 0,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid'),
          codeType: 'RK'
        }
      },
      storage: {
        inCount: 0,
        oldVal: 0,
        laidType: 0,
        providerId: '',
        storageTime: parseTime(new Date(), '{y}-{m}-{d}'),
        empId: this.$store.state.user.employeid,
        pastureId: this.$store.state.user.pastureid
      },
      TotalAmount: 0,
      orderPart: {},
      requestSparePart: {
        name: 'getPartListByProvider',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {
          pastureId: this.$store.state.user.pastureid
        }
      },
      orderCode: {},
      requestBuyeCode: {
        name: 'getBuyeCode',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid')
        }
      },
      getBuyDetailListParm: {
        name: 'getBuydetailByBig',
        returntype: 'Map',
        parammaps: {}
      },
      requeststoreHouse: {
        name: 'getWarehouseListByProvider',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid')
        }
      },
      requeststoreHouseAllo: {
        name: 'getWarehouselistDB',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid'),
          warehoseCode: ''
        }
      },
      warehoseCodeList: [],
      listAdd: [],
      isPrice: true,
      isPriceInput: false,
      postDataPramas: {},
      rowUpdateData: {},
      buttons: [],
      isPercentage: false,
      percentage: 1,
      // EAS同步
      easStatus: {
        easStatusList: [{ name: '同步成功', id: '1' }, { name: '同步失败', id: '0' }, { name: '关闭同步', id: '2' }],
        sapStatusList: [ { name: '所有', id: '0' }, { name: '已上传', id: '1' }, { name: '未上传', id: '2' }],
        dialogStatus: '',
        dialogFormVisible: false,
        tableKey: 0,
        total: 0,
        listLoading: true,
        list: [],
        getdataListParm: {
          name: 'getbigpartlaidSync',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        }
      }
    }
  },

  computed: {
    // 设置请求头
    headers() {
      return {
        // 设置token
        // eslint-disable-next-line no-undef
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'importStockLaid',
        importParams: '牧场,入库单编号,入库日期,物料编码,品名,规格型号,品牌,计量单位,数量,单价,总价,库位,供应商',
        sheetname: 'SheetJS'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      // process.env.VUE_APP_BASE_API是服务器的路径，也是axios的基本路径
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  watch: {
    listAdd: {
      deep: true,
      handler: function (item) {
          this.listAdd.forEach(function(i){
            if(parseInt(i.reportery) > (parseInt(i.amount)-parseInt(i.receiveAmount))){
              i.reportery = parseInt(i.amount)-parseInt(i.receiveAmount)
            }

          })
      }
    },
  },

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

  methods: {
    tableSort(column) {
      if (this.activeName == 'second') {
        sortChange(column, this.list2)
      } else if (this.activeName == 'first') {
        sortChange(column, this.listSee)
      }
    },
    get_auto_buttons() {
      // 新增



      const StorageSap = 'customs:storage:sap'
      const isStorageSap = checkButtons(this.$store.state.user.buttons, StorageSap)
      this.isStorageSap = isStorageSap

      const StorageAdd = 'customs:storage:add'
      const isStorageAdd = checkButtons(this.$store.state.user.buttons, StorageAdd)
      this.isStorageAdd = isStorageAdd

      const StorageTemplate = 'customs:storage:template'
      const isStorageTemplate = checkButtons(this.$store.state.user.buttons, StorageTemplate)
      this.isStorageTemplate = isStorageTemplate

      const StorageImport = 'customs:storage:import'
      const isStorageImport = checkButtons(this.$store.state.user.buttons, StorageImport)
      this.isStorageImport = isStorageImport

      const StorageExport = 'customs:storage:export'
      const isStorageExport = checkButtons(this.$store.state.user.buttons, StorageExport)
      this.isStorageExport = isStorageExport

      const StorageExportEAS = 'customs:storage:exportEAS'
      const isStorageExportEAS = checkButtons(this.$store.state.user.buttons, StorageExportEAS)
      this.isStorageExportEAS = isStorageExportEAS

      const StorageSee = 'customs:storage:see'
      const isStorageSee = checkButtons(this.$store.state.user.buttons, StorageSee)
      this.isStorageSee = isStorageSee

      const StorageDelete = 'customs:storage:delete'
      const isStorageDelete = checkButtons(this.$store.state.user.buttons, StorageDelete)
      this.isStorageDelete = isStorageDelete

      const StorageMethod1 = 'customs:storage:method1'
      const isStorageMethod1 = checkButtons(this.$store.state.user.buttons, StorageMethod1)
      this.isStorageMethod1 = isStorageMethod1

      const StorageMethod2 = 'customs:storage:method2'
      const isStorageMethod2 = checkButtons(this.$store.state.user.buttons, StorageMethod2)
      this.isStorageMethod2 = isStorageMethod2

      const StorageMethod3 = 'customs:storage:method3'
      const isStorageMethod3 = checkButtons(this.$store.state.user.buttons, StorageMethod3)
      this.isStorageMethod3 = isStorageMethod3

      const EasSynchronization = 'customs:storage:easSynchronization'
      const isEasSynchronization = checkButtons(this.$store.state.user.buttons, EasSynchronization)
      this.isEasSynchronization = isEasSynchronization

      const ManualSynchronization = 'customs:storage:manualSynchronization'
      const isManualSynchronization = checkButtons(this.$store.state.user.buttons, ManualSynchronization)
      this.isManualSynchronization = isManualSynchronization

      const CloseSynchronization = 'customs:storage:closeSynchronization'
      const isCloseSynchronization = checkButtons(this.$store.state.user.buttons, CloseSynchronization)
      this.isCloseSynchronization = isCloseSynchronization

      const IgnoreSynchronization = 'customs:storage:ignoreSynchronization'
      const isIgnoreSynchronization = checkButtons(this.$store.state.user.buttons, IgnoreSynchronization)
      this.isIgnoreSynchronization = isIgnoreSynchronization
    },
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        console.log('下拉框数据', response.data)
        this.findAllProvider = response.data.findAllProviderByCt.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.getDictByName = response.data.getDictByName.list
        this.findAllProvider2 = response.data.findAllProvider.list
      })
    },
    get_table_data() {
      this.listLoading = true
      if (this.$refs['inputDatetime'] !== undefined && this.$refs['inputDatetime'].value !== null) {
        this.getdataListParm.parammaps.startTime = this.$refs['inputDatetime'].value[0]
        this.getdataListParm.parammaps.stopTime = this.$refs['inputDatetime'].value[1]
      } else {
        this.getdataListParm.parammaps.startTime = ''
        this.getdataListParm.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        this.list = response.data.list
        this.pageNum = response.data.pageNum
        this.pageSize = response.data.pageSize
        if (response.data.total) {
          this.total = response.data.total
        }
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    handleClick(tab, event) {
      console.log(tab, event)
      if (tab.name === 'second') {
        this.get_table_data2()
      } else {
        this.get_table_data()
      }
    },
    get_table_data2() {
      this.listLoading2 = true
      if (this.$refs['inputDatetime2'] !== undefined && this.$refs['inputDatetime2'].value !== null) {
        this.getdataListParm2.parammaps.startTime = this.$refs['inputDatetime2'].value[0]
        this.getdataListParm2.parammaps.stopTime = this.$refs['inputDatetime2'].value[1]
      } else {
        this.getdataListParm2.parammaps.startTime = ''
        this.getdataListParm2.parammaps.stopTime = ''
      }
      GetDataByName(this.getdataListParm2).then(response => {
        console.log('table数据', response.data.list)
        this.list2 = response.data.list
        this.pageNum2 = response.data.pageNum
        this.pageSize2 = response.data.pageSize
        if (response.data.total) {
          this.total2 = response.data.total
        }
        setTimeout(() => {
          this.listLoading2 = false
        }, 100)
      })
    },
    form_search2() {
      this.listLoading2 = true
      if (this.getdataListParm2.parammaps.inputDatetime === null) {
        this.getdataListParm2.parammaps.inputDatetime = ''
      }
      this.getdataListParm2.offset = 1
      this.get_table_data2()
    },
    laidType: function(cellValue) {
      // console.log(cellValue.isZeroStock)
      if (cellValue.laidType === 0) {
        return '采购入库'
      } else if (cellValue.laidType === 1) {
        return '手动入库'
      } else if (cellValue.laidType === 2) {
        return '调拨入库'
      }
    },
    form_search() {
      console.log('点击了table搜索')
      this.listLoading = true
      if (this.getdataListParm.parammaps.inputDatetime === null) {
        this.getdataListParm.parammaps.inputDatetime = ''
      }
      this.getdataListParm.offset = 1
      this.get_table_data()
    },
    // 查看详情
    form_see(row) {
      this.seeTemp = Object.assign({}, row)
      this.TotalAmount = 0
      console.log('查看上方数据(从table读取)', this.seeTemp)
      this.dialogStatus = 'see'
      this.dialogFormVisible_See = true
      if (this.seeTemp.laidType === 0) {
        this.No1 = true
        this.No2 = false
        this.No3 = false
        this.isProvider = true
        this.isWarehoseCode = true
        this.isSumPrice = true
        this.isWarehoseCodeAllo = false
        this.isDel = true
      } else if (this.seeTemp.laidType === 1) {
        this.No1 = false
        this.No2 = true
        this.No3 = false
        this.isProvider = true
        this.isWarehoseCode = true
        this.isSumPrice = true
        this.isWarehoseCodeAllo = false
        this.isDel = true
      } else if (this.seeTemp.laidType === 2) {
        this.No1 = false
        this.No2 = false
        this.No3 = true
        this.isProvider = false
        this.isWarehoseCode = false
        this.isWarehoseCodeAllo = true
        this.isSumPrice = false
        this.isDel = false
      }
      this.getdataListSee.parammaps.id = row.id
      this.getSeeList()
    },
    getSeeList() {
      GetDataByName(this.getdataListSee).then(response => {
        console.log('查看下方table数据', response.data.list)
        this.listSee = response.data.list
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.TotalAmount += parseFloat(response.data.list[i].sumPrice)
            if (response.data.list[i].srcpath !== null && response.data.list[i].picpath !== null && response.data.list[i].srcpath !== undefined && response.data.list[i].picpath !== undefined) {
              this.listSee[i].srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              this.listSee[i].picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
            } else {
              this.listSee[i].srcpath = ''
              this.listSee[i].picpath = ''
            }
          }
          this.TotalAmount = this.TotalAmount.toFixed(2)
        }
        setTimeout(() => {
          this.listLoadingSee = false
        }, 100)
      })
    },
    resetCreateTemp() {
      this.listAdd = []
      this.storage.inCount = 0
      this.storage.storageTime = parseTime(new Date(), '{y}-{m}-{d}')
      this.storage.providerId = ''
      this.storage.employeId = this.$store.state.user.employeid
      this.storage.departmentId = this.$store.state.user.departmentid
      this.storage.pastureId = this.$store.state.user.pastureid
      this.storage.laidCode = ''
      this.TotalAmount = 0
    },
    form_add() {
      this.resetCreateTemp()
      this.storage.laidCode = ''
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.storage.pastureId = this.$store.state.user.pastureid
      this.storage.employeId = this.$store.state.user.employeid
      console.log(this.storage)
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
      this.getCreateNumber()
    },
    getCreateNumber() {
      GetDataByName(this.getParmCreateNumber).then(response => {
        this.$nextTick(() => {
          console.log('入库单号', response.data.list[0].orderCode)
          this.storage.laidCode = response.data.list[0].orderCode
          this.$forceUpdate()
        })
      })
    },
    changeProvider(value) {
      console.log(value)
      this.storage.providerId = value
      this.TotalAmount = 0
      console.log(this.findAllProvider.find(obj => obj.id === value).flexPrice)
      this.$set(this.storage, 'flexPrice', this.findAllProvider.find(obj => obj.id === value).flexPrice)

      if (parseInt(this.findAllProvider.find(obj => obj.id === value).flexPrice) === 1) {
        this.isPriceInput = true
        this.isPrice = false
      } else {
        this.isPriceInput = false
        this.isPrice = true
      }
      this.listAdd = []
    },
    buyeCodeSearch(queryString, cb) {
      console.log('采购单号模糊查询输入值', queryString)
      console.log(this.$refs['providerId'])
      if (this.storage.providerId !== '') {
        this.requestBuyeCode.parammaps['buyeCode'] = queryString
        this.requestBuyeCode.parammaps['providerId'] = this.storage.providerId
        GetDataByName(this.requestBuyeCode).then(response => {
          console.log('采购单号模糊查询搜索data', response.data.list)
          if (response.data.list === null) {
            this.buyeCodeList = []
          } else {
            this.buyeCodeList = response.data.list
          }
          cb(response.data.list)
        })
      } else {
        this.$notify({
          title: '',
          message: '请选择供应商',
          type: 'warning',
          duration: 2000
        })
      }
    },
    handleSelectBuyeCode(item) {
      console.log('采购单号模糊查询选中值', item)
      this.TotalAmount = 0
      // this.listAdd.push(item)
      this.storage.orderCode = item.buyeCode
      this.storage.orderCodeId = item.id
      this.getBuyDetailListParm.parammaps.id = item.id
      this.getBuyDetailListParm.parammaps.pastureId = Cookies.get('pastureid')
      this.getBuyDetailList()
    },

    getBuyDetailList() {
      GetDataByName(this.getBuyDetailListParm).then(response => {
        console.log('采购入库table-data', response.data.list)
        this.listAdd = response.data.list
        // this.listAdd.forEach(function(val) {
        //   val.warehoseCode = ''
        // })
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(this.listAdd[i], 'warehoseCode', response.data.list[i].warehoseCode)
            this.$set(this.listAdd[i], 'locationId', response.data.list[i].warehoseCodeId)
            if (response.data.list[i].srcpath !== null && response.data.list[i].picpath !== null && response.data.list[i].srcpath !== undefined && response.data.list[i].picpath !== undefined) {
              this.listAdd[i].srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              this.listAdd[i].picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
            } else {
              this.listAdd[i].srcpath = ''
              this.listAdd[i].picpath = ''
            }
          }
        }
        this.$forceUpdate()
      })
      this.$forceUpdate()
    },
    sparePartSearch(queryString, cb) {
      console.log('备件模糊查询输入值', queryString)
      console.log(this.$refs['providerId'])
      if (this.storage.providerId !== '') {
        this.requestSparePart.parammaps['partCode'] = queryString
        this.requestSparePart.parammaps['providerId'] = this.storage.providerId
        GetDataByName(this.requestSparePart).then(response => {
          console.log('备件模糊查询搜索data', response.data.list)
          if (response.data.list !== null) {
            cb(response.data.list)
          } else {
            cb([])
          }
        })
      } else {
        this.$notify({
          title: '',
          message: '请选择供应商',
          type: 'warning',
          duration: 2000
        })
      }
    },
    allocationSearch(queryString, cb) {
      console.log(queryString)
      this.requestAllocation.parammaps.applyCode = queryString
      GetDataByName(this.requestAllocation).then(response => {
        console.log('调拨单号模糊查询搜索data', response.data.list)
        if (response.data.list !== null) {
          cb(response.data.list)
        } else {
          cb([])
        }
      })
    },
    handleSelectAllocation(item) {
      console.log('调拨单号模糊查询选中值', item)
      this.storage.id = item.id
      this.getAllocationListParm.parammaps.id = item.id
      this.getAllocationList()
    },
    getAllocationList() {
      GetDataByName(this.getAllocationListParm).then(response => {
        console.log('调拨单号table-data', response.data.list)
        this.listAdd = response.data.list
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.TotalAmount += parseFloat(response.data.list[i].sumPrice)
            this.$set(this.listAdd[i], 'warehoseCode', '')
            // this.$set(this.listAdd[i], 'locationId', response.data.list[i].warehoseCodeId)
            // this.$set(this.listAdd[i], 'warehoseCode', response.data.list[i].warehoseCode)
            this.$set(this.listAdd[i], 'contractId', '-' + response.data.list[i].pastureId + this.listAdd[i].partId)
            if (response.data.list[i].srcpath !== null && response.data.list[i].picpath !== null && response.data.list[i].srcpath !== undefined && response.data.list[i].picpath !== undefined) {
              this.listAdd[i].srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              this.listAdd[i].picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
            } else {
              this.listAdd[i].srcpath = ''
              this.listAdd[i].picpath = ''
            }
          }
          this.TotalAmount = this.TotalAmount.toFixed(2)
        }
        this.$forceUpdate()
      })
    },

    handleSelectSparePart(item) {
      console.log('备件模糊查询选中值', item)
      if (this.listAdd.length > 0) {
        // eslint-disable-next-line no-redeclare
        if (this.listAdd.find(obj => obj.id === item.id)) {
          this.$message({
            type: 'warning',
            message: '此备件已存在，请重新选择备件'
          })
        } else {
          if (item.srcpath !== null && item.picpath !== null && item.srcpath !== undefined && item.picpath !== undefined) {
            this.$set(item, 'srcpath', process.env.VUE_APP_BASE_API + item.srcpath)
            this.$set(item, 'picpath', process.env.VUE_APP_BASE_API + item.picpath)
          } else {
            item.srcpath = ''
            item.picpath = ''
          }
          this.$set(item, 'locationId', item.warehoseCodeId)
          this.$set(item, 'warehoseCode', item.warehoseCode)
          this.listAdd.unshift(item)
        }
      } else {
        if (item.srcpath !== null && item.picpath !== null && item.srcpath !== undefined && item.picpath !== undefined) {
          this.$set(item, 'srcpath', process.env.VUE_APP_BASE_API + item.srcpath)
          this.$set(item, 'picpath', process.env.VUE_APP_BASE_API + item.picpath)
        } else {
          item.srcpath = ''
          item.picpath = ''
        }
        this.$set(item, 'locationId', item.warehoseCodeId)
        this.$set(item, 'warehoseCode', item.warehoseCode)
        this.listAdd.unshift(item)
      }
    },
    querySearchWarehoseCode(queryString, cb) {
      console.log('库位模糊查询输入值', queryString)
      this.requeststoreHouse.parammaps['warehoseCode'] = queryString
      this.requeststoreHouse.parammaps.providerId = this.storage.providerId
      GetDataByName(this.requeststoreHouse).then(response => {
        console.log('备件名称模糊查询搜索data', response.data.list)
        this.warehoseCodeList = response.data.list
        cb(this.warehoseCodeList)
      })
      this.$forceUpdate()
    },
    handleSelectWarehoseCode(item, row) {
      console.log('库位模糊查询选中值', item)
      console.log('库位模糊查询选中值所在行', row)
      this.$set(row, 'locationId', item.id)
      this.$set(row, 'warehoseCode', item.warehoseCode)
      this.$forceUpdate()
    },
    blurWarehoseCode(item, row) {
      console.log(item, row)
      row.warehoseCode = ''
      row.locationId = ''
    },
    querySearchWarehoseCodeAllo(queryString, cb) {
      console.log('库位模糊查询输入值', queryString)
      this.requeststoreHouseAllo.parammaps['warehoseCode'] = queryString
      GetDataByName(this.requeststoreHouseAllo).then(response => {
        console.log('备件名称模糊查询搜索data', response.data.list)
        this.warehoseCodeList = response.data.list
        cb(this.warehoseCodeList)
      })
      this.$forceUpdate()
    },
    handleSelectWarehoseCodeAllo(item, row) {
      console.log('库位模糊查询选中值', item)
      console.log('库位模糊查询选中值所在行', row)
      this.$set(row, 'locationId', item.id)
      this.$set(row, 'warehoseCode', item.warehoseCode)
      this.$forceUpdate()
    },
    blurWarehoseCodeAllo(item, row) {
      console.log(item, row)
      row.warehoseCode = ''
      row.locationId = ''
    },
    partDelete(row) {
      console.log(this.listAdd)
      MessageBox.confirm('设备名称：' + row.partName, '确认删除？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // console.log(this.list2)
        this.TotalAmount = 0
        console.log(row.id)
        for (var i = 0; i < this.listAdd.length; i++) {
          console.log(this.listAdd[i])
          if (this.listAdd[i].id === row.id) {
            var listAddIndex = this.listAdd.indexOf(this.listAdd[i])
          }
          if (listAddIndex > -1) {
            this.listAdd.splice(listAddIndex, 1)
            return
          }
          this.TotalAmount += parseFloat(this.listAdd[i].sumPrice)
        }
        this.TotalAmount = this.TotalAmount.toFixed(2)
      })
    },
    blurReportery() {
      console.log(this.listAdd)
      this.TotalAmount = 0
      for (let i = 0; i < this.listAdd.length; i++) {
        console.log(this.listAdd[i].sumPrice)
        // eslint-disable-next-line use-isnan
        if (this.listAdd[i].reportery !== undefined && this.listAdd[i].reportery !== 'undefined') {
          this.TotalAmount += parseFloat(this.listAdd[i].sumPrice)
        }
      }
      this.TotalAmount = this.TotalAmount.toFixed(2)
    },
    handleEmptySpareParts() {
      if (this.listAdd.length > 0) {
        const arr = []
        for (let i = 0; i < this.listAdd.length; i++) {
          if (this.listAdd[i].reportery == undefined || this.listAdd[i].reportery == null || this.listAdd[i].reportery == '') {
            arr.push(this.listAdd[i].id)
          }
        }
        if (arr.length == 0) {
          this.$message({ type: 'warning', message: '当前无备件需要清空', duration: 2000 })
          return false
        }
        MessageBox.confirm('是否清空入库数量为空备件？', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (arr.length > 0) {
            for (let i = 0; i < this.listAdd.length; i++) {
              for (let j = 0; j < arr.length; j++) {
                if (this.listAdd[i].id == arr[j]) {
                  this.listAdd.splice(i, 1)
                }
              }
            }
            this.$notify({ title: '成功', message: '清空成功', type: 'success', duration: 2000 })
          }
        }).catch(() => {
          this.$message({ type: 'info', message: '已取消' })
        })
      } else {
        this.$message({ type: 'warning', message: '当前无备件需要清空', duration: 2000 })
      }
    },
    add_dialog_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['storage'].validate(valid => {
        if (valid) {
          if (this.storage.laidCode == '' || this.storage.laidCode == null || this.storage.laidCode == undefined) {
            GetDataByName(this.getParmCreateNumber).then(response => {
              this.$nextTick(() => {
                console.log('入库单号', response.data.list[0].orderCode)
                this.storage.laidCode = response.data.list[0].orderCode
                this.$forceUpdate()
                this.add_dialog_saveSave()
              })
            })
          } else {
            this.add_dialog_saveSave()
          }
        }
      })
    },
    add_dialog_saveSave() {
      if (this.listAdd.length !== 0) {
        if (this.storage.laidType === 0) {
          // 采购
          for (var j = 0; j < this.listAdd.length; j++) {
            if (this.listAdd[j].locationId == null || this.listAdd[j].locationId == '' || this.listAdd[j].reportery == null || this.listAdd[j].reportery === '' || this.listAdd[j].price == null || this.listAdd[j].price == '') {
              this.$message({
                type: 'warning',
                message: '请检查库位及本次入库数量是否未填写',
                duration: 2000
              })
              return false
            } else {
              var rulesReportery = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
              var rulesPrice = /(^[1-9](\d+)?(\.\d{1,5})?$)|(^\d\.\d{1,5}$)/
              var maxReportery = parseFloat(this.listAdd[j].amount) - parseFloat(this.listAdd[j].receiveAmount)
              if (!rulesReportery.test(this.listAdd[j].reportery)) {
                this.$message({
                  type: 'error',
                  message: '本次入库请输入正数，最多保留两位小数点',
                  duration: 2000
                })
                return false
              }
              if (parseFloat(this.listAdd[j].reportery) > maxReportery) {
                this.$message({
                  type: 'error',
                  message: '本次入库数量不可大于未入库数',
                  duration: 2000
                })
                return false
              }
              // if (!rulesPrice.test(this.listAdd[j].price)) {
              //   this.$message({
              //     type: 'error',
              //     message: '单价请输入正数，最多保留五位小数点',
              //     duration: 2000
              //   })
              //   return false
              // }
            }
          }
          for (var i = 0; i < this.listAdd.length; i++) {
            this.listAdd[i].contractId = this.listAdd[i].id
            this.listAdd[i].providerId = this.storage.providerId
          }
          this.postDataPramas.common = { 'returnmap': '0' }
          this.postDataPramas.data = []
          this.postDataPramas.data[0] = { 'name': 'insertBigPartlaid', 'type': 'e', 'parammaps': {
            providerId: this.storage.providerId,
            pastureId: this.storage.pastureId,
            storageTime: this.storage.storageTime,
            laidCode: this.storage.laidCode,
            empId: this.storage.employeId,
            No1Id: this.storage.orderCode,
            laidType: this.storage.laidType,
            purchaseId: this.storage.orderCode
          }}
          this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
          this.postDataPramas.data[1].children = []
          this.postDataPramas.data[1].children[0] = { 'name': 'insertPartlaid', 'type': 'e', 'parammaps': {
            bigId: '@insertBigPartlaid.LastInsertId',
            buydetailId: '@insertSpotList.bid',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            buyAmount: '@insertSpotList.amount',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            orderNumber: '@insertSpotList.orderNumber',
            providerId: '@insertSpotList.providerId',
            brandId: '@insertSpotList.brandId',
            storageAmount: '@insertSpotList.reportery',
            contractId: '@insertSpotList.contractId',
            bigBuyerId: '@insertSpotList.id',
            receivedAmount: '@insertSpotList.receiveAmount',
            buyeCode: this.storage.orderCode,
            reporteryQ: '@insertSpotList.reporteryQ'
          }}
          this.postDataPramas.data[1].children[1] = { 'name': 'insertPartRepertory', 'type': 'e', 'parammaps': {
            reportery: '@insertSpotList.reportery',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            providerId: '@insertSpotList.providerId',
            providerName: '@insertSpotList.providerName',
            brand: '@insertSpotList.brand',
            brandId: '@insertSpotList.brandId',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            contractId: '@insertSpotList.contractId',
            flexPrice: this.storage.flexPrice
          }}
          this.postDataPramas.data[1].children[2] = { 'name': 'updateBuydetailAmount', 'type': 'e', 'parammaps': {
            reportery: '@insertSpotList.reportery',
            bid: '@insertSpotList.bid'
          }}
          this.postDataPramas.data[2] = { 'name': 'updateBuydetailAmountZero', 'type': 'e', 'parammaps': {
            'bigId': this.getBuyDetailListParm.parammaps.id
          }}
          ExecDataByConfig(this.postDataPramas).then(response => {
            console.log('新增保存发送参数', this.postDataPramas)
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getdataListParm.parammaps.inputDatetime = ''
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
          return true
        } else if (this.storage.laidType === 1) {
          for (var j = 0; j < this.listAdd.length; j++) {
            if (this.listAdd[j].locationId == null || this.listAdd[j].reportery == null || this.listAdd[j].reportery === '') {
              this.$message({
                type: 'warning',
                message: '请检查库位及本次入库数量是否未填写',
                duration: 2000
              })
              return false
            } else {
              var rulesReportery1 = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
              if (!rulesReportery1.test(this.listAdd[j].reportery)) {
                this.$message({
                  type: 'error',
                  message: '本次入库请输入正数，最多保留两位小数点',
                  duration: 2000
                })
                return false
              }
            }
            this.listAdd[j].storageAmount = 0
            this.listAdd[j].bigBuyerId = 0
            this.listAdd[j].receiveAmount = 0
            this.listAdd[j].amount = 0
            this.listAdd[j].buydetailId = -1
            this.listAdd[j].contractId = this.listAdd[j].id
            this.listAdd[j].providerId = this.storage.providerId
          }
          this.postDataPramas.common = { 'returnmap': '0' }
          this.postDataPramas.data = []
          this.postDataPramas.data[0] = { 'name': 'insertBigPartlaid', 'type': 'e', 'parammaps': {
            providerId: this.storage.providerId,
            pastureId: this.storage.pastureId,
            storageTime: this.storage.storageTime,
            laidCode: this.storage.laidCode,
            empId: this.storage.employeId,
            No1Id: this.storage.orderCode,
            laidType: this.storage.laidType
          }}
          this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
          this.postDataPramas.data[1].children = []
          this.postDataPramas.data[1].children[0] = { 'name': 'insertPartlaid', 'type': 'e', 'parammaps': {
            bigId: '@insertBigPartlaid.LastInsertId',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            buyAmount: 0,
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            orderNumber: '@insertSpotList.orderNumber',
            providerId: '@insertSpotList.providerId',
            brandId: '@insertSpotList.brandId',
            storageAmount: '@insertSpotList.reportery',
            contractId: '@insertSpotList.contractId',
            bigBuyerId: '@insertSpotList.bigBuyerId',
            receivedAmount: '@insertSpotList.receiveAmount',
            buydetailId: -1,
            reporteryQ: '@insertSpotList.reporteryQ'
          }}
          this.postDataPramas.data[1].children[1] = { 'name': 'insertPartRepertory', 'type': 'e', 'parammaps': {
            reportery: '@insertSpotList.reportery',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            providerId: '@insertSpotList.providerId',
            providerName: '@insertSpotList.providerName',
            brand: '@insertSpotList.brand',
            brandId: '@insertSpotList.brandId',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            contractId: '@insertSpotList.contractId',
            flexPrice: this.storage.flexPrice
          }}
          ExecDataByConfig(this.postDataPramas).then(response => {
            console.log('新增保存发送参数', this.postDataPramas)
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getdataListParm.parammaps.inputDatetime = ''
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
          return true
        } else if (this.storage.laidType === 2) {
          // 调拨入库
          for (var j = 0; j < this.listAdd.length; j++) {
            if (this.listAdd[j].locationId == null) {
              this.$message({
                type: 'warning',
                message: '请检查库位是否未填写',
                duration: 2000
              })
              return false
            }
            this.listAdd[j].storageAmount = 0
            this.listAdd[j].bigBuyerId = 0
            this.listAdd[j].receiveAmount = 0
            this.listAdd[j].buydetailId = -1
            this.listAdd[j].storageAmount = 0
            this.listAdd[j].reporteryQ = 0
          }
          this.postDataPramas.common = { 'returnmap': '0' }
          this.postDataPramas.data = []
          this.postDataPramas.data[0] = { 'name': 'insertBigPartlaid', 'type': 'e', 'parammaps': {
            providerId: this.storage.providerId,
            pastureId: Cookies.get('pastureid'),
            storageTime: this.storage.storageTime,
            laidCode: this.storage.laidCode,
            empId: this.storage.employeId,
            No1Id: this.storage.orderCode,
            laidType: this.storage.laidType
          }}
          this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
          this.postDataPramas.data[1].children = []
          this.postDataPramas.data[1].children[0] = { 'name': 'insertPartlaid', 'type': 'e', 'parammaps': {
            bigId: '@insertBigPartlaid.LastInsertId',
            pastureId: Cookies.get('pastureid'),
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            buyAmount: 0,
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            orderNumber: '@insertSpotList.orderNumber',
            providerId: '@insertSpotList.providerId',
            providerName: '@insertSpotList.providerName',
            brandId: '@insertSpotList.brandId',
            storageAmount: '@insertSpotList.amount',
            contractId: '@insertSpotList.contractId',
            bigBuyerId: '@insertSpotList.bigBuyerId',
            receivedAmount: '@insertSpotList.receiveAmount',
            buydetailId: -1,
            reporteryQ: '@insertSpotList.reporteryQ'
          }}
          this.postDataPramas.data[1].children[1] = { 'name': 'insertPartRepertory', 'type': 'e', 'parammaps': {
            reportery: '@insertSpotList.amount',
            pastureId: Cookies.get('pastureid'),
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            providerId: '@insertSpotList.providerId',
            providerName: '@insertSpotList.providerName',
            brand: '@insertSpotList.brand',
            brandId: '@insertSpotList.brandId',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            contractId: '@insertSpotList.contractId'
          }}
          this.postDataPramas.data[2] = { 'name': 'updateBigPartTransfer', 'type': 'e', 'parammaps': {
            id: this.storage.id,
            statue: 1,
            laidCode: this.storage.laidCode
          }}
          ExecDataByConfig(this.postDataPramas).then(response => {
            console.log('新增保存发送参数', this.postDataPramas)
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getdataListParm.parammaps.inputDatetime = ''
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
          return true
        }
      } else {
        this.$notify({
          title: '',
          message: '请选择备件',
          type: 'warning',
          duration: 2000
        })
        return false
      }
    },
    form_edit(row) {
      this.storage = Object.assign({}, row) // copy obj
      this.defaultCheckedKeys = [this.temp.eqClassId]
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        // this.$refs['temp'].clearValidate()
      })
    },
    edit_dialog_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['storage'].validate(valid => {
        if (valid) {
          this.postDataPramas.common = { 'returnmap': '0' }
          this.postDataPramas.data = []
          this.postDataPramas.data[0] = { 'name': 'insertBigPartlaid', 'type': 'v', 'parammaps': {
            pastureId: this.storage.providerId,
            storageTime: this.storage.storageTime,
            laidCode: this.storage.laidCode,
            empId: this.storage.employeId,
            No1Id: this.storage.No1Id,
            laidType: this.storage.laidType
          }}
          // eslint-disable-next-line no-irregular-whitespace
          this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
          this.postDataPramas.data[1].children = []
          this.postDataPramas.data[1].children[0] = { 'name': 'insertPartlaid', 'type': 'e', 'parammaps': {
            bigId: '@insertSpotList.bigId',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            orderNumber: '@insertSpotList.orderNumber',
            providerId: '@insertSpotList.providerId',
            brandId: '@insertSpotList.brandId',
            storageAmount: '@insertSpotList.storageAmount',
            contractId: '@insertSpotList.contractId',
            bigBuyerId: '@insertSpotList.bigBuyerId',
            receivedAmount: '@insertSpotList.receivedAmount'
          }}
          this.postDataPramas.data[1].children[2] = { 'name': 'insertPartRepertory', 'type': 'e', 'parammaps': {
            reportery: '@insertSpotList.reportery',
            pastureId: '@insertSpotList.pastureId',
            locationId: '@insertSpotList.locationId',
            partId: '@insertSpotList.partId',
            partCode: '@insertSpotList.partCode',
            partName: '@insertSpotList.partName',
            providerId: '@insertSpotList.providerId',
            providerName: '@insertSpotList.providerName',
            brand: '@insertSpotList.brand',
            brandId: '@insertSpotList.brandId',
            specification: '@insertSpotList.specification',
            price: '@insertSpotList.price',
            unit: '@insertSpotList.unit',
            contractId: '@insertSpotList.contractId'
          }}
          ExecDataByConfig(this.postDataPramas).then(response => {
            console.log('编辑保存发送参数', this.postDataPramas)
            if (response.msg === 'fail') {
              this.$notify({
                title: '保存失败',
                message: response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.get_table_data()
              this.dialogFormVisible = false
              this.$notify({
                title: '',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },

    handleCurrentChange(val) {
        this.currentRow = val;
        console.log("currentRow",this.currentRow)
    },

    checkboxInit(row,index){
      // console.log(row)
      if(row.ProofCode){
        return 0
      } else {

        var data1 = new Date(row.creatTime)
        var data2 = new Date('2022-10-25')
        if(data1 > data2){ return 1 } else {return 0}

      }


    },



    //监听 - 表格 - 勾选
    change_table_selection(val) {
      this.selectList = val
      console.log('勾选数据selectList', this.selectList)
    },

    sapUpload(){




      const that = this
      console.log("currentRow ProofCode",this.currentRow.ProofCode)

      var send_data = this.selectList

      if(send_data.length == 0){
        that.$notify({ title: '失败', message: '请勾选数据！'  , type: 'error', duration: 2000 })
        return false
      }

      console.log(that.isSap)

      if(that.isSap == 1){

         that.isSap = 0
         SapLaid(send_data).then(response => {
              console.log('response', response)

              if (response.msg !== 'fail') {
                that.$notify({ title: '成功', message: '上传成功', type: 'success', duration: 2000 })
                that.selectList = []
                that.get_table_data()


                } else {
                  that.$notify({ title: '失败', message: '上传失败'  , type: 'error', duration: 2000 })
                }



            })



            console.log(that.isSap)

      } else {

        that.$notify({ title: '失败', message: '正在请求中，请稍等几秒钟后再点击'  , type: 'error', duration: 2000 })
      }

      setTimeout(() => {
              that.isSap = 1
            }, 3000)








      // //  if(true){
      // if(this.currentRow.ProofCode){
      //   //如果有这个值说明已经上传了，不用上传
      //   console.log("currentRow ProofCode 这个值说明已经上传了，不用上传")

      // } else {
      //   console.log("currentRow ProofCode没有这个值")
      //     const laidCode = this.currentRow.laidCode
      //     const creatTime = this.currentRow.creatTime
      //     console.log("laidCode",laidCode)

      //       console.log("laidCode",laidCode)
      //       var send_data = {
      //             "laidCode":laidCode,
      //             "storageTime":creatTime,
      //             "pastureid":Cookies.get('pastureid')

      //       }

      //       SapLaid(send_data).then(response => {
      //         console.log('response', response)

      //         if (response.msg !== 'fail') {
      //           that.$notify({ title: '成功', message: '上传成功', type: 'success', duration: 2000 })
      //           that.get_table_data()

      //           } else {
      //             that.$notify({ title: '失败', message: '上传失败'  , type: 'error', duration: 2000 })
      //           }

      //       })

      // }

    },
    handleDelate(row) {
      console.log('点击了删除')
      this.seeTemp = Object.assign({}, row)
      this.getdataListSee.parammaps.id = this.seeTemp.id
      this.getSeeList()
      MessageBox.confirm('确认删除此条信息？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        this.postDataPramas.data[0] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listSee }}
        this.postDataPramas.data[0].children = []
        this.postDataPramas.data[0].children[0] = { 'name': 'updatePartRepertoryDel', 'type': 'e', 'parammaps': {
          id: '@insertSpotList.id',
          contractId: '@insertSpotList.contractId',
          partCode: '@insertSpotList.partCode',
          pastureId: row.pastureId
        }}
        this.postDataPramas.data[0].children[1] = { 'name': 'deletePartLaid', 'type': 'e', 'parammaps': {
          id: '@insertSpotList.id'
        }}
        this.postDataPramas.data[0].children[2] = { 'name': 'updateBuydetailDel', 'type': 'e', 'parammaps': {
          storageAmount: '@insertSpotList.storageAmount',
          buydetailId: '@insertSpotList.buydetailId'
        }}
        this.postDataPramas.data[1] = { 'name': 'deleteBigPartLaid', 'type': 'e', 'parammaps': {
          id: row.id
        }}
        ExecDataByConfig(this.postDataPramas).then(response => {
          this.get_table_data()
          this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },
    changeStorageType(val) {
      console.log('入库方式', val)
      this.TotalAmount = 0
      if (val === 0) { // No1采购 No2 手动
        this.No2 = false
        this.No1 = true
        this.No3 = false
        this.disabled = true
        this.listAdd = []
        this.isProvider = true
        this.isWarehoseCode = true
        this.isWarehoseCodeAllo = false
        this.isSumPrice = true
        this.isDel = true
      } else if (val === 1) {
        this.No2 = true
        this.No1 = false
        this.No3 = false
        this.disabled = false
        this.listAdd = []
        this.isProvider = true
        this.isWarehoseCode = true
        this.isWarehoseCodeAllo = false
        this.isSumPrice = true
        this.isDel = true
      } else if (val === 2) {
        this.No1 = false
        this.No2 = false
        this.No3 = true
        this.listAdd = []
        this.isProvider = false
        this.isWarehoseCode = false
        this.isWarehoseCodeAllo = true
        this.isSumPrice = false
        this.isDel = false
      }
    },
    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.$notify({
            title: '失败',
            message: '导入失败:' + res.data.err_count + '条!',
            type: 'danger',
            duration: 2000
          })
           import('@/vendor/Export2Excel').then(excel => {
             const list1 = res.data.result
             const tHeader = [
               '牧场', '入库单编号', '入库日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '数量', '单价', '总价', '库位', '供应商', 'error_msg'
             ]
             const filterVal = [
               '牧场', '入库单编号', '入库日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '数量', '单价', '总价', '库位', '供应商', 'error_msg'
             ]
             const data1 = this.formatJson(filterVal, list1)
             excel.export_json_to_excel({
               header: tHeader,
               data: data1,
               filename: this.requestParam.parammaps.formType,
               autoWidth: true,
               bookType: 'xlsx'
             })
           })
        }
      } else {
        this.$notify({
          title: '失败',
          message: '上传失败',
          type: 'danger',
          duration: 2000
        })
      }
    },
    handleDownload() {
      console.log('点击了导出')
      this.$alert('备件入库信息正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      this.isPercentage = true
      this.percentage = 1
      var timer = setInterval(() => {
        this.percentage += 5
        if (this.percentage > 95) {
          this.percentage = 99
          clearInterval(timer)
        }
        this.percentage = this.percentage
      }, 1000)
      this.requestParam.parammaps.formType = '备件入库信息'
      this.requestParam.parammaps.inputDatetime = this.getdataListParm.parammaps.inputDatetime
      this.requestParam.parammaps.pastureName = this.getdataListParm.parammaps.pastureName
      this.requestParam.parammaps.laidCode = this.getdataListParm.parammaps.laidCode
      this.requestParam.parammaps.laidType = this.getdataListParm.parammaps.laidType
      this.requestParam.parammaps.startTime = this.getdataListParm.parammaps.startTime
      this.requestParam.parammaps.stopTime = this.getdataListParm.parammaps.stopTime
      GetAccount(this.requestParam).then(response => {
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            this.$set(response.data.list[i], 'storageAmount', parseFloat(response.data.list[i].storageAmount))
            this.$set(response.data.list[i], 'price', parseFloat(response.data.list[i].price))
            this.$set(response.data.list[i], 'sumPrice', parseFloat(response.data.list[i].sumPrice))
            if(response.data.list[i].sterilisation == 1){
              this.$set(response.data.list[i], 'sterilisation', "已冲销")
            } else {
              this.$set(response.data.list[i], 'sterilisation', "未冲销")
            }
          }
        }
        this.$nextTick(() => {
          const ExcelDatas = [
            {
              tHeader: ['牧场', '入库单编号', '入库日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '数量', '单价', '总价', '库位', '供应商','冲销状态', 'error_msg'],
              filterVal: ['pastureName', 'laidCode', 'creatTime', 'partCode', 'partName', 'specification', 'brandName', 'unit', 'storageAmount', 'price', 'sumPrice', 'warehoseCode', 'providerName', 'sterilisation', ''],
              tableDatas: response.data.list,
              sheetName: '备件入库信息'
            }
          ]
          json2excel(ExcelDatas, '备件入库信息', true, 'xlsx')
        })
      })
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    // -------------------------------------------
    No1Search(queryString, cb) {
      console.log('采购单号模糊查询输入值', queryString)
      this.requestFilterParams.name = 'findPurchaseSolr'
      this.requestFilterParams.parammaps = {}
      this.requestFilterParams.parammaps['orderA'] = queryString
      this.requestFilterParams.parammaps['pastureId'] = this.$store.state.user.pastureid
      GetDataByName(this.requestFilterParams).then(response => {
        // console.log(response.data.list)
        cb(response.data.list)
      })
    },
    handleSelectPurchase(item) {
      console.log(item)
    },

    // 导出模板
    handleDownloadTemp() {
      this.requestParam.name = 'stockLaidDownTemp'
      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]
          }
        })
      )
    },
    handleDownloadEas1() {
      this.$alert('备件入库EAS信息正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      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 = 'downloadPartLaidEASYuan'
      this.requestParam.parammaps.inputDatetime = this.getdataListParm.parammaps.inputDatetime
      this.requestParam.parammaps.pastureName = this.getdataListParm.parammaps.pastureName
      this.requestParam.parammaps.laidCode = this.getdataListParm.parammaps.laidCode
      this.requestParam.parammaps.laidType = this.getdataListParm.parammaps.laidType
      this.requestParam.parammaps.startTime = this.getdataListParm.parammaps.startTime
      this.requestParam.parammaps.stopTime = this.getdataListParm.parammaps.stopTime
      GetAccount(this.requestParam).then(response => {
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        this.$nextTick(() => {
          import('@/vendor/Export2Excel').then(excel => {
            if (response.data.list !== null) {
              for (let i = 0; i < response.data.list.length; i++) {
                this.$set(response.data.list[i], '数量', parseFloat(response.data.list[i]['数量']))
                this.$set(response.data.list[i], '总价', parseFloat(response.data.list[i]['总价']))
                this.$set(response.data.list[i], '单价', parseFloat(response.data.list[i]['单价']))
              }
            }
            const list1 = response.data.list
            console.log(list1)
            const tHeader = [
              '牧场', '入库单编号', '入库日期', '供应商编码', '供应商', '入库人', '制单日期', '品名', '物料编码', '计量单位', '单价', '数量', '总价', '备注'
            ]
            const filterVal = [
              '牧场', '入库单编号', '入库日期', '供应商编码', '供应商', '入库人', '制单日期', '品名', '物料编码', '计量单位', '单价', '数量', '总价', '备注'
            ]

            // const tmerges=['B1:D2']
            if (list1 !== null) {
              const data1 = this.formatJsonTemp(filterVal, list1)
              excel.export_json_to_excel({
                // merges: tmerges,
                // multiHeader: tmultiHeader,
                header: tHeader,
                data: data1,
                filename: '备件入库EAS：',
                autoWidth: true,
                bookType: 'xlsx'
              })
            } else {
              this.$notify({
                title: '',
                message: '无备件领用完成信息，无法导出!',
                type: 'warning',
                duration: 2000
              })
            }
          })
        })
      })
    },
    // 导出
    handleDownloadEas() {
      this.$alert('备件入库EAS信息正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      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 = 'downloadPartLaidEAS'
      this.requestParam.parammaps.useForm = this.getdataListParm.parammaps.useForm
      this.requestParam.parammaps.createTime = this.getdataListParm.parammaps.createTime
      this.requestParam.parammaps.createTime = this.getdataListParm.parammaps.useStatus
      GetAccount(this.requestParam).then(response => {
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        this.$nextTick(() => {
          import('@/vendor/Export2Excel').then(excel => {
            const list1 = response.data.list
            const tHeader = [
              '*单据编号', '*业务日期', '*事务类型_编码', '事务类型_名称_l2', '付款方式_名称_l2', '*供应商_编码', '供应商_名称_l2', '创建者_用户名', '制单日期', '币别_编码', '*库存组织_编码', '库存组织_名称_l2', '成本中心_编码', '成本中心_名称_l2', '折算方式', '是否价外税', '是否含税', '是否是初始化单', '*汇率', '摘要', '部门_编码', '*采购入库单分录$仓库_编码', '采购入库单分录$仓管员_编码', '采购入库单分录$库位_编码', '采购入库单分录$物料_名称_l2', '*采购入库单分录$物料_编码', '*采购入库单分录$计量单位_编码', '采购入库单分录$辅助属性_编码', '采购入库单分录$采购员_编码', '采购入库单分录$采购组_编码', '*采购入库单分录$采购组织_编码', '采购入库单分录_供应商批次号', '采购入库单分录_单价', '采购入库单分录_实际单价', '*采购入库单分录_数量', '采购入库单分录_辅助数量', '采购入库单分录_单位材料成本', '采购入库单分录_单位采购成本', '采购入库单分录_含税单价', '采购入库单分录_金额', '采购入库单分录_税率', '采购入库单分录_税额', '采购入库单分录_价税合计', '采购入库单分录_实际含税单价', '采购入库单分录_实际成本', '采购入库单分录_采购成本', '采购入库单分录_采购费用', '采购入库单分录_材料成本', '采购入库单分录_本位币税额', '采购入库单分录_本位币价税合计', '采购入库单分录_批次', '采购入库单分录_生产日期', '采购入库单分录_到期日期', '采购入库单分录_折扣', '采购入库单分录_折扣率', '采购入库单分录_是否完全核销', '采购入库单分录_是否赠品', '采购入库单分录_备注', '采购入库单分录$项目号_编码', '采购入库单分录$跟踪号_编码', '业务类型_编码', '业务类型_名称'
            ]
            const filterVal = [
              '*单据编号', '*业务日期', '*事务类型_编码', '事务类型_名称_l2', '付款方式_名称_l2', '*供应商_编码', '供应商_名称_l2', '创建者_用户名', '制单日期', '币别_编码', '*库存组织_编码', '库存组织_名称_l2', '成本中心_编码', '成本中心_名称_l2', '折算方式', '是否价外税', '是否含税', '是否是初始化单', '*汇率', '摘要', '部门_编码', '*采购入库单分录$仓库_编码', '采购入库单分录$仓管员_编码', '采购入库单分录$库位_编码', '采购入库单分录$物料_名称_l2', '*采购入库单分录$物料_编码', '*采购入库单分录$计量单位_编码', '采购入库单分录$辅助属性_编码', '采购入库单分录$采购员_编码', '采购入库单分录$采购组_编码', '*采购入库单分录$采购组织_编码', '采购入库单分录_供应商批次号', '采购入库单分录_单价', '采购入库单分录_实际单价', '*采购入库单分录_数量', '采购入库单分录_辅助数量', '采购入库单分录_单位材料成本', '采购入库单分录_单位采购成本', '采购入库单分录_含税单价', '采购入库单分录_金额', '采购入库单分录_税率', '采购入库单分录_税额', '采购入库单分录_价税合计', '采购入库单分录_实际含税单价', '采购入库单分录_实际成本', '采购入库单分录_采购成本', '采购入库单分录_采购费用', '采购入库单分录_材料成本', '采购入库单分录_本位币税额', '采购入库单分录_本位币价税合计', '采购入库单分录_批次', '采购入库单分录_生产日期', '采购入库单分录_到期日期', '采购入库单分录_折扣', '采购入库单分录_折扣率', '采购入库单分录_是否完全核销', '采购入库单分录_是否赠品', '采购入库单分录_备注', '采购入库单分录$项目号_编码', '采购入库单分录$跟踪号_编码', '业务类型_编码', '业务类型_名称'
            ]
            const tmultiHeader = [['EAS', '7.5.0', '采购（委外）入库单导入',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
            ['purInWarehs', '采购（委外）入库单导入', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
              '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''],
            ['FNumber', 'FBizDate', 'FTransactionType_number', 'FTransactionType_name_l2', 'FPaymentType_name_l2', 'FSupplier_number', 'FSupplier_name_l2', 'FCreator_number', 'FCreateTime', 'FCurrency_number', 'FStorageOrgUnit_number', 'FStorageOrgUnit_name_l2', 'FCostCenterOrgUnit_number', 'FCostCenterOrgUnit_name_l2', 'FConvertMode', 'FIsPriceInTax', 'FIsInTax', 'FIsInitBill', 'FExchangeRate', 'FDescription', 'FAdminOrgUnit_number', 'FEntry$warehouse_number', 'FEntry$stocker_number', 'FEntry$location_number', 'FEntry$material_name_l2', 'FEntry$material_number', 'FEntry$unit_number', 'FEntry$assistProperty_number', 'FEntry$No1Person_number', 'FEntry$No1Group_number', 'FEntry$No1OrgUnit_number', 'FEntry_supplierLotNo', 'FEntry_price', 'FEntry_actualPrice', 'FEntry_qty', 'FEntry_assistQty', 'FEntry_unitMaterialCost', 'FEntry_unitPurchaseCost', 'FEntry_taxPrice', 'FEntry_amount', 'FEntry_taxRate', 'FEntry_tax', 'FEntry_taxAmount', 'FEntry_actualTaxPrice', 'FEntry_actualCost', 'FEntry_No1Cost', 'FEntry_No1Fee', 'FEntry_materialCost', 'FEntry_localTax', 'FEntry_localTaxAmount', 'FEntry_lot', 'FEntry_mfg', 'FEntry_exp', 'FEntry_discountAmount', 'FEntry_discountRate', 'FEntry_isFullWriteOff', 'FEntry_isPresent', 'FEntry_remark', 'FEntry$project_number', 'FEntry$trackNumber_number', 'FBizType_number', 'FBizType_name_l2'
            ]]
            // const tmerges=['B1:D2']
            if (list1 !== null) {
              const data1 = this.formatJsonTemp(filterVal, list1)
              excel.export_json_to_excel({
                // merges: tmerges,
                multiHeader: tmultiHeader,
                header: tHeader,
                data: data1,
                filename: '备件入库EAS：',
                autoWidth: true,
                bookType: 'xlsx'
              })
            } else {
              this.$notify({
                title: '',
                message: '无备件领用完成信息，无法导出!',
                type: 'warning',
                duration: 2000
              })
            }
          })
        })
      })
    },
    // 导出

    // 导入
    beforeImportExcel(file) {
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 10MB!')
      }
      return isLt2M
    },

    handleformNameSelect(item) {
      this.temp.assetName = item.assetName
      this.temp.assetId = item.assetId
      this.temp.deptName = item.deptName
      this.temp.pastureName = item.pastureName
    },
    formNumberSearch(queryString, cb) {
      this.requestFilterParams.name = 'findAssetM'
      this.requestFilterParams.parammaps['pastureId'] = Cookies.get('pastureid')
      this.requestFilterParams.parammaps['assetName'] = queryString
      GetDataByName(this.requestFilterParams).then(response => {
        if (response.data.list === null) {
          this.formNumberSearchList = []
        } else {
          this.formNumberSearchList = response.data.list
        }
        console.log(this.formNumberSearchList)
        var results = queryString ? this.formNumberSearchList.filter(this.createFilter(queryString)) : this.formNumberSearchList
        cb(results)
      })
    },

    handleEAS() {
      this.easStatus.dialogStatus = 'easStatus'
      this.easStatus.dialogFormVisible = true
      this.get_table_dataEasStatusLst()
    },
    get_table_dataEasStatusLst() {
      this.easStatus.listLoading = true
      GetDataByName(this.easStatus.getdataListParm).then(response => {
        if (response.data.list !== null) {
          this.easStatus.list = response.data.list
        } else {
          this.easStatus.list = []
        }
        this.easStatus.pageNum = response.data.pageNum
        this.easStatus.pageSize = response.data.pageSize
        if (response.data.total) {
          this.easStatus.total = response.data.total
        }
      })
      setTimeout(() => {
        this.easStatus.listLoading = false
      }, 100)
    },

    handleClose(row) {
      MessageBox.confirm('是否确认关闭同步此数据？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam = {}
        this.requestPam.name = 'updatebigpartlaidSync'
        this.requestPam.parammaps = {}
        this.requestPam.parammaps.issync = '2'
        this.requestPam.parammaps.id = row.id
        PostDataByName(this.reestParam).then((response) => {
          if (response.msg !== 'fl') {
            this.$notify({ title: '成功', message: '关闭同步成功', type: 'success', duration: 2000 })
            this.getLitEasStatusLs()
            this.get_table_data()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.getLiEasStatusLst()
            this.get_table_data()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消关闭同步' })
      })
    },
    handleManual(row) {
      MessageBox.confirm('是否确认同步此数据至EAS？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam = {}
        this.requestParam.typeIn = row.typeIn
        this.requestParam.billCode = row.billCode
        EasSync(this.requestParam).then((response) => {
          if (response.msg !== 'fail') {
            this.$notify({ title: '成功', message: '手动同步成功', type: 'success', duration: 2000 })
            this.get_table_dataEasStatusLst()
            this.get_table_data()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.get_table_dataEasStatusLst()
            this.get_table_data()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消手动同步' })
      })
    },
    handleIgnore(row) {
      MessageBox.confirm('是否确认忽略同步此数据？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam = {}
        this.requestParam.name = 'updatebigpartlaidSync'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.issync = '3'
        this.requestParam.parammaps.id = row.id
        PostDataByName(this.requestParam).then((response) => {
          if (response.msg !== 'fail') {
            this.$notify({ title: '成功', message: '忽略同步成功', type: 'success', duration: 2000 })
            this.get_table_dataEasStatusLst()
            this.get_table_data()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.get_table_dataEasStatusLst()
            this.get_table_data()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消忽略同步' })
      })
    }

  }
}
</script>
<style lang="scss">
  .inputDatetime .el-range-separator{
   padding: 0;
   margin: 0 10px;
  }
  .el-radio__label{
    padding-left: 2px !important;
  }
</style>
<style lang="scss" scoped>
  .el-radio{
    margin-right: 5px;
  }
</style>
