<!--工业锅炉运行水处理监督检验原始记录-->
<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <div class="sub-navbar">
        <el-button v-show="state === 'create'" type="success" icon="el-icon-edit" size="medium" @click="saveYsjl('add')">
          保存
        </el-button>
        <el-button v-show="state === 'update'" type="primary" icon="el-icon-edit" size="medium" @click="saveYsjl('upd')">
          更新
        </el-button>
        <el-button v-show="state === 'update'" type="success" icon="el-icon-upload2" size="medium" @click="saveYsjl('build')">
          生成报告
        </el-button>
        <el-button v-show="state !== 'create'" type="warning" icon="el-icon-view" size="medium" @click="common.viewYsjl(ysjl.id, 'YSJL')">
          预览
        </el-button>
      </div>
    </sticky>
    <el-tabs v-model="checkedTab" type="card">
      <el-tab-pane label="基本信息" name="first">
        <el-form ref="param" :model="param" 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" />
                </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">
                  <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="anquanguanlibumen">
                  <el-input v-model="ysjl.anquanguanlibumen" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系人" prop="shiyongdanweiLianxiren">
                  <el-input v-model="ysjl.shiyongdanweiLianxiren" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="联系电话" prop="shiyongdanweiDianhua">
                  <el-input v-model="ysjl.shiyongdanweiDianhua" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="持证水处理作业人员数" label-width="160px" prop="shuichulizuoyerenshu">
                  <el-input v-model="param.shuichulizuoyerenshu" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>锅炉情况</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="锅炉型号" prop="guigexinghao">
                  <el-input v-model="ysjl.guigexinghao" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="单位内编号" prop="danweineibubianhao">
                  <el-input v-model="ysjl.danweineibubianhao" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="设备代码" prop="shebeidaima">
                  <el-input v-model="ysjl.shebeidaima" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="使用登记证编号" prop="shiyongdengjibianhao">
                  <el-input v-model="ysjl.shiyongdengjibianhao" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定蒸发量(热功率)" label-width="140px" prop="edingzhengfaliang">
                  <el-input v-model="param.edingzhengfaliang" type="text">
                    <template slot="append">
                      t/h(MW)
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="额定压力"
                  label-width="140px"
                  :rules="[
                    { required: true, message: '请输入额定压力', trigger: ['blur', 'change'] }
                  ]"
                  prop="edingyali"
                >
                  <el-input v-model="param.edingyali" type="text">
                    <template slot="append">
                      MPa
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="出水温度" label-width="140px" prop="chukouwendu">
                  <el-input v-model="param.chukouwendu" type="text">
                    <template slot="append">
                      ℃
                    </template>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="锅炉循环方式"
                  :rules="[
                    { required: true, message: '请选择锅炉循环方式', trigger: 'change' }
                  ]"
                  prop="xunhuanfangshi"
                >
                  <el-select
                    v-model="param.xunhuanfangshi"
                    :disabled="edit"
                    type="text"
                    placeholder="请选择"
                    style="width:232px"
                    @change="setJyxmStandard"
                  >
                    <el-option label="自然循环" value="自然循环" />
                    <el-option v-if="ysjl.shebeileibiedaima === '1200'" label="强制循环" value="强制循环" />
                    <el-option label="直流" value="直流" />
                    <el-option label="贯流" value="贯流" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="过热器"
                  :rules="[
                    { required: true, message: '请选择过热器', trigger: 'change' }
                  ]"
                  prop="guoreqi"
                >
                  <el-select
                    v-model="param.guoreqi"
                    :disabled="edit"
                    type="text"
                    placeholder="请选择"
                    style="width:232px"
                    @change="setJyxmStandard"
                  >
                    <el-option label="有" value="有" />
                    <el-option label="无" value="无" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>水处理设备</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="水处理设备"
                  :rules="[
                    { required: true, message: '锅炉循环方式', trigger: 'change' }
                  ]"
                  prop="shuichulishebei"
                >
                  <el-select
                    v-model="param.shuichulishebei"
                    :disabled="edit"
                    type="text"
                    placeholder="请选择"
                    style="width:232px"
                    @change="setJyxmStandard"
                  >
                    <el-option label="反渗透" value="反渗透" />
                    <el-option label="离子交换" value="离子交换" />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="取样冷却器" prop="quyanglengqueqi">
                  <el-select v-model="param.quyanglengqueqi" :disabled="edit" type="text" placeholder="请选择" style="width:232px">
                    <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="guoneichuliyaoji">
                  <el-input v-model="param.guoneichuliyaoji" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="蒸汽冷凝水" prop="zhengqilengningshui">
                  <el-select v-model="param.zhengqilengningshui" :disabled="edit" type="text" placeholder="请选择" style="width:232px">
                    <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="caiyongyuanshui">
                  <el-input v-model="param.caiyongyuanshui" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="水处理方法"
                  :rules="[
                    { required: true, message: '请选择水处理方法', trigger: 'change' }
                  ]"
                  prop="shuichulifangfa"
                >
                  <el-select
                    v-model="param.shuichulifangfa"
                    :disabled="edit"
                    type="text"
                    placeholder="请选择"
                    style="width:232px"
                    @change="setJyxmStandard"
                  >
                    <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="xtclhyxzq" label-width="150px">
                  <el-select v-model="param.xtclhyxzq" :disabled="edit" type="text" placeholder="请选择" style="width:212px">
                    <el-option label="满足锅炉给水要求" value="满足锅炉给水要求" />
                    <el-option label="不能满足锅炉给水要求" value="不能满足锅炉给水要求" />
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>使用的主要设备</legend>
            <el-table ref="yqsbData" :data="yqsbData" border stripe style="width:100%">
              <el-table-column align="center" prop="C1" label="编号">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.C1" :label="scope.row.C2" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="C2" label="仪器名称">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.C2" type="text" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="C3" label="编号">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.C3" />
                </template>
              </el-table-column>
              <el-table-column align="center" prop="C4" label="仪器名称">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.C4" />
                </template>
              </el-table-column>
            </el-table>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <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:232px">
                    <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="18">
                <el-form-item label="执行标准" prop="jianyanyiju">
                  <el-input v-model="ysjl.jianyanyiju" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18" style="height: 90px">
                <el-form-item label="整改意见和期限" prop="wentijizai">
                  <el-input v-model="param.wentijizai" :rows="3" type="textarea" placeholder="" />
                </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%;" @change="getXcjyrq" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <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" type="date" placeholder="选择日期" editable 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" :disabled="edit" @setSignValue="singNameValue" />
              </el-col>
            </el-row>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="水质分析" name="second">
        <el-table :data="jyxmData" :span-method="tableJs.mergeColRows" border stripe style="width:100%;max-width: 2000px;">
          <el-table-column type="index" align="center" width="30" label="序号" />
          <el-table-column align="center" prop="jianyanxiang" width="40" label="水样" />
          <el-table-column align="center" prop="jianyanmu" width="130" label="项目" />
          <el-table-column align="center" width="100%" prop="c1" label="实测1">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c1" :disabled="edit" @blur="setRounding(scope.$index)" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="100%" prop="c2" label="实测2">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c2" :disabled="edit" @blur="setRounding(scope.$index)" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="90" prop="c3" label="空白">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c3" :disabled="edit" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="c9" label="标准值">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c9" :disabled="edit" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="110" prop="c4" label="实测值">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c4" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="jianyanneirong" width="40" label="水样" />
          <el-table-column align="center" prop="jianyanjieguo" width="130" label="项目" />
          <el-table-column align="center" width="100%" prop="c5" label="实测1">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c5" :disabled="edit" @blur="setRounding2(scope.$index)" @focus="setXdjdOrGlb1(scope.$index)" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="100%" prop="c6" label="实测2">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c6" :disabled="edit" @blur="setRounding2(scope.$index)" @focus="setXdjdOrGlb2(scope.$index)" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="90" prop="c7" label="空白">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c7" :disabled="edit" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="c10" label="标准值">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c10" :disabled="edit" />
            </template>
          </el-table-column>
          <el-table-column align="center" width="110" prop="c8" label="实测值">
            <template slot-scope="scope">
              <el-input v-model="scope.row.c8" />
            </template>
          </el-table-column>
          <!--<el-table-column align="center" width="200" prop="beizhu" label="标准值">
            <template slot-scope="scope">
              <el-input v-model="scope.row.beizhu" :disabled="edit" />
            </template>
          </el-table-column>-->
        </el-table>
        <br>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import SignName from '@/views/common/SignName'
import Utils from '@/utils/contact'
import Bzz from '../../common/gysclJyxmBzz.js'
export default {
  name: 'GlGysclYsjl',
  components: { SignName, Sticky },
  data() {
    return {
      jlbh1: 'SJG',
      jlbh2: '(' + new Date().getFullYear() + ')',
      jlbh3: '',
      ysjl: {},
      param: {},
      state: this.$route.query.state,
      jianyanrenyuan: '',
      jianjianyuan: '',
      departmentId: this.$store.getters.departmentId,
      isRepeat: false,
      edit: false,
      checkedTab: 'first',
      jyxmData: [],
      yqsbData: [
        { C1: '05-30-01', C2: '多功能电位滴定仪', C3: '05-26-01', C4: '锅炉用水多离子测定仪' },
        { C1: '05-07-06', C2: '台式电导率分析仪', C3: 'JS-25-01', C4: '碱式滴定管' },
        { C1: '010233100054', C2: 'PH计', C3: 'SS-25-05', C4: '酸式滴定管' },
        { C1: '05-13-03', C2: '台式浊度分析仪', C3: '05-04-04', C4: '电子天平' }
      ],
      // 表格合并相关
      // 参与列合并的字段，在这里增加即可
      cols: [
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanneirong
          }
        }
      ],
      // 参与行内合并的字段
      rows: [
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        }
      ],
      multipleSelection: [],
      ysjlId: this.$route.query.id,
      tableData: [] // 存储报告检验项目
    }
  },
  computed: {
    jilubianhao: function() {
      let bianhao
      if (this.ysjl.jilubianhao === null || this.ysjl.jilubianhao === undefined || this.ysjl.jilubianhao === '') {
        return this.jlbh1 + this.jlbh2 + '-' + this.jlbh3
      } else {
        bianhao = this.ysjl.jilubianhao
      }
      return this.judgeRepeat(bianhao, this.ysjl.id)
    }
  },
  watch: {
    jlbh3: function(val) {
      this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + '-' + val
      this.judgeRepeat(this.ysjl.jilubianhao, this.ysjl.id)
    },
    jilubianhao: function(newValue) {
      this.judgeRepeat(newValue, this.ysjl.id)
    }
  },
  created() {
    if (this.state === 'create') {
      this.initYsjl()
    } else {
      this.getYsjl(this.ysjlId)
      this.getFbjyxm(this.ysjlId)
      this.getJyxmByYsjl(this.ysjlId)
    }
  },
  methods: {
    initYsjl() {
      this.api({
        url: '/ysjl/initYsjl',
        method: 'post',
        data: {
          templateId: this.$route.query.templateId,
          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')
        this.getXcjyrq()
        this.ysjl.jilubianhao = this.jilubianhao
        this.ysjl.baogaobianhao = null // 避免从设备中取值导致信息错误
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.ysjl.jianyanjielun = '符合要求'
        this.ysjl.jianyanyiju = 'GB/T 1576《工业锅炉水质》'
        this.ysjl.anquanguanlibumen = '/'
        this.ysjl.danweineibubianhao = '/'
        this.ysjl.shebeidaima = '/'
        this.$set(this.param, 'shuichulizuoyerenshu', '/')
        this.$set(this.param, 'guoneichuliyaoji', '无')
        this.$set(this.param, 'caiyongyuanshui', '有')
        this.$set(this.param, 'wentijizai', '无')
        this.getMaxBh()
        this.getJyxm(1)
      })
    },
    getYsjl(id) {
      this.api({
        url: '/ysjl',
        method: 'get',
        params: {
          ysjlId: id
        }
      }).then(data => {
        this.ysjl = data.ysjl
        if (this.ysjl.jianyanrenyuan) {
          this.jianyanrenyuan = this.common.convertCnName(this.ysjl.jianyanrenyuan)
        }
        if (this.ysjl.jilubianhao === '' || this.ysjl.jilubianhao === null || this.ysjl.jilubianhao === undefined) {
          this.getMaxBh()
        }
        this.judgeRepeat(this.ysjl.jilubianhao, this.ysjl.id)
        this.getParam(this.ysjl.id, this.ysjl.shebeizhongleidaima)
      })
    },
    getParam(ysjlId, sbzldm) {
      // 根据原始记录id查询参数
      this.api({
        url: '/ysjl/getParamByYsjlId',
        method: 'get',
        params: {
          ysjlId: ysjlId,
          sbzldm: 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')
      }
    },
    // 查询检验项目
    getJyxm(sort) {
      this.api({
        url: '/jyxm/getCyJyxm',
        method: 'get',
        params: {
          templateId: this.ysjl.templateId,
          order: sort
        }
      }).then(data => {
        for (let i = 0; i < data.length; i++) {
          const jyxmRow = {}
          this.$set(jyxmRow, 'id', data[i].id)
          this.$set(jyxmRow, 'jianyanxiang', data[i].jianyanxiang)
          this.$set(jyxmRow, 'jianyanmu', data[i].jianyanmu)
          this.$set(jyxmRow, 'jianyanneirong', data[i].jianyanneirong)
          this.$set(jyxmRow, 'jianyanjieguo', data[i].jianyanjieguo)
          this.$set(jyxmRow, 'c1', '/')
          this.$set(jyxmRow, 'c2', '/')
          this.$set(jyxmRow, 'c3', '0')
          this.$set(jyxmRow, 'c4', '/')
          this.$set(jyxmRow, 'c5', '/')
          this.$set(jyxmRow, 'c6', '/')
          this.$set(jyxmRow, 'c7', '0')
          this.$set(jyxmRow, 'c8', '/')
          this.$set(jyxmRow, 'c9', '/')
          this.$set(jyxmRow, 'c10', '/')
          this.jyxmData.push(jyxmRow)
        }
        this.tableJs.getData(this.cols, this.rows, this.jyxmData)
      })
    },
    // 查询仪器设备
    getFbjyxm(id) {
      this.api({
        url: '/jyxm/getJyxmInfoByYsjl',
        method: 'get',
        params: {
          ysjlId: id,
          type: 'fbjyxm'
        }
      }).then(data => {
        this.yqsbData = JSON.parse(data)
      })
    },
    getJyxmByYsjl(id) {
      this.api({
        url: '/jyxm/getCyJyxmByYsjl',
        method: 'get',
        params: {
          ysjlId: id,
          isReport: false,
          order: 1
        }
      }).then(data => {
        this.jyxmData = JSON.parse(JSON.stringify(data))
        this.tableJs.getData(this.cols, this.rows, this.jyxmData)
      })
    },
    // 获取表格中的id, 不为空的检验结果和备注
    getProp(operation) {
      const retData = []
      for (let i = 0, length = this.jyxmData.length; i < length; i++) {
        const retRow = {}
        retRow.id = this.jyxmData[i].id
        retRow.c1 = this.jyxmData[i].c1 === null ? '' : this.jyxmData[i].c1
        retRow.c2 = this.jyxmData[i].c2 === null ? '' : this.jyxmData[i].c2
        retRow.c3 = this.jyxmData[i].c3 === null ? '' : this.jyxmData[i].c3
        retRow.c4 = this.jyxmData[i].c4 === null ? '' : this.jyxmData[i].c4
        retRow.c5 = this.jyxmData[i].c5 === null ? '' : this.jyxmData[i].c5
        retRow.c6 = this.jyxmData[i].c6 === null ? '' : this.jyxmData[i].c6
        retRow.c7 = this.jyxmData[i].c7 === null ? '' : this.jyxmData[i].c7
        if (operation === 'build') {
          if (retRow.c1 === '/') {
            retRow.c3 = '/'
          }
          if (retRow.c5 === '/') {
            retRow.c7 = '/'
          }
        }
        retRow.c8 = this.jyxmData[i].c8 === null ? '' : this.jyxmData[i].c8
        retRow.c9 = this.jyxmData[i].c9 === null ? '' : this.jyxmData[i].c9
        retRow.c10 = this.jyxmData[i].c10 === null ? '' : this.jyxmData[i].c10
        // 实测值为实测1 和实测2 自动求平均值
        // this.jyxmData[i].jianyanjieguo = (Number(this.jyxmData[i].jyjg1) + '' !== 'NaN' && Number(this.jyxmData[i].jyjg2) + '' !== 'NaN') ? (Number(this.jyxmData[i].jyjg1) + Number(this.jyxmData[i].jyjg2)) / 2 : this.jyxmData[i].jianyanjieguo
        // retRow.jianyanjieguo = this.jyxmData[i].jianyanjieguo
        retData.push(retRow)
      }
      return retData
    },
    saveYsjl: function(operation) {
      if (operation === 'add' && !this.jlbh3.trim()) {
        this.$message({ message: '请先确认报告编号是否完整！', type: 'warning' })
        return false
      }
      let type = ''
      if (operation === 'add') {
        this.ysjl.bglx = 1
        this.ysjl.zfState = false
        this.ysjl.jianyanxiangmu = 'gyscl'
        this.ysjl.jlprintState = 0
        this.ysjl.cjState = 'ysjl'
        this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + '-' + this.jlbh3
        type = 'post'
      } else if (operation === 'upd') {
        type = 'put'
      } else if (operation === 'build') {
        if (this.ysjl.jianyanrenyuan === null || 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
        }
        this.tableData = this.getBuildJyxm()
        type = 'put'
      }
      if (this.isRepeat) {
        this.$message({ message: '报告编号重复，请先修改报告编号再保存', type: 'error' })
        return false
      } else {
        this.$refs['param'].validate(valid => {
          if (valid) {
            const tableData = [] // 检验项目存储
            tableData.push(this.getProp(operation))
            this.api({
              url: '/ysjl',
              method: type,
              data: {
                ysjl: this.ysjl,
                param: this.param,
                jyxm: JSON.stringify(tableData),
                fbjyxm: JSON.stringify(this.yqsbData),
                bgjyxm: JSON.stringify([this.tableData]),
                flag: operation
              }
            }).then(data => {
              // 刷新任务列表，检验报告
              Utils.$emit('task-list')
              Utils.$emit('ysjl-list')
              Utils.$emit('bggl-daiban-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: '/ysjl/1000/dj/gyscl/' + this.ysjl.id,
                //   query: { state: 'update', id: this.ysjl.id, departmentId: this.ysjl.departmentId, jianyanrenyuan: this.ysjl.jianyanrenyuan }
                // })
              } else if (operation === 'upd') {
                Utils.$emit('ysjl-list')
                this.$message({ message: '更新成功', type: 'success' })
                // this.$refs.bill.updateChargeBill()
              } else {
                Utils.$emit('ysjl-list')
                // 修改16版任务状态
                this.common.updRenwuState(this.ysjl.id, 2, true)
                Utils.$emit('bggl-daiban-list')
                this.$message({ message: '生成报告成功', type: 'success' })
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
              }
              this.state = 'update'
            })
          } else {
            this.$message({ message: '有必填项没有填写！', type: 'info' })
          }
        })
      }
    },
    setJyxmStandard() { // 设置检验项目标准值
      try {
        this.getBuildJyxm()
      } catch (e) {
        // 不输出
        console.log('其他参数信息不全,导致报错。')
      }
    },
    // 检验项目标准值赋值
    getBuildJyxm() {
      let bgjyxm = []
      if (this.param.shuichulifangfa === '锅外处理') {
        if (this.ysjl.shebeileibiedaima === '1100') { // 蒸汽锅炉
          if (this.param.xunhuanfangshi === '自然循环') {
            if (Number(this.param.edingyali) <= 1.0) { // 额定蒸汽压力:p<=1.0
              bgjyxm = Bzz.getGwZqZrxhRadio1(this.jyxmData, this.param.shuichulishebei, this.param.guoreqi)
            } else if (Number(this.param.edingyali) <= 1.6) { // 额定蒸汽压力:1.0＜p≤1.6
              bgjyxm = Bzz.getGwZqZrxhRadio2(this.jyxmData, this.param.shuichulishebei, this.param.guoreqi)
            } else if (Number(this.param.edingyali) <= 2.5) { // 额定蒸汽压力:1.6＜p≤2.5
              bgjyxm = Bzz.getGwZqZrxhRadio3(this.jyxmData, this.param.shuichulishebei, this.param.guoreqi)
            } else if (Number(this.param.edingyali) <= 3.8) { // 额定蒸汽压力:2.5＜p≤3.8
              bgjyxm = Bzz.getGwZqZrxhRadio4(this.jyxmData, this.param.shuichulishebei, this.param.guoreqi)
            }
          } else if (this.param.xunhuanfangshi === '直流') {
            bgjyxm = Bzz.getGwZqZlRadio(this.jyxmData, this.param.edingyali)
          } else if (this.param.xunhuanfangshi === '贯流') {
            bgjyxm = Bzz.getGwZqGlRadio(this.jyxmData, this.param.edingyali, this.param.shuichulishebei, this.param.guoreqi)
          }
        } else if (this.ysjl.shebeileibiedaima === '1200') { // 热水锅炉，热水锅炉不区分循环方式，蒸汽压力，补给水类型和过热器
          bgjyxm = Bzz.getGwRsRadio(this.jyxmData)
        }
      } else if (this.param.shuichulifangfa === '单纯加药处理') { // 单纯加药处理
        if (this.ysjl.shebeileibiedaima === '1100') { // 蒸汽锅炉
          bgjyxm = Bzz.getDcjyZqRadio(this.jyxmData)
        } else if (this.ysjl.shebeileibiedaima === '1200') { // 热水锅炉
          bgjyxm = Bzz.getDcjyRsRadio(this.jyxmData)
        }
      } else if (this.param.shuichulifangfa === '部分软化和加药联合处理') { // 部分软化和加药联合处理
        if (this.ysjl.shebeileibiedaima === '1100') { // 蒸汽锅炉
          bgjyxm = Bzz.getBfrhZqRadio(this.jyxmData)
        } else if (this.ysjl.shebeileibiedaima === '1200') { // 热水锅炉
          bgjyxm = Bzz.getBfrhRsRadio(this.jyxmData)
        }
      }
      for (let i = 0; i < this.jyxmData.length; i++) {
        this.jyxmData[i].c9 = bgjyxm[i].c1
        this.jyxmData[i].c10 = bgjyxm[i].c3
      }
      return bgjyxm
    },
    // 查询最大记录编号
    getMaxBh() {
      const aheadPart = this.jlbh1 + this.jlbh2 + '-'
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: aheadPart,
          hinderPart: ''
        }
      }).then(data => {
        this.jlbh3 = data
      })
    },
    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
        }
      })
    },
    getXcjyrq() {
      const xcjyrq = new Date(this.ysjl.jianyanjieshuriqi)
      xcjyrq.setFullYear(xcjyrq.getFullYear() + 1, xcjyrq.getMonth(), xcjyrq.getDate() - 1)
      this.ysjl.xiacijianyanriqi = this.formatter.dateFormat('YYYY-MM-dd', xcjyrq)
    },
    setRounding(index) {
      if (isNaN(this.jyxmData[index].c1) || isNaN(this.jyxmData[index].c2)) {
        return false
      }
      // 四舍五入
      const c1 = (parseFloat(this.jyxmData[index].c1)).toFixed(2)
      this.jyxmData[index].c1 = c1
      const c2 = (parseFloat(this.jyxmData[index].c2)).toFixed(2)
      this.jyxmData[index].c2 = c2
      if (!isNaN(c1) && !isNaN(c2)) {
        this.jyxmData[index].c4 = parseFloat((parseFloat(c1) + parseFloat(c2)) / 2).toFixed(2)
      }
    },
    setRounding2(index) {
      if (isNaN(this.jyxmData[index].c5) || isNaN(this.jyxmData[index].c6)) {
        return false
      }
      // 四舍五入
      const c5 = (parseFloat(this.jyxmData[index].c5)).toFixed(2)
      this.jyxmData[index].c5 = c5
      const c6 = (parseFloat(this.jyxmData[index].c6)).toFixed(2)
      this.jyxmData[index].c6 = c6
      if (!isNaN(c5) && !isNaN(c6)) {
        this.jyxmData[index].c8 = parseFloat((parseFloat(c5) + parseFloat(c6)) / 2).toFixed(2)
      }
    },
    setXdjdOrGlb1(index) {
      // 锅水 相对碱度 =IF((O22*2-O21)*40/O20>0,(O22*2-O21)*40/O20,0)
      const c0 = (parseFloat(this.jyxmData[0].c5)).toFixed(2)
      if (index === 6) {
        const c1 = (parseFloat(this.jyxmData[1].c5)).toFixed(2)
        const c2 = (parseFloat(this.jyxmData[2].c5)).toFixed(2)
        if (!isNaN(c1) && !isNaN(c2) && !isNaN(c0)) {
          const a = parseFloat((parseFloat(c2) * 2 - parseFloat(c1)) * 40 / parseFloat(c0)).toFixed(2)
          this.jyxmData[index].c5 = a > 0 ? a : 0
        }
      }
      const c8 = (parseFloat(this.jyxmData[8].c5)).toFixed(2)
      if (index === 9) {
        if (!isNaN(c0) && !isNaN(c8)) {
          this.jyxmData[index].c5 = (parseFloat(c0) / parseFloat(c8)).toFixed(2)
        }
      }
    },
    setXdjdOrGlb2(index) {
      // 锅水 相对碱度 =IF((O22*2-O21)*40/O20>0,(O22*2-O21)*40/O20,0)
      const c0 = (parseFloat(this.jyxmData[0].c6)).toFixed(2)
      if (index === 6) {
        const c1 = (parseFloat(this.jyxmData[1].c6)).toFixed(2)
        const c2 = (parseFloat(this.jyxmData[2].c6)).toFixed(2)
        if (!isNaN(c1) && !isNaN(c2) && !isNaN(c0)) {
          const a = parseFloat((parseFloat(c2) * 2 - parseFloat(c1)) * 40 / parseFloat(c0)).toFixed(2)
          this.jyxmData[index].c6 = a > 0 ? a : 0
        }
      }
      const c8 = (parseFloat(this.jyxmData[8].c6)).toFixed(2)
      if (index === 9) {
        if (!isNaN(c0) && !isNaN(c8)) {
          this.jyxmData[index].c6 = (parseFloat(c0) / parseFloat(c8)).toFixed(2)
        }
      }
    }
  }
}
</script>
<style>
  .el-input.is-disabled .el-input__inner {
    color: #606266;
  }
  .el-textarea.is-disabled .el-textarea__inner {
    color: #606266;
  }
</style>
