<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 === 'update'" type="success" icon="el-icon-upload2" size="medium" @click="saveYsjl('build')">
          生成报告
        </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' || ysjl.baogaobianhao === null || ysjl.baogaobianhao === ''" :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-input v-model="bgbh4" style="width:80px" @blur="judgeRepeat(bgbh1 + bgbh2 + '-' + bgbh3 + '-%', ysjl.id)" />
                </el-form-item>
              </el-col>
              <el-col v-else :span="9">
                <el-form-item label="报告编号" prop="baogaobianhao">
                  <el-input v-if="state !== 'create'" v-model="ysjl.baogaobianhao" :disabled="edit" @blur="judgeRepeat(ysjl.baogaobianhao.substring(0, ysjl.baogaobianhao.lastIndexOf('-') + 1) + '%', 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="shebeimingcheng">
                  <el-input v-model="ysjl.shebeimingcheng" :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="qizhiweizhi">
                  <el-input v-model="param.qizhiweizhi" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="单位内编号" prop="danweineibubianhao">
                  <el-input v-model="ysjl.danweineibubianhao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="装置名称" prop="zhuangzhimingcheng">
                  <el-input v-model="param.zhuangzhimingcheng" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="使用登记证编号" prop="shiyongdengjibianhao">
                  <el-input v-model="ysjl.shiyongdengjibianhao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="使用单位名称" prop="shiyongdanwei">
                  <el-input v-model="ysjl.shiyongdanwei" :disabled="edit" />
                </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="ysjl.shiyongdanweiDizhi" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="安全管理人员" prop="anquanguanlirenyuan">
                  <el-input v-model="ysjl.anquanguanlirenyuan" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系电话" prop="anquanguanlidianhua">
                  <el-input v-model="ysjl.anquanguanlidianhua" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验金额(元)" prop="jianyanheding">
                  <el-input-number v-model="ysjl.jianyanheding" :disabled="ysjl.retreatState === 2 && ysjl.jfState" :controls="false" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>允许监控使用参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="压力" prop="yali">
                  <el-input v-model="param.yali" :disabled="edit">
                    <template slot="append">
                      (MPa)
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="温度" prop="wendu">
                  <el-input v-model="param.wendu" :disabled="edit">
                    <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="jiezhi">
                  <el-input v-model="param.jiezhi" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="其他" prop="qita">
                  <el-input v-model="param.qita" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <el-row :gutter="20">
              <el-col :span="18" style="height:90px">
                <el-form-item label="检查依据" prop="jianyanyiju">
                  <el-input v-model="ysjl.jianyanyiju" :disabled="edit" :rows="3" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20" style="height:60px">
              <el-col :span="18">
                <el-form-item label="问题及其处理" prop="wentijizai">
                  <el-input v-model="param.wentijizai" :disabled="edit" type="textarea" placeholder="[检验发现的缺陷位置、性质、程度及处理意见（必要时附图或者附页）]" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20" style="height:60px">
              <el-col :span="18">
                <el-form-item label="说明" prop="beizhu">
                  <el-input v-model="ysjl.beizhu" :disabled="edit" type="textarea" placeholder="（监控运行需要解决的问题及完成期限）" />
                </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" :disabled="edit" type="text" placeholder="请选择" style="width: 100%;" value="">
                    <el-option label="符合要求" value="符合要求" />
                    <el-option label="基本符合要求" value="基本符合要求" />
                    <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" type="date" 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" type="date" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="安全状况等级" prop="anquanzhuangkuangdengji">
                  <el-select v-model="ysjl.anquanzhuangkuangdengji" type="text" placeholder="请选择" style="width:232px" value="">
                    <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-col :span="9">
                <el-form-item label="下次年度检查日期" prop="xiacijianyanriqi">
                  <el-input v-if="ysjl.jianyanjielun === '不符合要求'" v-model="ysjl.xiacijianyanriqishuoming" type="text" disabled="true" />
                  <el-date-picker v-else v-model="ysjl.xiacijianyanriqi" :disabled="edit" type="date" value-format="yyyy-MM-dd" 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 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-table :data="bgfyData" :span-method="tableJs.mergeColRows" border stripe style="width:80%">
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="center" label="检验项目">
            <el-table-column align="center" prop="jianyanxiang" label="检验项" />
            <el-table-column align="center" prop="jianyanneirong" label="检验内容" />
          </el-table-column>
          <el-table-column align="center" prop="jianyanjieguo" label="检验结果">
            <template slot-scope="scope">
              <el-select v-model="scope.row.jianyanjieguo" :disabled="edit" type="text" placeholder="请选择" style="width: 100%;" value="">
                <el-option label="√" value="√" />
                <el-option label="×" value="×" />
                <el-option label="/" value="/" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="beizhu" label="说明">
            <template slot-scope="scope">
              <el-input v-model="scope.row.beizhu" :disabled="edit" placeholder="请输入内容" />
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="工业管道安全管理情况检查表" name="third">
        <el-table :data="glqkData" :span-method="tableJs.mergeColRows" border stripe style="width:80%">
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="left" prop="jianyanxiang" label="检验内容" />
          <el-table-column align="center" prop="jianyanjieguo" label="检查结果">
            <template slot-scope="scope">
              <el-select v-model="scope.row.jianyanjieguo" :disabled="edit" type="text" placeholder="请选择" style="width: 100%;" value="">
                <el-option label="√" value="√" />
                <el-option label="×" value="×" />
                <el-option label="/" value="/" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="beizhu" label="备注">
            <template slot-scope="scope">
              <el-input v-model="scope.row.beizhu" :disabled="edit" placeholder="请输入内容" />
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="工业管道运行状况检查表" name="forth">
        <el-table :data="yxzkData" :span-method="tableJs.mergeColRows" border stripe style="width:90%">
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="left" prop="jianyanxiang" label="检验内容" />
          <el-table-column align="center" prop="jianyanjieguo" label="检查结果" width="350">
            <template slot-scope="scope">
              <el-select v-model="scope.row.jianyanjieguo" :disabled="edit" type="text" placeholder="请选择" style="width: 100%;" value="">
                <el-option label="√" value="√" />
                <el-option label="×" value="×" />
                <el-option label="/" value="/" />
              </el-select>
            </template>
          </el-table-column>
          <el-table-column align="center" prop="beizhu" label="备注">
            <template slot-scope="scope">
              <el-input v-model="scope.row.beizhu" :disabled="edit" placeholder="请输入内容" />
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="工业管道定期检验明细表" name="fifth">
        <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" @childMethod="getJyxm" />
    </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.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-else 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 '../../addJyfa'
import SignName from '@/views/common/SignName'
import Utils from '@/utils/contact.js'
import mxb from '../mxb'
export default {
  name: 'GdNdReport',
  components: { SignName, Sticky, mxb },
  data() {
    return {
      // 预定义值
      edit: false, // 页面编辑状态
      bgfyData: [],
      glqkData: [],
      yxzkData: [],
      aqfjData: [],
      bgbh1: 'GD',
      bgbh2: '(' + (new Date().getFullYear()) + ')',
      bgbh3: '',
      bgbh4: 'GC',
      // 检验人员
      jianyanrenyuan: '',
      defaultParam: {},
      // 接收传入该页面的值
      // 页面状态 {create=> 创建，update=> 更新}
      state: this.$route.query.state,
      ysjl: {},
      departmentId: this.$route.query.departmentId,
      param: {},
      checkedTab: 'first',
      // 表格合并相关
      // 参与列合并的字段，在这里增加即可
      cols: [
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        }
      ],
      // 参与行内合并的字段
      rows: [
        {
          name: 'jianyanxiang',
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        }
      ],
      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'
      },
      // jyfaDialogVisible: false,
      // similarVisible: false,
      // similarTableData: [],
      isRepeat: false,
      tableData: [],
      yxzkHtml1: ''
    }
  },
  computed: {
    baogaobianhao: function() {
      if (this.state !== 'create') {
        return this.ysjl.baogaobianhao
      }
      return this.bgbh1 + this.bgbh2 + '-' + this.bgbh3 + '-' + this.bgbh4
    }
  },
  created() {
    if (this.state === 'create') {
      this.initYsjl()
    } else {
      this.getYsjl()
      this.getParam()
    }
    const jyxmtable = [1, 2, 3]
    for (let i = 0; i < jyxmtable.length; i++) {
      this.getJyxm(jyxmtable[i])
    }
  },
  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 : {}
        // 设置初始值
        const tempTime = new Date()
        this.ysjl.flowStatus = 1
        this.ysjl.jianyankaishiriqi = this.formatter.dateFormat('YYYY-MM-dd', tempTime)
        this.ysjl.jianyanjieshuriqi = this.formatter.dateFormat('YYYY-MM-dd', tempTime)
        let xcjyrq = (tempTime.getFullYear() + 2) + '-' + (tempTime.getMonth() + 1) + '-' + tempTime.getDate()
        xcjyrq = new Date(xcjyrq)
        xcjyrq.setDate(xcjyrq.getDate() - 1)
        this.ysjl.xiacijianyanriqi = this.formatter.dateFormat('YYYY-MM-dd', xcjyrq)
        this.ysjl.jianyanjielun = '符合要求'
        this.ysjl.xiacijianyanriqishuoming = '/'
        this.ysjl.shebeizhongleidaima = '8000'
        this.$set(this.param, 'zhuangzhimingcheng', this.ysjl.shebeimingcheng)
        this.ysjl.shebeimingcheng = ''
        this.ysjl.shejiriqi = '  年  月'
        this.$set(this.param, 'yanshouriqi', '  年  月')
        this.$set(this.ysjl, 'shejiriqi', '  年  月')
        this.$set(this.param, 'qizhiweizhi', '')
        this.$set(this.param, 'zhongzhiweizhi', '')
        this.$set(this.param, 'anquanzhuangkuangdengji', '1级')
        this.$set(this.param, 'fangfucengcailiao', '油漆')
        this.$set(this.param, 'shangciwentijizai', '有年度检查报告')
        this.$set(this.ysjl, 'shejishiyongnianxian', '图纸未注明')
        this.$set(this.param, 'qita', '无')
        this.param.wentijiqichuli = '注:检查发现的缺陷位置、性质、程度及处理意见（必要时附图或者附页，也可直接注明见某单项报告）'
        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() {
      const aheadPart = this.bgbh1 + this.bgbh2 + '-'
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: aheadPart,
          hinderPart: '',
          nblb: this.ysjl.neibuleibie
        }
      }).then(data => {
        this.bgbh3 = data
      })
    },
    // 查询检验项目
    getJyxm(sort) {
      let url = ''
      let data = {}
      if (this.state === 'create') {
        url = '/jyxm/getCyJyxm'
        data = {
          templateId: this.$route.query.modelId,
          order: sort
        }
      } else {
        url = '/jyxm/getCyJyxmByYsjl'
        data = {
          ysjlId: this.$route.query.id,
          isReport: true,
          order: sort
        }
      }
      this.api({
        url: url,
        method: 'get',
        params: data
      }).then(data => {
        switch (sort) {
          case 1:
            this.bgfyData = data
            break
          case 2:
            this.glqkData = data
            break
          case 3:
            this.yxzkData = data
            break
        }
        this.tableJs.getData(this.cols, this.rows, data)
      })
    },
    // 获取表格中的id, 不为空的检验结果和备注
    getProp: function(data) {
      data.forEach((row) => {
        if (!row.jianyanjieguo) {
          row.jianyanjieguo = ''
        }
        if (!row.beizhu) {
          row.beizhu = ''
        }
      })
      return data
    },
    /* toAddJyfa() {
      this.jyfaDialogVisible = true
    },
    // 查询同类报告
    getJyfaInfo() {
      this.api({
        url: '/ysjl/getJyfaInfo',
        method: 'get',
        params: {
          ysjlId: this.ysjl.id
        }
      }).then(data => {
        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' })
        }
        this.$refs.jyfa.getJyfaInfo()
      })
    },*/
    editChild(id, jianyanxiangmu, departmentId) {
      this.$router.push({ path: '/ysjl/' + this.ysjl.shebeizhongleidaima + '/nd/' + jianyanxiangmu, query: { id: id, jyxm: jianyanxiangmu, departmentId: departmentId }})
      this.similarVisible = false
    },
    saveYsjl: function(operation) {
      this.tableData = []
      this.tableData.push(this.getProp(this.bgfyData))
      this.tableData.push(this.glqkData)
      // 工业管道运行状况检查表
      this.tableData.push(this.yxzkData)
      let url = ''
      if (operation === 'add') {
        url = '/ysjl/saveYsjl'
        this.ysjl.baogaobianhao = this.bgbh1 + this.bgbh2 + '-' + this.bgbh3 + '-' + this.bgbh4
        this.ysjl.bglx = 1
        this.ysjl.flowStatus = '1'
        this.ysjl.cjState = 'bggl'
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.ysjl.jlprintState = 0
        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.$refs.mxb.saveMxb()
        this.save(operation, url)
      }
    },
    save(operation, url) {
      // 判断报告编号是否重复
      if (this.isRepeat) {
        this.$message({ message: '报告编号重复，请先修改报告编号再保存', type: 'error' })
        return false
      } else {
        if (!this.ysjl.baogaobianhao) {
          this.ysjl.baogaobianhao = this.bgbh1 + this.bgbh2 + '-' + this.bgbh3 + '-' + this.bgbh4
        }
        this.$refs['ysjl'].validate(valid => {
          if (valid) {
            this.api({
              url: url,
              method: 'post',
              data: {
                ysjl: this.ysjl,
                param: this.param,
                bgjyxm: JSON.stringify(this.tableData),
                flag: operation
              }
            }).then(data => {
              // 刷新任务列表，原始报告待办，原始报告已办，检验报告
              Utils.$emit('task-list')
              Utils.$emit('bggl-daiban-list')
              if (operation === 'add') {
                this.ysjl.id = data
                this.param.ysjlId = data
                this.$refs.mxb.createMxb(this.ysjl.id, 155)
                this.$message({ message: '保存成功', type: 'success' })
                // 刷新路由网址
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
                this.$router.push({
                  path: '/bggl/8000/dj/nd/edit/' + this.ysjl.id,
                  query: { state: 'update', id: this.ysjl.id, departmentId: this.ysjl.departmentId, sbzldm: this.ysjl.shebeizhongleidaima }
                })
              } else if (operation === 'upd') {
                this.$refs.mxb.saveMxb()
                this.$message({ message: '更新成功', type: 'success' })
              }
              this.info.ysjlId = this.ysjl.id
              this.state = 'update'
              this.$route.params.state = 'update'
            })
          }
        })
      }
    },
    judgeRepeat(bianhao, id) {
      this.api({
        url: '/ysjl/judgeRepeat',
        method: 'get',
        params: {
          ysjlId: id,
          bianhao: bianhao,
          nblb: this.ysjl.neibuleibie
        }
      }).then(data => {
        this.isRepeat = data > 0
      })
    },
    uploadWsFxFile(file) {
      this.common.uploadWsFxFile(file, this.ysjl)
      return false
    }
  }
}
</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: 0;
    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;
}
  .myTable .el-input__inner{
    padding: 0 5px;
    text-align: center;
  }
</style>
