<template>
  <div class="app-container">
    <div v-if="isPercentage" class="percentage" style="width: 210px;height: 90px;background: #fff;position: fixed;bottom: 0;left: 0;z-index: 9999999999999;">
      <h4 style="padding-left: 10px;line-height: 0;">导出进度：</h4>
      <el-progress style="padding-left: 10px;" :text-inside="true" :stroke-width="26" :percentage="percentage" />
    </div>
    <div class="filter-container">
      <el-select v-model="getdataListParm.parammaps.pastureName" style="width: 140px;" placeholder="牧场" class="filter-item" @change="changePastureName">
        <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-input v-model="getdataListParm.parammaps.applyCode" clearable placeholder="领用单号" style="width: 200px;" class="filter-item" />
      <el-select v-model="getdataListParm.parammaps.applyType" style="width: 120px;" clearable placeholder="领用类型" class="filter-item">
        <el-option v-for="item in collarType" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.departmentId" style="width: 120px;" clearable placeholder="领用部门" class="filter-item">
        <el-option v-for="item in findAllDepart" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.statue" style="width: 120px;" clearable placeholder="审核状态" class="filter-item">
        <el-option v-for="item in statues" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <el-select v-model="getdataListParm.parammaps.bstatue" style="width: 120px;" clearable placeholder="单据状态" class="filter-item">
        <el-option v-for="item in applystatueList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
      <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-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search">搜索</el-button>
      <div>
        <el-button v-if="isReceiveAdd" class="filter-item" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
        <el-button v-if="isReceiveExport" v-waves class="filter-item" type="success" icon="el-icon-upload2" @click="handleDownload">导出</el-button>
        <el-radio-group v-model="radioAll" style="margin-top:-9px" @change="changeAll()">
          <el-radio-button label="全部" />
          <el-badge :value="pending.total" class="item">
            <el-radio-button label="待处理" />
          </el-badge>
          <el-radio-button label="已处理" />
        </el-radio-group>
      </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"
    >
      <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="150px" prop="applyCode" />
      <el-table-column label="领用类型" min-width="90px" align="center" :formatter="applyType" />
      <el-table-column label="牧场" align="center" min-width="100px" prop="pastureName" />
      <el-table-column label="领用部门" align="center" min-width="100px" prop="departmentName" />
      <el-table-column label="领用人" align="center" min-width="100px" prop="empname" />
      <el-table-column label="领用日期" align="center" min-width="100px" sortable prop="createDate" />
      <el-table-column label="审核状态" min-width="90px" align="center" :formatter="SHStatus" />
      <el-table-column label="单据状态" min-width="90px" align="center" :formatter="applystatue" />
      <el-table-column label="操作" align="center" width="250" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="{row}">
          <el-button v-if="isReceiveSee" type="primary" size="mini" style="width:60px" @click="form_see(row)">查看</el-button>
          <el-button v-if="isReceiveUpdate && (row.SHStatus == 4 || row.SHStatus == 6 ||row.SHStatus == 8 || row.SHStatus == 10)" type="success" style="display:inline-block;width:60px;" size="mini" @click="form_edit(row)">编辑</el-button>
          <el-button v-else type="success" style="display:none;" size="mini" @click="form_edit(row)">编辑</el-button>
          <!-- 部门审核 -->
          <el-button v-if="isContractExamineBM && row.SHStatus == 2 && (row.departmentId == getdataListParm.parammaps.logindeptId || depids.filter(function (item) { return item == row.departmentId; }).length != 0)" type="success" style="display:inline-block;width:60px;" size="mini" @click="handleExamine(row)">审核1</el-button>
          <el-button v-else type="success" style="display:none" size="mini" @click="handleExamine(row)">审核1</el-button>

          <!-- 设备处长审核 -->
          <el-button v-if="isContractExamineSBCZ && row.SHStatus == 3" type="success" style="display:inline-block;width:60px;" size="mini" @click="handleExamine2(row)">审核2</el-button>
          <el-button v-else type="success" style="display:none" size="mini" @click="handleExamine2(row)">审核2</el-button>

          <!-- 场长助理审核 -->
          <el-button v-if="isContractExamineCZZL && row.SHStatus == 5" type="success" style="display:inline-block;width:60px" size="mini" @click="handleExamine3(row)">审核3</el-button>
          <el-button v-else type="success" style="display:none" size="mini" @click="handleExamine3(row)">审核3</el-button>

          <!-- 场长审核 -->
          <el-button v-if="isContractExamineCZ && row.SHStatus == 7" type="success" style="display:inline-block;width:60px;" size="mini" @click="handleExamine4(row)">审核4</el-button>
          <el-button v-else type="success" style="display:none" size="mini" @click="handleExamine4(row)">审核4</el-button>
          <!-- 删除 -->
          <el-button v-if="isReceiveDelete && (row.SHStatus == 4 || row.SHStatus == 6 ||row.SHStatus == 8 || row.SHStatus == 10)" style="display:inline-block;width:60px;" type="danger" size="mini" @click="form_delete(row)">删除</el-button>
          <el-button v-if="row.statue === 1 && isReceiveDelete" style="display:none" type="danger" size="mini" @click="form_delete(row)">删除</el-button>
          <!-- 关单 -->
          <el-button v-if="isReceiveClose && (row.SHStatus == 9 && row.statue < 2)" style="display:inline-block;width:60px;" type="danger" size="mini" @click="handleCustomsDeclaration(row)">关单</el-button>
          <el-button v-else style="display:none" type="danger" size="mini" @click="handleCustomsDeclaration(row)">关单</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="getdataListParm.offset" :limit.sync="getdataListParm.pagecount" @pagination="getList" />
    <!-- 新增 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="app-add">
        <el-form ref="createTemp" :rules="rules" :model="createTemp" label-position="right" label-width="100px" style="width: 100%;">
          <el-row>
            <el-col :span="8">
              <el-form-item label="领用单号：" prop="applyCode">
                <el-input ref="applyCode" v-model="createTemp.applyCode" disabled />
              </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%;" :disabled="dialogStatus=='update'" @change="changePasture">
                  <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="领用部门：" prop="departmentId">
                <el-select v-model="createTemp.departmentId" placeholder="领用部门" class="filter-item" style="width: 100%;" :disabled="dialogStatus=='update'" @change="changeDepart">
                  <el-option v-for="item in createDepartList" :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="applyType">
                <el-radio-group v-model="createTemp.applyType" :disabled="dialogStatus=='update'" @change="changeType">
                  <el-radio v-model="createTemp.applyType" :label="1">维修</el-radio>
                  <el-radio v-model="createTemp.applyType" :label="2">保养</el-radio>
                  <el-radio v-if="dialogStatus !=='create'" v-model="createTemp.applyType" :label="0">非维保</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="领用人：" prop="empId">
                <el-select v-model="createTemp.empId" placeholder="领用人" class="filter-item" style="width: 100%;" :disabled="dialogStatus=='update'">
                  <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="createDate">

                <el-date-picker v-model="createTemp.createDate" :picker-options="pickerOptions1" type="date" placeholder="领用日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :disabled="dialogStatus=='update'" />
                <!-- <el-date-picker v-model="createTemp.applyDate" :picker-options="pickerOptions1" type="date" placeholder="领用日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd" style="width: 100%;" :disabled="dialogStatus=='update'" /> -->
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="18">
              <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>
                    |  &nbsp;<b>品牌：</b><span class="addr">{{ item.brand }}</span>
                    |  &nbsp;<b>库存：</b><span class="addr">{{ item.reportery }}</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 type="index" label="序号" align="center" width="50px" />
          <el-table-column label="备件编号" min-width="90px" 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="brand" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.brand }}</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 v-if="No1" label="设备名称" prop="eqName" align="center" min-width="250">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.eqName"
                class="inline-input"
                :fetch-suggestions="querySearchEqName"
                value-key="eqName"
                placeholder="设备名称"
                @select="(value)=>
                {handleSelectEqName(value, scope.row)}"
                @blur="(value)=>
                {blurSelectEqName(value, scope.row)}"
              >
                <template slot-scope="{ item }">
                  <span class="addr">{{ item.eqName }}</span>
                  |<span class="addr">{{ item.eqCode }}</span>
                </template>
              </el-autocomplete>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" label="设备内部编号" prop="eqCode" align="center" min-width="150">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.eqCode"
                class="inline-input"
                :fetch-suggestions="querySearchCode"
                value-key="eqCode"
                placeholder="设备内部编号"
                @select="(value)=>
                {handleSelectEqCode(value, scope.row)}"
                @blur="(value)=>
                {blurSelectEqCode(value, scope.row)}"
              />
            </template>
          </el-table-column>
          <el-table-column label="库存数量" prop="reportery" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.reportery }}</span>
            </template>
          </el-table-column>
          <el-table-column label="领用数量" min-width="80px" align="center">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="amount">
                  <el-input ref="amount" v-model="scope.row.amount" style="margin-top:15px" @blur="(value)=> {blurAmount(value, scope.row)}" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="单价" prop="price" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="总价" prop="totalPrice" align="center" min-width="70">
            <template slot-scope="scope">
              <span>{{ scope.row.price * parseFloat(scope.row.amount) | keepTwoNum }}</span>
            </template>
          </el-table-column>
          <el-table-column label="用途" prop="note" align="center" min-width="60">
            <template slot-scope="scope">
              <el-form :model="scope.row">
                <el-form-item prop="note">
                  <el-input ref="note" v-model="scope.row.note" style="margin-top:15px" />
                </el-form-item>
              </el-form>
            </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[dialogStatus]" :visible.sync="dialogFormVisible_See" :close-on-click-modal="false" width="90%">
      <div class="app-container">
        <el-form ref="seeTemp" :rules="rules" :model="seeTemp" label-position="right" label-width="100px" style="width: 100%;">
          <el-row>
            <el-col :span="8">
              <el-form-item label="领用单号：" prop="applyCode">
                <el-input ref="applyCode" v-model="seeTemp.applyCode" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="牧场：" prop="pastureName">
                <el-input ref="pastureName" v-model="seeTemp.pastureName" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="领用部门：" prop="departmentName">
                <el-input ref="departmentName" v-model="seeTemp.departmentName" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="领用人：" prop="empname">
                <el-input ref="empname" v-model="seeTemp.empname" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="领用日期：" prop="createDate">
                <el-input ref="createDate" v-model="seeTemp.createDate" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="领用类型：" prop="applyType">
                <el-input ref="" v-model="seeTemp.applyType" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="seeTemp.applyType=='维修'">
            <el-col :span="8">
              <el-form-item label="报修单号:" prop="RUCode">
                <el-input ref="" v-model="seeTemp.RUCode" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="故障情况:" prop=" detail">
                <el-input ref="" v-model="seeTemp. detail" disabled style="width:100%;" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row v-if="seeTemp.applyType=='保养'">
            <el-col :span="8">
              <el-form-item label="保养单号:" prop="RUCode">
                <el-input ref="" v-model="seeTemp.RUCode" disabled style="width:100%;" />
              </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="listSee"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:30px"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
          @sort-change="tableSort"
        >
          <el-table-column type="index" label="序号" align="center" width="50px" />
          <el-table-column label="备件编号" min-width="120px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" align="center" min-width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件图片" 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="备件品牌" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.brandName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" label="设备名称" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.eqName }}</span>
            </template>
          </el-table-column>
          <el-table-column v-if="No1" label="设备编号" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.eqCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库存数量" sortable prop="reportery" align="center" min-width="80">
            <template slot-scope="scope">
              <span>{{ scope.row.reportery }}</span>
            </template>
          </el-table-column>
          <el-table-column label="领用数量" sortable prop="amount" min-width="60px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.amount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价" sortable prop="price" min-width="70px" align="center">
            <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">
            <template slot-scope="scope">
              <span>{{ scope.row.sumPrice }}</span>
            </template>
          </el-table-column>
          <el-table-column label="用途" prop="note" align="center" min-width="60">
            <template slot-scope="scope">
              <span>{{ scope.row.note }}</span>
            </template>
          </el-table-column>
          <el-table-column label="已出库数量" sortable prop="useAmount" align="center" min-width="120">
            <template slot-scope="scope">
              <span>{{ scope.row.useAmount }}</span>
            </template>
          </el-table-column>
        </el-table>
        <el-form
          ref="seeTemp"
          :rules="rules"
          :model="seeTemp"
          label-position="right"
          label-width="120px"
          style="width: 90%;margin:0 auto;"
        >
          <el-row>
            <el-col>
              <h3>流程进度：</h3>
              <el-steps :active="active" align-center finish-status="success">
                <el-step
                  v-for="(item,index) in activeList"
                  :key="index"
                  :title="item.title"
                  :status="item.status"
                >
                  <template slot="description">
                    <div class="step-row">
                      <div>{{ item.name }}&nbsp;&nbsp;{{ item.date }}</div>
                      <div>{{ item.reason }}</div>
                    </div>
                  </template>
                </el-step>
              </el-steps>
            </el-col>
          </el-row>
          <el-row>
            <el-col>
              <el-form-item label="操作：">
                <!-- 部门审核 -->
                <el-button v-if="isContractExamineBM && seeTemp.SHStatus == 2 && (seeTemp.departmentId ==getdataListParm.parammaps.logindeptId)" type="success" style="display:inline-block" @click="handleExamine()">审核1</el-button>
                <el-button v-else type="success" style="display:none" @click="handleExamine()">审核1</el-button>

                <!-- 设备处长审核 -->
                <el-button v-if="isContractExamineSBCZ && seeTemp.SHStatus == 3" type="success" style="display:inline-block" @click="handleExamine2()">审核2</el-button>
                <el-button v-else type="success" style="display:none" @click="handleExamine2()">审核2</el-button>

                <!-- 场长助理审核 -->
                <el-button v-if="isContractExamineCZZL && seeTemp.SHStatus == 5" type="success" style="display:inline-block" @click="handleExamine3()">审核3</el-button>
                <el-button v-else type="success" style="display:none" @click="handleExamine3()">审核3</el-button>

                <!-- 场长审核 -->
                <el-button v-if="isContractExamineCZ && seeTemp.SHStatus == 7" type="success" style="display:inline-block" @click="handleExamine4()">审核4</el-button>
                <el-button v-else type="success" style="display:none" @click="handleExamine4()">审核4</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="bottom:10px">
        <el-button @click="dialogFormVisible_See = false">关闭</el-button>
      </div>
    </el-dialog>

    <!-- 审核 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible_Examine" :close-on-click-modal="false" width="30%">
      <div class="app-examine">
        <h3 style="width: 100%;margin:0 0 0 5%;line-height:50px;">请确认审核结果:</h3>
        <el-form ref="examineTemp" :rules="rules" :model="examineTemp" label-position="right" style="width: 50%;margin:0 auto;">
          <el-row style="width:88%;height:150px;margin:0 auto;">
            <el-col :span="20">
              <el-form-item>
                <el-radio-group v-model="examineTemp.statueSH" @change="changeStatue">
                  <el-radio :label="1" checked>通过</el-radio>
                  <el-radio :label="2">不通过</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col v-if="isStatueReason" :span="20">
              <el-input v-model="examineTemp.workflowNote" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入不通过原因" />
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="dialogStatus==='examine'" type="primary" :disabled="isokDisable" @click="createExamineData()">确认</el-button>
        <el-button v-if="dialogStatus==='examine2'" type="primary" :disabled="isokDisable" @click="createExamineData2()">确认</el-button>
        <el-button v-if="dialogStatus==='examine3'" type="primary" :disabled="isokDisable" @click="createExamineData3()">确认</el-button>
        <el-button v-if="dialogStatus==='examine4'" type="primary" :disabled="isokDisable" @click="createExamineData4()">确认</el-button>
        <el-button @click="dialogFormVisible_Examine = false;">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// / 引入
import { GetDataByName, GetDataByNames, PostDataByName, ExecDataByConfig, checkButtons, failproccess, GetAccount } from '@/api/common'
import waves from '@/directive/waves'
import { parseTime, json2excel, sortChange } from '@/utils/index.js'
import { validateEMail } from '@/utils/validate.js'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
import Cookies from 'js-cookie'
import { getToken } from '@/utils/auth'
export default {
  name: 'Receive',
  components: { Pagination },
  directives: { waves },
  filters: {
    keepTwoNum(value) {
      value = Number(value)
      return value.toFixed(2)
    }
  },
  data() {
    return {
      findAllPasture: [], findAllDepart: [], findAllEmploye: [], createDepartList: [], edit: 0,
      requestParams: [
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }}
      ],
      getDepartParam: {
        name: 'findAllDepart', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }
      },
      dialogFormVisible: false,
      dialogStatus: '',
      isReceiveUpdate: [], isReceiveAdd: [], isReceiveTemplate: [], isReceiveImport: [], isReceiveExport: [], isReceiveSee: [], isReceiveDelete: [],
      isContractExamineBM: [], isContractExamineSBCZ: [], isContractExamineCZZL: [], isContractExamineCZ: [], isReceiveClose: [],
      isokDisable: false,
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      rules: {},
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now()// 当天之前的时间可选
        }
      },
      textMap: { see: '查看详情', create: '新增', examine: '审核', examine2: '审核', examine3: '审核', update: '编辑' },
      statues: [{ id: '0', name: '审核中' }, { id: '1', name: '已通过' }, { id: '2', name: '未通过' }],
      applystatueList: [{ id: '0', name: '正常' }, { id: '1', name: '已关闭' }],
      collarType: [{ id: '0', name: '非维保' }, { id: '1', name: '维修' }, { id: '2', name: '保养' }],
      radioAll: '全部',
      getdataListParm: {
        name: 'getBigpartapplyList', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
        parammaps: { pastureName: Cookies.get('pasturename'), applyCode: this.$route.query.applyCode, applyType: '', statue: '', departmentId: '', inputDatetime: '', startTime: '', stopTime: '', loginId: Cookies.get('employeid'), menu: 'Receive', logindeptId: Cookies.get('departmentid'), loginpastureId: Cookies.get('pastureid') }
      },
      tableKey: 0,
      listLoading: true,
      total: 0,
      list: [],
      dialogFormVisible_See: false,
      seeTemp: [],
      listSee: [],
      totalSee: 0,
      getdataListSee: {
        name: 'getpartapplyListBybig',
        returntype: 'Map',
        parammaps: {}
      },
      noMaintenance: true,
      repair: false,
      maintain: false,
      No1: true,
      createTemp: {
        applyType: 1,
        empId: this.$store.state.user.employeid,
        pastureId: this.$store.state.user.pastureid,
        createDate: parseTime(new Date(), '{y}-{m}-{d}'),
        departmentId: this.$store.state.user.departmentid
      },
      getParmCreateNumber: {
        name: 'autoCreatCode', page: 0, offset: 0, pagecount: 0, returntype: 'Map',
        parammaps: { pastureId: Cookies.get('pastureid'), codeType: 'LY' }
      },
      orderPart: {},
      requestSparePart: {
        name: 'getPartsListLY', page: 1, offset: 1, pagecount: 20, returntype: 'Map',
        parammaps: { pastureId: Cookies.get('pastureid') }
      },
      listAdd: [],
      EqNameList: [],
      requestEqName: {
        name: 'geteqbyNameCode', page: 1, offset: 1, pagecount: 10, returntype: 'Map',
        parammaps: { pastureId: Cookies.get('pastureid') }
      },
      EqCodeList: [],
      postDataPramas: {},
      activeList: [],
      active: 3,
      dialogFormVisible_Examine: false,
      examineTemp: {},
      isStatueReason: false,
      requestParam: {},
      buttons: [],
      downloadParam: {},
      isPercentage: false,
      percentage: 1,
      TotalAmount: 0,
      pending: {
        total: 0,
        getdataListParm: {
          name: 'getPartapplyWebListNO', page: 1, offset: 1, getTotal: 'total3', pagecount: 10, returntype: 'Map',
          parammaps: {}
        }
      },
      depids: []
    }
  },

  watch: {
 
    listAdd: {
      deep: true,
      handler: function (item) {
          

     

          this.listAdd.forEach(function(i){

            if(parseInt(i.amount) > parseFloat(i.reportery)){
              i.amount = i.reportery
            }
            
          })
 


          

         
      }
    },


    
 
  },

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

  methods: {
    tableSort(column) {
      sortChange(column, this.listSee)
    },
    get_auto_buttons() {
      if (Cookies.get('depids') !== undefined) {
        this.depids = Cookies.get('depids').split(',')
      } else {
        this.depids = []
      }
      const ReceiveUpdate = 'customs:basic:update'
      const isReceiveUpdate = checkButtons(this.$store.state.user.buttons, ReceiveUpdate)
      this.isReceiveUpdate = isReceiveUpdate

      const ReceiveAdd = 'customs:receive:add'
      const isReceiveAdd = checkButtons(this.$store.state.user.buttons, ReceiveAdd)
      this.isReceiveAdd = isReceiveAdd

      const ReceiveTemplate = 'customs:receive:template'
      const isReceiveTemplate = checkButtons(this.$store.state.user.buttons, ReceiveTemplate)
      this.isReceiveTemplate = isReceiveTemplate

      const ReceiveImport = 'customs:receive:import'
      const isReceiveImport = checkButtons(this.$store.state.user.buttons, ReceiveImport)
      this.isReceiveImport = isReceiveImport

      const ReceiveExport = 'customs:receive:export'
      const isReceiveExport = checkButtons(this.$store.state.user.buttons, ReceiveExport)
      this.isReceiveExport = isReceiveExport

      const ReceiveSee = 'customs:receive:see'
      const isReceiveSee = checkButtons(this.$store.state.user.buttons, ReceiveSee)
      this.isReceiveSee = isReceiveSee

      const ReceiveDelete = 'customs:receive:delete'
      const isReceiveDelete = checkButtons(this.$store.state.user.buttons, ReceiveDelete)
      this.isReceiveDelete = isReceiveDelete

      // 部门审核
      const ContractExamineBM = 'customs:receive:examineBM'
      const isContractExamineBM = checkButtons(this.$store.state.user.buttons, ContractExamineBM)
      this.isContractExamineBM = isContractExamineBM

      // 设备处长审核
      const ContractExamineSBCZ = 'customs:receive:examineSBCZ'
      const isContractExamineSBCZ = checkButtons(this.$store.state.user.buttons, ContractExamineSBCZ)
      this.isContractExamineSBCZ = isContractExamineSBCZ

      // 场长助理审核
      const ContractExamineCZZL = 'customs:receive:examineCZZL'
      const isContractExamineCZZL = checkButtons(this.$store.state.user.buttons, ContractExamineCZZL)
      this.isContractExamineCZZL = isContractExamineCZZL

      // 场长审核
      const ContractExamineCZ = 'customs:receive:examineCZ'
      const isContractExamineCZ = checkButtons(this.$store.state.user.buttons, ContractExamineCZ)
      this.isContractExamineCZ = isContractExamineCZ

      // 关单
      const ReceiveClose = 'customs:receive:close'
      const isReceiveClose = checkButtons(this.$store.state.user.buttons, ReceiveClose)
      this.isReceiveClose = isReceiveClose
    },
    getPendingList() {
      this.pending.getdataListParm.parammaps.pastureName = this.getdataListParm.parammaps.pastureName
      this.pending.getdataListParm.parammaps.applyType = this.getdataListParm.parammaps.applyType
      this.pending.getdataListParm.parammaps.statue = this.getdataListParm.parammaps.statue
      this.pending.getdataListParm.parammaps.departmentId = this.getdataListParm.parammaps.departmentId
      this.pending.getdataListParm.parammaps.inputDatetime = this.getdataListParm.parammaps.inputDatetime
      this.pending.getdataListParm.parammaps.loginId = this.getdataListParm.parammaps.loginId
      this.pending.getdataListParm.parammaps.menu = this.getdataListParm.parammaps.menu
      this.pending.getdataListParm.parammaps.logindeptId = this.getdataListParm.parammaps.logindeptId
      this.pending.getdataListParm.parammaps.loginpastureId = this.getdataListParm.parammaps.loginpastureId
      this.pending.getdataListParm.parammaps.empId = this.getdataListParm.parammaps.empId
      this.pending.getdataListParm.parammaps.pastureId = Cookies.get('pastureid')
      this.pending.getdataListParm.parammaps.deptId = Cookies.get('departmentid')
      GetDataByName(this.pending.getdataListParm).then(response => {
        this.pending.total = response.data.total3
      })
    },
    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 => {
        if (response.data.list !== null) {
          console.log('table数据', response.data.list)
          this.list = response.data.list
          this.pageNum = response.data.pageNum
          this.pageSize = response.data.pageSize
        } else {
          this.list = []
        }
        this.total = response.data.total
        setTimeout(() => {
          this.listLoading = false
        }, 100)
      })
    },

    changeAll() {
      console.log(this.radioAll)
      if (this.radioAll === '全部') {
        this.getdataListParm.name = 'getBigpartapplyList'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: Cookies.get('pasturename'),
          applyCode: '', applyType: '', statue: '', departmentId: '', inputDatetime: '', startTime: '', stopTime: '', menu: 'Receive',
          loginId: Cookies.get('employeid'),
          logindeptId: Cookies.get('departmentid'),
          loginpastureId: Cookies.get('pastureid')
        }
        this.getList()
      } else if (this.radioAll === '待处理') {
        this.getdataListParm.name = 'getPartapplyWebListNO'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: this.getdataListParm.parammaps.pastureName,
          applyCode: this.getdataListParm.parammaps.applyCode,
          applyType: this.getdataListParm.parammaps.applyType,
          statue: this.getdataListParm.parammaps.statue,
          departmentId: this.getdataListParm.parammaps.departmentId,
          inputDatetime: this.getdataListParm.parammaps.inputDatetime,
          startTime: this.getdataListParm.parammaps.startTime,
          stopTime: this.getdataListParm.parammaps.stopTime,
          loginId: Cookies.get('employeid'),
          menu: 'Receive',
          logindeptId: Cookies.get('departmentid'),
          loginpastureId: Cookies.get('pastureid'),
          empId: Cookies.get('employeid'),
          pastureId: Cookies.get('pastureid'),
          deptId: Cookies.get('departmentid')
        }
        this.getList()
      } else if (this.radioAll === '已处理') {
        this.getdataListParm.name = 'getPartapplyWebList'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: this.getdataListParm.parammaps.pastureName,
          applyCode: this.getdataListParm.parammaps.applyCode,
          applyType: this.getdataListParm.parammaps.applyType,
          statue: this.getdataListParm.parammaps.statue,
          departmentId: this.getdataListParm.parammaps.departmentId,
          inputDatetime: this.getdataListParm.parammaps.inputDatetime,
          startTime: this.getdataListParm.parammaps.startTime,
          stopTime: this.getdataListParm.parammaps.stopTime,
          loginId: Cookies.get('employeid'),
          menu: 'Receive',
          logindeptId: Cookies.get('departmentid'),
          loginpastureId: Cookies.get('pastureid'),
          empId: Cookies.get('employeid'),
          pastureId: Cookies.get('pastureid'),
          deptId: Cookies.get('departmentid')
        }
        this.getList()
      }
    },
    applyType: function(cellValue) {
      if (cellValue.applyType === '0') {
        return '非维保'
      } else if (cellValue.applyType === '1') {
        return '维修'
      } else if (cellValue.applyType === '2') {
        return '保养'
      }
    },
    SHStatus: function(cellValue) {
      if (cellValue.SHStatus == '2') {
        return '审核中'
      } else if (cellValue.SHStatus == '3') {
        return '审核中'
      } else if (cellValue.SHStatus == '4') {
        return '未通过'
      } else if (cellValue.SHStatus == '5') {
        return '审核中'
      } else if (cellValue.SHStatus == '6') {
        return '未通过'
      } else if (cellValue.SHStatus == '7') {
        return '审核中'
      } else if (cellValue.SHStatus == '8') {
        return '未通过'
      } else if (cellValue.SHStatus == '9') {
        return '已通过'
      } else if (cellValue.SHStatus == '10') {
        return '未通过'
      }
    },
    applystatue: function(cellValue) {
      if (cellValue.applystatue == '0') {
        return '正常'
      } else if (cellValue.applystatue == '1') {
        return '已关闭'
      }
    },
    form_search() {
      console.log('点击了table搜索')
      this.listLoading = true
      if (this.getdataListParm.parammaps.inputDatetime === null) {
        this.getdataListParm.parammaps.inputDatetime = ''
      }
      this.getdataListParm.offset = 1
      this.getList()
      this.getPendingList()
    },
    changeStatue(val) {
      console.log(val)
      if (val == 2) {
        this.isStatueReason = true
      } else {
        this.isStatueReason = false
      }
    },
    form_see(row) {
      this.TotalAmount = 0
      this.seeTemp = Object.assign({}, row)
      if (row.applyType === '0') {
        this.seeTemp.applyType = '非维保'
        this.No1 = false
      } else if (row.applyType === '1') {
        this.seeTemp.applyType = '维修'
        this.No1 = true
      } else {
        this.seeTemp.applyType = '保养'
        this.No1 = true
      }
      this.dialogStatus = 'see'
      this.dialogFormVisible_See = true
      this.getdataListSee.parammaps.id = row.id
      this.getSeeList()
      // 流程图
      var reason = '未通过原因:' + this.seeTemp.workflowNote
      if (this.seeTemp.sumPrices <= 500) {
        if (this.seeTemp.SHStatus === 2) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }]
          this.active = 1
        } else if (this.seeTemp.SHStatus === 3) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 4) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 9) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 6) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }]
          this.active = 3
        }
      }
      if (this.seeTemp.sumPrices > 500 && this.seeTemp.sumPrices <= 3000) {
        if (this.seeTemp.SHStatus === 2) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核' }, { title: '设备处长审核' }]
          this.active = 1
        } else if (this.seeTemp.SHStatus === 3) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 4) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson, status: 'error', reason: reason }, { title: '设备处长审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 9) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 6) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson, status: 'error', reason: reason }]
          this.active = 3
        }
      }
      if (this.seeTemp.sumPrices > 3000 && this.seeTemp.sumPrices <= 10000) {
        if (this.seeTemp.SHStatus === 2) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核' }, { title: '设备处长审核' }, { title: '设备助理审核' }]
          this.active = 1
        } else if (this.seeTemp.SHStatus === 3) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核' }, { title: '设备助理审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 4) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson, status: 'error', reason: reason }, { title: '设备处长审核' }, { title: '设备助理审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 5) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核' }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 6) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson, status: 'error', reason: reason }, { title: '设备助理审核' }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 9) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson }]
          this.active = 4
        } else if (this.seeTemp.SHStatus === 8) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson, status: 'error', reason: reason }]
          this.active = 4
        }
      }
      if (this.seeTemp.sumPrices > 10000) {
        if (this.seeTemp.SHStatus === 2) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核' }, { title: '设备处长审核' }, { title: '设备助理审核' }, { title: '场长审核' }]
          this.active = 1
        } else if (this.seeTemp.SHStatus === 3) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核' }, { title: '设备助理审核' }, { title: '场长审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 4) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson, status: 'error', reason: reason }, { title: '设备处长审核' }, { title: '设备助理审核' }, { title: '场长审核' }]
          this.active = 2
        } else if (this.seeTemp.SHStatus === 5) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核' }, { title: '场长审核' }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 6) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson, status: 'error', reason: reason }, { title: '设备助理审核' }, { title: '场长审核' }]
          this.active = 3
        } else if (this.seeTemp.SHStatus === 7) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson }, { title: '场长审核' }]
          this.active = 4
        } else if (this.seeTemp.SHStatus === 8) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson, status: 'error', reason: reason }, { title: '场长审核' }]
          this.active = 4
        } else if (this.seeTemp.SHStatus === 9) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson }, { title: '场长审核', date: this.seeTemp.CZChargeDate, name: this.seeTemp.CZChargePerson }]
          this.active = 5
        } else if (this.seeTemp.SHStatus === 10) {
          this.activeList = [{ title: '领用申请', date: this.seeTemp.createDate, name: this.seeTemp.empname }, { title: '部门审核', date: this.seeTemp.KGChargedate, name: this.seeTemp.KGChargePerson }, { title: '设备处长审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备助理审核', date: this.seeTemp.CGChargedate, name: this.seeTemp.CGChargePerson }, { title: '场长审核', date: this.seeTemp.CZChargeDate, name: this.seeTemp.CZChargePerson, status: 'error', reason: reason }]
          this.active = 5
        }
      }
    },
    getSeeList() {
      GetDataByName(this.getdataListSee).then(response => {
        console.log('查看下方table数据', response.data.list)
        this.listSee = response.data.list
        this.listAdd = response.data.list
        if (response.data.list !== null) {
          for (let i = 0; i < this.listAdd.length; i++) {
            console.log(response.data.list[i].sumPrice)
            this.TotalAmount += parseFloat(response.data.list[i].sumPrice)
            this.listAdd[i].brand = this.listAdd[i].brandName
          }
          this.TotalAmount = this.TotalAmount.toFixed(2)
        }
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            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 = ''
            }
          }
        }
        setTimeout(() => {
          this.listLoadingSee = false
        }, 100)
      })
    },
    resetCreateTemp() {
      this.createTemp.applyType = 1
      this.No1 = true
      this.createTemp.useType = 1
      this.createTemp.empId = parseInt(Cookies.get('employeid'))
      this.createTemp.pastureId = parseInt(Cookies.get('pastureid'))
      this.createTemp.createDate = parseTime(new Date(), '{y}-{m}-{d}')
      this.createTemp.receiveTime = parseTime(new Date(), '{y}-{m}-{d}')
      this.createTemp.departmentId = parseInt(Cookies.get('departmentid'))
      this.createTemp.applyCode = ''
      this.listAdd = []
    },
    form_add() {
      this.resetCreateTemp()
      this.edit = 1
      this.getDepartParam.parammaps.pastureId = this.createTemp.pastureId
      this.getCreateDepartDownList()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.createTemp.pastureId = this.$store.state.user.pastureid
      this.createTemp.employeId = this.$store.state.user.employeid
      console.log(this.createTemp)
      this.TotalAmount = 0
      this.$nextTick(() => {
        this.$refs['createTemp'].clearValidate()
      })
      this.getCreateNumber()
    },
    getCreateNumber() {
      GetDataByName(this.getParmCreateNumber).then(response => {
        this.$nextTick(() => {
          console.log('新增领用单号', response.data.list[0].orderCode)
          this.createTemp.applyCode = response.data.list[0].orderCode
          this.$forceUpdate()
        })
      })
    },
    sparePartSearch(queryString, cb) {
      console.log('备件模糊查询输入值', queryString)
      this.requestSparePart.parammaps.pastureId = this.createTemp.pastureId
      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)
        }
      })
    },
    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.listAdd.push(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.listAdd.push(item)
      }
      // this.getEqNameList()
    },
    querySearchEqName(queryString, cb) {
      console.log('备件名称/设备内部编号模糊查询输入值', queryString)
      this.requestEqName.parammaps['eqName'] = queryString
      GetDataByName(this.requestEqName).then(response => {
        console.log('备件名称模糊查询搜索data', response.data.list)
        this.EqNameList = response.data.list
        cb(this.EqNameList)
      })
    },
    handleSelectEqName(item, row) {
      console.log('备件名称/设备内部编号模糊查询选中值', item.eqName)
      console.log('备件名称/设备内部编号模糊查询选中值所在行', row)
      this.$set(row, 'eqCode', item.eqCode)
      this.$forceUpdate()
    },
    querySearchCode(queryString, cb) {
      console.log('备件名称/设备内部编号模糊查询输入值', queryString)
      this.requestEqName.parammaps['eqCode'] = queryString
      GetDataByName(this.requestEqName).then(response => {
        console.log('备件名称模糊查询搜索data', response.data.list)
        this.EqNameList = response.data.list
        cb(this.EqNameList)
      })
    },
    handleSelectEqCode(item, row) {
      console.log('备件名称/设备内部编号模糊查询选中值', item)
      console.log('备件名称/设备内部编号模糊查询选中值所在行', row)
      this.$set(row, 'eqName', item.eqName)
      this.$forceUpdate()
    },
    blurSelectEqName(item, row) {
      this.$set(row, 'eqName', '')
      this.$set(row, 'eqCode', '')
    },
    blurSelectEqCode(item, row) {
      this.$set(row, 'eqName', '')
      this.$set(row, 'eqCode', '')
    },
    changeType(val) {
      if (val === 1 || val === 2) {
        this.No1 = true
      } else {
        this.No1 = false
      }
    },
    blurAmount(value, row) {
      console.log(value, row)
      this.TotalAmount = 0
      this.$set(row, 'sumPrice', (parseFloat(row.price) * parseFloat(row.amount)).toFixed(2))

      console.log(this.listAdd)
      for (let i = 0; i < this.listAdd.length; i++) {
        this.TotalAmount += parseFloat(this.listAdd[i].sumPrice)
      }
      this.TotalAmount = 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.createTemp.applyCode == '' || this.createTemp.applyCode == null || this.createTemp.applyCode == undefined) {
            GetDataByName(this.getParmCreateNumber).then(response => {
              this.$nextTick(() => {
                console.log('新增领用单号', response.data.list[0].orderCode)
                this.createTemp.applyCode = response.data.list[0].orderCode
                this.$forceUpdate()
                this.add_dialog_saveSave()
              })
            })
          } else {
            this.add_dialog_saveSave()
          }
        }
      })
    },
    add_dialog_saveSave() {
      if (this.listAdd.length !== 0) {
        var rulesAmount = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
        if (this.createTemp.applyType === 0) {
          for (var j = 0; j < this.listAdd.length; j++) {
            // 设备名称eqName设备编号eqCode领用数量amount
            if (this.listAdd[j].amount == null || this.listAdd[j].amount === '') {
              this.$message({
                title: '',
                message: '请检查领用数量是否未填写',
                type: 'error',
                duration: 2000
              })
              return false
            } else {
              if (!rulesAmount.test(this.listAdd[j].amount)) {
                this.$message({ type: 'error', message: '请输入正数，最多保留两位小数点', duration: 2000 })
                return false
              } else if (parseFloat(this.listAdd[j].amount) > parseFloat(this.listAdd[j].reportery)) {
                this.$message({ type: 'error', message: '领用数量不可大于库存数量', duration: 2000 })
                return false
              }
            }
          }
        } else {
          for (var j = 0; j < this.listAdd.length; j++) {
            if (this.listAdd[j].eqName == null || this.listAdd[j].eqCode == null || this.listAdd[j].amount == null || this.listAdd[j].eqName === '' || this.listAdd[j].eqCode === '' || this.listAdd[j].amount === '') {
              this.$message({ title: '', message: '请检查备件名称或设备内部编号或领用数量是否未填写', type: 'error', duration: 2000 })
              return false
            } else {
              if (!rulesAmount.test(this.listAdd[j].amount)) {
                this.$message({ type: 'error', message: '领用数量请输入正数，最多保留两位小数点', duration: 2000 })
                return false
              } else if (parseFloat(this.listAdd[j].amount) > parseFloat(this.listAdd[j].reportery)) {
                this.$message({ type: 'error', message: '领用数量不可大于库存数量', duration: 2000 })
                return false
              }
            }
          }
        }
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        let mySumPrice = 0
        for (let i = 0; i < this.listAdd.length; i++) {
          mySumPrice += parseFloat(this.listAdd[i].price) * parseFloat(this.listAdd[i].amount)
        }
        if (mySumPrice > 500) {
          this.createTemp.SHStatus = 2
        } else {
          this.createTemp.SHStatus = 9
        }
        this.postDataPramas.data[0] = { 'name': 'insertBigpartapply', 'type': 'e', 'parammaps': {
          pastureId: this.createTemp.pastureId,
          applyCode: this.createTemp.applyCode,
          applyType: this.createTemp.applyType,
          departmentId: this.createTemp.departmentId,
          empId: this.createTemp.empId,
          applyDate: this.createTemp.createDate,
          SHStatus: this.createTemp.SHStatus
        }}
        // 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': 'insertpartapply', 'type': 'e', 'parammaps': {
          bigId: '@insertBigpartapply.LastInsertId',
          pastureId: '@insertSpotList.pastureId',
          partId: '@insertSpotList.partId',
          partCode: '@insertSpotList.partCode',
          partName: '@insertSpotList.partName',
          specification: '@insertSpotList.specification',
          brandId: '@insertSpotList.brandId',
          price: '@insertSpotList.price',
          amount: '@insertSpotList.amount',
          eqName: '@insertSpotList.eqName',
          eqCode: '@insertSpotList.eqCode',
          providerId: '@insertSpotList.providerId',
          note: '@insertSpotList.note',
          reportery: '@insertSpotList.reportery',
          contractId: '@insertSpotList.contractId',
          locationId: '@insertSpotList.locationId'
        }}
        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.dialogFormVisible = false
            this.getdataListParm.parammaps.inputDatetime = ''
            this.getList()
            this.getPendingList()
            this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
          }
        })
        return true
      } else {
        this.$notify({ title: '', message: '请选择备件', type: 'warning', duration: 2000 })
        return false
      }
    },
    // 新增删除
    partDelete(row) {
      console.log(this.listAdd)
      MessageBox.confirm('设备名称：' + row.partName, '确认删除？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        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
          }
        }
      })
    },
    get_select_list() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.getDepartDownList()
      })
    },
    getDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.findAllDepart = response.data.list
      })
    },
    changePastureName(item) {
      this.getDepartParam.parammaps.pastureId = this.findAllPasture.find(obj => obj.name == item).id
      this.getdataListParm.parammaps.departmentId = ''
      this.getDepartDownList()
    },
    getCreateDepartDownList() {
      GetDataByName(this.getDepartParam).then(response => {
        this.createDepartList = response.data.list
        if (this.edit == 1) {
          if (this.createDepartList.find(obj => obj.id == Cookies.get('departmentid'))) {
            this.createTemp.departmentId = parseInt(Cookies.get('departmentid'))
            this.createTemp.departmentName = this.createDepartList.find(obj => obj.id == Cookies.get('departmentid')).name
          } else {
            this.createTemp.departmentId = response.data.list[0].id
            this.createTemp.departmentName = response.data.list[0].name
          }
        }
      })
    },
    changePasture(item) {
      this.getDepartParam.parammaps.pastureId = item
      this.edit = 1
      this.getCreateDepartDownList()
    },
    changeDepart(item) {
      this.createTemp.departmentName = this.createDepartList.find(obj => obj.id == item).name
    },
    form_delete(row) {
      console.log('点击了删除')
      MessageBox.confirm('确认删除此条信息？', {
        confirmButtonText: '确认', cancelButtonText: '取消', type: 'warning'
      }).then(() => {
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        this.postDataPramas.data[0] = { 'name': 'deleteBigpartapply', 'type': 'e', 'parammaps': {
          id: row.id
        }}
        this.postDataPramas.data[1] = { 'name': 'deletepartapply', 'type': 'e', 'parammaps': {
          bigId: row.id
        }}
        ExecDataByConfig(this.postDataPramas).then(response => {
          this.getList()
          this.getPendingList()
          this.$notify({ title: '成功', message: '删除成功', type: 'success', duration: 2000 })
        })
      }).catch(() => {
        this.$message({ type: 'info', message: '已取消删除' })
      })
    },
    handleDownload() {
      this.$alert('备件领用正在导出中，请勿刷新或离开本页面，若导出时间过长，建议缩小导出数据范围重新导出', {})
      this.isPercentage = true
      this.percentage = 1
      var timer = setInterval(() => {
        this.percentage += 5
        if (this.percentage > 95) {
          this.percentage = 99
          clearInterval(timer)
        }
        this.percentage = this.percentage
      }, 1000)
      this.downloadParam.name = 'downloadpartapply'
      this.downloadParam.parammaps = this.getdataListParm.parammaps
      GetAccount(this.downloadParam).then(response => {
        if (response.data.list !== null) {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
          for (let i = 0; i < response.data.list.length; i++) {
            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))
            this.$set(response.data.list[i], 'amount', parseFloat(response.data.list[i].amount))
          }
        }
        this.$nextTick(() => {
          const ExcelDatas = [
            {
              tHeader: ['牧场名称', '领用单编号', '领用申请日期', '物料编码', '品名', '规格型号', '品牌', '计量单位', '领用数量', '单价', '总价', '设备名称', '牧场设备编号', '领用类型（0非维保，1维修，2保养）', '领用部门', '领用人'],
              filterVal: ['pastureName', 'applyCode', 'createDate', 'partCode', 'partName', 'specification', 'brandName', 'unit', 'amount', 'price', 'sumPrice', 'eqName', 'eqCode', 'applyType', 'departmentName', 'empname'],
              tableDatas: response.data.list,
              sheetName: '备件领用'
            }
          ]
          json2excel(ExcelDatas, '备件领用', true, 'xlsx')
        })
      })
    },

    handleExamine(row) {
      console.log('点击了部门审核')
      if (row == undefined) {
        this.examineTemp = this.seeTemp
        this.$set(this.seeTemp, 'statueSH', 1)
        this.$set(this.seeTemp, 'workflowNote', '')
      } else {
        this.examineTemp = Object.assign({}, row)
        this.$set(this.examineTemp, 'statueSH', 1)
        this.$set(this.examineTemp, 'workflowNote', '')
      }
      this.dialogStatus = 'examine'
      this.dialogFormVisible_Examine = true
      this.statueReason = false
    },
    createExamineData() {
      console.log('点击了部门审核确认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['examineTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'partapplyCharge'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            this.requestParam.parammaps.statue = 3
          } else {
            this.requestParam.parammaps.statue = 4
          }
          this.requestParam.parammaps.empId	 = Cookies.get('employeid')
          this.requestParam.parammaps.workflowNote = this.examineTemp.workflowNote
          PostDataByName(this.requestParam).then(response => {
            console.log('部门审核确认发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              if (this.getdataListParm.parammaps.inputDatetime === null) {
                this.getdataListParm.parammaps.inputDatetime = ''
              }
              this.getList()
              this.dialogFormVisible_Examine = false
              this.dialogFormVisible_See = false
              this.isStatueReason = false
              this.getPendingList()
              this.$notify({ title: '成功', message: '审核成功', type: 'success', duration: 2000 })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      })
    },
    handleExamine2(row) {
      console.log('点击了设备处长审核')
      if (row == undefined) {
        this.examineTemp = this.seeTemp
        this.$set(this.seeTemp, 'statueSH', 1)
        this.$set(this.seeTemp, 'workflowNote', '')
      } else {
        this.examineTemp = Object.assign({}, row)
        this.$set(this.examineTemp, 'statueSH', 1)
        this.$set(this.examineTemp, 'workflowNote', '')
      }
      this.dialogStatus = 'examine2'
      this.dialogFormVisible_Examine = true
      this.statueReason = false
    },
    createExamineData2() {
      console.log('点击了设备处长审核确认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['examineTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'partapplyCharge3'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            if (parseFloat(this.examineTemp.sumPrices) <= 3000) {
              this.requestParam.parammaps.statue = 9
            } else {
              this.requestParam.parammaps.statue = 5
            }
          } else {
            this.requestParam.parammaps.statue = 6
          }
          this.requestParam.parammaps.empId	 = Cookies.get('employeid')
          this.requestParam.parammaps.workflowNote = this.examineTemp.workflowNote
          PostDataByName(this.requestParam).then(response => {
            console.log('设备处长审核确认发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              if (this.getdataListParm.parammaps.inputDatetime === null) {
                this.getdataListParm.parammaps.inputDatetime = ''
              }
              this.getList()
              this.getPendingList()
              this.dialogFormVisible_Examine = false
              this.dialogFormVisible_See = false
              this.isStatueReason = false
              this.$notify({ title: '成功', message: '审核成功', type: 'success', duration: 2000 })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      })
    },
    handleExamine3(row) {
      console.log('点击了场长助理审核')
      if (row == undefined) {
        this.examineTemp = this.seeTemp
        this.$set(this.seeTemp, 'statueSH', 1)
        this.$set(this.seeTemp, 'workflowNote', '')
      } else {
        this.examineTemp = Object.assign({}, row)
        this.$set(this.examineTemp, 'statueSH', 1)
        this.$set(this.examineTemp, 'workflowNote', '')
      }
      this.dialogStatus = 'examine3'
      this.dialogFormVisible_Examine = true
      this.statueReason = false
    },
    createExamineData3() {
      console.log('点击了场长助理审核确认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['examineTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'partapplyCharge1'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            if (parseFloat(this.examineTemp.sumPrices) <= 10000) {
              this.requestParam.parammaps.statue = 9
            } else {
              this.requestParam.parammaps.statue = 7
            }
          } else {
            this.requestParam.parammaps.statue = 8
          }
          this.requestParam.parammaps.empId	 = Cookies.get('employeid')
          this.requestParam.parammaps.workflowNote = this.examineTemp.workflowNote
          PostDataByName(this.requestParam).then(response => {
            console.log('场长助理审核确认发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              if (this.getdataListParm.parammaps.inputDatetime === null) {
                this.getdataListParm.parammaps.inputDatetime = ''
              }
              this.getList()
              this.getPendingList()
              this.dialogFormVisible_Examine = false
              this.dialogFormVisible_See = false
              this.isStatueReason = false
              this.$notify({ title: '成功', message: '审核成功', type: 'success', duration: 2000 })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      })
    },
    handleExamine4(row) {
      console.log('点击了场长审核')
      if (row == undefined) {
        this.examineTemp = this.seeTemp
        this.$set(this.seeTemp, 'statueSH', 1)
        this.$set(this.seeTemp, 'workflowNote', '')
      } else {
        this.examineTemp = Object.assign({}, row)
        this.$set(this.examineTemp, 'statueSH', 1)
        this.$set(this.examineTemp, 'workflowNote', '')
      }
      this.dialogStatus = 'examine4'
      this.dialogFormVisible_Examine = true
      this.statueReason = false
    },
    createExamineData4() {
      console.log('点击了场长审核确认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['examineTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'partapplyCharge2'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            this.requestParam.parammaps.statue = 9
          } else {
            this.requestParam.parammaps.statue = 10
          }
          this.requestParam.parammaps.empId	 = Cookies.get('employeid')
          this.requestParam.parammaps.workflowNote = this.examineTemp.workflowNote
          PostDataByName(this.requestParam).then(response => {
            console.log('场长审核确认发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              if (this.getdataListParm.parammaps.inputDatetime === null) {
                this.getdataListParm.parammaps.inputDatetime = ''
              }
              this.getList()
              this.getPendingList()
              this.dialogFormVisible_Examine = false
              this.dialogFormVisible_See = false
              this.isStatueReason = false
              this.$notify({ title: '成功', message: '审核成功', type: 'success', duration: 2000 })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      })
    },

    form_edit(row) {
      console.log('点击了编辑')
      this.edit = 0
      this.getDepartParam.parammaps.pastureId = row.pastureId
      this.getCreateDepartDownList()
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      console.log(row)
      row.applyType = parseInt(row.applyType)
      this.createTemp = Object.assign({}, row)
      this.listAdd = []
      if (row.applyType == 0) { this.No1 = false }
      if (row.applyType == 1 || row.applyType == 2) { this.No1 = true }
      this.TotalAmount = 0
      this.getdataListSee.parammaps.id = row.id
      this.getSeeList()
    },
    edit_dialog_save() {
      console.log('点击了编辑')
      if (this.listAdd.length !== 0) {
        var rulesAmount = /(^[1-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
        for (var j = 0; j < this.listAdd.length; j++) {
          // 设备名称eqName设备编号eqCode领用数量amount
          if (this.listAdd[j].amount == null || this.listAdd[j].amount === '') {
            this.$message({ title: '', message: '请检查领用数量是否未填写', type: 'error', duration: 2000 })
            return false
          } else {
            if (!rulesAmount.test(this.listAdd[j].amount)) {
              this.$message({ type: 'error', message: '请输入正数，最多保留两位小数点', duration: 2000 })
              return false
            } else if (parseFloat(this.listAdd[j].amount) > parseFloat(this.listAdd[j].reportery)) {
              this.$message({ type: 'error', message: '领用数量不可大于库存数量', duration: 2000 })
              return false
            }
          }
        }
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        let mySumPrice = 0
        for (let i = 0; i < this.listAdd.length; i++) {
          mySumPrice += parseFloat(this.listAdd[i].price) * parseFloat(this.listAdd[i].amount)
        }
        if (mySumPrice > 500) {
          this.createTemp.SHStatus = 2
        } else {
          this.createTemp.SHStatus = 9
        }

        this.postDataPramas.data[0] = { 'name': 'updatepartapplyCharge', 'type': 'e', 'parammaps': {
          id: this.createTemp.id,
          SHStatus: this.createTemp.SHStatus
        }}
        this.postDataPramas.data[1] = { 'name': 'deletePartapply', 'type': 'e', 'parammaps': {
          bigId: this.createTemp.id
        }}
        // eslint-disable-next-line no-irregular-whitespace
        this.postDataPramas.data[2] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
        this.postDataPramas.data[2].children = []
        this.postDataPramas.data[2].children[0] = { 'name': 'insertPartapply', 'type': 'e', 'parammaps': {
          bigId: this.createTemp.id,
          pastureId: '@insertSpotList.pastureId',
          partId: '@insertSpotList.partId',
          partCode: '@insertSpotList.partCode',
          partName: '@insertSpotList.partName',
          specification: '@insertSpotList.specification',
          brandId: '@insertSpotList.brandId',
          price: '@insertSpotList.price',
          amount: '@insertSpotList.amount',
          eqName: '@insertSpotList.eqName',
          eqCode: '@insertSpotList.eqCode',
          providerId: '@insertSpotList.providerId',
          note: '@insertSpotList.note',
          reportery: '@insertSpotList.reportery',
          contractId: '@insertSpotList.contractId',
          locationId: '@insertSpotList.locationId'
        }}
        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.dialogFormVisible = false
            this.getdataListParm.parammaps.inputDatetime = ''
            this.getList()
            this.getPendingList()
            this.$notify({ title: '', message: '保存成功', type: 'success', duration: 2000 })
          }
        })
        return true
      } else {
        this.$notify({ title: '', message: '请选择备件', type: 'warning', duration: 2000 })
        return false
      }
    },

    // 关单
    handleCustomsDeclaration(row) {
      MessageBox.confirm('是否确认关单？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        this.postDataPramas.data[0] = { 'name': 'updateBigPartApplystatueV2', 'type': 'e', 'parammaps': { id: row.id }}
        ExecDataByConfig(this.postDataPramas).then(response => {
          if (response.msg === 'fail') {
            this.$notify({ title: '保存失败', message: response.data, type: 'warning', duration: 2000 })
          } else {
            this.getPendingList()
            this.$notify({ title: '成功', message: '保存成功', type: 'success', duration: 2000 })
            this.getList()
          }
        })
      }).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-table  {
    text-align: left !important;
  }
  h5{
    text-align:left;font-size: 14px;line-height:23px;margin:0;padding:0;
  }
  .pagination-container{
    display: block !important;
  }
  .el-date-editor--daterange{
    width: 250px;
    top:-3px;
  }
  .el-radio{
    margin-right: 5px;
  }
  /deep/ .el-badge__content.is-fixed{
    z-index: 1;
  }
</style>
