<!--整装锅炉安装监督检验-->
<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <div class="sub-navbar">
        <el-button v-if="state === 'create'" type="success" icon="el-icon-edit" size="medium" @click="saveYsjl('add')">
          保存
        </el-button>
        <el-button v-if="state === 'update'" type="primary" icon="el-icon-edit" size="medium" @click="saveYsjl('upd')">
          更新
        </el-button>
        <el-button v-if="state === 'update'" type="success" icon="el-icon-upload2" size="medium" @click="saveYsjl('build')">
          生成报告
        </el-button>
        <el-button type="primary" size="medium" @click="Signjyxm">
          <svg-icon icon-class="sign" />
          检验项目批量签名
        </el-button>
        <el-button type="danger" icon="el-icon-delete" size="medium" @click="signClear">
          批量清除签名
        </el-button>
        <el-button type="success" size="medium" icon="el-icon-edit" @click="batchUpdDate">
          批量修改日期
        </el-button>
        <el-button v-if="state !== 'create'" type="warning" icon="el-icon-view" size="medium" @click="common.viewYsjl(ysjl.id, 'YSJL')">
          预览
        </el-button>
        <Ft v-if="state !== 'create'" :state="state" :ysjl="ysjl" :ysjl-id="Number(ysjlId ? ysjlId : 0)" :department-id="Number(departmentId ? departmentId : 0)" style="margin-left: 10px;" />
      </div>
    </sticky>
    <el-tabs v-model="checkedTab" type="card">
      <el-tab-pane label="基本信息" name="first">
        <el-form ref="ysjl" :model="ysjl" class="el-form" label-position="right" label-width="130px">
          <fieldset>
            <legend>基本信息</legend>
            <el-row :gutter="25">
              <el-col v-if="state === 'create' || ysjl.jilubianhao === null || ysjl.jilubianhao === ''" :span="14">
                <el-form-item label="记录编号">
                  <el-input v-model="jlbh1" style="width:80px" disabled />
                  <el-input v-model="jlbh2" style="width:80px" disabled />-
                  <el-input v-model="jlbh3" style="width:80px" disabled />-
                  <el-input v-model="jlbh4" style="width:85px" @blur="judgeRepeat(jlbh1 + jlbh2 + jlbh3 + '-' + jlbh4 , ysjl.id)" />
                </el-form-item>
              </el-col>
              <el-col v-else :span="9">
                <el-form-item label="记录编号" prop="jilubianhao">
                  <el-input v-if="state !== 'create'" v-model="ysjl.jilubianhao" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col v-if="isRepeat" :span="2" style="vertical-align: middle;padding-top: 3px;font-size: 15px;">
                <span style="color:red">编号重复</span>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="使用单位（产权单位）" prop="shiyongdanwei" label-width="160px">
                  <el-input v-model="ysjl.shiyongdanwei" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="设备使用地点" prop="anzhuangdidian">
                  <el-input v-model="ysjl.anzhuangdidian" 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="ysjl.shiyongdanweiLianxiren" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="电话" prop="shiyongdanweiDianhua">
                  <el-input v-model="ysjl.shiyongdanweiDianhua" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="单位邮编" prop="shiyongdanweiYoubian">
                  <el-input v-model="ysjl.shiyongdanweiYoubian" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="锅炉型号" prop="guigexinghao">
                  <el-input v-model="ysjl.guigexinghao" />
                </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="ysjl.zhizaodanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="制造日期" prop="zhizaoriqi">
                  <el-date-picker v-model="ysjl.zhizaoriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="产品编号" prop="chanpinbianhao">
                  <el-input v-model="ysjl.chanpinbianhao" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="使用编号" prop="danweineibubianhao">
                  <el-input v-model="ysjl.danweineibubianhao" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="额定出力" prop="edingchuli">
                  <el-input v-model="param.edingchuli" />
                </el-form-item>
              </el-col>
              <el-col :span="3">
                <el-select v-model="param.edinggonglv" :disabled="true" type="text" placeholder="请选择">
                  <el-option label="t/h" value="t/h" />
                  <el-option label="MW" value="MW" />
                </el-select>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定压力" prop="edingyali">
                  <el-input v-model="param.edingyali">
                    <template slot="append">
                      MPa
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备代码" prop="shebeidaima">
                  <el-input v-model="ysjl.shebeidaima" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="使用压力" prop="shiyongyali">
                  <el-input v-model="param.shiyongyali">
                    <template slot="append">
                      MPa
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="额定温度" prop="edingwendu">
                  <el-input v-model="param.edingwendu">
                    <template slot="append">
                      ℃
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="设备类别" prop="shebeileibiedaima">
                  <el-select v-model="ysjl.shebeileibiedaima" filterable allow-create default-first-option style="width: 100%" @change="getSbpzList">
                    <el-option v-for="item in sblbList" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备品种(名称)" prop="shebeipinzhongdaima">
                  <el-select v-model="ysjl.shebeipinzhongdaima" filterable allow-create default-first-option style="width: 100%" @change="setSbpz">
                    <el-option v-for="item in sbpzList" :key="item.value" :label="item.label" :value="item.value" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="允许工作压力" prop="gongzuoyali">
                  <el-input v-model="param.gongzuoyali">
                    <template slot="append">
                      MPa
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="允许工作温度" prop="yunxugongzuowendu">
                  <el-input v-model="param.yunxugongzuowendu">
                    <template slot="append">
                      ℃
                    </template>
                  </el-input>
                </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="ysjl.shigongdanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="许可级别" prop="shigongxukezhengjibie">
                  <el-input v-model="ysjl.shigongxukezhengjibie" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="许可证编号" prop="shigongxukezheng">
                  <el-input v-model="ysjl.shigongxukezheng" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="告知书编号" prop="gaozhibianhao">
                  <el-input v-model="param.gaozhibianhao" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="施工单位联系人" prop="shigongdanweiLianxiren">
                  <el-input v-model="ysjl.shigongdanweiLianxiren" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="施工单位联系电话" prop="shigongdanweiDianhua">
                  <el-input v-model="ysjl.shigongdanweiDianhua" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <el-row :gutter="20" style="text-align:left;margin-left: 50px;font-size: 18px;color: #606266;line-height: 40px;font-weight: bolder;">
              按照《中华人民共和国特种设备安全法》、《特种设备安全监察条例》的规定，该锅炉的<u>（安装）</u><br>
              经我机构实施监督检验，安全性能
              <el-select v-model="ysjl.baogaojielun" placeholder="请选择" style="width: 100px;" @change="changeJyjl">
                <el-option label="符合" value="符合" />
                <el-option label="不符合" value="不符合" />
              </el-select>《锅炉安全技术规程》的要求，特发此证书。
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="是否有监督检验工作联络单或监督检验工作意见通知书" prop="hasYijiantongzhishu" label-width="350px">
                  <el-input v-model="param.hasYijiantongzhishu" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18" style="height: 70px;">
                <el-form-item label="处理情况" prop="quexianjiqichuli">
                  <el-input v-model="param.quexianjiqichuli" :rows="3" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20" style="margin-top: 20px;">
              <el-col :span="9">
                <!-- 开始安装日期就是开工告知日期 -->
                <el-form-item label="开始安装日期" prop="gaozhiriqi">
                  <el-date-picker v-model="param.gaozhiriqi" type="date" value-format="yyyy年MM月dd日" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="水压试验日期" prop="shiyanriqi">
                  <el-date-picker v-model="param.shiyanriqi" type="date" placeholder="选择日期" style="width: 75%;" />
                  <el-button type="primary" title="同步检验项中第1大项到第9大项的监检日期" icon="el-icon-refresh" size="mini" @click="syncRq(0, 38, param.shiyanriqi)" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="试运行完毕日期" prop="shiyunxingriqi">
                  <el-date-picker v-model="param.shiyunxingriqi" type="date" value-format="yyyy年MM月dd日" placeholder="选择日期" style="width: 75%;" />
                  <el-button type="primary" title="同步检验项中第10大项到第12大项的监检日期" icon="el-icon-refresh" size="mini" @click="syncRq(44, bgfyData.length, param.shiyunxingriqi)" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="安装资料送审日期" prop="anzhuangziliaosongshenriqi">
                  <el-date-picker v-model="param.anzhuangziliaosongshenriqi" type="date" value-format="yyyy年MM月dd日" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验日期" prop="jianyanjieshuriqi">
                  <el-date-picker v-model="ysjl.jianyanjieshuriqi" type="date" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="下次检验日期" prop="xiacijianyanriqi">
                  <el-date-picker v-model="ysjl.xiacijianyanriqi" type="date" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="10">
              <el-col :span="9">
                <el-form-item label="检验人员" prop="jianyanrenyuan">
                  <el-input v-model="jianyanrenyuan" disabled />
                  <el-input v-show="false" v-model="ysjl.jianyanrenyuan" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <sign-name :jianyanrenyuan="jianyanrenyuan" :ysjl="ysjl" @setSignValue="signNameValue" />
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18" style="height: 130px;">
                <el-form-item label="说明:" prop="beizhu">
                  <el-input v-model="ysjl.beizhu" :rows="5" :disabled="edit" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="整装锅炉安装监督检验项目表" name="second">
        <el-form class="el-form">
          <el-row :gutter="20">
            <el-col :span="18" style="height: 170px;">
              <el-form-item label="其他记录的内容:" prop="shuoming" label-width="150px">
                <el-input v-model="param.shuoming" :rows="5" :disabled="edit" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table ref="bgfyData" :data="bgfyData" :span-method="tableJs.mergeColRows" border stripe style="width:90%" @row-click="onRowClick">
          <el-table-column type="selection" width="55" prop="checkbox" />
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="center" label="监检项目">
            <el-table-column align="center" prop="jianyanxiang" width="70" label="检验项" />
            <el-table-column align="left" prop="jianyanneirong" label="检验内容" />
          </el-table-column>
          <el-table-column align="center" prop="xiangmuleibie" width="100" label="类别">
            <template slot-scope="scope">
              <!--              <el-checkbox-group v-if="showXmlb(scope.$index)" v-model="scope.row.xiangmuleibie" @change="changeXmlb(scope.$index)">-->
              <!--                <el-checkbox label="B" true-label="B" false-label="C" :disabled="edit || editStatus(scope.$index)" border />-->
              <!--                <el-checkbox label="C" true-label="C" false-label="B" :disabled="edit || editStatus(scope.$index)" border />-->
              <!--              </el-checkbox-group>-->
              <el-select v-if="showXmlb(scope.$index)" v-model="scope.row.xiangmuleibie" style="width:60px;" :disabled="edit || editStatus(scope.$index)" @change="changeXmlb(scope.$index)">
                <el-option value="B">
                  B
                </el-option>
                <el-option value="C">
                  C
                </el-option>
              </el-select>
              <span v-else>{{ scope.row.xiangmuleibie }}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" label="检验检测情况或结果">
            <el-table-column align="center" prop="jyjg1" width="90" label="合格">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.jyjg1" label="√" true-label="√" border @change="changeJyjg(scope.$index, 'jyjg1')" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="jyjg2" width="90" label="不合格">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.jyjg2" label="√" true-label="√" border @change="changeJyjg(scope.$index, 'jyjg2')" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="jianyanjieguo" width="90" label="无此项">
              <template slot-scope="scope">
                <el-checkbox v-model="scope.row.jianyanjieguo" label="√" true-label="√" border @change="changeJyjg(scope.$index, 'jianyanjieguo')" />
              </template>
            </el-table-column>
          </el-table-column>
          <el-table-column :formatter="formatterJianjianyuan" align="center" prop="jianjianyuan" width="100" label="监检员" />
          <el-table-column align="center" prop="querenriqi" width="160" label="日期">
            <template slot-scope="scope">
              <el-date-picker v-model="scope.row.querenriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane v-if="state !== 'create'" label="检验收费情况" name="jysfqk">
        <complex-bill v-if="complexShow" ref="bill" :ysjl="ysjl" />
      </el-tab-pane>
    </el-tabs>
    <el-dialog :visible.sync="jyxmrqShow" title="批量修改日期" width="500px" @close="closeDialog">
      <template>
        <el-date-picker v-model="querenriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
      </template>
      <span slot="footer" class="dialog-footer">
        <el-button @click="jyxmrqShow = false">取 消</el-button>
        <el-button type="primary" @click="batchUpd">确 定</el-button>
      </span>
    </el-dialog>
    <sign-name v-show="signShow" ref="qmButton" :ysjl="ysjl" :jianyanrenyuan="xmjianyanrenyuan" field-name="xmqianming" @setSignValue="signNameValue" />
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import SignName from '@/views/common/SignName'
import Utils from '@/utils/contact'
import merge from 'webpack-merge'
import Ft from '@/views/ysjl/1000/common/glft'
import ComplexBill from '@/views/chargeBill/components/complex'

export default {
  name: 'GlZgjdYsjl',
  components: { SignName, Sticky, Ft, ComplexBill },
  data() {
    return {
      jlbh1: 'GZA(',
      jlbh2: new Date().getFullYear(),
      jlbh3: ')',
      jlbh4: '',
      ysjl: {},
      param: {},
      jyxm: 'zgjd',
      path: '/ysjl/1000/zg/zgjd/',
      state: this.$route.query.state,
      jianyanrenyuan: '',
      departmentId: this.$route.query.departmentId,
      isRepeat: false,
      edit: false,
      bgfyData: [],
      tableData: [],
      checkedTab: 'first',
      xmjianyanrenyuan: '',
      // 表格合并相关
      // 参与列合并的字段，在这里增加即可
      cols: [
        {
          name: 'checkbox', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        },
        {
          name: 'jianjianyuan',
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'querenriqi',
          getValue(row) {
            return row.jianyanxiang
          }
        }
      ],
      // 参与行内合并的字段
      rows: [
        {
          name: 'jianyanxiang',
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        },
        {
          name: 'jianjianyuan',
          getValue(row) {
            return row.jianyanxiang
          }
        }
      ],
      signShow: false,
      jyxmrqShow: false,
      querenriqi: new Date(),
      sblbList: [],
      sbpzList: [],
      ysjlId: this.$route.query.id,
      fieldArr: ['jyjg1', 'jyjg2', 'jianyanjieguo'],
      xmlbList: ['B', 'C'],
      showXmlbIndexListZg: [1, 16, 22, 45, 46, 47, 48, 49, 50, 51, 52],
      disabledEdit: [46, 47, 48, 49, 50, 51, 52],
      complexShow: false
    }
  },
  computed: {
    jilubianhao: function() {
      let bianhao
      if (!this.ysjl.jilubianhao) {
        return this.jlbh1 + this.jlbh2 + this.jlbh3 + '-' + this.jlbh4
      } else {
        bianhao = this.ysjl.jilubianhao
      }
      return this.judgeRepeat(bianhao, this.ysjl.id)
    }
  },
  watch: {
    jlbh4: function(val) {
      this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + this.jlbh3 + '-' + val
      this.judgeRepeat(this.ysjl.jilubianhao, this.ysjl.id)
    },
    jilubianhao: function(newValue) {
      this.judgeRepeat(newValue, this.ysjl.id)
    }
  },
  created() {
    if (this.state === 'create') {
      this.api({
        url: '/ysjl/initYsjl',
        method: 'post',
        data: {
          modelId: this.$route.query.modelId,
          renwuId: this.$route.query.renwuId,
          neibuleibie: this.$route.query.neibuleibie,
          sblbdm: this.$route.query.sblbdm,
          sblbmc: this.$route.query.sblbmc,
          sbpzdm: this.$route.query.sbpzdm,
          sbpzmc: this.$route.query.sbpzmc
        }
      }).then(data => {
        this.ysjl = data.ysjl
        this.param = (data.param !== null && data.param !== undefined) ? data.param : {}
        this.ysjl.jianyanjieshuriqi = this.formatter.dateFormat('YYYY-MM-dd')
        const currentDate = new Date()
        const xcjyrq = new Date((currentDate.getFullYear() + 1) + '-' + (currentDate.getMonth() + 1) + '-' + currentDate.getDate())
        this.ysjl.xiacijianyanriqi = xcjyrq.setDate(xcjyrq.getDate() - 1)
        this.ysjl.jianyanjielun = '合格'
        this.ysjl.baogaojielun = '符合'
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.$set(this.param, 'shiyunxingriqi', this.formatter.dateFormat('YYYY年MM月dd日'))
        this.ysjl.beizhu = '/'
        this.ysjl.zhizaoriqi = ''
        this.changeEdgl()
        this.getSbList('1000', this.ysjl.shebeileibiedaima, 3)
      })
      this.getMaxBh()
      this.$set(this.param, 'hasYijiantongzhishu', '无。')
    } else {
      this.getYsjl(this.$route.query.id)
    }
    this.getSbList('1000', undefined, 2)
    this.getJyxm(1)
  },
  methods: {
    /**
     * 格式化监检员
     */
    formatterJianjianyuan(row) {
      if (row.jianjianyuan) {
        if (typeof (row.jianjianyuan) === 'number') {
          row.jianjianyuan = row.jianjianyuan.toString()
        }
        return this.common.convertCnName(row.jianjianyuan)
      }
    },
    // 签名方法
    signNameValue(data) {
      if (data.fieldName === 'xmqianming') {
        this.jyxmController.findFirstJyxAndSignName(this.$refs.bgfyData.selection, this.bgfyData, data)
        this.signShow = false
      } else {
        this.ysjl.jianyanrenyuan = data.id
        this.jianyanrenyuan = data.name
        if (this.state !== 'create') {
          this.common.signName(this.ysjl.id, this.ysjl.jianyanrenyuan)
          Utils.$emit('ysjl-list')
        }
      }
    },
    // 查询最大记录编号
    getMaxBh() {
      const aheadPart = this.jlbh1 + '' + this.jlbh2 + '' + this.jlbh3
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: aheadPart + '-',
          hinderPart: ''
        }
      }).then(data => {
        this.jlbh4 = data
      })
    },
    getSbpzList(val) {
      this.changeEdgl()
      let obj = {}
      obj = this.sblbList.find((item) => { // 这里的sblbList就是上面遍历的数据源
        return item.value === val // 筛选出匹配数据
      })
      this.ysjl.shebeileibie = obj.label
      this.ysjl.shebeipinzhongdaima = ''
      this.ysjl.shebeipinzhong = ''
      if (val) {
        this.getSbList('1000', val, 3)
      }
    },
    setSbpz(val) {
      let obj = {}
      obj = this.sbpzList.find((item) => { // 这里的userList就是上面遍历的数据源
        return item.value === val // 筛选出匹配数据
      })
      this.ysjl.shebeipinzhong = obj.label
    },
    getSbList(sbzl, sblb, level) {
      this.api({
        url: '/sedirectory/getList',
        method: 'get',
        params: {
          sbzl: sbzl,
          sblb: sblb,
          level: level
        }
      }).then(data => {
        switch (level) {
          case 2:
            this.sblbList = data
            return ''
          case 3:
            this.sbpzList = data
            return ''
          default:
            this.sbzlList = data
            return ''
        }
      })
    },
    getYsjl(id) {
      this.api({
        url: '/ysjl/getYsjlById',
        method: 'get',
        params: {
          ysjlId: id
        }
      }).then(data => {
        this.ysjl = data.ysjl
        this.complexShow = true
        if (this.ysjl.jianyanrenyuan !== null && this.ysjl.jianyanrenyuan.length > 0) {
          this.jianyanrenyuan = this.common.convertCnName(this.ysjl.jianyanrenyuan)
        }
        // 查询最大记录编号
        if (this.ysjl.jilubianhao === null || this.ysjl.jilubianhao === undefined || this.ysjl.jilubianhao === '') {
          this.getMaxBh()
        }
        this.getParam(this.ysjl.id, this.ysjl.shebeizhongleidaima)
        this.changeEdgl()
        this.getSbList('1000', this.ysjl.shebeileibiedaima, 3)
      })
    },
    getParam(ysjlId, sbzldm) {
      // 根据原始记录id查询参数
      this.api({
        url: '/ysjl/getParamByYsjlId',
        method: 'get',
        params: {
          ysjlId: ysjlId,
          sbzldm: sbzldm
        }
      }).then(data => {
        this.param = data
      })
    },
    // 查询检验项目
    getJyxm(sort) {
      this.jyxmController.getJyxm(this.$route.query.modelId, this.$route.query.id, sort, this.state, false).then(data => {
        switch (sort) {
          case 1:
            this.bgfyData = data
            this.jyxmController.initJjyJyxm(this.state, this.bgfyData)
            this.tableJs.getData(this.cols, this.rows, this.bgfyData)
            break
        }
      })
    },
    /**
     * 获取表格中的id, 不为空的检验结果和备注
     */
    getProp: function(data) {
      const retData = []
      const fields = ['xiangmuleibie', 'jyjg1', 'jyjg2', 'jianyanjieguo', 'jianjianyuan', 'querenriqi']
      for (let i = 0; i < data.length; i++) {
        const retRow = {}
        retRow.id = data[i].id
        fields.forEach(field => {
          if (data[i][field]) {
            retRow[field] = data[i][field]
          }
        })
        retData.push(retRow)
      }
      return retData
    },
    /**
     * 检验项目批量签名
     */
    Signjyxm() {
      if (this.$refs.bgfyData.selection.length === 0) {
        this.$message('请在列表选择要签名的数据。')
        return
      }
      this.signShow = true
      this.$refs.qmButton.dialogFormVisible = true
    },
    /**
     * 检验项目清除签名
     */
    signClear: function() {
      if (this.$refs.bgfyData.selection.length === 0) {
        this.$message('请在列表选择要清除签名的数据。')
        return
      }
      this.$refs.qmButton.clearSign()
    },
    closeDialog() {
      this.jyxmrqShow = false
    },
    onRowClick(row) {
      this.$refs.bgfyData.toggleRowSelection(row)
    },
    batchUpdDate() {
      if (this.$refs.bgfyData.selection.length === 0) {
        this.$message('请在列表选择要修改日期的数据。')
        return false
      }
      this.jyxmrqShow = true
    },
    batchUpd() {
      for (let i = 0; i < this.$refs.bgfyData.selection.length; i++) {
        this.$refs.bgfyData.selection[i].querenriqi = this.querenriqi
        for (let j = 0; j < this.bgfyData.length; j++) {
          if (this.bgfyData[j].id === this.$refs.bgfyData.selection[i].id) {
            this.$set(this.bgfyData[j], this.$refs.bgfyData.selection[i])
          }
        }
      }
      this.jyxmrqShow = false
    },
    saveYsjl: function(operation) {
      if (operation === 'add') {
        if (!this.jlbh4.trim()) {
          this.$message({ message: '请先确认记录编号是否完整！', type: 'warning' })
          return false
        }
      }
      this.tableData = []
      this.tableData.push(this.getProp(this.bgfyData))
      let url = ''
      this.ysjl.bglx = 1
      this.ysjl.cjState = 'ysjl'
      this.ysjl.zfState = '0'
      this.ysjl.jlprintState = 0
      if (operation === 'add') {
        url = '/ysjl/saveYsjl'
        this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + this.jlbh3 + '-' + this.jlbh4
        this.ysjl.jianyanxiangmu = this.jyxm
      } else if (operation === 'build') {
        if (!this.ysjl.jianyanrenyuan) {
          this.$message({
            type: 'error',
            message: '请先签名再生成报告!'
          })
          return false
        }
        if (this.ysjl.sfdId === null || this.ysjl.sfdId === '') {
          this.$message({
            type: 'error',
            message: '请先追加或者创建收费单后在尝试!'
          })
          return false
        }
        url = '/ysjl/updateYsjl'
      } else if (operation === 'upd') {
        url = '/ysjl/updateYsjl'
      }
      if (this.isRepeat) {
        this.$message({ message: '记录编号重复，请先修改记录编号再保存', type: 'error' })
        return false
      } else {
        this.$refs['ysjl'].validate(valid => {
          if (valid) {
            this.api({
              url: url,
              method: 'post',
              data: {
                ysjl: this.ysjl,
                param: this.param,
                jyxm: JSON.stringify(this.tableData),
                flag: operation
              }
            }).then(data => {
              Utils.$emit('task-list')
              Utils.$emit('ysjl-list')
              if (operation === 'add' && data !== '') {
                this.$message({ message: '保存成功, 请前往待办记录中查看。', type: 'success' })
                this.ysjl.id = data
                this.param.ysjlId = data
                // 刷新路由网址
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
                // this.$router.push({
                //   path: this.path + this.ysjl.id,
                //   query: { state: 'update', id: this.ysjl.id, departmentId: this.ysjl.departmentId, jianyanrenyuan: this.ysjl.jianyanrenyuan }
                // })
              } else if (operation === 'upd') {
                this.$message({ message: '更新成功', type: 'success' })
                // 替换路由中的参数
                this.$router.push({
                  query: merge(this.$route.query, { 'jianyanrenyuan': this.ysjl.jianyanrenyuan })
                })
                // this.$refs.bill.updateChargeBill()
              } else {
                Utils.$emit('ysjl-yb-list')
                Utils.$emit('bggl-daiban-list')
                this.$message({ message: '生成报告成功', type: 'success' })
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
              }
              this.state = 'update'
            })
          }
        })
      }
    },
    judgeRepeat(bianhao, id) {
      this.api({
        url: '/ysjl/judgeRepeat',
        method: 'get',
        params: {
          ysjlId: id,
          bianhao: bianhao
        }
      }).then(data => {
        if (data > 0) {
          this.isRepeat = true
        } else {
          this.isRepeat = false
        }
      })
    },
    changeJyjl(val) {
      if (val === '符合') {
        // 性能符合的时候下次检验日期加一年减一天
        this.ysjl.jianyanjielun = '合格'
        const xcjyrq = new Date(this.ysjl.jianyanjieshuriqi)
        xcjyrq.setFullYear(xcjyrq.getFullYear() + 1)
        this.ysjl.xiacijianyanriqi = xcjyrq.setDate(xcjyrq.getDate() - 1)
      } else {
        // 性能不符合的时候下次检验日期加三个月减一天
        this.ysjl.jianyanjielun = '不合格'
        const xcjyrq = new Date(this.ysjl.jianyanjieshuriqi)
        xcjyrq.setMonth(xcjyrq.getMonth() + 1 + 2)
        this.ysjl.xiacijianyanriqi = xcjyrq.setDate(xcjyrq.getDate() - 1)
      }
    },
    /**
     * 改变额定功率：蒸汽锅炉是t/h，其他的是MW
     */
    changeEdgl() {
      if (this.ysjl.shebeileibiedaima === '1100') {
        this.param.edinggonglv = 't/h'
      } else {
        this.param.edinggonglv = 'MW'
      }
    },
    /**
     *
     * @param $index
     * @param field
     */
    changeJyjg($index, field) {
      this.fieldArr.forEach(currentField => {
        if (field !== currentField) {
          this.bgfyData[$index][currentField] = ''
        }
      })
    },
    /**
     * 同步检验项目中的日期
     * 水压试验日期同步1-9大项
     * 试运行日期同步10-12大项
     * @param startIndex  索引
     * @param count       最大索引
     * @param riqi        同步的日期
     */
    syncRq(startIndex, count, riqi) {
      for (let i = startIndex; i < count; i++) {
        if (i === 0) {
          this.bgfyData[i].querenriqi = this.param.shiyanriqi
        } else if (i + 1 < this.bgfyData.length && this.bgfyData[i].jianyanxiang !== this.bgfyData[i + 1].jianyanxiang) {
          this.bgfyData[i + 1].querenriqi = riqi.replace('年', '-').replace('月', '-').replace('日', '')
        }
      }
    },
    /**
     * 是否展示项目类别
     * @param $index
     * @returns {number}
     */
    showXmlb($index) {
      return this.showXmlbIndexListZg.filter(index => {
        return index === $index
      }).length
    },
    /**
     * 是否可编辑
     * @param $index
     * @returns {boolean}
     */
    editStatus($index) {
      return this.disabledEdit.filter(index => {
        return index === $index
      }).length > 0
    },
    /**
     * 改变部分项目类别
     * @param $index
     */
    changeXmlb($index) {
      if ($index === 45) {
        this.disabledEdit.forEach(index => {
          this.bgfyData[index].xiangmuleibie = this.bgfyData[$index].xiangmuleibie
        })
      }
    }
  }
}
</script>
