<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" placeholder="牧场" style="width:120px" class="filter-item">
            <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-input v-model="getdataListParm.parammaps.contractCode" placeholder="合同编号" style="width: 140px;" class="filter-item" />
          <el-select v-model="getdataListParm.parammaps.statue" clearable placeholder="合同状态" class="filter-item" style="width: 120px;">
            <el-option v-for="item in statues" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-select v-model="getdataListParm.parammaps.providerName" filterable clearable style="width: 140px;" placeholder="供应商" class="filter-item">
            <el-option v-for="item in findAllProvider" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-select v-model="getdataListParm.parammaps.stuteSH" clearable placeholder="审核状态" class="filter-item" style="width: 120px;">
            <el-option v-for="item in shStatues" :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="isContractAdd" class="filter-item" type="primary" icon="el-icon-edit" @click="form_add">新增</el-button>
            <el-button v-if="isContractTemplate" v-waves class="filter-item" type="info" icon="el-icon-tickets" @click="handleDownloadTemp">模板</el-button>
            <el-upload style="display: inline-block;" :headers="headers" :data="uploadData" :action="uploadExcelUrl" :show-file-list="false" :before-upload="beforeImportExcel" :on-success="handleImportExcelSuccess">
              <el-button v-if="isContractImport" v-waves class="filter-item" type="warning" icon="el-icon-download">导入</el-button>
            </el-upload>
            <el-button v-if="isContractExport" 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-radio-button label="待处理" />
              <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"
          :cell-class-name="tableCellClassName"
        >
          <el-table-column label="序号" align="center" type="index" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index + (pageNum-1) * pageSize + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="牧场" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.pastureName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同编号" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.contractCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同状态" min-width="100px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.statue }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" min-width="120px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同开始日期" sortable prop="startTime" min-width="110px" align="center" />
          <el-table-column label="合同截止日期" sortable prop="stopTime" min-width="110px" align="center" />
          <el-table-column label="录入人" prop="creatorMan" min-width="100px" align="center" />
          <el-table-column label="录入时间" sortable prop="creatorTime" min-width="110px" align="center" />
          <el-table-column label="审核状态" min-width="110px" align="center" :formatter="SHStatus" />
          <el-table-column label="操作" align="center" width="300px" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <el-button v-if="isContractSee" type="primary" size="mini" @click="form_see(row)">查看</el-button>
              <el-button v-if="isContractChange && row.statue=='正常' && row.SHStatus == 7" type="warning" size="mini" @click="handleChange(row)">变更</el-button>
              <!-- <el-button type="success" size="mini" @click="form_edit(row)">编辑</el-button> -->
              <!-- 设备主管审核 -->
              <el-button v-if="isContractExamineZG && row.SHStatus == 2" type="success" style="display:inline-block" 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="isContractExamineZL && row.SHStatus == 3" type="success" style="display:inline-block" 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="isContractExamineZX && row.SHStatus == 5" type="success" style="display:inline-block" size="mini" @click="handleExamine3(row)">审核2</el-button>
              <el-button v-else type="success" style="display:none" size="mini" @click="handleExamine3(row)">审核2</el-button>
              <el-button v-if="isContractDelete && (row.SHStatus == 4 || row.SHStatus == 6 || row.SHStatus == 8) " type="danger" size="mini" @click="form_delete(row)">删除</el-button>
              <el-button v-if="isContractDelete2" type="danger" size="mini" @click="form_delete(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" placeholder="牧场" style="width:120px" class="filter-item">
            <el-option v-for="item in findAllPasture" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-input v-model="getdataListParm2.parammaps.contractCode" placeholder="合同编号" style="width: 140px;" class="filter-item" />
          <el-select v-model="getdataListParm2.parammaps.statue" clearable placeholder="合同状态" class="filter-item" style="width: 120px;">
            <el-option v-for="item in statues" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-input v-model="getdataListParm2.parammaps.partCode" placeholder="备件编号" style="width: 140px;" class="filter-item" />
          <el-input v-model="getdataListParm2.parammaps.partName" placeholder="备件名称" style="width: 140px;" class="filter-item" />
          <el-select v-model="getdataListParm2.parammaps.providerName" filterable clearable style="width: 140px;" placeholder="供应商" class="filter-item">
            <el-option v-for="item in findAllProvider" :key="item.id" :label="item.name" :value="item.name" />
          </el-select>
          <el-date-picker ref="inputDatetime2" v-model="getdataListParm2.parammaps.inputDatetime" class="inputDatetime" type="datetimerange" style="width: 250px;top:-3px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" />
          <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="form_search2">搜索</el-button>
        </div>
        <el-table
          :key="tableKey2"
          v-loading="listLoading2"
          element-loading-text="给我一点时间"
          :data="list2"
          border
          fit
          highlight-current-row
          style="width: 100%;"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
          :cell-class-name="tableCellClassName"
        >
          <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="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.pastureName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同编号" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.contractCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同状态" min-width="100px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.statue }}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商" min-width="120px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.providerName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同开始日期" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.startTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="合同截止日期" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.stopTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="零库存" min-width="100px" align="center" :formatter="isZeroStock" />
          <el-table-column label="备件编号" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.specification }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件品牌" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.brand }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计划量" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.planAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.remark }}</span>
            </template>
          </el-table-column>
          <el-table-column label="录入人" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.creatorMan }}</span>
            </template>
          </el-table-column>
          <el-table-column label="录入日期" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.creatorTime }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="审核状态" min-width="110px" align="center" :formatter="SHStatus" /> -->
        </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-add">
        <el-form
          ref="createTemp"
          :rules="rules"
          :model="createTemp"
          label-position="right"
          label-width="120px"
          style="width: 90%;margin:0 auto;"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="合同编号：" prop="contractCode">
                <el-input ref="contractCode" v-model="createTemp.contractCode" 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="isDisabled">
                  <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="providerName">
                <el-autocomplete
                  v-model="createTemp.providerName"
                  :disabled="dialogStatus==='change'"
                  value-key="name"
                  class="inline-input"
                  :fetch-suggestions="providerSearch"
                  placeholder="请输入供应商名称或供应商编号"
                  style="width:100%;"
                  @focus="handleFocusProvider"
                  @blur="handleBlurProvider"
                  @select="handleSelectProvider"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开始日期：" prop="startTime">
                <el-date-picker
                  v-model="createTemp.startTime"
                  :disabled="isDisabled"
                  type="date"
                  placeholder="开始日期"
                  style="width:100%;"
                  :picker-options="pickerOptions1"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="截止日期：" prop="stopTime">
                <el-date-picker
                  v-model="createTemp.stopTime"
                  style="width:100%;"
                  :disabled="isDisabled"
                  type="date"
                  placeholder="结束日期"
                  :picker-options="pickerOptions2"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col v-if="dialogStatus=='create'" :span="8">
              <el-form-item label="合同状态：" prop="statue">
                <el-select v-model="createTemp.statue" clearable placeholder="合同状态" class="filter-item" style="width: 100%;" disabled>
                  <el-option
                    v-for="item in statues"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="dialogStatus=='change'" :span="8">
              <el-form-item label="合同状态：" prop="statue">
                <el-select v-model="createTemp.statue" clearable placeholder="合同状态" class="filter-item" style="width: 100%;"@change="changeStatues">
                  <el-option
                    v-for="item in statues2"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="零库存：" prop="isZeroStock">
                <el-radio-group v-model="createTemp.isZeroStock" :disabled="isDisabled" @change="changeIsZero">
                  <el-radio v-model="createTemp.isZeroStock" :label="1">是</el-radio>
                  <el-radio v-model="createTemp.isZeroStock" :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="creatorId">
                <el-select ref="creatorId" v-model="createTemp.creatorId" :disabled="isDisabled" 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="creatorTime">
                <el-date-picker
                  v-model="createTemp.creatorTime"
                  :disabled="isDisabled"
                  type="date"
                  :picker-options="pickerOptions3"
                  placeholder="录入日期"
                  style="width:100%;"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注：" prop="remark">
                <el-input
                  v-model="createTemp.remark"
                  :disabled="isDisabled"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="16">
              <el-form-item label="备件：" prop="partCode">
                <el-autocomplete
                  v-model="orderPart.partCode"
                  :disabled="isDisabled"
                  value-key="name"
                  class="inline-input"
                  :fetch-suggestions="sparePartSearch"
                  placeholder="请输入备件编号或备件名称或备件规格"
                  style="width:100%"
                  @select="handleSelectSparePart"
                >
                  <template slot-scope="{ item }">
                    <b>备件编号：</b><div class="name" style="display: inline;">{{ item.partCode }}</div>&nbsp;
                    |  &nbsp;<b>备件名称：</b><span class="addr">{{ item.partName }}</span>&nbsp;
                    |  &nbsp;<b>备件规格：</b><span class="addr">{{ item.specification }}</span>
                  </template>
                </el-autocomplete>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          :key="tableKey"
          v-loading="listLoadingAdd"
          element-loading-text="给我一点时间"
          :data="listAdd"
          border
          fit
          highlight-current-row
          style="width: 100%;margin-bottom:50px"
          :row-style="rowStyle"
          :cell-style="cellStyle"
          class="elTable"
        >
          <el-table-column label="序号" align="center" type="index" width="50" />
          <!-- <el-table-column label="序号" align="center" type="index" width="50px">
            <template slot-scope="scope">
              <span>{{ scope.$index }}</span>
            </template>
          </el-table-column> -->
          <el-table-column label="备件编号" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="80px" align="center">
            <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="备件品牌" min-width="120px" align="center">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.brand"
                :disabled="isDisabled"
                value-key="brandName"
                class="inline-input"
                :fetch-suggestions="brandSearch"
                placeholder="请输入品牌"
                style="width:100%;"
                @focus="handleFocusBrand( scope.row)"
                @blur="handleBlurBrand(scope.row)"
                @select="(value)=>
                {handleSelectBrand(value, scope.row)}"
              />
            </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 label="计划量" min-width="70px" align="center" valign="middle">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="planAmount">
                  <el-input ref="planAmount" v-model="scope.row.planAmount" style="margin-top:15px" :disabled="isDisabled" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="单价" min-width="80px" align="center" valign="middle">
            <template slot-scope="scope">
              <el-input v-model="scope.row.price" :disabled="isDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="110px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" type="textarea" placeholder="备注" :disabled="isDisabled" autosize maxlength="100" show-word-limit />
            </template>
          </el-table-column>
          <el-table-column v-if="isDisabled2" label="操作" align="center" width="100px" 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:5px">
          <el-button type="primary" :disabled="isokDisable" @click="dialogStatus==='create'?add_dialog_save():add_dialog_save()">保存并关闭</el-button>
          <el-button @click="dialogFormVisible = false;getList();createTemp.providerName=''">取消并关闭</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 变更 -->
    <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible_change" :close-on-click-modal="false" width="90%">
      <div class="app-add">
        <el-form
          ref="createTemp"
          :rules="rules"
          :model="createTemp"
          label-position="right"
          label-width="120px"
          style="width: 90%;margin:0 auto;"
        >
          <el-row>
            <el-col :span="8">
              <el-form-item label="合同编号：" prop="contractCode">
                <el-input ref="contractCode" v-model="createTemp.contractCode" 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="isDisabled">
                  <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="providerName">
                <el-autocomplete
                  v-model="createTemp.providerName"
                  :disabled="dialogStatus==='change'"
                  value-key="name"
                  class="inline-input"
                  :fetch-suggestions="providerSearch"
                  placeholder="请输入供应商名称或供应商编号"
                  style="width:100%;"
                  @focus="handleFocusProvider"
                  @blur="handleBlurProvider"
                  @select="handleSelectProvider"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开始日期：" prop="startTime">
                <el-date-picker
                  v-model="createTemp.startTime"
                  :disabled="isDisabled"
                  type="date"
                  placeholder="开始日期"
                  :picker-options="pickerOptions1"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width:100%"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="截止日期：" prop="stopTime">
                <el-date-picker
                  v-model="createTemp.stopTime"
                  :disabled="isDisabled"
                  type="date"
                  placeholder="结束日期"
                  :picker-options="pickerOptions2"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  style="width:100%"
                  @change="changeTime"
                />
              </el-form-item>
            </el-col>
            <el-col v-if="dialogStatus=='create'" :span="8">
              <el-form-item label="合同状态：" prop="statue">
                <el-select v-model="createTemp.statue" clearable placeholder="合同状态" class="filter-item" style="width: 100%;" disabled>
                  <el-option
                    v-for="item in statues"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col v-if="dialogStatus=='change'" :span="8">
              <el-form-item label="合同状态：" prop="statue">
                <el-select v-model="createTemp.statue" clearable placeholder="合同状态" class="filter-item" style="width: 100%;"@change="changeStatues">
                  <el-option
                    v-for="item in statues2"
                    :key="item.id"
                    :label="item.name"
                    :value="item.name"
                  />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="零库存：" prop="isZeroStock">
                <el-radio-group v-model="createTemp.isZeroStock" :disabled="isDisabled" @change="changeIsZero">
                  <el-radio v-model="createTemp.isZeroStock" :label="1">是</el-radio>
                  <el-radio v-model="createTemp.isZeroStock" :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="creatorId">
                <el-select ref="creatorId" v-model="createTemp.creatorId" :disabled="isDisabled" 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="creatorTime">
                <el-date-picker
                  v-model="createTemp.creatorTime"
                  :disabled="isDisabled"
                  type="date"
                  :picker-options="pickerOptions3"
                  placeholder="录入日期"
                  style="width:100%;"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注：" prop="remark">
                <el-input
                  v-model="createTemp.remark"
                  :disabled="isDisabled"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="10">
              <el-form-item label="备件：" prop="partCode">
                <el-autocomplete
                  v-model="orderPart.partCode"
                  :disabled="isDisabled"
                  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>
        <el-table
          :key="tableKey"
          v-loading="listLoadingAdd"
          element-loading-text="给我一点时间"
          :data="listAdd"
          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 + (pageNumChange-1) * pageSizeChange + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件编号" min-width="90px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="80px" align="center">
            <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="备件品牌" min-width="120px" align="center">
            <template slot-scope="scope">
              <el-autocomplete
                v-model="scope.row.brand"
                :disabled="isDisabled"
                value-key="brandName"
                class="inline-input"
                :fetch-suggestions="brandSearch"
                placeholder="请输入品牌"
                style="width:100%;"
                @focus="handleFocusBrand( scope.row)"
                @blur="handleBlurBrand(scope.row)"
                @select="(value)=>
                {handleSelectBrand(value, scope.row)}"
              />
            </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 label="计划量" min-width="70px" align="center" valign="middle">
            <template slot-scope="scope">
              <el-form :model="scope.row" :rules="rules">
                <el-form-item prop="planAmount">
                  <el-input ref="planAmount" v-model="scope.row.planAmount" style="margin-top:15px" :disabled="isDisabled" />
                </el-form-item>
              </el-form>
            </template>
          </el-table-column>
          <el-table-column label="单价" min-width="80px" align="center" valign="middle">
            <template slot-scope="scope">
              <el-input v-model="scope.row.price" :disabled="isDisabled" />
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="110px" align="center">
            <template slot-scope="scope">
              <el-input v-model="scope.row.remark" type="textarea" placeholder="备注" :disabled="isDisabled" autosize maxlength="100" show-word-limit />
            </template>
          </el-table-column>
          <el-table-column v-if="isDisabled2" label="操作" align="center" width="100px" class-name="small-padding fixed-width" fixed="right">
            <template slot-scope="{row}">
              <a class="primary" :disabled="isokDisable" @click="partSmallSave(row)">保存</a>
              <a class="del" :disabled="isokDisable" @click="partSmallDelete(row)">删除</a>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalChange>0" :total="totalChange" :page.sync="getdataListParmChange.offset" :limit.sync="getdataListParmChange.pagecount" @pagination="getListChange" />
        <div slot="footer" class="dialog-footer" style="bottom:5px">
          <el-button type="primary" :disabled="isokDisable" @click="dialogStatus==='change'?changeData():changeData()">保存并关闭</el-button>
          <el-button @click="dialogFormVisible_change = false;getList();createTemp.providerName=''">取消并关闭</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-contentcard">
        <el-form ref="seeTemp" :rules="rules" :model="seeTemp" label-position="right" label-width="120px" style="width: 90%;margin:0 auto;">
          <el-row>
            <el-col :span="8">
              <el-form-item label="牧场：" prop="pastureName">
                <span> {{ seeTemp.pastureName }} </span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="合同编号：" prop="contractCode">
                <span> {{ seeTemp.contractCode }} </span>
                <!-- <el-input ref="contractNO" v-model="seeTemp.contractNO" /> -->
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="供应商：" prop="providerName">
                <span> {{ seeTemp.providerName }} </span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="开始日期：" prop="startTime">
                <span> {{ seeTemp.startTime }} </span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="截止日期：" prop="stopTime">
                <span> {{ seeTemp.stopTime }} </span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="合同状态：" prop="statue">
                <span> {{ seeTemp.statue }} </span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="零库存：" prop="isZeroStock">
                <el-radio-group v-model="seeTemp.isZeroStock" disabled @change="changeIsZero">
                  <el-radio v-model="seeTemp.isZeroStock" :label="1">是</el-radio>
                  <el-radio v-model="seeTemp.isZeroStock" :label="0">否</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入人：" prop="creatorMan">
                <span> {{ seeTemp.creatorMan }} </span>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="录入日期：" prop="creatorTime">
                <span> {{ seeTemp.creatorTime }} </span>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="备注：" prop="remark">
                <span> {{ seeTemp.remark }} </span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          :key="tableKey"
          element-loading-text="给我一点时间"
          :data="listSee"
          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 + (pageNumSee-1) * pageSizeSee + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件编号" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partCode }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件名称" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.partName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备件规格" min-width="80px" align="center">
            <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="备件品牌" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.brand }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计量单位" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.unit }}</span>
            </template>
          </el-table-column>
          <el-table-column label="计划量" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.planAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="单价" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.price }}</span>
            </template>
          </el-table-column>
          <el-table-column label="备注" min-width="80px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.remark }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalSee>0" :total="totalSee" :page.sync="getdataListParmSee.offset" :limit.sync="getdataListParmSee.pagecount" @pagination="getListSee" />
        <el-form
          ref="seeTemp"
          :rules="rules"
          :model="seeTemp"
          label-position="right"
          label-width="120px"
          style="width: 90%;margin:0 auto;"
        >
          <el-row>
            <el-col>
              <el-form-item label="流程进度" />
              <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="isContractExamineZG && seeTemp.SHStatus == 2" 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="isContractExamineZL && 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="isContractExamineZX && seeTemp.SHStatus == 5" type="success" style="display:inline-block" @click="handleExamine3()">审核2</el-button>
                <el-button v-else type="success" style="display:none" @click="handleExamine3()">审核2</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer" style="right:30px;position:absolute;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 @click="dialogFormVisible_Examine = false;">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 引入
import { GetDataByName, GetDataByNames, checkButtons, PostDataByName, ExecDataByConfig, failproccess, GetAccount } from '@/api/common'
import waves from '@/directive/waves' // waves directive
import { parseTime } 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 TreeSelect from '@/components/TreeSelect'
import Cookies from 'js-cookie'
import { getToken } from '@/utils/auth'
import { json2excel } from '@/utils/index.js'
export default {
  name: 'Contract',
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      listLoadingAdd: false,
      listLoadingSee: true,
      total: 0,
      listLoading: true,
      requestParam: {},
      // 1-2:table&搜索传参

      // 合同明细/编辑表格

      stockAAA: {
        stockA: '',
        stockNumber: '',
        stockName: '',
        specification: '',
        amount: '',
        note: ''
      },
      postDataPramas: {},
      requestFilterParams: {
        returntype: 'Map',
        parammaps: {}
      },
      temp: {},

      searchBtnVisible: true,
      dialogPvVisible: false,
      // 校验规则

      parentClass: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      nodeKey: 'id',
      defaultCheckedKeys: [],
      selectionIndex: [],
      // ---------------------------------
      isContractAdd: [], isContractTemplate: [], isContractImport: [], isContractExport: [], isContractSee: [], isContractChange: [], isContractDelete: [], isContractDelete2: [],
      isContractExamineZG: [],
      //  isContractExamineZL: [],
      isContractExamineZX: [],
      statues: [{ id: '0', name: '正常' }, { id: '1', name: '已过期' }, { id: '2', name: '终止' }],
      statues2: [{ id: '0', name: '正常' }, { id: '2', name: '终止' }],
      shStatues: [{ id: '0', name: '审核中' }, { id: '1', name: '已通过' }, { id: '2', name: '未通过' }],
      findAllProvider: [],
      findAllAssetType: [],
      findAllPasture: [],
      findAllDepart: [],
      findAllEmploye: [],
      findAllCategory: [],
      // 2-1.请求下拉框接口
      requestParams: [
        { name: 'findAllProvider', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllAssetType', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllPasture', offset: 0, pagecount: 0, returntype: 'Map', parammaps: { 'id': Cookies.get('pastureid') }},
        { name: 'findAllDepart', offset: 0, pagecount: 0, params: [] },
        { name: 'findAllEmploye', offset: 0, pagecount: 0, parammaps: { 'pastureId': Cookies.get('pastureid') }},
        { name: 'findAllCategory', offset: 0, pagecount: 0, params: [] }
      ],
      isokDisable: false,
      disabled: true,
      tableKey: 0,
      rules: {
        providerName: [{ required: true, message: '必填', trigger: 'blur' }],
        providerId: [{ required: true, message: '必填', trigger: 'blur' }],
        startTime: [{ required: true, message: '必填', trigger: 'blur' }],
        stopTime: [{ required: true, message: '必填', trigger: 'blur' }],
        statue: [{ required: true, message: '必填', trigger: 'blur' }]
      },
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' },
      dialogFormVisible: false,
      dialogStatus: '',
      dialogFormVisible_change: false,
      dialogFormVisible_See: false,
      textMap: {
        card: '合同明细打印',
        create: '新增合同',
        update: '编辑',
        change: '变更',
        examine: '审核',
        examine2: '审核2',
        examine3: '审核3'
      },
      radioAll: '全部',
      getdataListParm: {
        name: 'providerPactList',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          pastureName: Cookies.get('pasturename'),
          contractCode: '',
          statue: '',
          stuteSH: '',
          providerName: '',
          inputDatetime: ''
        }
      },
      list: [],
      activeName: 'first',
      tableKey2: 0,
      listLoading2: true,
      total2: 0,
      list2: [],
      getdataListParm2: {
        name: 'contractDetail',
        page: 1,
        offset: 1,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {
          inputDatetime: '',
          providerName: '',
          contractCode: '',
          stopTime: '',
          startTime: '',
          statue: '',
          partCode: '',
          partName: '',
          pastureName: Cookies.get('pasturename')
        }
      },
      getdataListParmBeforeUploading: {
        name: 'clearPastureStock',
        page: 0,
        offset: 0,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {}
      },
      getdataListParmSee: {
        name: 'getcontratListBybig',
        returntype: 'Map',
        page: 0,
        offset: 0,
        pagecount: 10,
        parammaps: {}
      },
      totalSee: 0,
      getdataListParmChange: {
        name: 'getcontratListBybigtemp',
        returntype: 'Map',
        page: 0,
        offset: 0,
        pagecount: 10,
        parammaps: {}
      },
      listLoadingChange: true,
      totalChange: 0,

      activeList: [],
      active: 3,
      seeTemp: {},
      listSee: [],
      totalSee: 0,
      listAdd: [],
      requestBrand: {
        name: 'getBrandByPartCode',
        page: 0,
        offset: 0,
        pagecount: 10,
        returntype: 'Map',
        parammaps: {}
      },
      BrandList: [],
      createTemp: {
        pastureId: this.$store.state.user.pastureid,
        providerName: '',
        startTime: '',
        stopTime: '',
        statue: '',
        isZeroStock: 0,
        creatorId: this.$store.state.user.employeid,
        creatorTime: parseTime(new Date(), '{y}-{m}-{d}')
      },
      pickerOptions3: {
        disabledDate(time) {
          return time.getTime() > Date.now()// 当天之前的时间可选
        }
      },
      pickerOptions1: {
        disabledDate: (time) => {
          if (this.createTemp.stopTime !== '') {
            return parseTime(time.getTime(), '{y}-{m}-{d}') > parseTime(Date.now(), '{y}-{m}-{d}') || parseTime(time.getTime(), '{y}-{m}-{d}') >= this.createTemp.stopTime
          } else {
            return time.getTime() > Date.now()
          }
        }
      },
      pickerOptions2: {
        disabledDate: (time) => {
          // return time.getTime() < this.createTemp.startTime || time.getTime() > Date.now()
          return parseTime(time.getTime(), '{y}-{m}-{d}') <= this.createTemp.startTime
        }
      },
      getParmCreateNumber: {
        name: 'autoCreatCode',
        page: 0,
        offset: 0,
        pagecount: 0,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid'),
          codeType: 'HT'
        }
      },
      requestSparePart: {
        name: 'getPartsListHT',
        page: 1,
        offset: 1,
        pagecount: 20,
        returntype: 'Map',
        parammaps: {
          pastureId: Cookies.get('pastureid')
        }
      },
      orderPart: {},

      examineTemp: {},
      dialogFormVisible_Examine: false,
      isStatueReason: false,
      isDisabled: false,
      isDisabled2: false,
      buttons: [],
      isPercentage: false,
      percentage: 1,
      downloadParam: {},
      getParmChargeContractSHStatus: {
        name: 'chargeContractSHStatus',
        parammaps: {}
      },
      getdataListParmCopybigcontract: {
        name: 'Copybigcontract',
        parammaps: {}
      }
    }
  },
  computed: {
    // 设置请求头
    headers() {
      return {
        // 设置token
        // eslint-disable-next-line no-undef
        token: getToken()
      }
    },
    uploadData() {
      return {
        name: 'updatePastureStock',
        importParams: '合同编号,牧场,合同开始日期,合同截止日期,供应商,物料编码,品名,规格型号,计量单位,品牌,计划量,单价,备注,一级分类,二级分类,三级分类,填写人,填写时间,分管副场审核,分管副场审核时间,场长审核,场长审核时间,运营办审核,运营办审核时间,过期处理人,过期处理时间',
        sheetname: 'SheetJS'
      }
    },
    // 设置上传地址
    uploadExcelUrl() {
      // process.env.VUE_APP_BASE_API是服务器的路径，也是axios的基本路径
      return process.env.VUE_APP_BASE_API + 'authdata/ImportExcel'
    }
  },
  created() {
    const that = this
    GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
      that.buttons = response.data.list
      that.getButtons()
    })
    this.getDownList()
    this.getList()
  },
  methods: {
    getButtons() {
      // 新增
      const ContractAdd = 'customs:contract:add'
      const isContractAdd = checkButtons(this.$store.state.user.buttons, ContractAdd)
      this.isContractAdd = isContractAdd
      // 模板
      const ContractTemplate = 'customs:contract:template'
      const isContractTemplate = checkButtons(this.$store.state.user.buttons, ContractTemplate)
      this.isContractTemplate = isContractTemplate
      // 导入
      const ContractImport = 'customs:contract:import'
      const isContractImport = checkButtons(this.$store.state.user.buttons, ContractImport)
      this.isContractImport = isContractImport
      // 导出
      const ContractExport = 'customs:contract:export'
      const isContractExport = checkButtons(this.$store.state.user.buttons, ContractExport)
      this.isContractExport = isContractExport
      // 查看
      const ContractSee = 'customs:contract:see'
      const isContractSee = checkButtons(this.$store.state.user.buttons, ContractSee)
      this.isContractSee = isContractSee
      // 变更
      const ContractChange = 'customs:contract:change'
      const isContractChange = checkButtons(this.$store.state.user.buttons, ContractChange)
      this.isContractChange = isContractChange
      // 删除
      const ContractDelete = 'customs:contract:delete'
      const isContractDelete = checkButtons(this.$store.state.user.buttons, ContractDelete)
      this.isContractDelete = isContractDelete
      // 高级删除
      const ContractDelete2 = 'customs:contract:delete2'
      const isContractDelete2 = checkButtons(this.$store.state.user.buttons, ContractDelete2)
      this.isContractDelete2 = isContractDelete2

      // isContractExamineZG: [], isContractExamineZL: [], isContractExamineZX: [],
      // 设备主管审核
      const ContractExamineZG = 'customs:contract:examineZG'
      const isContractExamineZG = checkButtons(this.$store.state.user.buttons, ContractExamineZG)
      this.isContractExamineZG = isContractExamineZG
      // 设备助理审核
      // const ContractExamineZL = 'customs:contract:examineZL'
      // const isContractExamineZL = checkButtons(this.$store.state.user.buttons, ContractExamineZL)
      // this.isContractExamineZL = isContractExamineZL
      // 设备中心审核
      const ContractExamineZX = 'customs:contract:examineZX'
      const isContractExamineZX = checkButtons(this.$store.state.user.buttons, ContractExamineZX)
      this.isContractExamineZX = isContractExamineZX
    },
    getDownList() {
      GetDataByNames(this.requestParams).then(response => {
        this.findAllProvider = response.data.findAllProvider.list
        this.findAllAssetType = response.data.findAllAssetType.list
        this.findAllPasture = response.data.findAllPasture.list
        this.findAllDepart = response.data.findAllDepart.list
        this.findAllEmploye = response.data.findAllEmploye.list
        this.findAllCategory = response.data.findAllCategory.list
      })
    },
    getList() {
      this.listLoading = true
      console.log(this.$refs['inputDatetime'])
      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 = ''
      }
      console.log('table发送数据', this.getdataListParm.parammaps)
      GetDataByName(this.getdataListParm).then(response => {
        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
        }, 300)
      })
    },
    form_search() {
      this.listLoading = true
      if (this.getdataListParm.parammaps.inputDatetime === null) {
        this.getdataListParm.parammaps.inputDatetime = ''
      }
      // this.getdataListParm.parammaps.providerName = this.createTemp.providerName
      this.getdataListParm.offset = 1
      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 => {
        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
        }, 300)
      })
    },
    form_search2() {
      this.listLoading2 = true
      if (this.getdataListParm2.parammaps.inputDatetime === null) {
        this.getdataListParm2.parammaps.inputDatetime = ''
      }
      this.getdataListParm2.offset = 1
      this.getList2()
    },
    changeAll() {
      console.log(this.radioAll)
      if (this.radioAll === '全部') {
        this.getdataListParm.name = 'providerPactList'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: Cookies.get('pasturename'),
          contractCode: '',
          statue: '',
          stuteSH: '',
          providerName: '',
          inputDatetime: ''
        }
        this.getList()
      } else if (this.radioAll === '待处理') {
        this.getdataListParm.name = 'providerPactWebListNO'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: this.getdataListParm.parammaps.pastureName,
          contractCode: this.getdataListParm.parammaps.contractCode,
          statue: this.getdataListParm.parammaps.statue,
          stuteSH: this.getdataListParm.parammaps.stuteSH,
          providerName: this.getdataListParm.parammaps.providerName,
          inputDatetime: this.getdataListParm.parammaps.inputDatetime,
          empId: Cookies.get('employeid'),
          pastureId: Cookies.get('pastureid'),
          deptId: Cookies.get('departmentid')
        }
        this.getList()
      } else if (this.radioAll === '已处理') {
        this.getdataListParm.name = 'providerPactWebList'
        this.getdataListParm.offset = 1
        this.getdataListParm.parammaps = {
          pastureName: this.getdataListParm.parammaps.pastureName,
          contractCode: this.getdataListParm.parammaps.contractCode,
          statue: this.getdataListParm.parammaps.statue,
          stuteSH: this.getdataListParm.parammaps.stuteSH,
          providerName: this.getdataListParm.parammaps.providerName,
          inputDatetime: this.getdataListParm.parammaps.inputDatetime,
          empId: Cookies.get('employeid'),
          pastureId: Cookies.get('pastureid'),
          deptId: Cookies.get('departmentid')
        }
        this.getList()
      }
    },
    SHStatus: function(cellValue) {
      // console.log(cellValue.isZeroStock)
      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 '未通过'
      }
    },
    isZeroStock: function(cellValue) {
      if (cellValue.isZeroStock == 0) {
        return '否'
      } else if (cellValue.isZeroStock == 1) {
        return '是'
      }
    },
    form_see(row) {
      this.seeTemp = Object.assign({}, row) // copy obj
      this.dialogStatus = 'card'
      this.dialogFormVisible_See = true
      // this.seeTemp.isZeroStock = 1

      // this.$nextTick(() => {
      //   this.seeTemp.isZeroStock = JSON.stringify(this.seeTemp.isZeroStock)
      // })
      console.log('查看上方数据(从table读取)', this.seeTemp.isZeroStock)
      // 基础信息
      this.getdataListParmSee.parammaps.id = row.id
      this.getListSee()
      // 流程图
      var reason = '未通过原因:' + this.seeTemp.workflowNote
      if (this.seeTemp.SHStatus == 2) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { title: '办公室主任审核' }, { title: '设备中心审核' }]
        this.active = 1
      } else if (this.seeTemp.SHStatus == 3) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { title: '办公室主任审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备中心审核' }]
        this.active = 2
      } else if (this.seeTemp.SHStatus == 4) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { title: '办公室主任审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson, status: 'error', reason: reason }, { title: '设备中心审核' }]
        this.active = 2
      } else if (this.seeTemp.SHStatus == 5) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { title: '办公室主任审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备中心审核' }]
        this.active = 2
      } else if (this.seeTemp.SHStatus == 6) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { title: '办公室主任审核', date: this.seeTemp.chargeDate, name: this.seeTemp.chargePerson }, { title: '设备中心审核' }]
        this.active = 3
      } else if (this.seeTemp.SHStatus == 7) {
        this.activeList = [{ title: '合同录入', date: this.seeTemp.creatorTime, name: this.seeTemp.creatorMan }, { 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.creatorTime, name: this.seeTemp.creatorMan }, { 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
      }
    },
    getListSee() {
      GetDataByName(this.getdataListParmSee).then(response => {
        this.listSee = response.data.list
        this.pageNumSee = response.data.pageNum
        this.pageSizeSee = response.data.pageSize
        if (response.data.total) {
          this.totalSee = response.data.total
        }
        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) {
              const srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              const picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
              this.listSee[i].srcpath = srcpath
              this.listSee[i].picpath = picpath
            } else {
              this.listSee[i].srcpath = ''
              this.listSee[i].picpath = ''
            }
          }
        }

        console.log('查看下方table数据', this.listSee)
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingSee = false
        }, 300)
      })
    },

    resetCreateTemp() {
      // 格式化日期
      parseTime(new Date(), '{y}-{m}-{d}')
      this.temp.defaultCheckedKeys = []
      this.list2 = null
      this.listAdd = []
      // ---
      this.createTemp.pastureId = this.$store.state.user.pastureid
      this.createTemp.providerName = ''
      this.createTemp.startTime = ''
      this.createTemp.stopTime = ''
      this.createTemp.statue = ''
      this.createTemp.isZeroStock = 0
      this.createTemp.creatorId = this.$store.state.user.employeid
      this.createTemp.creatorTime = parseTime(new Date(), '{y}-{m}-{d}')
      this.createTemp.contractCode = ''
    },
    form_add() {
      this.resetCreateTemp()
      this.dialogStatus = 'create'
      this.dialogFormVisible = true
      this.createTemp.pastureId = this.$store.state.user.pastureid
      this.createTemp.record = '#409EFF'
      this.isDisabled2 = true
      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.contractCode = response.data.list[0].orderCode
          this.$forceUpdate()
        })
      })
    },
    changeTime(val) {
      if (parseTime(new Date(), '{y}-{m}-{d}') <= this.createTemp.stopTime) {
        this.createTemp.statue = '正常'
        this.createTemp.statueId = 0
      } else {
        this.createTemp.statue = '已过期'
        this.createTemp.statueId = 1
      }
    },
    sparePartSearch(queryString, cb) {
      console.log('备件模糊查询输入值', queryString)
      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)
      // this.listAdd.push(item)
      if (this.listAdd.length > 0) {
        // eslint-disable-next-line no-redeclare
        if (this.listAdd.find(obj => obj.partId === item.partId)) {
          this.$message({
            type: 'warning',
            message: '此备件已存在，请重新选择备件'
          })
        } else {
          if (item.srcpath !== null && item.picpath !== null && item.srcpath !== undefined && item.picpath !== undefined) {
            this.$set(item, 'srcpath', process.env.VUE_APP_BASE_API + item.srcpath)
            this.$set(item, 'picpath', process.env.VUE_APP_BASE_API + item.picpath)
          } else {
            item.srcpath = ''
            item.picpath = ''
          }
          this.$set(item, 'myid', new Date().getTime())
          this.listAdd.unshift(item)
        }
      } else {
        if (item.srcpath !== null && item.picpath !== null) {
          this.$set(item, 'srcpath', process.env.VUE_APP_BASE_API + item.srcpath)
          this.$set(item, 'picpath', process.env.VUE_APP_BASE_API + item.picpath)
        } else {
          item.srcpath = ''
          item.picpath = ''
        }
        this.$set(item, 'myid', new Date().getTime())
        this.listAdd.unshift(item)
      }
    },
    brandSearch(queryString, cb) {
      console.log('品牌模糊查询输入值', queryString)
      this.requestBrand.parammaps['brandName'] = queryString
      GetDataByName(this.requestBrand).then(response => {
        console.log('品牌模糊查询搜索data', response.data.list)
        this.BrandList = response.data.list
        cb(this.BrandList)
      })
    },
    handleSelectBrand(item, row) {
      console.log('品牌模糊查询选中值', item)
      console.log('品牌模糊查询选中值所在行', row)
      this.$set(row, 'brandName', item.brandName)
      this.$set(row, 'brandId', item.brandId)
      this.$forceUpdate()
    },
    handleFocusBrand(row) {
      this.$set(row, 'brandName', '')
      this.$set(row, 'brandId', '')
    },
    handleBlurBrand(row) {
      if (row.brandId == '') {
        this.$set(row, 'brand', '')
        this.$set(row, 'brandName', '')
        this.$set(row, 'brandId', '')
      }
    },
    partDelete(row) {
      console.log(this.listAdd)
      MessageBox.confirm('设备名称：' + row.partName, '确认删除？', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // console.log(this.list2)
        for (var i = 0; i < this.listAdd.length; i++) {
          console.log(this.listAdd[i])
          if (this.listAdd[i].myid === row.myid) {
            var listAddIndex = this.listAdd.indexOf(this.listAdd[i])
          }
          if (listAddIndex > -1) {
            this.listAdd.splice(listAddIndex, 1)
            return
          }
        }
      })
    },
    add_dialog_save() {
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['createTemp'].validate(valid => {
        if (valid) {
          if (this.createTemp.contractCode == '' || this.createTemp.contractCode == null || this.createTemp.contractCode == undefined) {
            GetDataByName(this.getParmCreateNumber).then(response => {
              this.$nextTick(() => {
                console.log('合同编号', response.data.list[0].orderCode)
                this.createTemp.contractCode = response.data.list[0].orderCode
                this.$forceUpdate()
                this.add_dialog_saveSave()
              })
            })
          } else {
            this.add_dialog_saveSave()
          }
        }
      })
    },
    add_dialog_saveSave() {
      if (this.listAdd.length !== 0) {
        for (var j = 0; j < this.listAdd.length; j++) {
          if (this.listAdd[j].planAmount == null || this.listAdd[j].brand == null || this.listAdd[j].price == null || this.listAdd[j].planAmount == '' || this.listAdd[j].brand === '' || this.listAdd[j].brandId === '' || this.listAdd[j].price == '' || this.listAdd[j].brand == undefined || this.listAdd[j].brandId == undefined) {
            this.$message({
              type: 'warning',
              message: '请检查备件品牌或计划量或单价是否为空',
              duration: 2000
            })
            return false
          } else {
            var rulesPlanAmount = /^[1-9]\d*$/
            if (!rulesPlanAmount.test(parseFloat(this.listAdd[j].planAmount))) {
              this.$message({
                type: 'error',
                message: '计划量请输入正整数',
                duration: 2000
              })
              return false
            } else {
              var rulesPrice = /(^[1-9](\d+)?(\.\d{1,5})?$)|(^\d\.\d{1,5}$)/
              if (!rulesPrice.test(parseFloat(this.listAdd[j].price))) {
                this.$message({
                  type: 'error',
                  message: '价格请输入正数,最多保留小数点后五位',
                  duration: 2000
                })
                return false
              }
            }
          }
        }
        this.postDataPramas.common = { 'returnmap': '0' }
        this.postDataPramas.data = []
        this.postDataPramas.data[0] = { 'name': 'insertBigContract', 'type': 'e', 'parammaps': {
          pastureId: this.createTemp.pastureId,
          providerId: this.createTemp.providerId,
          providerName: this.createTemp.providerName,
          startTime: this.createTemp.startTime,
          stopTime: this.createTemp.stopTime,
          contractCode: this.createTemp.contractCode,
          creatorId: this.createTemp.creatorId,
          creatorMan: this.createTemp.creatorMan,
          creatorTime: this.createTemp.creatorTime,
          isZeroStock: this.createTemp.isZeroStock,
          statue: 1
        }}
        this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
        this.postDataPramas.data[1].children = []
        this.postDataPramas.data[1].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
          bigId: '@insertBigContract.LastInsertId',
          pastureId: this.createTemp.pastureId,
          pastureName: '@insertSpotList.pastureName',
          partId: '@insertSpotList.partId',
          partName: '@insertSpotList.partName',
          partCode: '@insertSpotList.partCode',
          specification: '@insertSpotList.specification',
          price: '@insertSpotList.price',
          brandId: '@insertSpotList.brandId',
          brand: '@insertSpotList.brand',
          planAmount: '@insertSpotList.planAmount',
          remark: '@insertSpotList.remark',
          unit: '@insertSpotList.unit'
        }}
        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.getList()
            this.dialogFormVisible = false
            this.createTemp.providerName = ''
            this.$notify({
              title: '',
              message: '保存成功',
              type: 'success',
              duration: 2000
            })
          }
        })
        return true
      } else {
        this.$notify({
          title: '',
          message: '请选择备件',
          type: 'warning',
          duration: 2000
        })
        return false
      }
    },
    beforeUploading() {
      PostDataByName(this.getdataListParmBeforeUploading).then(response => {
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 300)
      })
    },
    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
    },
    changeStatue(val) {
      console.log(val)
      if (val == 2) {
        this.isStatueReason = true
      } else {
        this.isStatueReason = false
      }
    },
    createExamineData() {
      console.log('点击了设备主管审核确认')
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      this.$refs['examineTemp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'contractCharge'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            this.requestParam.parammaps.statue = 5
          } 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.$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 = 'contractCharge3'
          this.requestParam.parammaps = {}
          this.requestParam.parammaps.id = this.examineTemp.id
          if (this.examineTemp.statueSH === 1) {
            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.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) {
          if (this.examineTemp.statueSH === 1) {
            this.requestParam.common = { 'returnmap': '0' }
            this.requestParam.data = []
            this.requestParam.data[0] = { 'name': 'contractCharge1', 'type': 'e', 'parammaps': {
              statue: 7,
              empId: Cookies.get('employeid'),
              workflowNote: this.examineTemp.workflowNote,
              id: this.examineTemp.id
            }}
            this.requestParam.data[1] = { 'name': 'updateBigcontractbyCode', 'type': 'e', 'parammaps': {
              precontractCode: this.examineTemp.precontractCode
            }}

            ExecDataByConfig(this.requestParam).then(response => {
              console.log('新增保存发送参数', this.requestParam)
              if (response.msg === 'fail') {
                this.$notify({
                  title: '保存失败',
                  message: response.data,
                  type: 'warning',
                  duration: 2000
                })
              } else {
                this.getList()
                this.dialogFormVisible_Examine = false
                this.dialogFormVisible_See = false
                this.isStatueReason = false
                this.$notify({
                  title: '',
                  message: '保存成功',
                  type: 'success',
                  duration: 2000
                })
              }
            })
          } else {
            this.requestParam.name = 'contractCharge1'
            this.requestParam.parammaps = {}
            this.requestParam.parammaps.id = this.examineTemp.id
            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.dialogFormVisible_Examine = false
                this.dialogFormVisible_See = false
                this.isStatueReason = false
                this.$notify({
                  title: '成功',
                  message: '审核成功',
                  type: 'success',
                  duration: 2000
                })
              } else {
                failproccess(response, this.$notify)
              }
            })
          }
        }
      })
    },
    getListChange() {
      GetDataByName(this.getdataListParmChange).then(response => {
        this.$nextTick(() => {
          this.listAdd = response.data.list
        })
        this.pageNumChange = response.data.pageNum
        this.pageSizeChange = response.data.pageSize
        if (response.data.total) {
          this.totalChange = response.data.total
        }
        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) {
              const srcpath = process.env.VUE_APP_BASE_API + response.data.list[i].srcpath
              const picpath = process.env.VUE_APP_BASE_API + response.data.list[i].picpath
              this.listAdd[i].srcpath = srcpath
              this.listAdd[i].picpath = picpath
            } else {
              this.listAdd[i].srcpath = ''
              this.listAdd[i].picpath = ''
            }
          }
        }

        console.log('变更下方table数据', this.listSee)
        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoadingChange = false
        }, 300)
      })
    },
    handleChange(row) {
      this.getParmChargeContractSHStatus.parammaps.contractCode = row.contractCode
      GetDataByName(this.getParmChargeContractSHStatus).then(response => {
        this.$nextTick(() => {
          if (response.data.list[0].flag == 0) {
            this.getdataListParmCopybigcontract.parammaps.id = row.id
            this.getdataListParmCopybigcontract.parammaps.pastureId = row.pastureId
            GetDataByName(this.getdataListParmCopybigcontract).then(response => {
              this.dialogStatus = 'change'
              this.dialogFormVisible_change = true
              this.createTemp = Object.assign({}, row)
              this.createTemp.precontractCode = row.contractCode
              this.isDisabled = false
              this.isDisabled2 = true
              this.getCreateNumber()
              this.getdataListParmChange.parammaps.id = response.data.list[0].msg
              this.getListChange()
            })
          } else {
            this.$message({
              message: '此合同变更审核中，不可重复变更',
              type: 'warning'
            })
          }
        })
      })
    },
    changeStatues(val) {
      if (val == '终止') {
        this.isDisabled = true
        this.isDisabled2 = false
      } else {
        this.isDisabled = false
        this.isDisabled2 = true
      }
    },
    partSmallSave(row) {
      console.log(row)
      this.isokDisable = true
      setTimeout(() => {
        this.isokDisable = false
      }, 1000)
      if (row.id == null || row.id == undefined) {
        if (row.brand == '' || row.brandId == '' || row.planAmount == '' || row.price == '') {
          this.$message({
            message: '请检查备件品牌或计划量或单价是否为空',
            type: 'warning'
          })
          return false
        } else {
          this.postDataPramas.name = 'updatecontrattempNoId'
          this.postDataPramas.parammaps = {}
          this.postDataPramas.parammaps.bigId = this.getdataListParmChange.parammaps.id
          this.postDataPramas.parammaps.pastureId = this.createTemp.pastureId
          this.postDataPramas.parammaps.pastureName = this.createTemp.pastureName
          this.postDataPramas.parammaps.partId = row.partId
          this.postDataPramas.parammaps.partName = row.partName
          this.postDataPramas.parammaps.partCode = row.partCode
          this.postDataPramas.parammaps.specification = row.specification
          this.postDataPramas.parammaps.price = row.price
          this.postDataPramas.parammaps.brandId = row.brandId
          this.postDataPramas.parammaps.brand = row.brand
          this.postDataPramas.parammaps.planAmount = row.planAmount
          this.postDataPramas.parammaps.remark = row.remark
          this.postDataPramas.parammaps.unit = row.unit
          PostDataByName(this.postDataPramas).then(response => {
            console.log('保存发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              this.getListChange()
              this.$notify({
                title: '成功',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      } else {
        if (row.brand == '' || row.brandId == '' || row.planAmount == '' || row.price == '') {
          this.$message({
            message: '请检查备件品牌或计划量或单价是否为空',
            type: 'warning'
          })
          return false
        } else {
          this.postDataPramas.name = 'updatecontrattemp'
          this.postDataPramas.parammaps = {}
          this.postDataPramas.parammaps.brandId = row.brandId
          this.postDataPramas.parammaps.brand = row.brand
          this.postDataPramas.parammaps.planAmount = row.planAmount
          this.postDataPramas.parammaps.price = row.price
          this.postDataPramas.parammaps.remark = row.remark
          this.postDataPramas.parammaps.id = row.id
          PostDataByName(this.postDataPramas).then(response => {
            console.log('保存发送参数', this.requestParam)
            if (response.msg !== 'fail') {
              this.getListChange()
              this.$notify({
                title: '成功',
                message: '保存成功',
                type: 'success',
                duration: 2000
              })
            } else {
              failproccess(response, this.$notify)
            }
          })
        }
      }
    },
    partSmallDelete(row) {
      if (row.id == null || row.id == undefined) {
        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].myid === row.myid) {
              var listAddIndex = this.listAdd.indexOf(this.listAdd[i])
            }
            if (listAddIndex > -1) {
              this.listAdd.splice(listAddIndex, 1)
              return
            }
          }
        })
      } else {
        MessageBox.confirm('确认删除此信息?', {
          confirmButtonText: '确认',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.postDataPramas.name = 'deletecontrattemp'
          this.postDataPramas.parammaps = {}
          this.postDataPramas.parammaps['id'] = row.id
          PostDataByName(this.postDataPramas).then(() => {
            this.getListChange()
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    changeData() {
      if (this.createTemp.statue == '终止') {
        this.isokDisable = true
        setTimeout(() => {
          this.isokDisable = false
        }, 1000)
        this.$refs['createTemp'].validate(valid => {
          if (valid) {
            this.postDataPramas = {}
            this.postDataPramas.name = 'updatecontractstatu'
            this.postDataPramas.parammaps = {}
            this.postDataPramas.parammaps.id = this.createTemp.id
            PostDataByName(this.postDataPramas).then(response => {
              console.log('变更保存发送参数', this.requestParam)
              if (response.msg !== 'fail') {
                this.dialogFormVisible_change = false
                this.getList()
                this.$notify({
                  title: '成功',
                  message: '变更成功',
                  type: 'success',
                  duration: 2000
                })
              } else {
                failproccess(response, this.$notify)
              }
            })
          }
        })
        // this.$refs['createTemp'].validate(valid => {
        //   if (valid) {
        //     if (valid) {
        //       if (this.listAdd.length !== 0) {
        //         for (var j = 0; j < this.listAdd.length; j++) {
        //           if (this.listAdd[j].planAmount == null || this.listAdd[j].brand == null || this.listAdd[j].price == null || this.listAdd[j].planAmount == '' || this.listAdd[j].brand === '' || this.listAdd[j].brandId === '' || this.listAdd[j].price == '' || this.listAdd[j].brand == undefined || this.listAdd[j].brandId == undefined) {
        //             this.$message({
        //               type: 'warning',
        //               message: '请检查备件品牌或计划量或单价是否为空',
        //               duration: 2000
        //             })
        //             return false
        //           } else {
        //             var rulesPlanAmount = /^[1-9]\d*$/
        //             if (!rulesPlanAmount.test(parseFloat(this.listAdd[j].planAmount))) {
        //               this.$message({
        //                 type: 'error',
        //                 message: '计划量请输入正整数',
        //                 duration: 2000
        //               })
        //               return false
        //             } else {
        //               var rulesPrice = /(^[1-9](\d+)?(\.\d{1,3})?$)|(^\d\.\d{1,3}$)/
        //               if (!rulesPrice.test(parseFloat(this.listAdd[j].price))) {
        //                 this.$message({
        //                   type: 'error',
        //                   message: '价格请输入正数,最多保留小数点后三位',
        //                   duration: 2000
        //                 })
        //                 return false
        //               }
        //             }
        //           }
        //         }

        //         this.postDataPramas.common = { 'returnmap': '0' }
        //         this.postDataPramas.data = []
        //         this.postDataPramas.data[0] = { 'name': 'insertBigContract', 'type': 'e', 'parammaps': {
        //           pastureId: this.createTemp.pastureId,
        //           providerId: this.createTemp.providerId,
        //           providerName: this.createTemp.providerName,
        //           startTime: this.createTemp.startTime,
        //           stopTime: this.createTemp.stopTime,
        //           contractCode: this.createTemp.precontractCode + '(终止)' + parseTime(new Date(), '{y}-{m}-{d} {h}:{i}:{s}'),
        //           creatorId: this.createTemp.creatorId,
        //           creatorMan: this.createTemp.creatorMan,
        //           creatorTime: this.createTemp.creatorTime,
        //           isZeroStock: this.createTemp.isZeroStock,
        //           statue: 0,
        //           remark: this.createTemp.remark,
        //           precontractCode: this.createTemp.precontractCode
        //         }}
        //         this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
        //         this.postDataPramas.data[1].children = []
        //         this.postDataPramas.data[1].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
        //           bigId: '@insertBigContract.LastInsertId',
        //           pastureId: this.createTemp.pastureId,
        //           pastureName: this.createTemp.pastureName,
        //           partId: '@insertSpotList.partId',
        //           partName: '@insertSpotList.partName',
        //           partCode: '@insertSpotList.partCode',
        //           specification: '@insertSpotList.specification',
        //           price: '@insertSpotList.price',
        //           brandId: '@insertSpotList.brandId',
        //           brand: '@insertSpotList.brand',
        //           planAmount: '@insertSpotList.planAmount',
        //           remark: '@insertSpotList.remark',
        //           unit: '@insertSpotList.unit'
        //         }}
        //         // this.postDataPramas.data[2] = { 'name': 'updateBigcontract', 'type': 'e', 'parammaps': {
        //         //   id: this.createTemp.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.getList()
        //             this.dialogFormVisible_change = false
        //             this.createTemp.providerName = ''
        //             this.$notify({
        //               title: '',
        //               message: '保存成功',
        //               type: 'success',
        //               duration: 2000
        //             })
        //           }
        //         })
        //         return true
        //       } else {
        //         this.$notify({
        //           title: '',
        //           message: '请选择备件',
        //           type: 'warning',
        //           duration: 2000
        //         })
        //         return false
        //       }
        //     }
        //   }
        // })
      } else {
        this.isokDisable = true
        setTimeout(() => {
          this.isokDisable = false
        }, 1000)
        this.$refs['createTemp'].validate(valid => {
          if (valid) {
            this.postDataPramas.name = 'Copybigcontracttemp'
            this.postDataPramas.parammaps = {}
            this.postDataPramas.parammaps.id = this.getdataListParmChange.parammaps.id
            PostDataByName(this.postDataPramas).then(response => {
              console.log('变更保存发送参数', this.requestParam)
              if (response.msg !== 'fail') {
                this.dialogFormVisible_change = false
                this.getList()
                this.$notify({
                  title: '成功',
                  message: '变更成功',
                  type: 'success',
                  duration: 2000
                })
              } else {
                failproccess(response, this.$notify)
              }
            })
          }
        })
        // this.$refs['createTemp'].validate(valid => {

        // if (valid) {
        //   if (valid) {
        //     if (this.listAdd.length !== 0) {
        //       for (var j = 0; j < this.listAdd.length; j++) {
        //         if (this.listAdd[j].planAmount == null || this.listAdd[j].brand == null || this.listAdd[j].price == null || this.listAdd[j].planAmount == '' || this.listAdd[j].brand === '' || this.listAdd[j].brandId === '' || this.listAdd[j].price == '' || this.listAdd[j].brand == undefined || this.listAdd[j].brandId == undefined) {
        //           this.$message({
        //             type: 'warning',
        //             message: '请检查备件品牌或计划量或单价是否为空',
        //             duration: 2000
        //           })
        //           return false
        //         } else {
        //           var rulesPlanAmount = /^[1-9]\d*$/
        //           if (!rulesPlanAmount.test(parseFloat(this.listAdd[j].planAmount))) {
        //             this.$message({
        //               type: 'error',
        //               message: '计划量请输入正整数',
        //               duration: 2000
        //             })
        //             return false
        //           } else {
        //             var rulesPrice = /(^[1-9](\d+)?(\.\d{1,3})?$)|(^\d\.\d{1,3}$)/
        //             if (!rulesPrice.test(parseFloat(this.listAdd[j].price))) {
        //               this.$message({
        //                 type: 'error',
        //                 message: '价格请输入正数,最多保留小数点后三位',
        //                 duration: 2000
        //               })
        //               return false
        //             }
        //           }
        //         }
        //       }
        //       this.postDataPramas.common = { 'returnmap': '0' }
        //       this.postDataPramas.data = []
        //       this.postDataPramas.data[0] = { 'name': 'insertBigContract', 'type': 'e', 'parammaps': {
        //         pastureId: this.createTemp.pastureId,
        //         providerId: this.createTemp.providerId,
        //         providerName: this.createTemp.providerName,
        //         startTime: this.createTemp.startTime,
        //         stopTime: this.createTemp.stopTime,
        //         contractCode: this.createTemp.contractCode,
        //         creatorId: this.createTemp.creatorId,
        //         creatorMan: this.createTemp.creatorMan,
        //         creatorTime: this.createTemp.creatorTime,
        //         isZeroStock: this.createTemp.isZeroStock,
        //         statue: 1,
        //         remark: this.createTemp.remark,
        //         precontractCode: this.createTemp.precontractCode
        //       }}
        //       this.postDataPramas.data[1] = { 'name': 'insertSpotList', 'resultmaps': { 'list': this.listAdd }}
        //       this.postDataPramas.data[1].children = []
        //       this.postDataPramas.data[1].children[0] = { 'name': 'insertContract', 'type': 'e', 'parammaps': {
        //         bigId: '@insertBigContract.LastInsertId',
        //         pastureId: this.createTemp.pastureId,
        //         pastureName: this.createTemp.pastureName,
        //         partId: '@insertSpotList.partId',
        //         partName: '@insertSpotList.partName',
        //         partCode: '@insertSpotList.partCode',
        //         specification: '@insertSpotList.specification',
        //         price: '@insertSpotList.price',
        //         brandId: '@insertSpotList.brandId',
        //         brand: '@insertSpotList.brand',
        //         planAmount: '@insertSpotList.planAmount',
        //         remark: '@insertSpotList.remark',
        //         unit: '@insertSpotList.unit'
        //       }}
        //       // this.postDataPramas.data[2] = { 'name': 'updateBigcontract', 'type': 'e', 'parammaps': {
        //       //   id: this.createTemp.id
        //       // }}
        //       console.log(this.listAdd[0].brandId)
        //       console.log(this.listAdd[0].brand)
        //       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.getList()
        //           this.dialogFormVisible_change = false
        //           this.createTemp.providerName = ''
        //           this.$notify({
        //             title: '',
        //             message: '保存成功',
        //             type: 'success',
        //             duration: 2000
        //           })
        //         }
        //       })
        //       return true
        //     } else {
        //       this.$notify({
        //         title: '',
        //         message: '请选择备件',
        //         type: 'warning',
        //         duration: 2000
        //       })
        //       return false
        //     }
        //   }
        // }
        // })
      }
    },
    // --------------------------------------------
    // 导出
    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 = 'contractDownload'
      this.downloadParam.parammaps = this.getdataListParm.parammaps
      GetAccount(this.downloadParam).then(response => {
        if (response.data.list !== '') {
          this.percentage = 99
          setTimeout(() => {
            this.isPercentage = false
          }, 2000)
        }
        this.$nextTick(() => {
          const ExcelDatas = [
            {
              tHeader: ['合同编号', '牧场', '合同开始日期', '合同截止日期', '供应商', '物料编码', '品名', '规格型号', '计量单位', '品牌', '计划量', '单价', '备注', '一级分类', '二级分类', '三级分类', '填写人', '填写时间', '合同状态', '是否零库存（0否，1是）'],
              filterVal: ['contractCode', 'pastureName', 'startTime', 'stopTime', 'providerName', 'partCode', 'partName', 'specification', 'unit', 'brand', 'planAmount', 'price', 'remark', '', '', '', 'creatorMan', 'creatorTime', 'statue', 'isZeroStock'],
              tableDatas: response.data.list,
              sheetName: '合同管理'
            }
          ]
          json2excel(ExcelDatas, '合同管理', true, 'xlsx')
        })
      })
    },
    // 导出模板
    handleDownloadTemp() {
      this.requestParam.name = 'pStockDownTemp'
      GetDataByName(this.requestParam).then(response => {
        this.$nextTick(() => {
          import('@/vendor/Export2Excel').then(excel => {
            const list1 = response.data.list
            const tHeader = [
              '合同编号', '牧场', '合同开始日期', '合同截止日期', '供应商', '物料编码', '品名', '规格型号', '计量单位', '品牌', '计划量', '单价', '备注', '一级分类', '二级分类', '三级分类', '填写人', '填写时间'
            ]
            const filterVal = [
              '合同编号', '牧场', '合同开始日期', '合同截止日期', '供应商', '物料编码', '品名', '规格型号', '计量单位', '品牌', '计划量', '单价', '备注', '一级分类', '二级分类', '三级分类', '填写人', '填写时间'
            ]
            const data1 = this.formatJsonTemp(filterVal, list1)
            excel.export_json_to_excel({
              header: tHeader,
              data: data1,
              filename: '合同信息模板',
              autoWidth: true,
              bookType: 'xlsx'
            })
          })
        })
      })
    },
    formatJsonTemp(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    beforeImportExcel(file) {
      const isLt2M = file.size / 1024 / 1024 < 6
      if (!isLt2M) {
        this.$message.error('上传文件大小不能超过 6MB!')
      }
      return isLt2M
    },
    handleImportExcelSuccess(res, file) {
      this.getList()
      if (res.msg === 'ok') {
        this.$message({
          title: '成功',
          message: '导入成功:' + res.data.success + '条!',
          type: 'success',
          duration: 2000
        })
        if (res.data.err_count > 0) {
          this.$notify({
            title: '失败',
            message: '导入失败:' + res.data.err_count + '条!',
            type: 'danger',
            duration: 2000
          })
           import('@/vendor/Export2Excel').then(excel => {
             const list1 = res.data.result
             const tHeader = [
               '合同编号', '牧场', '合同开始日期', '合同截止日期', '供应商', '物料编码', '品名', '规格型号', '计量单位', '品牌', '计划量', '单价', '备注', '一级分类', '二级分类', '三级分类', '填写人', '填写时间', '分管副场审核', '分管副场审核时间', '场长审核', '场长审核时间', '运营办审核', '运营办审核时间', '过期处理人', '过期处理时间', '报错信息'
             ]
             const filterVal = [
               '合同编号', '牧场', '合同开始日期', '合同截止日期', '供应商', '物料编码', '品名', '规格型号', '计量单位', '品牌', '计划量', '单价', '备注', '一级分类', '二级分类', '三级分类', '填写人', '填写时间', '分管副场审核', '分管副场审核时间', '场长审核', '场长审核时间', '运营办审核', '运营办审核时间', '过期处理人', '过期处理时间', 'error_msg'
             ]
             const data1 = this.formatJson(filterVal, list1)
             excel.export_json_to_excel({
               header: tHeader,
               data: data1,
               filename: '合同报错信息',
               autoWidth: true,
               bookType: 'xlsx'
             })
           })
        }
      } else {
        this.$notify({
          title: '失败',
          message: '上传失败,文件格式错误',
          type: 'danger',
          duration: 2000
        })
      }
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v =>
        filterVal.map(j => {
          if (j === 'timestamp') {
            return parseTime(v[j])
          } else {
            return v[j]
          }
        })
      )
    },
    // 供应商模糊查询

    providerSearch(queryString, cb) {
      var returnList = this.findAllProvider
      var results = queryString ? returnList.filter(this.createFilter(queryString)) : returnList
      // 调用 callback 返回建议列表的数据
      cb(results)
    },
    createFilter(queryString) {
      return returnValue => {
        return (
          returnValue.name.toLowerCase().indexOf(queryString.toLowerCase()) >= 0
        )
      }
    },
    handleSelectProvider(item) {
      console.log(item)
      this.$set(this.createTemp, 'providerId', item.id)
      this.$set(this.createTemp, 'providerName', item.name)
      // this.createTemp.providerId = item.id
      // this.createTemp.providerName = item.name
    },
    handleFocusProvider() {
      this.createTemp.providerId = ''
      this.createTemp.providerName = ''
    },
    handleBlurProvider() {
      if (this.createTemp.providerId == '') {
        this.createTemp.providerId = ''
        this.createTemp.providerName = ''
      }
    },

    // 1-1: table&搜索

    tableCellClassName({ row, column, rowIndex, columnIndex }) {
      row.index = rowIndex
      column.index = columnIndex
    },
    selected(select) {
      // this.batchCancelId = []
      this.selectionIndex = []
      this.selectionIndex.push(3, 4, 5)
      // console.log(this.selectionIndex)
    },
    // 2-2：下拉框

    popoverHide(checkedIds, checkedData) {
      this.temp.categoryId = checkedIds
      this.temp.stockNumber = checkedData.checkNumber
      // console.log(checkedIds, checkedData.checkNumber)
    },

    handleModifyStatus(row, status) {
      this.$message({
        message: '操作成功',
        type: 'success'
      })
      row.status = status
    },

    // 合同明细打印

    edit_dialog_save() {
      this.$refs['temp'].validate(valid => {
        if (valid) {
          this.requestParam.name = 'updateStock'
          this.requestParam.parammaps = this.temp
          PostDataByName(this.requestParam).then(response => {
            console.log(response)
            if (response.msg === 'fail') {
              this.$notify({
                title: '失败',
                message: '保存失败-' + response.data,
                type: 'warning',
                duration: 2000
              })
            } else {
              this.getList()
              this.dialogFormVisible = false
              this.$notify({
                title: '成功',
                message: '修改成功',
                type: 'success',
                duration: 2000
              })
            }
          })
        }
      })
    },
    // 修改
    form_edit(row) {
      this.temp = Object.assign({}, row) // copy obj
      // 基础信息
      this.defaultCheckedKeys = [this.temp.categoryId]
      this.dialogStatus = 'update'
      this.dialogFormVisible = true
      this.getdataListParmSee.parammaps.pastureId = row.pastureId
      this.getdataListParmSee.parammaps.contractNO = row.contractNO
      this.getListCard()
    },
    getListCard() {
      GetDataByName(this.getdataListParmSee).then(response => {
        // this.list2 = response.data.list
        console.log(this.list2)
        // 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.listLoadingAdd = false
        }, 300)
      })
    },

    // 删除
    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': 'deleteBigContract', 'type': 'e', 'parammaps': {
          id: row.id
        }}
        this.postDataPramas.data[1] = { 'name': 'deleteContract', 'type': 'e', 'parammaps': {
          bigId: row.id
        }}
        ExecDataByConfig(this.postDataPramas).then(response => {
          this.getList()
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
        })
      })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 编号/名称
    stockSearch(queryString, cb) {
      this.requestFilterParams.parammaps = {}
      this.requestFilterParams.name = 'findByDimStock'
      this.requestFilterParams.parammaps['stockA'] = queryString

      GetDataByName(this.requestFilterParams).then(response => {
        // console.log(response.data.list)
        cb(response.data.list)
      })
    },
    handleStockSelect(item) {
      var ss = 0
      GetDataByName(this.requestFilterParams).then(response => {
        this.$nextTick(() => {
          if (response.data.list.length > 0) {
            this.stockAAA = {}
            if (item.repertory <= 0) {
              this.$notify({
                title: '添加失败',
                message: '此备件无库存了，请联系库管尽快补货哦...',
                type: 'warning',
                duration: 2000
              })
            } else {
              if (this.list2 === null) {
                this.list2 = []
              }
              this.list2.some((item1, i) => {
                if (item1.stockNumber === item.stockNumber) {
                  ss = 1
                }
              })
              if (ss === 0) { this.list2.push(item) }
            }
          }
        })
      })
    },
    changeIsZero(val) {
      console.log(val)
    }
  }
}
</script>
