<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="primary" icon="el-icon-circle-check-outline" size="medium" @click="toAddJyfa">
          添加检验方案
        </el-button>
        <el-button v-if="state !== 'create'" type="info" icon="el-icon-info" size="medium" @click="getJyfaInfo">
          查看同类报告
        </el-button>
        <el-button v-if="state !== 'create'" type="warning" icon="el-icon-view" size="medium" @click="common.viewYsjl(ysjl.id, 'JYBG')">
          预览
        </el-button>
      </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="20">
              <el-col v-if="state === 'create'" :span="13">
                <el-form-item label="记录编号">
                  <el-input v-model="bgbh1" style="width:80px" disabled />
                  <el-input v-model="bgbh2" style="width:80px" disabled />-
                  <el-input v-model="bgbh3" style="width:80px" @blur="judgeRepeat(bgbh1 + bgbh2 + bgbh3 , ysjl.id)" />
                </el-form-item>
              </el-col>
              <el-col v-if="state !== 'create'" :span="9">
                <el-form-item label="记录编号" prop="baogaobianhao">
                  <el-input v-if="state !== 'create'" v-model="ysjl.baogaobianhao" :disabled="edit" @blur="judgeRepeat(ysjl.baogaobianhao, ysjl.id)" />
                </el-form-item>
              </el-col>
              <el-col v-if="isRepeat" :span="2">
                <span style="color:red">编号重复</span>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="工程名称" prop="gongchengmingcheng">
                  <el-input v-model="param.gongchengmingcheng" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="工程地址" prop="gongchengdizhi">
                  <el-input v-model="param.gongchengdizhi" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="工程规模" prop="gongchengguimo">
                  <el-input v-model="param.gongchengguimo" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="管道级别" prop="guandaojibie">
                  <el-input v-model="param.guandaojibie" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="设计压力" prop="shejiyali">
                  <el-input v-model="param.shejiyali" :disabled="edit">
                    <template slot="append">
                      (MPa)
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="输送介质" prop="shusongjiezhi">
                  <el-input v-model="param.shusongjiezhi" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="开工时间" prop="kaigongshijian">
                  <el-date-picker v-model="param.kaigongshijian" :disabled="edit" 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="jungongshijian">
                  <el-date-picker v-model="param.jungongshijian" :disabled="edit" 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="18">
                <el-form-item label="建设单位" prop="jianshedanwei">
                  <el-input v-model="param.jianshedanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="管道设计单位" prop="shejidanwei">
                  <el-input v-model="ysjl.shejidanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="工程规划许可证号" prop="guihuaxukezheng">
                  <el-input v-model="param.guihuaxukezheng" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设计证书编号" prop="shejiwenjianhao">
                  <el-input v-model="ysjl.shejiwenjianhao" :disabled="edit" />
                </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="18">
                <el-form-item label="防腐施工单位" prop="fangfushigongdanwei">
                  <el-input v-model="param.fangfushigongdanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="安装许可证编号" prop="shigongxukezheng">
                  <el-input v-model="ysjl.shigongxukezheng" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="防腐资质证书编号" prop="fangfuzizhizhengshu">
                  <el-input v-model="param.fangfuzizhizhengshu" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="监理单位" prop="jianlidanwei">
                  <el-input v-model="param.jianlidanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检测单位" prop="jiancedanwei">
                  <el-input v-model="param.jiancedanwei" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="监理资质证书号" prop="jianlizizhizhengshu">
                  <el-input v-model="param.jianlizizhizhengshu" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="资格证书编号" prop="jiancezizhizhenghao">
                  <el-input v-model="param.jiancezizhizhenghao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="授权书文号" prop="shouquanshuwenhao">
                  <el-input v-model="param.shouquanshuwenhao" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设计温度" prop="shejiwendu">
                  <el-input v-model="param.shejiwendu" :disabled="edit">
                    <template slot="append">
                      (℃)
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检验规范" prop="anzhuangguifan">
                  <el-input v-model="param.anzhuangguifan" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验结论" prop="jianyanjielun">
                  <el-select v-model="ysjl.jianyanjielun" placeholder="请选择" style="width: 100%;">
                    <el-option label="合格" value="合格" />
                    <el-option label="不合格" value="不合格" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="安全状况等级为" prop="anquanzhuangkuangdengji">
                  <el-select v-model="ysjl.anquanzhuangkuangdengji" type="text" placeholder="请选择" style="width: 100%;">
                    <el-option label="1级" value="1级" />
                    <el-option label="2级" value="2级" />
                    <el-option label="3级" value="3级" />
                    <el-option label="4级" value="4级" />
                    <el-option label="5级" value="5级" />
                    <el-option label="-" value="-" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验开始日期" prop="jianyankaishiriqi">
                  <el-date-picker v-model="ysjl.jianyankaishiriqi" :disabled="edit" 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="jianyanjieshuriqi">
                  <el-date-picker v-model="ysjl.jianyanjieshuriqi" :disabled="edit" 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="xiacijianyanriqi">
                  <el-date-picker v-model="ysjl.xiacijianyanriqi" :disabled="edit" 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="zhengshubianhao">
                  <el-input v-model="param.zhengshubianhao" type="text" />
                </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 v-if="state !== 'bgView'" :span="9">
                <sign-name :ysjl="ysjl" :jianyanrenyuan="jianyanrenyuan" @setSignValue="singNameValue" />
              </el-col>
            </el-row>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="压力管道基本情况" name="second">
        <el-form ref="ysjl" :model="ysjl" class="el-form" label-position="right" label-width="130px">
          <fieldset>
            <legend>基本信息</legend>
            <el-row :gutter="20" style="height: 130px;">
              <el-col :span="18">
                <el-form-item label="工程简介" prop="gongchengjianjie">
                  <el-input v-model="param.gongchengjianjie" :disabled="edit" :rows="5" type="textarea" placeholder="内容包括工程名称施工单位投资规模管道的基本属性相关情况的描述" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="工程地址" prop="gongchengdizhi">
                  <el-input v-model="param.gongchengdizhi" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="工程规模" prop="gongchengguimo">
                  <el-input v-model="param.gongchengguimo" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="建设单位" prop="jianshedanwei">
                  <el-input v-model="param.jianshedanwei" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="设计单位" prop="shejidanwei">
                  <el-input v-model="ysjl.shejidanwei" disabled />
                </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" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="监理单位" prop="jianlidanwei">
                  <el-input v-model="param.jianlidanwei" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="防腐单位" prop="fangfushigongdanwei">
                  <el-input v-model="param.fangfushigongdanwei" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检测单位" prop="jiancedanwei">
                  <el-input v-model="param.jiancedanwei" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20" style="height: 110px;">
              <el-col :span="18">
                <el-form-item label="主要元件供货单位" prop="gonghuodanwei">
                  <el-input v-model="param.gonghuodanwei" :disabled="edit" :rows="4" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="开工竣工时间" prop="kaigongjungongshijian">
                  <el-input :value="(param.kaigongshijian ? param.kaigongshijian : '') + '-' + (param.jungongshijian ? param.jungongshijian : '')" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="管道级别" prop="guandaojibie">
                  <el-input v-model="param.guandaojibie" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="设计参数" prop="shejicanshu">
                  <el-input :value="'设计压力：' + (param.shejiyali ? param.shejiyali : '') + 'Mpa、设计温度：' + (param.shejiwendu ? param.shejiwendu : '') + '℃'" disabled />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="主体材质" prop="zhuticaizhi">
                  <el-input v-model="param.zhuticaizhi" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="管道规格" prop="guigexinghao">
                  <el-input v-model="ysjl.guigexinghao" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="一览表" name="third">
        <span v-if="state === 'create'" style="color: red;font-size: 26px;">请在保存后编辑一览表</span>
        <mxb v-show="state !== 'create'" ref="mxb" />
      </el-tab-pane>
    </el-tabs>
    <el-dialog :visible.sync="jyfaDialogVisible" title="添加检验方案" width="600px" @close="closeJyfaDialog">
      <jyfa ref="jyfa" :info="info" />
    </el-dialog>
    <el-dialog :visible.sync="similarVisible" title="同类报告查看" width="800px" @close="closeJyfaDialog">
      <el-table ref="similarTable" :data="similarTableData" border style="width: 100%;" height="350">
        <el-table-column align="center" label="报告类型" prop="bglx" min-width="50" />
        <el-table-column align="left" label="检验项目" prop="jyxmLabel" width="200">
          <template slot-scope="scope">
            <div style="text-decoration:underline;cursor:pointer;" @click="editChild(scope.row.id, scope.row.jianyanxiangmu, departmentId, scope.row.modelId)">
              {{ scope.row.jyxmLabel }}
            </div>
          </template>
        </el-table-column>
        <el-table-column align="center" label="处理人" prop="renlingren" min-width="40" />
        <el-table-column align="center" label="检验人员" prop="jianyanrenyuan" min-width="40" />
        <el-table-column align="center" label="办结状态" prop="flowstatus" min-width="30">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.flowstatus==='未办结'" type="danger">
              未办结
            </el-tag>
            <el-tag v-if="scope.row.flowstatus==='已办结'" type="success">
              已办结
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column property="" label="操作" align="center" width="95">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" title="删除检验方案" circle icon="el-icon-delete" @click="delYsjl(scope.row.jyxmLabel, scope.row.bglx, scope.row.id)" />
            <el-button v-if="scope.row.bglx ==='分项检测' && scope.row.flowstatus === '未办结'" type="primary" size="mini" title="办结" circle icon="el-icon-check" @click="bjYsjl(scope.row.id, '1')" />
            <el-button v-if="scope.row.bglx ==='分项检测' && scope.row.flowstatus === '已办结'" type="primary" size="mini" title="取消办结" circle icon="el-icon-close" @click="bjYsjl(scope.row.id, '0')" />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import jyfa from '@/views/bggl/addJyfa'
import SignName from '@/views/common/SignName'
import Utils from '@/utils/contact.js'
import mxb from './mxb'
export default {
  name: 'GdJjReport',
  components: { SignName, Sticky, jyfa, mxb },
  data() {
    return {
      // 预定义值
      edit: false, // 页面编辑状态
      bgbh1: 'GDA',
      bgbh2: '(' + (new Date().getFullYear()) + ')',
      bgbh3: '',
      // 检验人员
      jianyanrenyuan: '',
      // 检验方案
      jyfaDialogVisible: false,
      // 接收传入该页面的值
      // 页面状态 {create=> 创建，update=> 更新}
      state: this.$route.query.state,
      ysjl: {},
      departmentId: this.$route.query.departmentId,
      param: {},
      checkedTab: 'first',
      info: {
        modelId: this.$route.query.modelId,
        sbzldm: this.$route.query.sbzldm,
        sblbdm: this.$route.query.sblbdm,
        ysjlId: this.$route.query.id,
        departmentId: this.$route.query.departmentId,
        jylb: this.$route.query.jylb,
        nblb: this.$route.query.neibuleibie,
        type: 'JYBG'
      },
      similarVisible: false,
      similarTableData: [],
      isRepeat: false,
      tableData: []
    }
  },
  computed: {
    baogaobianhao: function() {
      if (this.state !== 'create') {
        return this.ysjl.baogaobianhao
      }
      return this.bgbh1 + this.bgbh2 + '-' + this.bgbh3
    }
  },
  created() {
    if (this.state === 'create') {
      this.initYsjl()
    } else {
      this.getYsjl()
      this.getParam()
    }
  },
  methods: {
    initYsjl() {
      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 ? data.param : {}
        this.ysjl.flowStatus = 1
        this.ysjl.jianyanjielun = '符合要求'
        this.ysjl.xiacijianyanriqishuoming = '/'
        this.ysjl.shebeizhongleidaima = '8000'
        // 设置初始值
        const tempTime = new Date()
        this.ysjl.jianyankaishiriqi = this.formatter.dateFormat('YYYY-MM-dd', tempTime)
        this.ysjl.jianyanjieshuriqi = this.formatter.dateFormat('YYYY-MM-dd', tempTime)
        // 下次检验日期 = 当前年份加两年，日份减一天
        const xcjyrq = (tempTime.getFullYear() + 2) + '-' + (tempTime.getMonth() + 1) + '-' + (tempTime.getDate() - 1)
        this.ysjl.xiacijianyanriqi = xcjyrq
        this.ysjl.shejishiyongnianxian = '年'
        this.ysjl.jianyanjielun = '合格'
        this.ysjl.anquanzhuangkuangdengji = '1级'
        this.ysjl.shejiriqi = '  年  月'
        this.param.yanshouriqi = '  年  月'
        this.getMaxBh()
      })
    },
    getYsjl() {
      this.api({
        url: '/ysjl/getYsjlById',
        method: 'get',
        params: {
          ysjlId: this.$route.query.id
        }
      }).then(data => {
        this.ysjl = data.ysjl
        if (this.ysjl.jianyanrenyuan) {
          this.jianyanrenyuan = this.common.convertCnName(this.ysjl.jianyanrenyuan)
        }
        if (this.ysjl.baogaobianhao.indexOf('COPY') !== -1) {
          // 如果时复制报告自动获取最大编号
          this.getMaxBh()
        } else if (this.ysjl.baogaobianhao) {
          this.judgeRepeat(this.ysjl.baogaobianhao.substring(0, this.ysjl.baogaobianhao.lastIndexOf('-') + 1), this.ysjl.id)
        }
        this.$refs.mxb.getMxbInfo(this.$route.query.id)
      })
    },
    getParam() {
      // 根据原始报告id查询参数
      this.api({
        url: '/ysjl/getParamByYsjlId',
        method: 'get',
        params: { ysjlId: this.$route.query.id, sbzldm: this.$route.query.sbzldm }
      }).then(data => {
        this.param = data
      })
    },
    // 签名方法
    singNameValue(data) {
      this.jianyanrenyuan = data.name
      this.ysjl.jianyanrenyuan = data.id
      if (this.state !== 'create') {
        this.common.signName(this.ysjl.id, this.ysjl.jianyanrenyuan)
        Utils.$emit('ysjl-list')
      }
    },
    // 查询最大记录编号
    getMaxBh() {
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: this.bgbh1 + this.bgbh2 + '-' + this.bgbh3,
          hinderPart: ''
        }
      }).then(data => {
        this.bgbh3 = data
      })
    },
    saveYsjl: function(operation) {
      let url = ''
      if (operation === 'add') {
        url = '/ysjl/saveYsjl'
        this.ysjl.baogaobianhao = this.bgbh1 + this.bgbh2 + '-' + this.bgbh3
        this.ysjl.bglx = 1
        this.ysjl.cjState = 'bggl'
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.save(operation, url)
      } else if (operation === 'build') {
        if (this.ysjl.jianyanrenyuan === null || this.ysjl.jianyanrenyuan === '') {
          this.$message({
            type: 'error',
            message: '请先签名再生成报告!'
          })
          return false
        }
        // 判断分项原始记录是否办结
        this.api({
          url: '/ysjl/judgeState',
          method: 'get',
          params: {
            ysjlIds: this.ysjl.id,
            bglx: '2,3'
          }
        }).then(data => {
          if (data === 0) {
            this.$message.error('请先办结无损分项原始记录再生成报告！')
            return false
          } else {
            url = '/ysjl/updateYsjl'
            this.save(operation, url)
          }
        })
      } else if (operation === 'upd') {
        url = '/ysjl/updateYsjl'
        this.save(operation, url)
      }
    },
    save(operation, url) {
      // 判断报告编号是否重复
      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: '[]',
                flag: operation
              }
            }).then(data => {
              // 刷新任务列表，原始记录待办，原始记录已办，检验报告
              Utils.$emit('task-list')
              Utils.$emit('bggl-daiban-list')
              if (operation === 'add' && data !== '') {
                this.info.ysjlId = data
                this.ysjl.id = data
                this.$refs.mxb.createMxb(this.ysjl.id, 12)
                this.$message({ message: '保存成功', type: 'success' })
              } else if (operation === 'upd') {
                this.$refs.mxb.saveMxb()
                this.$message({ message: '更新成功', type: 'success' })
              }
              this.$route.params.state = 'update'
              this.state = 'update'
              this.info.ysjlId = this.ysjl.id
            })
          }
        })
      }
    },
    toAddJyfa() {
      this.jyfaDialogVisible = true
    },
    // 查询同类报告
    getJyfaInfo() {
      this.api({
        url: '/ysjl/getJyfaInfo',
        method: 'get',
        params: {
          ysjlId: this.ysjl.id
        }
      }).then(data => {
        data.forEach((v, k) => {
          // 明细表是固定的  所以不需要展示
          if (v.jianyanxiangmu === 'mxb') {
            data.splice(k, 1)
          }
        })
        this.similarTableData = data
        this.similarVisible = true
      })
    },
    closeJyfaDialog() {
      this.jyfaDialogVisible = false
    },
    // 删除检验方案
    delYsjl(jianyanxiangmu, bglx, ysjlId) {
      this.$confirm('原始记录删除后将无法恢复，是否确认删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(data => {
        this.api({
          url: '/ysjl/delJyfa',
          method: 'get',
          params: {
            ysjlId: ysjlId,
            bglx: bglx,
            jianyanxiangmu: jianyanxiangmu
          }
        }).then(data => {
          Utils.$emit('modifyMajorInspectionItemBySub')
          this.$message({ message: '删除成功', type: 'success' })
          this.getJyfaInfo()
          this.$refs.jyfa.getJyfaInfo()
        })
      }).catch(e => {
        this.$message({ message: '删除失败', type: 'error' })
      })
    },
    // 办结分项原始记录 status：0：取消办结，1：办结
    bjYsjl(ysjlId, status) {
      this.api({
        url: '/fx/endFx',
        method: 'get',
        params: {
          ysjlId: ysjlId,
          status: status
        }
      }).then(data => {
        this.getJyfaInfo()
        if (status === '0') {
          this.$message({ message: '取消办结成功', type: 'success' })
        } else if (status === '1') {
          this.$message({ message: '办结成功', type: 'success' })
        }
      })
    },
    editChild(id, jianyanxiangmu, departmentId, modelId) {
      if (jianyanxiangmu !== 'mxb') {
        this.api({
          url: '/template/getById',
          method: 'get',
          params: {
            id: modelId
          }
        }).then(data => {
          const queryParam = { id: id, jyxm: jianyanxiangmu, departmentId: departmentId }
          this.$router.push({ path: data.tempPath, query: queryParam })
          this.$parent.$parent.jyfaDialogVisible = false
        })
        this.similarVisible = false
      }
    },
    judgeRepeat(bianhao, id) {
      this.api({
        url: '/ysjl/judgeRepeat',
        method: 'get',
        params: {
          ysjlId: id,
          bianhao: bianhao
        }
      }).then(data => {
        this.isRepeat = data > 0
      })
    }
  }
}
</script>

<style>
  .el-input__inner {
    border: 1px solid #00000075;
    border-radius: 4px;
  }
  .el-textarea__inner {
    border: 1px solid #91393975;
    border-radius: 4px;
  }
  .el-form-item__error {
    padding-top: 0px;
    position: absolute;
  }
  .el-input.is-disabled .el-input__inner {
    color: #606266;
  }
  .el-textarea.is-disabled .el-textarea__inner {
    color: #606266;
  }
  .el-dialog__body {
    padding-top: 10px;
  }
</style>
