<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.orderNumber" 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.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-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
          <div>
            <el-button v-if="isRetreatAdd" class="filter-item" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
            <el-button v-if="isEasSynchronization" class="filter-item" type="primary" style="float: right;" @click="handleEAS">EAS同步</el-button>

            <el-button   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"
          @selection-change="change_table_selection"
          @current-change="handleCurrentChange"
        >
        <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="出库单号" min-width="150px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.useForm }}</span>
            </template>
          </el-table-column>
          <el-table-column label="牧场" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.pastureName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="部门" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.departmentName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="录入人" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.quitName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="退库日期" sortable prop="quitDate" min-width="80px" 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 label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <el-button v-if="isRetreatSee" type="primary" size="mini" @click="form_see(row)">查看</el-button>
              <el-button v-if="isRetreatDelate" 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="getList" />
      </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.useForm" 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" style="width: 140px;" filterable clearable placeholder="供应商" class="filter-item">
            <el-option v-for="item in findAllProvider" :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-button v-if="isRetreatExport" v-waves class="filter-item" type="success" icon="el-icon-upload2" @click="handleDownload">导出</el-button>
          </div>
        </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="tableSort1"
        >
          <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.useForm }}</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.brand }}</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.location }}</span>
            </template>
          </el-table-column>
          <el-table-column label="出库数量" sortable prop="useNumber" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.useNumber }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="退库数量" sortable prop="quitNumber" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.quitNumber }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="单价" sortable prop="price" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span><br>
            </template>
          </el-table-column>
          <el-table-column label="总价" sortable prop="sumPrice" 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.note }}</span>
            </template>
          </el-table-column>
          <el-table-column label="录入人" align="center" min-width="90px">
            <template slot-scope="scope">
              <span>{{ scope.row.quitName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="退库日期" min-width="120px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.quitDate }}</span><br>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total2>0" :total="total2" :page.sync="getdataListParm2.offset" :limit.sync="getdataListParm2.pagecount" @pagination="getList2" />
      </el-tab-pane>
    </el-tabs>
    <!-- 弹出层新增or修改 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="app-container">
        <el-form ref="createTemp" :rules="rules" :model="createTemp" label-position="right" label-width="100px" style="width: 90%;margin:0 auto;">
          <el-row>
            <el-col :span="8">
              <el-form-item label="出库单号：" prop="applyCode">
                <el-autocomplete
                  v-model="createTemp.applyCode"
                  value-key="useForm"
                  class="inline-input"
                  :fetch-suggestions="spareNumberSearch"
                  placeholder="请输入出库单号"
                  style="width:100%"
                  @select="handleSelectSpareNumber"
                  @blur="handleBlurSpareNumber"
                >
                  <template slot-scope="{ item }">
                    <span class="addr">{{ item.useForm }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="牧场：" prop="pastureId">
                <el-select v-model="createTemp.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="deptId">
                <el-select v-model="createTemp.deptId" placeholder="部门" class="filter-item" style="width:100%">
                  <el-option
                    v-for="item in findAllDepart"
                    :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="quitId">
                <el-select v-model="createTemp.quitId" 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-col :span="8">
              <el-form-item label="退库日期" prop="quitDate">
                <el-date-picker
                  v-model="createTemp.quitDate"
                  :picker-options="pickerOptions"
                  type="date"
                  placeholder="退库日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width:100%"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="退库原因:" prop="note">
                <el-input ref="note" v-model="createTemp.note" placeholder="退库原因" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="备件：" prop="partCode">
                <el-autocomplete
                  v-model="createTemp.partCode"
                  value-key="name"
                  class="inline-input"
                  :fetch-suggestions="sparePartSearch"
                  placeholder="请输入备件编号或备件名称或备件规格"
                  style="width:550px"
                  @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-form>
        <h5 style="float:right;">总金额：{{ TotalAmount }}</h5>
        <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表格 -->
          <el-table-column label="序号" align="center" type="index" width="50px" />
          <el-table-column label="备件编号" prop="partCode" align="center" min-width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" prop="partName" align="center" min-width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" prop="specification" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件图片" prop="picpath" min-width="110px" align="center">
            <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="60">
            <template slot-scope="scope">
              <span>{{ scope.row.brandName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" prop="providerName" align="center" min-width="60">
            <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="60">
            <template slot-scope="scope">
              <span>{{ scope.row.warehoseCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="已退库数量" prop="quitNumberC" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.quitNumberC }}</span>
            </template>
          </el-table-column>
          <el-table-column label="已出库数量" prop="checkoutNumber" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.checkoutNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column label="退库数量" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="quitNumber">
                  <el-input v-model="scope.row.quitNumber" style="margin-top:15px" @blur="blurQuitNumber" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="单价" min-width="110px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总价" min-width="110px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.price * parseFloat(scope.row.quitNumber) | keepTwoNum }}</span>
            </template>
          </el-table-column>
          <el-table-column 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>
        <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;getList()">取消并关闭</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 查看 -->
    <el-dialog :title="textMap[dialogStatusSee]" :visible.sync="dialogFormVisibleSee" :close-on-click-modal="false" width="90%">
      <div class="app-containerSee">
        <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="useForm">
                <el-input ref="useForm" v-model="seeTemp.useForm" 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="departmentName">
                <el-input ref="departmentName" v-model="seeTemp.departmentName" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="quitName">
                <el-input ref="quitName" v-model="seeTemp.quitName" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="退库日期：" prop="quitDate">
                <el-input ref="quitDate" v-model="seeTemp.quitDate" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="退库原因：" prop="note">
                <el-input ref="note" v-model="seeTemp.note" 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"
          @sort-change="tableSort2"
        >
          <el-table-column label="序号" align="center" type="index" width="50px" />
          <el-table-column label="备件编号" prop="partCode" align="center" min-width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" prop="partName" align="center" min-width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" prop="specification" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件图片" prop="picpath" min-width="110px" align="center">
            <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="brand" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.brand }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" prop="providerName" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库位" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.location }}</span>
            </template>
          </el-table-column>
          <el-table-column label="已退库数量" sortable prop="applyNumber" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.applyNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column label="已出库数量" sortable prop="useNumber" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.useNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column label="退库数量" sortable prop="quitNumber" min-width="120px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.quitNumber }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价" sortable prop="price" min-width="110px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总价" sortable prop="sumPrice" min-width="110px" align="center" valign="middle">
            <template slot-scope="scope">
              <span>{{ scope.row.sumPrice }}</span>
            </template>
          </el-table-column>
        </el-table>
        <div slot="footer" class="dialog-footer" style="bottom:5px;">
          <el-button @click="dialogFormVisibleSee = 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="useForm" />
          <el-table-column label="牧场" min-width="110px" align="center" prop="pastureName" />
          <el-table-column label="部门" min-width="110px" align="center" prop="departmentName" />
          <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="getListEasStatusLst" />
      </div>
      <div slot="footer" class="dialog-footer" style="bottom: 10px;">
        <el-button @click="easStatus.dialogFormVisible = false;getList()">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// / 引入
import { GetDataByName, GetDataByNames, ExecDataByConfig, GetAccount, PostDataByName, EasSync, checkButtons,SapQuit } 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'
export default {
  isSap:1,
      isSrm:1,
  selectList: [],
  name: 'Retreat',
  components: { Pagination },
  directives: { waves },
  filters: {
    keepTwoNum(value) {
      value = Number(value)
      return value.toFixed(2)
    }
  },
  data() {
    return {
      buttons: [],

      currentRow:{},
      isRetreatsap: [],
      isRetreatSee: [], isRetreatExport: [], isRetreatAdd: [], isRetreatDelate: [],
      isEasSynchronization: [], isManualSynchronization: [], isCloseSynchronization: [], isIgnoreSynchronization: [],
      isokDisable: false,
      findAllProvider: [],
      findAllPasture: [],
      findAllDepart: [],
      findAllEmploye: [],
      requestParams: [
        { name: 'findAllProvider', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid'), 'eId': Cookies.get('employeid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }}
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()// 当天之前的时间可选
        }
      },
      textMap: {
        zgExamine: '主管审核',
        kgExamine: '库管审核',
        zlExamine: '审核',
        update: '编辑',
        create: '新增',
        see: '查看',
        ImportInfo: '导入信息',
        easStatus: 'EAS同步—同步失败数据'
      },
      rules: {
        applyCode: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      statues: [{ id: '1', name: '审核中' }, { id: '2', name: '已通过' }, { id: '3', name: '未通过' }],
      getdataListParm: {
        name: 'getBigPartquitlist',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureName: Cookies.get('pasturename'),
          useForm: '',
          inputDatetime: '',
          startTime: '',
          stopTime: '',
          easStatus: ''
        }
      },
      tableKey: 0,
      listLoading: true,
      total: 0,
      list: [],

      activeName: 'first',
      tableKey2: 0,
      listLoading2: true,
      total2: 0,
      list2: [],
      getdataListParm2: {
        name: 'getPartquitDetaillist',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          inputDatetime: '',
          useForm: '',
          startTime: '',
          stopTime: '',
          partCode: '',
          partName: '',
          providerId: '',
          pastureName: Cookies.get('pasturename')
        }
      },

      requestParam: {
        name: 'insertAsset',
        offset: 0,
        pagecount: 0,
        parammaps: {}
      },
      listLoadingSee: true,
      listSee: [],
      totalSee: 0,
      dialogStatusSee: '',
      dialogFormVisibleSee: false,
      seeTemp: {},
      getdataListSee: {
        name: 'getPartquitlist',
        returntype: 'Map',
        parammaps: {}
      },
      dialogFormVisible: false,
      dialogStatus: '',
      createTemp: {
        useForm: '',
        applyCode: '',
        quitDate: parseTime(new Date(), '{y}-{m}-{d}'),
        deptId: this.$store.state.user.departmentid,
        quitId: this.$store.state.user.employeid,
        note: '',
        pastureId: this.$store.state.user.pastureid
      },
      requestSparePart: {
        name: 'getpartUseListBybigTK',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {}
      },
      requestSpareNumber: {
        name: 'getBigpartusecode',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid')
        }
      },
      getParmCreateAmount: {
        name: 'getPartsAmountList',
        page: 0,
        offset: 0,
        pagecount: 0,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid')
        }
      },
      listAdd: [],
      postDataPramas: {},
      downloadParam: {},
      TotalAmount: 0,
      isPercentage: false,
      percentage: 1,
      // EAS同步
      easStatus: {
        easStatusList: [{ name: '同步成功', id: '1' }, { name: '同步失败', id: '0' }, { name: '关闭同步', id: '2' }],
        dialogStatus: '',
        dialogFormVisible: false,
        tableKey: 0,
        total: 0,
        listLoading: true,
        list: [],
        getdataListParm: {
          name: 'getbigpartquitSync',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        }
      }
    }
  },

  computed: {

  },
  watch: {
    listAdd: {
      deep: true,
      handler: function (item) {
          this.listAdd.forEach(function(i){
            if(parseInt(i.quitNumber) > (parseInt(i.checkoutNumber)-parseInt(i.quitNumberC))){
              i.quitNumber = parseInt(i.checkoutNumber)-parseInt(i.quitNumberC)
            }
                
          })  
      }
    },
  },
  created() {
    const that = this
    GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
      that.buttons = response.data.list
      console.log(that.buttons, 'that.buttons')
      that.get_auto_buttons()
    })
    this.get_select_list()
    this.getList()
  },

  methods: {
    tableSort1(column) {
      sortChange(column, this.list2)
    },
    tableSort2(column) {
      sortChange(column, this.listSee)
    },
    get_auto_buttons() {
      const RetreatAdd = 'customs:Retreat:add'
      const isRetreatAdd = checkButtons(this.$store.state.user.buttons, RetreatAdd)
      this.isRetreatAdd = isRetreatAdd


      const Retreatsap = 'customs:Retreat:sap'
      const isRetreatsap = checkButtons(this.$store.state.user.buttons, Retreatsap)
      this.isRetreatsap = isRetreatsap

      const RetreatSee = 'customs:Retreat:see'
      const isRetreatSee = checkButtons(this.$store.state.user.buttons, RetreatSee)
      this.isRetreatSee = isRetreatSee
      const RetreatExport = 'customs:Retreat:export'
      const isRetreatExport = checkButtons(this.$store.state.user.buttons, RetreatExport)
      this.isRetreatExport = isRetreatExport
      const RetreatDelate = 'customs:Retreat:delate'
      const isRetreatDelate = checkButtons(this.$store.state.user.buttons, RetreatDelate)
      this.isRetreatDelate = isRetreatDelate

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

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

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

      const IgnoreSynchronization = 'customs:retreat:ignoreSynchronization'
      const isIgnoreSynchronization = checkButtons(this.$store.state.user.buttons, IgnoreSynchronization)
      this.isIgnoreSynchronization = isIgnoreSynchronization
    },
    getList() {
      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
        }
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },
    statue: function(cellValue) {
      // console.log(cellValue.isZeroStock)
      if (cellValue.statue == 0) {
        return '审核中'
      } else if (cellValue.statue == 1) {
        return '已通过'
      } else {
        return '未通过'
      }
    },
    form_search() {
      console.log('点击了table搜索')
      if (this.getdataListParm.parammaps.inputDatetime === null) {
        this.getdataListParm.parammaps.inputDatetime = ''
      }
      this.getdataListParm.offset = 1
      this.listLoading = true
      this.getList()
    },
    handleClick(tab, event) {
      console.log(tab, event)
      if (tab.name === 'second') {
        this.getList2()
      } else {
        this.getList()
      }
    },
    getList2() {
      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.getList2()
    },
    resetCreateTemp() {
      this.createTemp.useForm = ''
      this.createTemp.pastureId = this.$store.state.user.pastureid
      this.createTemp.deptId = this.$store.state.user.departmentid
      this.createTemp.applyCode = ''
      this.createTemp.note = ''
      this.createTemp.quitId = this.$store.state.user.employeid
      this.createTemp.quitDate = parseTime(new Date(), '{y}-{m}-{d}')
      this.listAdd = []
      this.TotalAmount = 0
      this.createTemp.id = ''
    },
    form_add() {
      this.resetCreateTemp()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
    },
    spareNumberSearch(queryString, cb) {
      console.log('出库单号模糊查询输入值', queryString)
      this.requestSpareNumber.parammaps['applyCode'] = queryString
      GetDataByName(this.requestSpareNumber).then(response => {
        console.log('出库单号模糊查询搜索data', response.data.list)
        cb(response.data.list)
      })
    },
    handleSelectSpareNumber(item) {
      console.log('出库单号模糊查询选中值', item)
      console.log('出库单号模糊查询选中值', item.id)
      this.createTemp.applyCode = item.useForm
      this.createTemp.id = item.id
      this.listAdd = []
      this.TotalAmount = 0
      this.$forceUpdate()
    },
    sparePartSearch(queryString, cb) {
      console.log('备件模糊查询输入值', queryString)
      this.requestSparePart.parammaps.id = this.createTemp.id
      this.requestSparePart.parammaps['partCode'] = queryString
      GetDataByName(this.requestSparePart).then(response => {
        console.log('备件模糊查询搜索data', response.data.list)
        if (response.data.list == null) {
          cb([])
        } else {
          cb(response.data.list)
        }
      })
    },

    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
      
         SapQuit(send_data).then(response => {
              console.log('response', response)
                
              if (response.msg !== 'fail') {
                that.$notify({ title: '成功', message: '上传成功', type: 'success', duration: 2000 })

                that.selectList = []
                that.getList()
                
                } else {
                  that.$notify({ title: '失败', message: '上传失败'  , type: 'error', duration: 2000 })
                }
            })
            
      } 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没有这个值")
      //   console.log("currentRow ProofCode",this.currentRow.ProofCode)
      //     const useForm = this.currentRow.useForm 
      //     const creatTime = this.currentRow.creatTime 
      //     console.log("useForm",useForm)
      //       var send_data = {
      //             "useForm":useForm,
      //             "quitDate":creatTime,
      //             "pastureid":Cookies.get('pastureid')
              
      //       }
      //       SapQuit(send_data).then(response => {
      //         console.log('response', response)
                
      //         if (response.msg !== 'fail') {
      //           that.$notify({ title: '成功', message: '上传成功', type: 'success', duration: 2000 })

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

    },

    handleBlurSpareNumber() {
      this.createTemp.applyCode = ''
      this.createTemp.id = ''
    },
    handleSelectSparePart(item) {
      console.log('备件模糊查询选中值', item)
      this.$set(item, 'sumPrice', (parseFloat(item.quitNumber) * parseFloat(item.price)).toFixed(2))
      console.log('备件模糊查询选中值', item.id)
      console.log(this.listAdd)
      this.TotalAmount = 0

      if (this.listAdd.length > 0) {
        if (this.listAdd.find(obj => obj.id === item.id)) {
          this.$message({
            type: 'warning',
            message: '此备件已存在，请重新选择备件'
          })
          for (let i = 0; i < this.listAdd.length; i++) {
            this.TotalAmount += parseFloat(this.listAdd[i].quitNumber) * parseFloat(this.listAdd[i].price)
            this.TotalAmount = parseFloat((this.TotalAmount).toFixed(2))
          }
        } else {
          this.getParmCreateAmount.parammaps.partCode = item.partCode
          GetDataByName(this.getParmCreateAmount).then(response => {
            this.$nextTick(() => {
              console.log('新增根据编号获取备件库存数量', response.data.list[0].reporteryNum)
              item.reportery = response.data.list[0].reporteryNum
              this.listAdd.unshift(item)
              for (let i = 0; i < this.listAdd.length; i++) {
                this.TotalAmount += parseFloat(this.listAdd[i].quitNumber) * parseFloat(this.listAdd[i].price)
                this.TotalAmount = parseFloat((this.TotalAmount).toFixed(2))
              }
              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.$forceUpdate()
            })
          })
          console.log(this.listAdd.length)
        }
      } else {
        this.getParmCreateAmount.parammaps.partCode = item.partCode
        GetDataByName(this.getParmCreateAmount).then(response => {
          this.$nextTick(() => {
            console.log('新增根据编号获取备件库存数量', response.data.list[0].reporteryNum)
            this.$set(item, 'reportery', response.data.list[0].reporteryNum)
            // item.reportery = response.data.list[0].reporteryNum
            this.listAdd.unshift(item)
            for (let i = 0; i < this.listAdd.length; i++) {
              this.TotalAmount += parseFloat(this.listAdd[i].quitNumber) * parseFloat(this.listAdd[i].price)
              this.TotalAmount = parseFloat((this.TotalAmount).toFixed(2))
            }

            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.$forceUpdate()
          })
        })
      }
      this.$forceUpdate()
    },
    blurQuitNumber() {
      this.TotalAmount = 0
      for (let i = 0; i < this.listAdd.length; i++) {
        // console.log((parseFloat(this.listAdd[i].price) * parseFloat(this.listAdd[i].quitNumber)).toFixed(2))
        this.TotalAmount += parseFloat(this.listAdd[i].price) * parseFloat(this.listAdd[i].quitNumber)
        this.TotalAmount = parseFloat((this.TotalAmount).toFixed(2))
      }
    },
    add_dialog_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          console.log(this.listAdd)
          if (this.listAdd.length !== 0) {
            for (var j = 0; j < this.listAdd.length; j++) {
              console.log(this.listAdd[j].refundNumber)
              // eslint-disable-next-line use-isnan
              if (this.listAdd[j].quitNumber == null || this.listAdd[j].quitNumber === '') {
                this.$message({
                  type: 'warning',
                  message: '请检查退库数量是否未填写',
                  duration: 2000
                })
                return false
              } else {
                var rulesQuitNumber = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
                console.log(this.listAdd[j].quitNumber)
                console.log(this.listAdd[j].checkoutNumber)
                // 领用数量quitNumberC已出库数量checkoutNumber退库数量quitNumber
                console.log('退库数量', this.listAdd[j].quitNumber)
                console.log('已出库数量', this.listAdd[j].checkoutNumber)
                console.log('领用数量', this.listAdd[j].quitNumberC)
                var minNumber = parseFloat(this.listAdd[j].checkoutNumber) - parseFloat(this.listAdd[j].quitNumberC)
                console.log(minNumber)
                if (!rulesQuitNumber.test(parseFloat(this.listAdd[j].quitNumber))) {
                  this.$message({
                    type: 'error',
                    message: '退库数量请输入正数，最多保留两位小数点',
                    duration: 2000
                  })
                  return false
                } else if (parseFloat(this.listAdd[j].quitNumber) > minNumber) {
                  this.$message({
                    type: 'error',
                    message: '退库数量不可大于出库数量-已退库数量',
                    duration: 2000
                  })
                  return false
                }
              }
            }
            this.postDataPramas.common = { 'returnmap': '0' }
            this.postDataPramas.data = []
            this.postDataPramas.data[0] = { 'name': 'insertBigPartquit', 'type': 'e', 'parammaps': {
              pastureId: this.createTemp.pastureId,
              deptId: this.createTemp.deptId,
              useForm: this.createTemp.applyCode,
              employeId: this.createTemp.employeId,
              quitId: this.createTemp.quitId,
              quitDate: this.createTemp.quitDate,
              note: this.createTemp.note
            }}
            // 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': 'insertPartquit', 'type': 'e', 'parammaps': {
              bigId: '@insertBigPartquit.LastInsertId',
              location: '@insertSpotList.warehoseCode',
              partId: '@insertSpotList.partId',
              partCode: '@insertSpotList.partCode',
              partName: '@insertSpotList.partName',
              specification: '@insertSpotList.specification',
              price: '@insertSpotList.price',
              unit: '@insertSpotList.unit',
              brand: '@insertSpotList.brandName',
              contractId: '@insertSpotList.contractId',
              providerName: '@insertSpotList.providerName',
              providerId: '@insertSpotList.providerId',
              applyNumber: '@insertSpotList.quitNumberC',
              quitNumber: '@insertSpotList.quitNumber',
              useNumber: '@insertSpotList.checkoutNumber',
              reportery: '@insertSpotList.reportery',
              partUseId: '@insertSpotList.id'
            }}
            this.postDataPramas.data[1].children[1] = { 'name': 'updatePartRepertoryTK', 'type': 'e', 'parammaps': {
              quitNumber: '@insertSpotList.quitNumber',
              providerId: '@insertSpotList.providerId',
              partCode: '@insertSpotList.partCode',
              contractId: '@insertSpotList.contractId',
              price: '@insertSpotList.price',
              locationId: '@insertSpotList.locationId'
            }}
            this.postDataPramas.data[1].children[2] = { 'name': 'updatePartUseQuit', 'type': 'e', 'parammaps': {
              quitNumber: '@insertSpotList.quitNumber',
              id: '@insertSpotList.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.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
                this.dialogFormVisible = false
                setTimeout(() => {
                  this.getList()
                }, 1000)
              }
            })
            return true
          } else {
            this.$message({
              title: '',
              message: '请选择备件',
              type: 'warning',
              duration: 2000
            })
            return false
          }
        }
      })
    },
    partDelete(row) {
      console.log(this.listAdd)
      MessageBox.confirm('设备名称：' + row.partName, '确认删除？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // console.log(this.list2)
        this.TotalAmount = 0
        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].quitNumber) * parseFloat(this.listAdd[i].price)
          this.TotalAmount = parseFloat((this.TotalAmount).toFixed(2))
        }
      })
    },
    handleDelate(row) {
      console.log('点击了删除')
      this.seeTemp = Object.assign({}, row)
      this.getdataListSee.parammaps.bigId = 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': 'updatePartRepertoryTKDel', 'type': 'e', 'parammaps': {
          quitNumber: '@insertSpotList.quitNumber',
          providerId: '@insertSpotList.providerId',
          partCode: '@insertSpotList.partCode',
          contractId: '@insertSpotList.contractId',
          pastureId: row.pastureId
        }}
        this.postDataPramas.data[0].children[1] = { 'name': 'deletePartQuit', 'type': 'e', 'parammaps': {
          id: '@insertSpotList.id'
        }}
        this.postDataPramas.data[0].children[2] = { 'name': 'updatePartUseDel', 'type': 'e', 'parammaps': {
          quitNumber: '@insertSpotList.quitNumber',
          partUseId: '@insertSpotList.partUseId'
        }}
        this.postDataPramas.data[1] = { 'name': 'deleteBigPartQuit', 'type': 'e', 'parammaps': {
          id: row.id
        }}
        ExecDataByConfig(this.postDataPramas).then(response => {
          this.getList()
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
        })
      })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 查看
    form_see(row) {
      this.dialogStatusSee = 'see'
      this.dialogFormVisibleSee = true
      this.seeTemp = Object.assign({}, row)
      this.seeTemp.quitDate = parseTime(this.seeTemp.quitDate, '{y}-{m}-{d}')
      this.TotalAmount = 0
      console.log('查看上方数据(从table读取)', this.seeTemp)
      this.getSeeList()
    },
    getSeeList() {
      this.getdataListSee.parammaps.bigId = this.seeTemp.id
      GetDataByName(this.getdataListSee).then(response => {
        console.log('查看下方table数据', response.data.list)
        this.listSee = response.data.list
        if (response.data.list !== null) {
          this.TotalAmount = 0
          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)
      })
    },
    form_edit(row) {
      this.temp = Object.assign({}, row) // copy obj
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.$nextTick(() => {
        this.$refs['temp'].clearValidate()
      })
    },
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllProvider = response.data.findAllProvider.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllDepart = response.data.findAllDepart.list
        this.findAllEmploye = response.data.findAllEmploye.list
      })
    },
    handleDownload() {
      console.log('点击了导出')
      this.$alert('退库记录正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      this.isPercentage = true
      this.percentage = 1
      var timer = setInterval(() => {
        this.percentage += 5
        if (this.percentage > 95) {
          this.percentage = 99
          clearInterval(timer)
        }
        this.percentage = this.percentage
      }, 1000)
      this.downloadParam.name = 'getPartquitDetaillist'
      this.downloadParam.parammaps = this.getdataListParm2.parammaps
      GetAccount(this.downloadParam).then(response => {
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        this.$nextTick(() => {
          const ExcelDatas = [
            {
              tHeader: ['牧场', '出库单号', '备件编号', '备件名称', '备件规格', '备件品牌', '计量单位', '供应商', '库位', '出库数量', '退库数量', '单价', '总价', '退库原因', '录入人', '退库日期'],
              filterVal: ['pastureName', 'useForm', 'partCode', 'partName', 'specification', 'brand', 'unit', 'providerName', 'location', 'useNumber', 'refundNumber', 'price', 'sumPrice', 'note', 'empname', 'quitDate'],
              tableDatas: response.data.list,
              sheetName: '退库记录'
            }
          ]
          json2excel(ExcelDatas, '退库记录', true, 'xlsx')
        })
      })
    },
    handleEAS() {
      this.easStatus.dialogStatus = 'easStatus'
      this.easStatus.dialogFormVisible = true
      this.getListEasStatusLst()
    },
    getListEasStatusLst() {
      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.requestParam.name = 'updatebigpartquitSync'
        this.requestParam.parammaps = {}
        this.requestParam.parammaps.issync = '2'
        this.requestParam.parammaps.id = row.id
        PostDataByName(this.requestParam).then((response) => {
          if (response.msg !== 'fail') {
            this.$notify({ title: '成功', message: '关闭同步成功', type: 'success', duration: 2000 })
            this.getListEasStatusLst()
            this.getList()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.getListEasStatusLst()
            this.getList()
          }
        })
      }).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.getListEasStatusLst()
            this.getList()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.getListEasStatusLst()
            this.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消手动同步' })
      })
    },
    handleIgnore(row) {
      MessageBox.confirm('是否确认忽略同步此数据？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.requestParam = {}
        this.requestParam.name = 'updatebigpartquitSync'
        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.getListEasStatusLst()
            this.getList()
          } else {
            this.$notify({ title: '失败', message: response.data, type: 'warning', duration: 2000 })
            this.getListEasStatusLst()
            this.getList()
          }
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消忽略同步' })
      })
    }

    // ---------------------------------------------------------------------
  }
}
</script>
<style lang="scss" scoped>
  .pagination-container{
    display: block !important;
  }
</style>
