<!--工业锅炉内部检验-->
<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px">
      <div class="sub-navbar">
        <el-button
          v-if="state === 'create'"
          type="success"
          icon="el-icon-edit"
          size="medium"
          @click="saveYsjl('add')"
        >
          保存
        </el-button>
        <el-button
          v-if="state === 'update'"
          type="primary"
          icon="el-icon-edit"
          size="medium"
          @click="saveYsjl('upd')"
        >
          更新
        </el-button>
        <el-button
          v-if="state === 'update'"
          type="success"
          icon="el-icon-upload2"
          size="medium"
          @click="saveYsjl('build')"
        >
          生成报告
        </el-button>
        <el-button
          v-if="state !== 'create'"
          type="warning"
          icon="el-icon-view"
          size="medium"
          @click="common.viewYsjl(ysjl.id, 'YSJL', false)"
        >
          预览
        </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="140px"
        >
          <fieldset>
            <legend>基本信息</legend>
            <el-row :gutter="25">
              <el-col v-if="state === 'create' || !ysjl.jilubianhao" :span="10">
                <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: 85px" />
                </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="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="shiyongdanweiDizhi">
                  <el-input
                    v-model="ysjl.shiyongdanweiDizhi"
                    :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"
                    :disabled="edit"
                    type="text"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item
                  label="使用单位统一社会信用代码"
                  prop="shiyongdanweiCode"
                  label-width="240px"
                >
                  <el-input v-model="ysjl.shiyongdanweiCode" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item
                  label="使用单位安全管理人员"
                  prop="anquanguanlirenyuan"
                  label-width="180px"
                >
                  <el-input
                    v-model="ysjl.anquanguanlirenyuan"
                    :disabled="edit"
                  />
                </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"
                    :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="zhizaodanwei">
                  <el-input v-model="ysjl.zhizaodanwei" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item
                  label="改造（重大修理）单位名称"
                  prop="gaizaodanwei"
                  label-width="200px"
                >
                  <el-input v-model="ysjl.gaizaodanwei" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="设备品种" prop="shebeipinzhong">
                  <el-input v-model="ysjl.shebeipinzhong" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备注册代码" prop="shebeidaima">
                  <el-input v-model="ysjl.shebeidaima" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="规格型号" prop="guigexinghao">
                  <el-input v-model="ysjl.guigexinghao" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="产品编号" prop="chanpinbianhao">
                  <el-input v-model="ysjl.chanpinbianhao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="投入使用日期" prop="touyongriqi">
                  <el-date-picker
                    v-model="ysjl.touyongriqi"
                    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="shejishiyongnianxian">
                  <el-input
                    v-model="ysjl.shejishiyongnianxian"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row
              v-if="fromType !== 4 && fromType !== 5 && fromType !== 5"
              :gutter="20"
            >
              <el-col :span="9">
                <el-form-item label="工作级别" prop="gongzuojibie">
                  <el-input v-model="ysjl.gongzuojibie" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType === 2 || fromType === 3" :gutter="20">
              <el-col :span="18">
                <el-form-item label="取物装置" prop="quwuzhuangzhi">
                  <el-radio-group v-model="param.quwuzhuangzhi">
                    <el-radio label="吊钩">
                      吊钩
                    </el-radio>
                    <el-radio label="抓斗">
                      抓斗
                    </el-radio>
                    <el-radio label="吸盘">
                      吸盘
                    </el-radio>
                    <el-radio label="集装箱吊具">
                      集装箱吊具
                    </el-radio>
                    <el-radio label="其他">
                      其他
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType === 1" :gutter="20">
              <el-col :span="18">
                <el-form-item label="吊具形式" prop="quwuzhuangzhi">
                  <el-radio-group v-model="param.quwuzhuangzhi">
                    <el-radio label="吊钩">
                      吊钩
                    </el-radio>
                    <el-radio label="抓斗">
                      抓斗
                    </el-radio>
                    <el-radio label="吸盘">
                      吸盘
                    </el-radio>
                    <el-radio label="集装箱吊具">
                      集装箱吊具
                    </el-radio>
                    <el-radio label="其他">
                      其他
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType !== 4 && fromType !== 5" :gutter="20">
              <el-col :span="18">
                <el-form-item label="检验类别" prop="jianyanleibie">
                  <el-radio-group v-model="ysjl.jianyanleibie">
                    <el-radio label="SC">
                      首次检验
                    </el-radio>
                    <el-radio label="DQ">
                      定期检验
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="工作环境" prop="jianyanhuanjing">
                  <el-radio-group v-model="param.jianyanhuanjing">
                    <el-radio label="露天">
                      露天
                    </el-radio>
                    <el-radio label="非露天">
                      非露天
                    </el-radio>
                    <el-radio label="高温">
                      高温
                    </el-radio>
                    <el-radio label="粉尘">
                      粉尘
                    </el-radio>
                    <el-radio label="有毒">
                      有毒
                    </el-radio>
                    <el-radio label="其他">
                      其他
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>

            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item
                  label="检验安全环境条件"
                  prop="jianyanhuanjingtiaojian"
                >
                  <el-radio-group v-model="ysjl.jianyanhuanjingtiaojian">
                    <el-radio label="符合">
                      符合
                    </el-radio>
                    <el-radio label="不符合">
                      不符合
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType == 1">
            <legend>技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定起重量" prop="edingqizhongliang">
                  <el-input v-model="param.edingqizhongliang">
                    <span slot="suffix">t</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="跨度" prop="kuadu">
                  <el-input v-model="param.kuadu" :disabled="edit">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="起升高度" prop="qishenggaodu">
                  <el-input v-model="param.qishenggaodu">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="起升速度" prop="qishengsudu">
                  <el-input v-model="param.qishengsudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="大车运行速度" prop="dacheyunxingsudu">
                  <el-input v-model="param.dacheyunxingsudu">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="小车运行速度" prop="xiaocheyunxingsudu">
                  <el-input v-model="param.xiaocheyunxingsudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType == 2 || fromType == 5">
            <legend>技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="最大额定起重量" prop="edingqizhongliang">
                  <el-input v-model="param.edingqizhongliang">
                    <span slot="suffix">t</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="变幅速度" prop="bianfusudu">
                  <el-input v-model="param.bianfusudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定起重力矩" prop="edingqizhongliju">
                  <el-input v-model="param.edingqizhongliju">
                    <span slot="suffix">t·m</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="工作幅度" prop="kuadu">
                  <el-input v-model="param.kuadu">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="起升速度" prop="qishengsudu">
                  <el-input v-model="param.qishengsudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="起升高度" prop="qishenggaodu">
                  <el-input v-model="param.qishenggaodu">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="回转速度" prop="huizhuansudu">
                  <el-input v-model="param.huizhuansudu" :disabled="edit">
                    <span slot="suffix">r/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="大车运行速度" prop="dacheyunxingsudu">
                  <el-input v-model="param.dacheyunxingsudu">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType == 1" :gutter="20">
              <el-col :span="18">
                <el-form-item label="取物装置" prop="quwuzhuangzhi">
                  <el-radio-group v-model="param.quwuzhuangzhi">
                    <el-radio label="吊钩">
                      吊钩
                    </el-radio>
                    <el-radio label="抓斗">
                      抓斗
                    </el-radio>
                    <el-radio label="吸盘">
                      吸盘
                    </el-radio>
                    <el-radio label="集装箱吊具">
                      集装箱吊具
                    </el-radio>
                    <el-radio label="其他">
                      其他
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType == 3">
            <legend>技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="最大额定起重量" prop="edingqizhongliang">
                  <el-input v-model="param.edingqizhongliang">
                    <span slot="suffix">t</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="最大额定起重力矩" prop="bianfusudu">
                  <el-input v-model="param.bianfusudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="工作幅度" prop="kuadu">
                  <el-input v-model="param.kuadu">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="回转速度" prop="huizhuansudu">
                  <el-input v-model="param.huizhuansudu" :disabled="edit">
                    <span slot="suffix">r/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="起升高度" prop="qishenggaodu">
                  <el-input v-model="param.qishenggaodu">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="起升速度" prop="qishengsudu">
                  <el-input v-model="param.qishengsudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType == 4">
            <legend>技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定载重量" prop="edingqizhongliang">
                  <el-input v-model="param.edingqizhongliang">
                    <span slot="suffix">t</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="提升高度（检验结束时）"
                  prop="qishenggaodu"
                >
                  <el-input v-model="param.qishenggaodu" :disabled="edit">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定乘员数" prop="edingzaikerenshu">
                  <el-input v-model="param.edingzaikerenshu">
                    <span slot="suffix">人</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="额定速度" prop="edingsudu">
                  <el-input v-model="param.edingsudu" :disabled="edit">
                    <span slot="suffix">r/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="层站数">
                  <el-input v-model="param.cengshu">
                    <span slot="suffix">层</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="驱动方式" prop="qudong">
                  <el-input v-model="param.qudong" :disabled="edit">
                    <span slot="suffix">r/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="防坠安全器、限速器、安全钳编号"
                  prop="faxBianhao"
                >
                  <el-input v-model="ysjl.faxBianhao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="防坠安全器、限速器、安全钳型号"
                  prop="faxXinghao"
                >
                  <el-input v-model="ysjl.faxXinghao" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="防坠安全器、限速器、安全钳有效标定期限"
                  prop="faxBiaodingqixian"
                >
                  <el-input v-model="ysjl.faxBiaodingqixian" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType == 6">
            <legend>技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="适停车辆重量"
                  prop="shitingcheliangzhongliang"
                >
                  <el-input v-model="param.shitingcheliangzhongliang">
                    <span slot="suffix">t</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item
                  label="适停车辆尺寸（长×宽×高）"
                  prop="shitingcheliangchicun"
                >
                  <el-input
                    v-model="param.shitingcheliangchicun"
                    :disabled="edit"
                  >
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="层数" prop="cengshu">
                  <el-input v-model="param.cengshu">
                    <span slot="suffix">人</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="纵移速度" prop="zongyisudu">
                  <el-input v-model="param.zongyisudu" :disabled="edit">
                    <span slot="suffix">m/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="泊位数" prop="boweishu">
                  <el-input v-model="param.boweishu">
                    <span slot="suffix">辆</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="横移速度" prop="hengyisudu">
                  <el-input v-model="param.hengyisudu" :disabled="edit">
                    <span slot="suffix">r/min</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  label="单车进出最大时间"
                  prop="danchejinchuzuidashijian"
                >
                  <el-input
                    v-model="ysjl.danchejinchuzuidashijian"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="驱动方式" prop="qudong">
                  <el-input v-model="ysjl.qudong" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <el-row :gutter="20" style="margin-bottom: 20px">
              <el-col :span="18">
                <el-form-item label="检验依据" prop="jianyanyiju">
                  <el-input v-model="ysjl.jianyanyiju" type="textarea" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检验工具" prop="jianyangongju">
                  <el-input
                    v-model="param.jianyangongju"
                    style="width: 100px"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检验结论" prop="jianyanjielun">
                  <el-radio-group v-model="ysjl.jianyanjielun">
                    <el-radio label="合格">
                      合格
                    </el-radio>
                    <el-radio label="不合格">
                      不合格
                    </el-radio>
                    <el-radio label="复检合格">
                      复检合格
                    </el-radio>
                    <el-radio label="复检不合格">
                      复检不合格
                    </el-radio>
                  </el-radio-group>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18" style="height: auto">
                <el-form-item label="备注" prop="beizhu">
                  <el-input
                    v-model="ysjl.beizhu"
                    type="textarea"
                    :autosize="{ minRows: 2, maxRows: 5 }"
                    :disabled="edit"
                  />
                  <span v-if="fromType === 5">（需备注扶墙架道数）</span>
                </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"
                    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"
                    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="departmentId">
                  <el-cascader
                    v-model="departmentId"
                    :props="{ value: 'id', label: 'name', checkStrictly: true }"
                    :options="tree"
                    :show-all-levels="false"
                    @change="handleChange"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <template>
              <el-row :gutter="10">
                <el-col :span="9">
                  <el-form-item label="检验人员" prop="jianyanrenyuan">
                    <el-input v-model="ysjl.jianyanrenyuan" disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <sign-name
                    :jianyanrenyuan="jianyanrenyuan"
                    :ysjl="ysjl"
                    :custom-clear-sign="customClearSign"
                    @setSignValue="signNameValue"
                  />
                </el-col>
              </el-row>
              <!-- <el-row :gutter="10">
                <el-col :span="9">
                  <el-form-item label="编制" prop="jianyanrenyuan">
                    <el-input v-model="ysjl.jianyanrenyuan" disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="9">
                  <sign-name
                    :jianyanrenyuan="jianyanrenyuan"
                    :ysjl="ysjl"
                    :custom-clear-sign="customClearSign"
                    @setSignValue="signNameValue"
                  />
                </el-col>
              </el-row> -->
            </template>
          </fieldset>
        </el-form>
      </el-tab-pane>
      <el-tab-pane label="检验项目" name="second">
        <el-table
          ref="sybjSData"
          :data="sybjSData"
          :span-method="tableJs.mergeColRows"
          border
          stripe
          style="width: 90%"
        >
          <el-table-column align="center" label="检验项目">
            <el-table-column align="center" prop="jianyanxiang" width="200" />
            <el-table-column align="left" prop="jianyanneirong" />
          </el-table-column>
          <el-table-column align="center" prop="D1" label="检验结果">
            <template slot-scope="scope">
              <el-select
                v-model="scope.row.jianyanjieguo"
                :disabled="edit"
                type="text"
                placeholder="请选择"
                style="width: 100%"
                filterable
                allow-create
                default-first-option
              >
                <el-option label="√" value="√" />
                <el-option label="○" value="○" />
                <el-option label="×" value="×" />
                <el-option label="/" value="/" />
              </el-select>
            </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 merge from 'webpack-merge'
import { getDepartmentTreeList } from '@/api/common.js'

export default {
  name: 'GlGynbYsjl',
  components: { SignName, Sticky },
  props: {
    fromType: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      jlbh1: 'QD',
      jlbh2: '(' + new Date().getFullYear() + ')',
      jlbh3: '',
      ysjl: {
        shiyongdanwei: ''
      },
      chepai: '鲁·',
      param: {},
      state: this.$route.query.state,
      jianyanrenyuan: '',
      departmentId: this.$store.getters.departmentId,
      isRepeat: false,
      edit: false,
      sybjSData: [],
      tableData: [],
      tree: [],
      checkedTab: 'first',
      ysjlId: this.$route.query.id,
      // 表格合并相关
      // 参与列合并的字段，在这里增加即可
      cols: [
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) {
            // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        }
      ],
      rows: [
        {
          name: 'jianyanxiang',
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        }
      ]
    }
  },
  computed: {},
  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)
    }
  },
  // 添加F5刷新监听事件
  mounted() {
    window.addEventListener('beforeunload', this.beforeunloadHandler, false)
  },
  created() {
    if (this.state === 'create') {
      this.initYsjl()
      this.getJyxm(1)
      // 查询最大记录编号
      this.getMaxBh()
    } else {
      this.getYsjl(this.$route.query.id)
      this.getJyxm(1)
    }
    this.getDepartment()
  },
  beforeDestroy() {
    window.removeEventListener('beforeunload', this.beforeunloadHandler, false)
  },
  methods: {
    getDepartment() {
      getDepartmentTreeList().then((res) => {
        console.log(res, 555)
        this.tree = res
      })
    },
    handleChange(v) {
      this.ysjl.departmentId = v[1]
    },
    /**
     * 签名方法
     * @param data
     */
    signNameValue(data) {
      this.ysjl.jianyanrenyuan = String(data.id)
      this.jianyanrenyuan = data.name
      this.common.signName(this.ysjl.id, this.ysjl.jianyanrenyuan)
    },
    customClearSign(fieldName) {
      const data = {
        id:
          this.ysjl.jianyanrenyuan &&
          this.common
            .deleteElement(
              this.ysjl.jianyanrenyuan.split(','),
              String(this.$store.getters.userId)
            )
            .join(','),
        name:
          this.jianyanrenyuan &&
          this.common
            .deleteElement(
              this.jianyanrenyuan.split(','),
              this.$store.getters.nickname
            )
            .join(','),
        fieldName: fieldName
      }
      this.signNameValue(data)
    },
    // 查询最大记录编号
    getMaxBh() {
      const aheadPart = this.jlbh1 + this.jlbh2
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: aheadPart + '-',
          hinderPart: ''
        }
      }).then((data) => {
        this.jlbh3 = data
      })
    },
    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.departmentId = this.ysjl.departmentId
        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.jianyanjielun = '符合要求'
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.ysjl.beizhu = '/'
        this.$set(this.param, 'qita', '/')
        // // 制造日期、投用日期、上次检验日期设置成正确的日期格式
        // this.ysjl.zhizaoriqi = this.common.checkDateFormat(this.ysjl.zhizaoriqi)
        this.ysjl.touyongriqi = this.common.checkDateFormat(
          this.ysjl.touyongriqi
        )
        // this.param.shangcijianyanriqi = this.common.checkDateFormat(this.param.shangcijianyanriqi)
      })
    },
    getYsjl(id) {
      this.api({
        url: '/ysjl',
        method: 'get',
        params: {
          ysjlId: id
        }
      }).then((data) => {
        this.ysjl = data
        this.departmentId = this.ysjl.departmentId
        if (
          this.ysjl.jianyanrenyuan !== null &&
          this.ysjl.jianyanrenyuan.length > 0
        ) {
          this.jianyanrenyuan = this.common.convertCnName(
            this.ysjl.jianyanrenyuan
          )
        }
        // 查询最大记录编号
        if (
          this.ysjl.jilubianhao === null ||
          this.ysjl.jilubianhao === undefined ||
          this.ysjl.jilubianhao === ''
        ) {
          this.getMaxBh()
        }
        this.getParam(this.ysjl.id, this.ysjl.shebeizhongleidaima)
      })
    },
    getParam(ysjlId, sbzldm) {
      // 根据原始记录id查询参数
      this.api({
        url: '/ysjl/getParamByYsjlId',
        method: 'get',
        params: {
          ysjlId: ysjlId,
          sbzldm: sbzldm
        }
      }).then((data) => {
        this.param = data
      })
    },
    getJyxm(sort) {
      if (this.$route.query.state === 'update') {
        this.jyxmService
          .getJdCyJyxm(this.ysjlId, this.$route.query.templateId, sort)
          .then((data) => {
            this.sybjSData = data
            this.tableJs.getData(this.cols, undefined, this.sybjSData)
          })
      } else {
        this.jyxmService
          .getCyJyxm(this.$route.query.templateId, sort)
          .then((data) => {
            data.forEach((row) => {
              row.dicJyxmId = row.id
            })

            this.sybjSData = data
            this.tableJs.getData(this.cols, undefined, this.sybjSData)
          })
      }
    },
    saveYsjl: function(operation) {
      if (operation === 'add') {
        if (this.jlbh3.trim() === '') {
          this.$message({
            message: '请先确认记录编号是否完整！',
            type: 'warning'
          })
          return false
        }
      }
      // 把第一个检验项目表中的检验结果单独放到字段中
      const tableData = []
      this.sybjSData.forEach((row) => {
        tableData.push({
          ysjlId: this.ysjlId,
          id: row.id,
          beizhu: row.beizhu,
          dicJyxmId: row.dicJyxmId,
          jianyanjieguo: row.jianyanjieguo || '',
          jianyanjielun: row.jianyanjielun || '',
          jyxmMode: 0,
          sort: row.sort,
          orders: row.orders,
          cjState: 0
        })
      })
      let method = ''
      this.ysjl.bglx = 1
      this.ysjl.cjState = 'ysjl'
      this.ysjl.zfState = 0
      this.ysjl.jianyanxiangmu = 'gynb'
      this.ysjl.jlprintState = 0
      if (this.ysjl.jianyanjielun === '不符合要求') {
        this.ysjl.xiacijianyanriqi = null
      }
      if (operation === 'add') {
        this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + '-' + this.jlbh3
        method = 'post'
      } 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
        }
        method = 'put'
      } else if (operation === 'upd') {
        method = 'put'
      }
      if (this.isRepeat) {
        this.$message({
          message: '记录编号重复，请先修改记录编号再保存',
          type: 'error'
        })
        return false
      } else {
        this.$refs['ysjl'].validate((valid) => {
          if (valid) {
            const jyxm = tableData
            this.api({
              url: '/ysjl',
              method: method,
              data: {
                ysjl: this.ysjl,
                param: this.param,
                cyJyxm: {},
                jdJyxm: jyxm
              }
            }).then((data) => {
              Utils.$emit('task-list')
              Utils.$emit('ysjl-list')
              if (operation === 'add' && data !== '') {
                this.$message({
                  message: '保存成功, 请前往待办记录中查看。',
                  type: 'success'
                })
                this.ysjl.id = data
                this.param.ysjlId = data
                // 刷新路由网址
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
              } else if (operation === 'upd') {
                this.$message({ message: '更新成功', type: 'success' })
                // 替换路由中的参数
                this.$router.push({
                  query: merge(this.$route.query, {
                    jianyanrenyuan: this.ysjl.jianyanrenyuan
                  })
                })
                // this.$refs.bill.updateChargeBill()
              } else {
                Utils.$emit('ysjl-list')
                Utils.$emit('ysjl-yb-list')
                Utils.$emit('bggl-daiban-list')
                this.$message({ message: '生成报告成功', type: 'success' })
                this.$store.dispatch('delCurrentViews', {
                  view: this.$route,
                  $router: this.$router
                })
              }
              this.state = 'update'
            })
          }
        })
      }
    },
    judgeRepeat(bianhao, id) {
      this.api({
        url: '/ysjl/judgeRepeat',
        method: 'get',
        params: {
          ysjlId: id,
          bianhao: bianhao
        }
      }).then((data) => {
        if (data > 0) {
          this.isRepeat = true
        } else {
          this.isRepeat = false
        }
      })
    },
    getXcjyrq() {
      const xcjyrq = new Date(this.ysjl.jianyanjieshuriqi)
      xcjyrq.setFullYear(
        xcjyrq.getFullYear() + 2,
        xcjyrq.getMonth(),
        xcjyrq.getDate() - 1
      )
      this.ysjl.xiacijianyanriqi = this.formatter.dateFormat(
        'YYYY-MM-dd',
        xcjyrq
      )
    },
    setYsjlData(data) {
      this.ysjl.sfdId = data
    },
    // F5刷新监听
    beforeunloadHandler(e) {
      e.returnValue = ''
    }
  }
}
</script>
