<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <div class="sub-navbar">
        <template v-if="formState !== 'finish'">
          <el-button v-if="formState === 'create' || formState === 'newBuild'" type="success" icon="el-icon-edit" size="medium" @click="bjdSave(false)">
            保存并核价
          </el-button>
          <template v-else>
            <el-button type="success" icon="el-icon-edit" size="medium" @click="bjdSave(false)">
              更新/核价
            </el-button>
            <template v-if="sbzldm === '3000' || sbzldm === '4000'">
              <el-button type="primary" icon="el-icon-circle-check-outline" size="medium" @click="openZiliaoshencha()">
                资料审查
              </el-button>
              <el-button type="info" icon="el-icon-circle-check-outline" size="medium" @click="bztz()">
                补证通知
              </el-button>
              <template v-if="bjd.byslState">
                <el-button type="danger" icon="el-icon-circle-check-outline" size="medium" @click="bysl()">
                  不予受理
                </el-button>
              </template>
              <template v-else>
                <el-button type="danger" disabled icon="el-icon-circle-check-outline" size="medium">
                  不予受理
                </el-button>
              </template>
            </template>
            <el-button type="warning" icon="el-icon-circle-check-outline" size="medium" @click="bjdSave(true)">
              审核通过
            </el-button>
          </template>
          <template v-if="bjd.bjType === 'cyqp'">
            <el-upload
              :show-file-list="false"
              :before-upload="beforeUpload"
              style="display: inline-flex"
              action=""
            >
              <el-button type="primary" size="medium" icon="el-icon-upload">
                导入数据
              </el-button>
            </el-upload>
          </template>
        </template>
        <template v-else>
          <el-button v-if="sbzldm === '3000' || sbzldm === '4000'" type="primary" icon="el-icon-circle-check-outline" size="medium" @click="openZiliaoshencha()">
            资料查看
          </el-button>
          <el-button type="success" icon="el-icon-printer" @click="viewHzd">
            打印回执单
          </el-button>
        </template>
        <el-button type="success" icon="el-icon-download" size="medium" @click="common.downloadTemplate(templateName)">
          下载导入模板
        </el-button>
      </div>
    </sticky>
    <el-tabs v-model="checkedTab" type="border-card">
      <el-tab-pane label="检验项目申请表" name="first">
        <el-form ref="bjd" :model="bjd" :rules="rules" class="small-space" label-position="right" label-width="120px">
          <fieldset>
            <legend>设备种类</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验类别:" prop="jianyanleibie">
                  <el-input v-model="jianyanleibie" type="text" disabled />
                  <el-input v-show="false" v-model="bjd.jianyanleibie" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备种类:" prop="shebeizhonglei">
                  <el-input v-model="bjd.shebeizhonglei" disabled />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>基本信息</legend>
            <template v-if="bjd.bjType === 'cyqp'">
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="施工单位:" prop="shigongdanwei">
                    <el-input v-model="bjd.shigongdanwei" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
            </template>
            <template v-else>
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item :rules="[{ required: true, message: '使用单位不能为空', trigger: 'change'}]" label="使用单位:" prop="shiyongdanwei">
                    <el-input v-model="bjd.shiyongdanwei" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="单位地址:" prop="shiyongdanweiDizhi">
                    <el-input v-model="bjd.shiyongdanweiDizhi" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="9">
                  <el-form-item label="联系人:" prop="shiyongdanweiLianxiren">
                    <el-input v-model="bjd.shiyongdanweiLianxiren" type="text" />
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item :rules="[{ required: true, message: '使用单位电话不能为空', trigger: 'change'}]" label="联系电话:" prop="shiyongdanweiDianhua">
                    <el-input v-model="bjd.shiyongdanweiDianhua" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="施工单位:" prop="shigongdanwei">
                    <el-input v-model="bjd.shigongdanwei" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="9">
                  <el-form-item label="联系人:" prop="shigongdanweiLianxiren">
                    <el-input v-model="bjd.shigongdanweiLianxiren" type="text" />
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item label="联系电话:" prop="shigongdanweiDianhua">
                    <el-input v-model="bjd.shigongdanweiDianhua" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="18">
                  <el-form-item label="制造单位:" prop="zhizaodanwei">
                    <el-input v-model="bjd.zhizaodanwei" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
            </template>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item :rules="[{ required: true, message: '区划名称不能为空', trigger: 'change'}]" label="区划名称:" prop="quhuadaima">
                  <el-select v-model="bjd.quhuadaima" placeholder="请选择" style="width: 100%" @change="quhuaChange">
                    <el-option v-for="item in areas" :key="item.value" :label="item.label" :value="item.value" style="width: 100%" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item :rules="[{ required: true, message: '检验科室不能为空', trigger: 'change'}]" label="检验科室:" prop="departmentId">
                  <el-select v-model="bjd.departmentId" placeholder="请选择" style="width: 100%">
                    <el-option v-for="dept in depts" :key="dept.id" :label="dept.name" :value="dept.id" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item :rules="[{ required: true, message: '受理日期不能为空', trigger: 'change'}]" label="受理日期:" prop="shouliriqi">
                  <el-date-picker v-model="bjd.shouliriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item :rules="[{ required: true, message: '报检日期不能为空', trigger: 'change'}]" label="报检日期:" prop="baojianriqi">
                  <el-date-picker v-model="bjd.baojianriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <div v-if="formState === 'finish'">
              <el-row :gutter="20">
                <el-col :span="9">
                  <el-form-item label="受理人:" prop="shouliren">
                    <el-input v-model="bjd.shouliren" type="text" />
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <el-form-item label="最后修改人:" prop="updateBy">
                    <el-input v-model="bjd.updateBy" type="text" />
                  </el-form-item>
                </el-col>
              </el-row>
            </div>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item :rules="[{ required: true, message: '报检人电话不能为空，该电话用于短信通知企业网上交费。', trigger: 'change'}]" label="报检人电话:" prop="baojiandianhua">
                  <el-input v-model="bjd.baojiandianhua" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>非税系统交费信息</legend>
            <el-row :gutter="20">
              <el-col :span="18">
                <span style="color: red;font-size: 20px;">请正确填写发票信息中的内容和收取电子发票的邮箱地址</span>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="缴费单位全称:" prop="jiaokuandanwei">
                  <el-input v-model="bjd.jiaokuandanwei" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="接收发票邮箱:" :rules="[{ required: false, message: '请输入邮箱地址', trigger: 'blur' },{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }]" prop="jiaokuanyouxiang">
                  <el-input v-model="bjd.jiaokuanyouxiang" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="联系人:" prop="jiaokuanren">
                  <el-input v-model="bjd.jiaokuanren" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系电话:" prop="jiaokuandianhua">
                  <el-input v-model="bjd.jiaokuandianhua" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="查询报检电话:" prop="baojiandianhua">
                  <el-input v-model="bjd.baojiandianhua" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="缴款码:" prop="jiaokuanma">
                  <el-input v-model="bjd.jiaokuanma" disabled />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>领取信息</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="领取方式:" prop="lingqufangshi">
                  <el-select v-model="bjd.lingqufangshi" style="width: 240px;" @change="lqfsChange">
                    <el-option label="自取" value="自取" />
                    <el-option label="自打印" value="自打印" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-button v-if="bjd.lingqufangshi === '邮寄'" type="warning" icon="el-icon-circle-check-outline" size="medium" @click="postInfoSave">
                修改地址
              </el-button>
            </el-row>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="申请检验设备明细表" name="second">
        <template v-if="formState !== 'finish'">
          <el-button type="success" size="mini" icon="el-icon-edit" @click="openDialogParam()">
            批量修改
          </el-button>
          <el-button type="success" size="mini" icon="el-icon-circle-plus-outline" @click="addRow">
            添加
          </el-button>
          <el-button type="danger" size="mini" icon="el-icon-remove-outline" @click="delRow()">
            删除
          </el-button>
          <span style="margin-left: 20px;color: red;">如若【设备类别】相同，只编辑填写第一条即可！</span>
        </template>
        <el-switch v-model="fixedFlag" active-color="#13ce66" inactive-color="#ff4949" @change="editFixedHidden()" />
        <el-table
          ref="bjBaseList"
          v-adaptive="{bottomOffset: 50}"
          height="0"
          :data="tableData"
          :row-class-name="tableRowClassName"
          fit
          highlight-current-row
          border
          stripe
          style="width:100%;margin-top: 5px;"
          @row-click="onRowClick"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="40" />
          <el-table-column align="center" type="index" width="50" label="序号" />
          <el-table-column align="center" prop="neibuleibie" min-width="130" label="检验类别(项目)">
            <template slot-scope="scope">
              <el-select v-model="scope.row.neibuleibie" placeholder="请选择" @change="beforeHejia">
                <el-option v-for="item in jylbs" :key="item.code" :label="item.name" :value="item.code" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column v-if="sbzldm === '4000'" align="center" prop="shigongleibie" min-width="130" label="施工类别">
            <template slot-scope="scope">
              <el-select v-model="scope.row.shigongleibie" placeholder="请选择">
                <el-option key="新装" label="新装" value="新装" />
                <el-option key="移装" label="移装" value="移装" />
                <el-option key="改造" label="改造" value="改造" />
                <el-option key="重大修理" label="重大修理" value="重大修理" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="sblbpz" min-width="280" label="设备类别/品种">
            <template slot-scope="scope">
              <el-cascader
                :ref="'cascader'+scope.$index"
                v-model="scope.row.sblbpz"
                :options="sblbList"
                style="width: 100%"
                @change="sblbpzChange(scope.$index)"
              />
            </template>
          </el-table-column>
          <!-- 车用气瓶：23T0 (bjd.bjType: cyqp) -->
          <template v-if="bjd.bjType === 'cyqp'">
            <el-table-column align="center" prop="shebeidaima" min-width="200" label="设备代码">
              <template slot-scope="scope">
                <el-input v-model="scope.row.shebeidaima" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="chanpinbianhao" min-width="150" label="产品编号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.chanpinbianhao" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="shigongriqi" min-width="170" label="安装日期">
              <template slot-scope="scope">
                <el-date-picker v-model="scope.row.shigongriqi" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="shigongxukezheng" min-width="150" label="安装许可证编号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.shigongxukezheng" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="zhizaodanwei" min-width="200" label="气瓶制造单位">
              <template slot-scope="scope">
                <el-input v-model="scope.row.zhizaodanwei" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="zhizaoriqi" min-width="170" label="制造日期">
              <template slot-scope="scope">
                <el-date-picker v-model="scope.row.zhizaoriqi" value-format="yyyy-MM-dd" type="date" placeholder="选择日期" style="width: 100%;" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="s33" min-width="120" label="公称压力">
              <template slot-scope="scope">
                <el-input v-model="scope.row.s33" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="s34" min-width="150" label="工作介质">
              <template slot-scope="scope">
                <el-input v-model="scope.row.s34" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="s29" min-width="160" label="车辆牌号/车辆底盘号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.s29" placeholder="请输入内容" />
              </template>
            </el-table-column>
          </template>
          <template v-else-if="sbzldm === '8000'">
            <el-table-column align="center" prop="shebeimingcheng" min-width="180" label="设备名称">
              <template slot-scope="scope">
                <el-input v-model="scope.row.shebeimingcheng" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="guandaojibie" label="管道级别">
              <template slot-scope="scope">
                <el-input v-model="scope.row.s7" placeholder="请输入" />
              </template>
            </el-table-column>
          </template>
          <template v-else>
            <el-table-column align="center" prop="shebeimingcheng" min-width="180" label="设备名称">
              <template slot-scope="scope">
                <el-input v-model="scope.row.shebeimingcheng" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="danweineibubianhao" min-width="160" label="单位内编号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.danweineibubianhao" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="shebeidaima" min-width="205" label="设备代码">
              <template slot-scope="scope">
                <el-input v-model="scope.row.shebeidaima" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="chanpibianhao" min-width="175" label="出厂编号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.chanpinbianhao" placeholder="请输入内容" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="guigexinghao" min-width="155" label="规格型号">
              <template slot-scope="scope">
                <el-input v-model="scope.row.guigexinghao" placeholder="请输入内容" />
              </template>
            </el-table-column>
          </template>
          <!-- 第一次进来不对核定参数展示 后台进行信息提取后在做核价处理 -->
          <template v-if="formState !== 'create'">
            <template v-if="sbzldm === '2000' && bjd.bjType !== 'cyqp'">
              <el-table-column align="center" prop="rongji" label="容积">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s5" placeholder="请输入" />
                </template>
              </el-table-column>
            </template>
            <template v-else-if="sbzldm === '3000'">
              <el-table-column align="center" prop="ceng" label="层" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s1" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="quduanchangdu" label="区段长度" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s14" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="tishenggaodu" label="提升高度" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s16" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="gonggongjiaotong" label="公共交通" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss1" placeholder="请选择" @change="beforeHejia">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="fujian" label="复检" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss2" placeholder="请选择" @change="beforeHejia">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="xiansuqi" label="限速器" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss3" placeholder="请选择" @change="beforeHejia">
                    <el-option label="不校验" value="0" />
                    <el-option label="校验" value="1" />
                  </el-select>
                </template>
              </el-table-column>
            </template>
            <template v-else-if="sbzldm === '4000'">
              <el-table-column align="center" prop="kuadu" label="跨度" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s1" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="edingqizhongliang" label="额定起重量" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s2" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="edingqizhongliju" label="额定起重力矩" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s3" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="qishenggaodu" label="起升高度" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s4" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="boweishu" label="存车容量" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s12" placeholder="请输入" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="eliehuanjing" label="恶劣检验环境" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss1" placeholder="请选择">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="sijishi" label="有司机室" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss2" placeholder="请选择" @change="beforeHejia">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="fugan" label="副杆" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss3" placeholder="请选择">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
              <el-table-column align="center" prop="fujian" label="复检" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.ss4" placeholder="请选择" @change="beforeHejia">
                    <el-option label="×" value="0" />
                    <el-option label="√" value="1" />
                  </el-select>
                </template>
              </el-table-column>
            </template>
            <template v-else-if="sbzldm === '5000'">
              <el-table-column align="center" prop="edingqizhongliang" width="100" label="额定起重量" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s1" placeholder="请输入" @keyup.enter.native="beforeHejia" @blur="beforeHejia" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="paizhaohaoma" width="140" label="厂车牌照编号" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.s5" placeholder="请输入" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="ranliaozhonglei" width="120" label="燃料种类" fixed="right">
                <template slot-scope="scope">
                  <el-select v-model="scope.row.s6" placeholder="请选择">
                    <el-option label="汽油" value="汽油" />
                    <el-option label="柴油" value="柴油" />
                    <el-option label="电" value="电" />
                    <el-option label="液化气" value="液化气" />
                  </el-select>
                </template>
              </el-table-column>
            </template>
            <template v-if="sbzldm !== '1000'">
              <el-table-column v-if="formState !== 'create' && formState !== 'newBuild'" prop="xitongheding" width="90" label="标准费用" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.xitongheding" placeholder="待核定" disabled />
                </template>
              </el-table-column>
              <el-table-column v-if="formState !== 'create' && formState !== 'newBuild'" prop="datingheding" width="90" label="核定费用" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.datingheding" placeholder="请输入" />
                </template>
              </el-table-column>
              <el-table-column v-if="formState !== 'create' && formState !== 'newBuild'" prop="jianyanheding" width="90" label="检验核定" fixed="right">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.jianyanheding" placeholder="请输入" />
                </template>
              </el-table-column>
            </template>
          </template>
        </el-table>
      </el-tab-pane>
      <!-- 修改检验类别/设备类别/设备品种方法 -->
      <el-dialog :title="editParamTitle" :visible.sync="dialogFormParam" @close="dialogFormParam = false">
        <el-form ref="param" :model="param" class="small-space" label-position="right" label-width="120px">
          <div v-if="formState !== 'finish'">
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="检验类别:" prop="neibuleibie">
                  <el-select v-model="param.neibuleibie" placeholder="请选择">
                    <el-option v-for="item in jylbs" :key="item.code" :label="item.name" :value="item.code" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设备类别:" prop="sblb">
                  <el-select v-model="param.sblb" value-key="value" @change="sblbChange">
                    <el-option v-for="item in sblbList" :key="item.value" :label="item.label" :value="item" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设备品种:" prop="sbpz">
                  <el-select
                    v-model="param.sbpz"
                    value-key="value"
                  >
                    <el-option v-for="item in sbpzList" :key="item.value" :label="item.label" :value="item" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="8">
                <el-form-item label="核定价格" prop="datingheding">
                  <el-input v-model="param.datingheding" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="检验核定价格" prop="jianyanheding">
                  <el-input v-model="param.jianyanheding" />
                </el-form-item>
              </el-col>
              <el-col v-if="sbzldm === '4000'" :span="8">
                <el-form-item label="施工类别" prop="shigongleibie">
                  <el-select v-model="param.shigongleibie" placeholder="请选择">
                    <el-option key="新装" label="新装" value="新装" />
                    <el-option key="移装" label="移装" value="移装" />
                    <el-option key="改造" label="改造" value="改造" />
                    <el-option key="重大修理" label="重大修理" value="重大修理" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </el-form>
        <div style="color: red">
          根据选中的条数进行修改，否则全部修改！
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormParam = false">
            取 消
          </el-button>
          <el-button type="primary" @click="editRow">
            确 定
          </el-button>
        </div>
      </el-dialog>
      <el-dialog title="设备列表" width="70%" :visible.sync="baseListVisible" @close="baseListVisible = false">
        <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="batchAddToBjBase">
          添加
        </el-button>
        <el-table
          ref="baseTable"
          :data="baseList"
          border
          fit
          highlight-current-row
          stripe
          :row-class-name="tableRowClassName"
          @selection-change="baseSelectionChange"
          @row-click="checkSelection"
        >
          <el-table-column type="selection" width="45" />
          <el-table-column align="center" label="序号" width="40">
            <template slot-scope="scope">
              <span v-text="getIndex(scope.$index)" />
            </template>
          </el-table-column>
          <el-table-column align="center" label="设备种类" prop="shebeizhonglei" min-width="80" />
          <el-table-column align="center" label="使用单位" prop="shiyongdanwei" min-width="150" />
          <el-table-column align="center" label="制造单位" prop="zhizaodanwei" min-width="150" />
          <el-table-column align="center" label="设备代码" prop="shebeidaima" min-width="100" />
          <el-table-column :formatter="clearBlank" align="center" label="出厂编号" prop="chanpinbianhao" min-width="80" />
          <el-table-column :formatter="clearBlank" align="center" label="单位内部编号" prop="danweineibubianhao" min-width="60" />
          <el-table-column :formatter="clearBlank" align="center" label="区划名称" prop="quhuamingcheng" min-width="50" />
          <el-table-column align="center" label="操作" min-width="50">
            <template slot-scope="scope">
              <el-button type="primary" size="small" icon="el-icon-circle-plus-outline" @click="addToBjBase(scope.$index)" />
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="totalCount>0" :total="totalCount" :page-num.sync="listQuery.pageNum" :page-row.sync="listQuery.pageRow" @pagination="getBaseList" />
      </el-dialog>
      <el-dialog title="邮寄信息" width="800px" :visible.sync="formYJVisible" @close="formYJVisible = false">
        <el-form ref="postInfo" :model="postInfo" label-position="right" label-width="120px">
          <el-row :gutter="20">
            <el-col :span="22">
              <el-form-item label="使用单位:" prop="shiyongdanwei">
                <el-input v-model="postInfo.shiyongdanwei" type="text" disabled />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="11">
              <el-form-item label="收件人姓名:" prop="nickname">
                <el-input v-model="postInfo.nickname" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="11">
              <el-form-item label="收件人电话:" prop="tel">
                <el-input v-model="postInfo.tel" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="22">
              <el-form-item label="收件人地址:" prop="addr">
                <el-input v-model="postInfo.addr" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="formYJVisible = false">取 消</el-button>
          <el-button type="primary" @click="savePostInfo()">确 定</el-button>
        </span>
      </el-dialog>
    </el-tabs>
    <el-dialog title="原始材料内容比对" width="98%" top="5px" :visible.sync="baseInfoContentVisible" :close-on-press-escape="false" @close="baseInfoContentVisible = false">
      <el-container style="border: 1px solid #eee;height:700px">
        <el-aside width="250px" style="background-color: rgb(238, 241, 246)">
          <el-input v-model="filterLabel" size="mini" placeholder="输入关键字进行过滤" />
          <el-tree
            ref="treeFiles"
            :data="treeFilesData"
            :default-expanded-keys="[104, 105, 106, 107, 108, 109, 110, 111, 112, 1, 2, 3, 48]"
            show-checkbox
            :filter-node-method="filterNode"
            node-key="id"
            :props="defaultProps"
          >
            <span slot-scope="{ node, data }" class="span-ellipsis">
              <span :title="node.label" style="margin-left: 3px;">
                <span v-if="data.children" style="color: #36a3f7">
                  {{ data.children.length }}
                </span>{{ node.label }}
              </span>

            </span>
          </el-tree>
        </el-aside>
        <el-container style="width: 48%">
          <el-header style="text-align: center; font-size: 18px; height: 36px">
            <el-button type="primary" icon="el-icon-circle-check-outline" size="medium" @click="lookImgLeft()">
              加载数据到左侧
            </el-button>
          </el-header>
          <el-main>
            <div class="demo-image__lazy" style="margin-top:0px">
              <el-image v-for="url in leftUrls" :key="url" :src="url" :preview-src-list="leftUrls" />
            </div>
          </el-main>
        </el-container>
        <el-container style="width: 48%">
          <el-header style="text-align: center; font-size: 18px; height: 36px; vertical-align: middle">
            <el-button type="primary" icon="el-icon-circle-check-outline" size="medium" @click="lookImgRight()">
              加载数据到右侧
            </el-button>
          </el-header>
          <el-main>
            <div class="demo-image__lazy">
              <el-image v-for="url in rightUrls" :key="url" :src="url" :preview-src-list="rightUrls" />
            </div>
          </el-main>
        </el-container>
      </el-container>
    </el-dialog>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import Utils from '../../utils/contact.js'
import Pagination from '@/components/Pagination'
import axios from 'axios'
import { deleteRenwuFn } from '@/api/common'

export default {
  name: 'AddProjectJJ',
  components: { Sticky, Pagination },
  data() {
    return {
      bjd: {
        id: '',
        departmentId: '',
        shiyongdanwei: '',
        shiyongdanweiDizhi: '',
        shiyongdanweiLianxiren: '',
        shiyongdanweiDianhua: '',
        shigongdanwei: '',
        shigongdanweiLianxiren: '',
        shigongdanweiDianhua: '',
        weibaodanwei: '',
        weibaodanweiLianxiren: '',
        weibaodanweiDianhua: '',
        jianyanleibie: 'JJ',
        shebeizhonglei: this.$route.params.sbzl,
        shebeizhongleidaima: this.$route.params.sbzldm,
        quhuamingcheng: '',
        quhuadaima: '',
        lingqufangshi: '自取',
        bjType: this.$route.query.bjType
      },
      param: {
        neibuleibie: '',
        shebeileibiedaima: '',
        sblb: '',
        sbpz: ''
      },
      sbzldm: this.$route.params.sbzldm,
      baseIds: '', // 省局设备主键
      tableData: [], // 参数列表
      tableDataParam: [], // 详细参数信息
      jylbs: [], // 检验类别
      depts: [], // 检验科室
      areas: [], // 区划数组
      checkedTab: 'first',
      formState: this.$route.params.formState, // 验证是创建/修改/完成
      delRowIndex: [],
      selection: [],
      rules: {},
      dialogFormParam: false,
      title: '核定价格',
      editParamTitle: '批量修改设备信息',
      sbpzList: [],
      baseListVisible: false,
      baseInfoContentVisible: false,
      baseList: [],
      listQuery: {
        pageNum: 1, // 页码
        pageRow: 20, // 每页条数
        order: undefined, // 排序字段
        sort: undefined, // 排序方式
        shebeizhongleidaima: this.$route.params.sbzldm,
        shidaima: '3701'
      },
      jianyanleibie: '监督检验',
      totalCount: 0,
      baseSelection: [],
      formYJVisible: false,
      postInfo: {
        nickname: '',
        tel: '',
        addr: ''
      }, // 报告邮寄信息
      bjdDepartment: {
        shebeizhonglei: '',
        jianyanleibie: '',
        quhuamingcheng: ''
      },
      sblbList: [],
      leftUrls: [],
      rightUrls: [],
      treeFilesData: [],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      templateName: '',
      fixedFlag: true,
      fixedWidth: '',
      filterLabel: ''
    }
  },
  watch: {
    'bjd.shiyongdanwei': {
      handler(newVal, oldVal) {
        this.postInfo.shiyongdanwei = newVal
      },
      immediate: true
    },
    filterLabel(val) {
      this.$refs.treeFiles.filter(val)
    }
  },
  created() {
    if (this.formState === 'newBuild') {
      this.tableData = []
      this.$set(this.bjd, 'shouliriqi', new Date())
      this.$set(this.bjd, 'baojianriqi', new Date())
      this.getSblb()
      if (this.bjd.shebeizhongleidaima === '8000') {
        this.bjd.shiyongdanwei = '/'
        this.bjd.shiyongdanweiDianhua = '/'
      }
    } else if (this.formState === 'update' || this.formState === 'finish') {
      // 查询报检信息
      this.getBjdInfo()
    } else if (this.formState === 'create') { // 直接起草过来的数据
      // 先加载当前的数据
      this.tableData = this.$route.query.params
      if (this.tableData !== null && this.tableData !== undefined) {
        // ***第一次起草
        this.bjd = this.tableData[0] // 将第一条数据给报检单基本信息赋值
        this.bjd.baojiandianhua = this.bjd.shigongdanweiDianhua
        // 拿到省局主键
        for (let i = 0; i < this.tableData.length; i++) {
          // 初始化参数
          this.setDefaultValue(this.tableData[i])
        }
      }
      this.$nextTick(() => {
        this.$refs.bjBaseList.doLayout()
      })
      this.getSblb()
    }
    if (this.bjd.bjType === 'cyqp') {
      this.templateName = '车用气瓶报检导入模板.xlsx'
    }
    // 区划跟科室加载完成后读取关联数据
    if (this.formState === 'create') {
      this.getBjdDepartment()
    }
    this.getJylb()
    this.getArea()
    this.getDepts()
  },
  methods: {
    /**
     * 过滤
     */
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    getBjdInfo() {
      this.apibjd({
        url: '/bjd/getBjdById',
        method: 'get',
        params: {
          bjdId: this.$route.params.id
        }
      }).then(data => {
        this.bjd = data
        if (this.bjd.dataSource === 1 && this.formState !== 'finish') {
          this.$set(this.bjd, 'shouliriqi', new Date())
        }
        if (this.bjd.baojiandianhua === undefined || this.bjd.baojiandianhua === null) {
          this.bjd.baojiandianhua = this.bjd.shigongdanweiDianhua
        }
        this.getSblb()
        // 查询报检参数信息
        this.getParamById()
      })
    },
    getParamById() {
      this.apibjd({
        url: '/renwu/getParamByBjdId',
        method: 'get',
        params: {
          bjdId: this.bjd.id
        }
      }).then(data => {
        this.tableData = data
        for (const tableObj of this.tableData) {
          const sblbpz = []
          sblbpz.push(tableObj.shebeileibiedaima)
          sblbpz.push(tableObj.shebeipinzhongdaima)
          this.$set(tableObj, 'sblbpz', sblbpz)
        }
        this.$nextTick(() => {
          this.$refs.bjBaseList.doLayout()
        })
        if (this.formState !== 'finish') {
          this.beforeHejia()
        }
      })
    },
    // 报检设备设置默认值
    setDefaultValue(obj) {
      this.$set(this.bjd, 'shouliriqi', new Date())
      this.$set(this.bjd, 'baojianriqi', new Date())
      this.bjd.lingqufangshi = '自取'
      this.$set(obj, 'neibuleibie', 'JD')
      if (this.bjd.shebeizhongleidaima === '1000') {
        this.$set(obj, 'neibuleibie', 'ZG')
      } else if (this.bjd.shebeizhongleidaima === '4000') {
        this.$set(obj, 'shigongleibie', '新装')
      }
      // 设备类别代码初始化（存在省局有设备代码是错误的情况）
      if (obj.shebeileibiedaima !== '' && obj.shebeileibiedaima !== null && obj.shebeileibiedaima !== undefined) {
        if (obj.shebeileibiedaima.substring(0, 2) + '00' === this.sbzldm) {
          let sblbdm = obj.shebeileibiedaima.substring(2, 3)
          if (this.sbzldm === '5000') {
            if (sblbdm !== '2') {
              sblbdm = '1'
            }
          }
          sblbdm = this.sbzldm.substring(0, 1) + sblbdm + '00'
          obj.shebeileibiedaima = sblbdm
        }
      } else {
        const sbzldm = this.sbzldm.substring(0, 1)
        let sblbdm = sbzldm + '100'
        let sbpzdm = sbzldm + '110'
        if (this.bjd.shebeidaima !== undefined && this.bjd.shebeidaima !== null) {
          sbpzdm = this.bjd.shebeidaima.substring(0, 4)
          sblbdm = sbpzdm.substring(0, 2) + '00'
        }
        obj.shebeileibiedaima = sblbdm
        obj.shebeipinzhongdaima = sbpzdm
      }
      const sblbpz = []
      sblbpz.push(obj.shebeileibiedaima)
      if (obj.shebeipinzhongdaima !== '' && obj.shebeipinzhongdaima !== null) {
        sblbpz.push(obj.shebeipinzhongdaima)
      }
      obj.sblbpz = sblbpz
      // 将关键信息默认‘/’
      if (obj.danweineibubianhao === 'null' || obj.danweineibubianhao === '' || obj.danweineibubianhao === null) {
        obj.danweineibubianhao = '/'
      }
      // 增加核价默认值
      obj.ss1 = 0
      obj.ss2 = 0
      obj.ss3 = 0
      obj.ss4 = 0
      obj.ss5 = 0
      obj.ss6 = 0
    },
    getSblb() {
      this.getSblbList('2', this.sbzldm, undefined)
    },
    getSblbList(level, sbzl, sblb) { // 设备类别下拉菜单
      this.api({
        url: '/sedirectory/getList',
        method: 'get',
        params: {
          level: level,
          sbzl: sbzl,
          sblb: sblb
        }
      }).then(data => {
        switch (level) {
          case '2':
            this.sblbList = data
            break
          case '3':
            this.sbpzList = data
            break
        }
      })
    },
    getJylb() {
      // 检验类别
      this.api({
        url: '/category/getCategoryList',
        method: 'get',
        params: {
          parentCode: 'JJ',
          species: this.bjd.shebeizhongleidaima
        }
      }).then(data => {
        this.jylbs = data
      })
    },
    getArea() { // 查询区划
      this.api({
        url: '/area/getShiArea',
        method: 'get',
        params: {
          shidaima: '370100'
        }
      }).then(data => {
        this.areas = data
      })
    },
    getDepts() { // 查询科室
      this.api({
        url: '/department/getDepartmentByCode',
        method: 'get',
        params: {
          code: this.bjd.shebeizhongleidaima
        }
      }).then(data => {
        this.depts = data
      })
    },
    getBjdDepartment() {
      this.bjdDepartment.shebeizhonglei = this.bjd.shebeizhongleidaima
      this.bjdDepartment.jianyanleibie = this.bjd.jianyanleibie
      this.bjdDepartment.quhumingcheng = this.bjd.quhuadaima
      this.apibjd({
        url: '/bjdDepartment/getObj',
        method: 'get',
        params: this.bjdDepartment
      }).then(data => {
        if (data != null) {
          this.bjdDepartment = data
          this.$set(this.bjd, 'departmentId', this.bjdDepartment.departmentId)
        }
      })
    },
    // 领取方式修改方法
    lqfsChange(val) {
      if (val === '邮寄') {
        this.formYJVisible = true
      }
    },
    quhuaChange(val) {
      const obj = this.areas.find((item) => {
        return item.value === val
      })
      this.bjd.quhuamingcheng = obj.label
    },
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex
    },
    sblbChange(sblb) {
      this.getSblbList('3', this.bjd.shebeizhongleidaima, sblb.value)
    },
    handleSelectionChange(val) {
      this.selection = val
      this.delRowIndex = []
      for (let i = 0; i < val.length; i++) {
        this.delRowIndex.push(val[i].index)
      }
    },
    // 表格单击选中行
    onRowClick(row) {
      this.$refs.bjBaseList.toggleRowSelection(row)
    },
    addRow: function() { // 添加行数据
      if (this.formState === 'newBuild' || (this.tableData !== null && this.tableData.length > 0 && this.tableData[0].generateType)) {
        const sblbpz = []
        sblbpz.push(this.sbzldm.substr(0, 1) + '100')
        sblbpz.push(this.sbzldm.substr(0, 1) + '110')
        const d = {
          shebeileibie: '',
          shebeileibiedaima: sblbpz[0],
          shebeipinzhong: '',
          shebeipinzhongdaima: sblbpz[1],
          sblbpz: sblbpz,
          shebeimingcheng: '',
          baseId: '',
          shebeidaima: '/',
          chanpinbianhao: '/',
          guigexinghao: '/',
          generateType: true
        }
        if (this.sbzldm === '8000') {
          d.shebeimingcheng = this.sblbList.filter(sblb => sblb.value === sblbpz[0])[0].children.filter(sbpz => sbpz.value === sblbpz[1])[0].label
        }
        this.tableData.push(d)
        setTimeout(() => {
          this.$refs.bjBaseList.setCurrentRow(d)
        }, 10) // 用于延时渲染后选中这行
      } else {
        this.baseListVisible = true
        // 查询设备
        this.getBaseList()
      }
    },
    getBaseList() {
      this.listQuery.shiyongdanwei = this.bjd.shiyongdanwei
      this.apibjd({
        url: '/apprizes/list',
        method: 'get',
        params: this.listQuery
      }).then(data => {
        this.baseList = data.list
        this.totalCount = data.totalCount
      })
    },
    getIndex($index) {
      // 表格序号
      return (this.listQuery.pageNum - 1) * this.listQuery.pageRow + $index + 1
    },
    baseSelectionChange(val) {
      this.baseSelection = val
      this.addRowIndex = []
      for (let i = 0; i < val.length; i++) {
        this.addRowIndex.push(val[i].index)
      }
    },
    batchAddToBjBase() {
      if (this.addRowIndex !== null && this.addRowIndex.length > 0) {
        for (let i = 0; i < this.addRowIndex.length; i++) {
          if (this.judgeContact(this.tableData, this.baseList[this.addRowIndex[i]])) {
            /* this.$message({
              type: 'info',
              message: '选中的设备中有已经报检的数据，已自动筛选！'
            }) */
          } else {
            // 创建报检单----直接放到报检设备列表
            this.setDefaultValue(this.baseList[this.addRowIndex[i]])
            const table = this.baseList[this.addRowIndex[i]]
            table.baseId = table.id
            table.id = ''
            this.tableData.push(table)
          }
          this.$message({
            type: 'success',
            message: '已添加！'
          })
        }
      } else {
        this.$message({
          type: 'warning',
          message: '请选择要报检的数据！'
        })
      }
    },
    addToBjBase(index) {
      this.setDefaultValue(this.baseList[index])
      const table = this.baseList[index]
      table.baseId = table.id
      table.id = ''
      if (this.judgeContact(this.tableData, this.baseList[index])) {
        this.$confirm('该设备已存在，是否继续添加！！！', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.tableData.push(this.baseList[index])
        })
      } else {
        this.tableData.push(this.baseList[index])
      }
    },
    // 判断报检列表中是否包含选中的设备
    judgeContact(list, obj) {
      let flag = false
      for (let i = 0; i < list.length; i++) {
        if (list[i].id === obj.id) {
          flag = true
        }
      }
      return flag
    },
    checkSelection(row) {
      this.$refs.baseTable.toggleRowSelection(row)
    },
    clearBlank(row, column, cellValue) {
      if (cellValue !== null && cellValue !== '' && cellValue !== 'null') {
        return cellValue
      }
      return '/'
    },
    sblbpzChange(index) {
      const sblbpz = this.tableData[index].sblbpz
      this.tableData[index].shebeileibiedaima = sblbpz[0]
      this.tableData[index].shebeipinzhongdaima = sblbpz[1]
      this.sblbList.forEach(item => {
        if (item.value === sblbpz[0]) {
          this.tableData[index].shebeileibie = item.label
          item.children.forEach(itemc => {
            if (itemc.value === sblbpz[1]) {
              this.tableData[index].shebeipinzhong = itemc.label
              if (this.bjd.shebeizhongleidaima === '8000') {
                this.tableData[index].shebeimingcheng = this.tableData[index].shebeipinzhong
              }
            }
          })
        }
      })
    },
    editRow: function() { // 修改行数据
      if (this.delRowIndex.length === 0) {
        for (let i = 0; i < this.tableData.length; i++) {
          if (this.param.neibuleibie !== '') {
            this.tableData[i].neibuleibie = this.param.neibuleibie
          }
          if (this.param.sblb !== '') {
            this.tableData[i].shebeileibiedaima = this.param.sblb.value
            this.tableData[i].shebeileibie = this.param.sblb.label
          }
          if (this.param.sbpz !== '') {
            this.tableData[i].shebeipinzhongdaima = this.param.sbpz.value
            this.tableData[i].shebeipinzhong = this.param.sbpz.label
          }
        }
      } else {
        for (let i = 0; i < this.selection.length; i++) {
          if (this.param.neibuleibie !== undefined) {
            this.selection[i].neibuleibie = this.param.neibuleibie
          }
          if (this.param.sblb.value !== undefined) {
            this.tableData[i].shebeileibiedaima = this.param.sblb.value
            this.tableData[i].shebeileibie = this.param.sblb.label
          }
          if (this.param.sbpz.value !== undefined) {
            this.tableData[i].shebeipinzhongdaima = this.param.sbpz.value
            this.tableData[i].shebeipinzhong = this.param.sbpz.label
          }
          if (this.param.datingheding !== undefined) {
            this.tableData[i].datingheding = this.param.datingheding
          }
          if (this.param.jianyanheding !== undefined) {
            this.tableData[i].jianyanheding = this.param.jianyanheding
          }
          if (this.param.shigongleibie !== undefined) {
            this.tableData[i].shigongleibie = this.param.shigongleibie
          }
          const sblbpz = []
          if (this.tableData[i].shebeileibiedaima !== undefined) {
            sblbpz.push(this.tableData[i].shebeileibiedaima)
          }
          if (this.tableData[i].shebeipinzhongdaima !== undefined) {
            sblbpz.push(this.tableData[i].shebeipinzhongdaima)
          }
          if (sblbpz.length > 0) {
            this.tableData[i].sblbpz = sblbpz
          }
        }
      }
      // this.tableData.push()
      this.dialogFormParam = false
    },
    delRow: function() { // 删除行数据
      if (this.delRowIndex.length === 0) {
        this.$message({
          type: 'error',
          message: '请选中需要删除的数据！'
        })
        return false
      } else {
        this.$confirm('该条数据删除后无法恢复,是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // 对delRowIndex进行排序，因为删除一个元素后index值会变
          this.delRowIndex.sort(function(x, y) {
            if (x < y) {
              return 1
            }
            if (x > y) {
              return -1
            }
            return 0
          })
          for (let i = 0; i < this.delRowIndex.length; i++) {
            // 在实际数据中进行删除
            if (this.formState !== 'create') {
              // 前提条件要满足非新建报检
              const delid = this.tableData[this.delRowIndex[i]].id
              if (delid != null) {
                deleteRenwuFn({ id: delid }).then((data) => {
                  // 不做处理
                })
              }
            }
            this.tableData.splice(this.delRowIndex[i], 1)
          }
          this.$refs.bjBaseList.clearSelection()
          this.delRowIndex = []
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    },
    bysl() {
      this.$prompt('请输入不予受理原因！', '提示', {
        inputType: 'textarea',
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        if (value === null) {
          this.$message({ message: '请填写不予受理原因！', type: 'warning' })
          return false
        }
        this.apibjd({
          url: '/bjd/updBjdBysl',
          method: 'get',
          params: {
            bjdId: this.bjd.id,
            reason: '资料审查人：' + `${this.$store.getters.username}` + '。原因：' + value
          }
        }).then(data => {
          if (data.returnCode === '100') {
            this.$message.success('不予受理操作成功！')
            if (this.bjd.dataSource === 1) {
              this.smsSendResult('未通过，不得进行下道工序的施工', '', '查看详情')
              // 【济南市特种设备检验研究院】您的43项目报检申请资料审核未通过，不得进行下道工序的施工，请登录企业管理平台查看详情。咨询电话：89738113。
              // 您的${project}项目报检申请资料审核${status}。请${action}登录企业管理平台${action1}。咨询电话：${phone}。
            }
            Utils.$emit('bjd-list')
          } else {
            this.$message.error('不予受理操作失败！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消操作！'
        })
      })
    },
    bztz() {
      this.$prompt('请输入补证通知原因！', '提示', {
        inputType: 'textarea',
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        if (value === null) {
          this.$message({ message: '请填写补证通知原因！', type: 'warning' })
          return false
        }
        this.apibjd({
          url: '/bjd/updBjdBztz',
          method: 'get',
          params: {
            bjdId: this.bjd.id,
            reason: '补证原因：' + value + '。【资料审查人：' + `${this.$store.getters.nickname}` + '(' + this.formatter.dateFormat('YYYY-MM-dd') + ')】'
          }
        }).then(data => {
          if (data.returnCode !== undefined && data.returnCode === '400') {
            this.$message.error('补证通知操作失败！')
          } else {
            Utils.$emit('bjd-list')
            if (this.bjd.dataSource === 1) {
              this.smsSendResult('未通过，不得进行下道工序的施工', '', '查看详情，尽快补齐资料')
            }
            this.$message.success('补证通知操作成功！')
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消操作！'
        })
      })
    },
    judgeNull(str) {
      if (!str || str.toString().replace(/(^s*)|(s*$)/g, '').length === 0) {
        return true
      } else {
        return false
      }
    },
    openDialogParam() {
      this.dialogFormParam = true
    },
    // 修改邮寄地址
    savePostInfo(operation) {
      this.$refs['postInfo'].validate(valid => {
        if (valid) {
          this.apibjd({
            url: 'postInfo/save',
            method: 'post',
            data: this.postInfo
          }).then(data => {
            this.$message({ message: '保存成功', type: 'success' })
          })
        }
      })
    },
    bjdSave(audit) {
      if (audit) {
        let message = '请确认是否要审核通过'
        if (this.bjd.shebeizhongleidaima === '3000' || this.bjd.shebeizhongleidaima === '4000') {
          message = '请确认资料已审核完毕/检验价格已经核定？？？是否继续？？'
          if (this.$store.getters.userId !== 10221 && this.$store.getters.userId !== 10003) {
            // 莱芜科室先收费，此处需要跳过。
            if (this.bjd.ziliaorenlingren.indexOf(this.$store.getters.userId) === -1) {
              // 如果资料认领人中缺少当前人员不允许当前人员进行审核操作。
              this.$message({
                type: 'warning',
                message: '审核受限，您不属于当前资料审核人！！！监督检验报检设备需经科室资料审核！请核价后提示企业将资料递交到科室。'
              })
              return false
            }
          }
        }
        this.$confirm(message, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.bjdQurenSave(audit)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消操作！'
          })
        })
      } else {
        this.bjdQurenSave(audit)
      }
    }, // 报检单保存
    bjdQurenSave(audit) {
      this.$refs['bjd'].validate(valid => {
        if (valid) {
          if (this.judgeNull(this.bjd.quhuadaima)) {
            this.$message({
              type: 'error',
              message: '区划不能为空！'
            })
            return false
          }
          if (this.tableData === null || this.tableData.length === 0) {
            this.$message({
              type: 'error',
              message: '报检设备不能为空！'
            })
            return false
          } else {
            for (let i = 0; i < this.tableData.length; i++) {
              if (this.judgeNull(this.tableData[0].shebeileibiedaima)) {
                this.$message({
                  type: 'error',
                  message: '请选择第一条设备的设备类别！'
                })
                return false
              } else if (this.judgeNull(this.tableData[i].chanpinbianhao)) {
                this.$message({
                  type: 'error',
                  message: '出厂编号不能同时为空！'
                })
                return false
              }
              if (this.judgeNull(this.tableData[i].shebeileibiedaima)) {
                if (this.sbzldm === 'F000') {
                  this.tableData[i].shebeileibiedaima = '7300'
                  this.tableData[i].shebeileibie = '压力管道阀门'
                } else {
                  this.tableData[i].shebeileibiedaima = this.tableData[0].shebeileibiedaima
                  this.tableData[i].shebeileibie = this.tableData[0].shebeileibie
                }
              }
              // 设置区划
              this.tableData[i].quhuadaima = this.bjd.quhuadaima
              this.tableData[i].quhuamingcheng = this.bjd.quhuamingcheng
            }
          }
          this.bjd.jianyanleibie = 'JJ'
          this.bjd.totalNum = this.tableData.length
          if (this.bjd.ziliaozhonglei === '' || this.bjd.ziliaozhonglei === undefined || this.bjd.ziliaozhonglei === null) {
            this.bjd.ziliaozhonglei = '3'
          }
          let url = ''
          if (this.formState === 'create' || this.formState === 'newBuild') {
            url = 'bjd/saveBjd'
          } else {
            url = 'bjd/updateBjd'
          }
          this.apibjd({
            url: url,
            method: 'post',
            data: {
              bjd: this.bjd,
              paramList: this.tableData,
              audit: audit
            }
          }).then(data => {
            Utils.$emit('bjd-list')
            Utils.$emit('allot-list')
            if (audit) {
              this.$store.dispatch('delCurrentViews', {
                view: this.$route,
                $router: this.$router
              })
              this.$message({ message: '审核成功', type: 'success' })
              if (this.bjd.dataSource === 1) {
                this.smsSendResult('已通过', '根据施工进度', '【申请现场检验】')
                // 您的${project}项目报检申请资料审核${status}。请${action}登录企业管理平台${action1}。咨询电话：${phone}。
                // 【济南市特种设备检验研究院】您的43项目报检申请资料审核已通过，请根据施工进度登录企业管理平台[申请现场检验]。咨询电话:89738113。
              }
            } else {
              this.tableData = data.tableData
              for (const tableObj of this.tableData) {
                const sblbpz = []
                sblbpz.push(tableObj.shebeileibiedaima)
                sblbpz.push(tableObj.shebeipinzhongdaima)
                this.$set(tableObj, 'sblbpz', sblbpz)
              }
              if (this.formState === 'create' || this.formState === 'newBuild') {
                this.$message({ message: '保存成功', type: 'success' })
                this.bjd = data.bjd
                this.formState = 'update'
                this.beforeHejia()
                this.$refs.bjBaseList.doLayout()
              } else {
                this.$message({ message: '修改成功', type: 'success' })
              }
            }
          })
        } else {
          this.$message({ type: 'error', message: '保存失败，存在必填项！' })
        }
      })
    },
    beforeUpload(file) {
      let importField = []
      if (this.bjd.bjType === 'cyqp') {
        importField = [
          [{ label: '安装单位', value: 'shigongdanwei' }, { label: '区划名称', value: 'quhuamingcheng' }],
          [{ label: '设备代码', value: 'shebeidaima' }, { label: '产品编号', value: 'chanpinbianhao' }, { label: '安装日期', value: 'shigongriqi' }, { label: '安装许可证编号', value: 'shigongxukezheng' },
            { label: '气瓶制造单位', value: 'zhizaodanwei' }, { label: '制造日期', value: 'zhizaoriqi' }, { label: '公称压力', value: 's33' }, { label: '工作介质', value: 's34' },
            { label: '车辆牌号/车辆底盘号', value: 's29' }]
        ]
      }
      this.bjdController.beforeUpload(this, file, importField, this.sbzldm, this.bjd.bjType)
      return false
    },
    beforeHejia() {
      // 核定价格
      for (let i = 0; i < this.tableData.length; i++) {
        // 初始化参数
        // if (this.tableData[i].neibuleibie) {
        //   this.tableData[i].neibuleibie = 'DQ'
        // }
        if (this.formState === 'finish') {
          this.$message.warning('只允许更新核定费用，已审核的参数修改无效！！！')
          return false
        }
        if (this.sbzldm === '1000') {
          // 2
        } else if (this.sbzldm === '2000') {
          // 1
        } else if (this.sbzldm === '3000') {
          if (this.tableData[i].shebeileibiedaima !== undefined) {
            if (this.tableData[i].shebeileibiedaima.substring(0, 2) === '30') {
              const sblbdm = this.tableData[i].shebeileibiedaima.substring(2, 3)
              this.tableData[i].shebeileibiedaima = '3' + sblbdm + '00'
            }
          }
          this.calculate.calculateDt(this.tableData[i])
        } else if (this.sbzldm === '4000') {
          if (this.tableData[i].shebeileibiedaima !== '') {
            if (this.tableData[i].shebeileibiedaima.substring(0, 2) === '40') {
              const sblbdm = this.tableData[i].shebeileibiedaima.substring(2, 3)
              this.tableData[i].shebeileibiedaima = '4' + sblbdm + '00'
            }
          }
          this.calculate.calculateQZ(this.tableData[i])
        } else if (this.sbzldm === '5000') {
          if (this.tableData[i].shebeileibiedaima !== '') {
            if (this.tableData[i].shebeileibiedaima.substring(0, 2) === '50') {
              let sblbdm = this.tableData[i].shebeileibiedaima.substring(2, 3)
              if (sblbdm !== '2') {
                sblbdm = '1'
              }
              this.tableData[i].shebeileibiedaima = '5' + sblbdm + '00'
            }
          }
          this.calculate.calculateCC(this.tableData[i])
        }
      }
    },
    postInfoSave() {
      this.formYJVisible = true
      console.log('领取地址修改')
    },
    printHzd() {
      this.apibjd({
        url: '/bjd/printHzd',
        method: 'get',
        params: {
          bjdIds: this.bjd.id
        }
      }).then(data => {
        this.preview({
          url: '/print/generatePdfListing',
          method: 'post',
          data: {
            info: data.bjd,
            paramList: data.renwu,
            viewType: 'HZD'
          }
        }).then(data => {
          data = data.replace(/\\/g, '/')
          window.open(data)
        }).catch(() => {
          this.deleteCurrentView()
        })
      }).catch(() => {
        this.deleteCurrentView()
      })
    },
    deleteCurrentView() {
      this.$store.dispatch('delCurrentViews', {
        view: this.$route,
        $router: this.$router
      })
    },
    openZiliaoshencha() {
      this.getFiles()
      this.baseInfoContentVisible = true
    },
    getFiles() {
      if (this.bjd.qyId === undefined || this.bjd.qyId === '' || this.bjd.qyId === null) {
        return false
      }
      if (this.bjd.qyId > '19841') {
        this.apibjd({
          url: '/bjdfiles/getFilesJSON2',
          method: 'get',
          params: {
            zhonglei: this.sbzldm,
            bjdId: this.bjd.qyId
          }
        }).then(data => {
          this.treeFilesData = data
          console.log(this.treeFilesData)
        })
      } else {
        this.apibjd({
          url: '/bjdfiles/getFilesJSON',
          method: 'get',
          params: {
            zhonglei: this.sbzldm,
            bjdId: this.bjd.qyId
          }
        }).then(data => {
          this.treeFilesData = data
          console.log(this.treeFilesData)
        })
      }
    },
    lookImgLeft() {
      this.leftUrls = []
      const imgsData = this.$refs.treeFiles.getCheckedNodes()
      for (let i = 0; i < imgsData.length; i++) {
        if (imgsData[i].url !== undefined) {
          this.leftUrls.push(process.env.VUE_APP_IMG_URL + imgsData[i].url)
        }
      }
      this.$refs.treeFiles.setCheckedNodes([{}])
    },
    lookImgRight() {
      this.rightUrls = []
      const imgsData = this.$refs.treeFiles.getCheckedNodes()
      for (let i = 0; i < imgsData.length; i++) {
        if (imgsData[i].url !== undefined) {
          this.rightUrls.push(process.env.VUE_APP_IMG_URL + imgsData[i].url)
        }
      }
      this.$refs.treeFiles.setCheckedNodes([{}])
    },
    smsSendResult(result, action, remark) {
      let sydw = this.bjd.shiyongdanwei
      const devicetype = this.bjd.shebeizhongleidaima === '3000' ? '0' : '1'
      if (sydw.length > 19) { // 字符超过20后导致无法发送短信，需要进行截取。
        sydw = sydw.substring(0, 17) + '...'
      }
      // 发送短信
      axios.defaults.headers.common['area'] = 'jinan'
      axios.put(`${process.env.VUE_APP_SMS_URL}${this.bjd.shigongdanweiDianhua}?deviceType=` + devicetype, { // devicetype 0 是电梯 1 是其他没有电话 phone
        phone: '0531-89738113',
        project: sydw, // 使用单位项目
        status: result, // 未通过
        action: action,
        action1: remark
      }).then((response) => {
        console.log(response)
      }).catch(() => {
        this.$message.warning('短信发送失败！！！')
      })
    },
    viewHzd() {
      this.apibjd({
        url: '/bjd/printHzd',
        method: 'get',
        params: {
          bjdIds: this.bjd.id
        }
      }).then(data => {
        this.preview({
          url: '/print/generatePdfListing',
          method: 'post',
          data: {
            info: data.bjd,
            paramList: data.renwu,
            viewType: 'HZD'
          }
        }).then(data => {
          data = data.replace(/\\/g, '/')
          window.open(data)
        })
      })
    },
    editFixedHidden() {
      const els = document.getElementsByClassName('el-table__fixed-right')
      if (!this.fixedFlag) {
        this.fixedWidth = els[0].style.width
      }
      if (this.fixedFlag) {
        els[0].style.width = this.fixedWidth
      } else {
        els[0].style.width = '270px'
      }
    }
  }
}
</script>
<style>
  .el-textarea__inner {
    height: 300px
  }
  .el-image-viewer__wrapper {
    width: 50%
  }
  .span-ellipsis {
    width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
</style>
