<!--锅炉改造和重大修理-->
<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>
        <template v-else>
          <el-button
            type="primary"
            icon="el-icon-edit"
            size="medium"
            @click="saveYsjl('upd')"
          >
            更新
          </el-button>
          <el-button
            type="success"
            icon="el-icon-upload2"
            size="medium"
            @click="saveYsjl('build')"
          >
            生成报告
          </el-button>
          <el-button
            type="warning"
            icon="el-icon-view"
            size="medium"
            @click="common.viewYsjl(ysjl.id, 'YSJL')"
          >
            预览
          </el-button>
        </template>
      </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="14">
                <el-form-item label="记录编号">
                  <el-input v-model="jlbh1" style="width: 80px" disabled />
                  <el-input v-model="jlbh2" style="width: 80px" disabled />
                  <el-input v-model="jlbh3" style="width: 80px" disabled />-
                  <el-input v-model="jlbh4" style="width: 85px" />
                </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="9">
                <el-form-item label="设备类别" prop="shebeileibie">
                  <el-select
                    v-model="ysjl.shebeileibie"
                    filterable
                    allow-create
                    default-first-option
                    style="width: 100%"
                    @change="changXh"
                  >
                    <el-option
                      v-for="item in xinghaoList"
                      :key="item.id"
                      :label="item.xinghao"
                      :value="item.xinghao"
                    />
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备品种" prop="shebeipinzhong">
                  <el-input
                    v-model="ysjl.shebeipinzhong"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="产品编号" prop="chanpinbianhao">
                  <el-input v-model="ysjl.chanpinbianhao" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="制造日期" prop="zhizaoriqi">
                  <el-date-picker
                    v-model="ysjl.zhizaoriqi"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="制造单位名称" prop="zhizaodanwei">
                  <el-input
                    v-model="ysjl.zhizaodanwei"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 1 ||
                  fromType === 5 ||
                  fromType === 3 ||
                  fromType === 8 ||
                  fromType === 10 ||
                  fromType === 12
              "
              :gutter="20"
            >
              <el-col :span="18">
                <el-form-item label="使用单位名称" prop="shiyongdanwei">
                  <el-input
                    v-model="ysjl.shiyongdanwei"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 2 ||
                  fromType === 4 ||
                  fromType === 6 ||
                  fromType === 8 ||
                  fromType === 10 ||
                  fromType === 12
              "
              :gutter="20"
            >
              <el-col :span="18">
                <el-form-item
                  label="施工单位名称"
                  prop="shigongdanweimingcheng"
                >
                  <el-input
                    v-model="ysjl.shigongdanweimingcheng"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 2 ||
                  fromType === 4 ||
                  fromType === 6 ||
                  fromType === 8 ||
                  fromType === 10 ||
                  fromType === 12
              "
              :gutter="20"
            >
              <el-col :span="9">
                <el-form-item
                  label="施工单位许可证编号"
                  prop="shigongdanweixukezhengbianhao"
                >
                  <el-input
                    v-model="ysjl.shigongdanweixukezhengbianhao"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="施工类别" prop="shigongleibie">
                  <el-input
                    v-model="ysjl.shigongleibie"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 2 ||
                  fromType === 6 ||
                  fromType === 8 ||
                  fromType === 12
              "
              :gutter="20"
            >
              <el-col :span="18">
                <el-form-item label="安装地点" prop="anzhuangdidian">
                  <el-input
                    v-model="ysjl.anzhuangdidian"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType !== 6 &&
                  fromType !== 8 &&
                  fromType !== 10 &&
                  fromType !== 12
              "
              :gutter="20"
            >
              <el-col :span="9">
                <el-form-item label="安全管理人员" prop="anquanguanlirenyuan">
                  <el-input
                    v-model="ysjl.anquanguanlirenyuan"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系电话" prop="shiyongdanweiDianhua">
                  <el-input
                    v-model="ysjl.shiyongdanweiDianhua"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col v-if="fromType !== 10" :span="9">
                <el-form-item label="使用单位代码" prop="shiyongdanweiCode">
                  <el-input
                    v-model="ysjl.shiyongdanweiCode"
                    type="text"
                    :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"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 1 ||
                  fromType === 5 ||
                  fromType === 7 ||
                  fromType === 8 ||
                  fromType === 11
              "
              :gutter="20"
            >
              <el-col :span="18">
                <el-form-item label="注册代码" prop="zhucedaima">
                  <el-input
                    v-model="ysjl.zhucedaima"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType !== 6 && fromType !== 10" :gutter="20">
              <el-col :span="18">
                <el-form-item label="设备使用地点" prop="anzhuangdidian">
                  <el-input
                    v-model="ysjl.anzhuangdidian"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType !== 6 &&
                  fromType !== 8 &&
                  fromType !== 10 &&
                  fromType !== 12
              "
              :gutter="20"
            >
              <el-col :span="9">
                <el-form-item label="单位内编号" prop="danweineibubianhao">
                  <el-input
                    v-model="ysjl.danweineibubianhao"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="改造日期" prop="gaizaoriqi">
                  <el-date-picker
                    v-model="ysjl.gaizaoriqi"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col
                v-if="
                  fromType !== 6 &&
                    fromType !== 8 &&
                    fromType !== 10 &&
                    fromType !== 12
                "
                :span="9"
              >
                <el-form-item label="改造单位名称" prop="gaizaodanwei">
                  <el-input
                    v-model="ysjl.gaizaodanwei"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="设备代码" prop="shebeidaima">
                  <el-input
                    v-model="ysjl.shebeidaima"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType === 2 ||
                  fromType === 6 ||
                  fromType == 10 ||
                  fromType == 12
              "
              :gutter="20"
            >
              <el-col :span="9">
                <el-form-item label="联系人" prop="lianxiren">
                  <el-input
                    v-model="param.lianxiren"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系电话" prop="dianhua">
                  <el-input
                    v-model="param.dianhua"
                    type="number"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="维护保养单位名称" prop="weibaodanwei">
                  <el-input
                    v-model="ysjl.weibaodanwei"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item
                  v-if="
                    fromType === 5 ||
                      fromType === 6 ||
                      fromType === 7 ||
                      fromType === 8
                  "
                  label="维护保养单位电话"
                  prop="weibaodanweiDianhua"
                >
                  <el-input
                    v-model="ysjl.weibaodanweiDianhua"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
                <el-form-item
                  v-else
                  label="维保电话"
                  prop="weibaodanweiDianhua"
                >
                  <el-input
                    v-model="ysjl.weibaodanweiDianhua"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="型号" prop="guigexinghao">
                  <el-input
                    v-model="ysjl.guigexinghao"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row
              v-if="
                fromType !== 6 &&
                  fromType !== 5 &&
                  fromType !== 7 &&
                  fromType !== 8 &&
                  fromType !== 10 &&
                  fromType !== 11 &&
                  fromType !== 12
              "
              :gutter="20"
            >
              <el-col :span="18">
                <el-form-item
                  label="现场检验条件"
                  prop="xianchangjianyantiaojian"
                >
                  <el-radio-group v-model="ysjl.xianchangjianyantiaojian">
                    <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 === 7 || fromType === 8" :gutter="20">
              <el-col :span="9">
                <el-form-item label="整机防爆标志" prop="zhengjifangbaobiaozhi">
                  <el-input
                    v-model="param.zhengjifangbaobiaozhi"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="燃爆物质" prop="ranbaowuzhi">
                  <el-input
                    v-model="param.ranbaowuzhi"
                    type="text"
                    :disabled="edit"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType === 7 || fromType === 8" :gutter="20">
              <el-col :span="18">
                <el-form-item label="区域防爆等级" prop="quyufangbaodengji">
                  <el-input v-model="param.quyufangbaodengji" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="设备名称" prop="shebeimingcheng">
                  <el-input v-model="ysjl.shebeimingcheng" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-if="fromType !== 5 && fromType !== 6">
            <legend>设备技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="额定载重量" prop="edingzaizhongliang">
                  <el-input v-model="param.edingzaizhongliang" type="text">
                    <span slot="suffix">/kg</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item v-if="fromType === 4" label="额定速度">
                  <el-input v-model="param.edingsuduShangxing" type="text">
                    <span slot="suffix">m/s</span>
                  </el-input>
                  <el-input v-model="param.edingsuduXiaxing" type="text">
                    <span slot="suffix">m/s</span>
                  </el-input>
                </el-form-item>
                <el-form-item v-else label="额定速度" prop="edingsudu">
                  <el-input v-model="param.edingsudu" type="text">
                    <span slot="suffix">m/s</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="层站门数" prop="cnegzhanmenshu">
                  <el-input
                    v-model="param.ceng"
                    type="text"
                    style="width: 50px"
                  />层
                  <el-input
                    v-model="param.zhan"
                    type="text"
                    style="width: 50px"
                  />站
                  <el-input
                    v-model="param.men"
                    type="text"
                    style="width: 50px"
                  />门
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="控制方式" prop="kongzhifangshi">
                  <el-input v-model="param.kongzhifangshi" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row v-if="fromType === 3 || fromType === 4" :gutter="20">
              <el-col :span="9">
                <el-form-item label="油缸数量" prop="youguanshuliang">
                  <el-input v-model="param.youguanshuliang" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="顶升形式" prop="dingshengxingshi">
                  <el-input v-model="param.dingshengxingshi" type="text" />
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset v-else>
            <legend>设备技术参数</legend>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="名义速度" prop="mingyisudu">
                  <el-input v-model="param.mingyisudu" type="text">
                    <span slot="suffix">m/s</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="名义宽度" prop="mingyikuandu">
                  <el-input v-model="param.mingyikuandu" type="text">
                    <span slot="suffix">mm</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="倾斜角" prop="qingxiejiao">
                  <el-input v-model="param.qingxiejiao" type="text">
                    <span slot="suffix">°</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="输送能力" prop="shusongnengli">
                  <el-input v-model="param.shusongnengli" type="text">
                    <span slot="suffix">p/h</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="9">
                <el-form-item label="提升高度" prop="tishenggaodu">
                  <el-input v-model="param.tishenggaodu" type="text">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="使用区长度" prop="quduanchangdu">
                  <el-input v-model="param.quduanchangdu" type="text">
                    <span slot="suffix">m</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </fieldset>
          <fieldset>
            <legend>检验信息</legend>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="检验依据" prop="jianyanyiju">
                  <el-input v-model="ysjl.jianyanyiju" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="主要检验仪器和设备" prop="gongjuxianghao">
                  <el-input
                    v-model="param.gongjuxianghao"
                    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"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="检验日期" prop="jianyanjieshuriqi">
                  <el-input v-model="ysjl.jianyanjieshuriqi" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="现场检验日期" prop="xianchangjianyanriqi">
                  <el-date-picker
                    v-model="ysjl.xianchangjianyanriqi"
                    value-format="yyyy-MM-dd"
                    placeholder="选择日期"
                    style="width: 100%"
                  />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col v-if="fromType !== 5" :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-col :span="9">
                <el-form-item label="下次检验日期" prop="xiacijianyanriqi">
                  <el-date-picker
                    v-model="ysjl.xiacijianyanriqi"
                    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="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">
        <Inspection :bgfy-data="bgfyData" :jybg-data="jybgData" />
      </el-tab-pane>
      <el-tab-pane
        v-if="fromType === 5 || fromType === 6"
        label="附表1"
        name="three"
      >
        <zdft-fb ref="table4" :table-data.sync="fubiao1" :state.sync="state" />
      </el-tab-pane>
      <template v-else>
        <el-tab-pane label="附表一" name="four">
          <Table
            ref="table1"
            :tabel-header="arrayGroup[0].header"
            :table-data.sync="fubiao1"
          />
        </el-tab-pane>
        <el-tab-pane label="附表二" name="five">
          <Table
            ref="table2"
            :tabel-header="arrayGroup[1].header"
            :table-data.sync="fubiao2"
          />
        </el-tab-pane>
        <el-tab-pane
          v-if="
            fromType === 1 ||
              fromType === 3 ||
              fromType === 7 ||
              fromType === 8 ||
              fromType === 9
          "
          label="附表三"
          name="six"
        >
          <phxsb
            ref="table3"
            :table-data.sync="fubiao3"
            :ysjl-param.sync="param"
            @loadPhxsImage="loadPhxsImage"
          />
        </el-tab-pane>
      </template>
    </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 Inspection from '@/views/ysjl/3000/common/inspection-items'
import Table from '@/views/ysjl/3000/dj/common/table'
import Phxsb from '@/views/ysjl/3000/dj/common/phxsb'
import ZdftFb from '@/views/ysjl/3000/dj/common/zdftFb'
import { getDepartmentTreeList } from '@/api/common.js'

export default {
  name: 'BaseInfo',
  components: { SignName, Sticky, Inspection, Table, Phxsb, ZdftFb },
  props: {
    arrayGroup: {
      required: true,
      type: Array
    },
    fromType: {
      required: true,
      type: Number
    },
    jlbh1: {
      type: String,
      default: 'DT'
    }
  },
  data() {
    return {
      ysjl: {},
      param: {},
      jlbh2: '',
      jlbh3: new Date().getFullYear(),
      jlbh4: '',
      isRepeat: false,
      jianyanrenyuan: '',
      departmentId: this.$route.query.departmentId,
      edit: false,
      state: this.$route.query.state,
      bgfyData: [],
      ysjlId: this.$route.query.id,
      checkedTab: 'first',
      userList: [],
      xinghaoList: [],
      jybgData: [],
      cols: [
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) {
            // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanmu',
          getValue(row) {
            return row.jianyanmu
          }
        }
      ],
      rows: [
        {
          name: 'jianyanxiang',
          getValue(row) {
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanneirong',
          getValue(row) {
            return row.jianyanneirong
          }
        }
      ],
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now()
        }
      },
      pic: '',
      fubiao1: [],
      fubiao2: [],
      fubiao3: [],
      tree: []
    }
  },
  created() {
    if (this.state === 'create') {
      this.initYsjl()
      if (this.fromType === 5 || this.fromType === 6) {
        this.fubiao1 = [
          {
            D2: '第一次',
            D1: ''
          },
          {
            D2: '第二次',
            D1: ''
          },
          {
            D2: '第三次',
            D1: ''
          }
        ]
      }
    } else {
      this.getYsjl()
      this.getParam()
      this.getJyxmInfoByYsjl()
    }
    this.getDepartment()
    // this.getDicJyxm(1)
    this.userList = this.$store.getters.allUser.filter(
      (user) => user.departmentId === 74 && user.clientType === 'System'
    )
  },
  methods: {
    getDepartment() {
      getDepartmentTreeList().then((res) => {
        this.tree = res
      })
    },
    handleChange(v) {
      this.ysjl.departmentId = v[1]
    },
    initYsjl() {
      this.ysjlService.init(this.$route.query).then((data) => {
        this.ysjl = data.ysjl
        this.param = data.param ? data.param : {}
        this.ysjl.jianyanjieshuriqi = this.formatter.dateFormat('YYYY-MM-dd')
        this.ysjl.bglx = 1
        this.ysjl.cjState = 'ysjl'
        this.ysjl.xianchangjianyantiaojian = '符合'
        this.departmentId = this.ysjl.departmentId
        if (data.ysjl.shebeileibiedaima === '3300') {
          this.jlbh2 = '(F)'
        } else if (data.ysjl.shebeileibiedaima === '3200') {
          this.jlbh2 = '(Y)'
        } else if (data.ysjl.shebeileibiedaima === '3400') {
          if (data.ysjl.shebeipinzhongdaima === '3420') {
            this.jlbh2 = '(X)'
          } else if (data.ysjl.shebeipinzhongdaima === '3430') {
            this.jlbh2 = '(Z)'
          }
        } else {
          this.jlbh2 = '(C)'
        }
        this.getJyxm(1)
        this.getSbList()
        this.getMaxBh()
      })
    },
    getSbList() {
      this.api({
        url: '/sedirectory/getList',
        method: 'get',
        params: {
          sbzl: this.$route.query.sbzldm,
          sblb: this.$route.query.sblbdm,
          level: 2
        }
      }).then((data) => {
        this.xinghaoList = data
      })
    },
    getJyxmInfoByYsjl() {
      this.ysjlService.getJyxmInfoByYsjl(this.ysjlId).then((data) => {
        if (!data.fbjyxm) {
          return
        }
        const fubiao = JSON.parse(data.fbjyxm)
        if (!fubiao.length) {
          return
        }
        if (fubiao[0]) {
          this.fubiao1 = fubiao[0]
        }
        if (fubiao[1]) {
          this.fubiao2 = fubiao[1]
        }
        if (fubiao[2]) {
          this.fubiao3 = fubiao[2]
        }
      })
    },
    getYsjl() {
      this.ysjlService.getYsjl(this.ysjlId).then((data) => {
        this.ysjl = data
        this.departmentId = this.ysjl.departmentId
        this.ysjl.imagePath = ''
        if (
          this.ysjl.jianyanrenyuan !== null &&
            this.ysjl.jianyanrenyuan.length > 0
        ) {
          this.jianyanrenyuan = this.common.convertCnName(
            this.ysjl.jianyanrenyuan
          )
        }
        this.ysjlService
          .judgeRepeat(this.ysjl.jilubianhao, this.ysjl.id)
          .then((data) => {
            this.isRepeat = data
          })
        this.getJyxm(1)
      })
    },
    getParam() {
      const id = this.ysjlId || this.$route.query.templateId
      this.ysjlService.getParam(id, this.$route.query.sbzldm).then((data) => {
        this.param = 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
        }
      })
    },
    getJyxm(sort) {
      if (this.$route.query.state === 'update') {
        this.jyxmService
          .getJdCyJyxm(this.ysjlId, this.$route.query.templateId, sort, 0)
          .then((data) => {
            this.bgfyData = data
            this.tableJs.getData(this.cols, this.rows, this.bgfyData)
          })
        this.jyxmService
          .getJdCyJyxm(this.ysjlId, this.ysjl.jybgTemplateId, sort, 1)
          .then((data) => {
            this.jybgData = data
          })
      } else {
        this.jyxmService
          .getCyJyxm(this.$route.query.templateId, sort)
          .then((data) => {
            data.forEach((row) => {
              row.dicJyxmId = row.id
            })
            this.bgfyData = data
            this.tableJs.getData(this.cols, this.rows, this.bgfyData)
          })
        this.jyxmService
          .getCyJyxm(this.ysjl.jybgTemplateId, sort)
          .then((data) => {
            data.forEach((row) => {
              row.dicJyxmId = row.id
            })
            this.jybgData = data
          })
      }
    },
    /**
     * 查询最大记录编号
     */
    getMaxBh() {
      const aheadPart = this.jlbh1 + this.jlbh2 + this.jlbh3 + '-'
      this.api({
        url: '/ysjl/gainCurrentBh',
        method: 'get',
        params: {
          aheadPart: aheadPart,
          hinderPart: ''
        }
      }).then((data) => {
        this.jlbh4 = data
        this.ysjlService
          .judgeRepeat(this.ysjl.jilubianhao, this.ysjl.id)
          .then((data) => {
            this.isRepeat = data
          })
      })
    },
    /**
     * 签名方法
     * @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)
    },
    saveYsjl(operation) {
      if (operation !== 'add' && this.pic) {
        this.uploadPhxsBase64File(operation)
      } else {
        this.buildSaveData(operation)
      }
    },
    sortClass(sortData) {
      const groupBy = (array, f) => {
        const groups = {}
        array.forEach((o) => {
          const group = JSON.stringify(f(o))
          groups[group] = groups[group] || []
          groups[group].push(o)
        })
        return Object.keys(groups).map((group) => {
          return groups[group]
        })
      }
      const sorted = groupBy(sortData, (item) => {
        return item.jybgJyjlIndex // 返回需要分组的对象
      })
      return sorted
    },
    buildSaveData(operation) {
      let fubiao
      if (this.fromType === 5 || this.fromType === 6) {
        fubiao = [this.$refs.table4.tableData]
      } else {
        fubiao = [this.fubiao1, this.fubiao2, this.fubiao3]
      }

      const subArr = this.sortClass(this.bgfyData)
      subArr.forEach((item) => {
        if (item.some((k) => k.jianyanjieguo.indexOf('X') === 0)) {
          this.jybgData[item[0].jybgJyjlIndex - 1].jianyanjielun = '不合格'
        } else if (item.every((k) => k.jianyanjieguo.indexOf('√') === 0)) {
          this.jybgData[item[0].jybgJyjlIndex - 1].jianyanjielun = '合格'
        } else if (item.every((k) => k.jianyanjieguo.indexOf('/') === 0)) {
          this.jybgData[item[0].jybgJyjlIndex - 1].jianyanjielun = '无此项'
        }
      })
      const tableData = []
      this.bgfyData.forEach((row) => {
        tableData.push({
          ysjlId: this.ysjlId,
          beizhu: row.beizhu,
          dicJyxmId: row.dicJyxmId,
          jianyanjieguo: row.jianyanjieguo || '',
          jianyanjielun: row.jianyanjielun || '',
          jyxmMode: 0,
          sort: row.sort,
          orders: row.orders,
          cjState: 0
        })
      })
      this.jybgData.forEach((row) => {
        tableData.push({
          ysjlId: this.ysjlId,
          beizhu: row.beizhu,
          dicJyxmId: row.dicJyxmId,
          jianyanjieguo: row.jianyanjieguo || '',
          jianyanjielun: row.jianyanjielun || '',
          jyxmMode: 0,
          sort: row.sort,
          orders: row.orders,
          cjState: 1
        })
      })
      if (operation === 'add') {
        this.ysjl.jilubianhao = this.jlbh1 + this.jlbh2 + this.jlbh3 + '-' + this.jlbh4
        this.save(operation, 'post', tableData, fubiao)
      } else if (operation === 'build') {
        this.ysjl.baogaobianhao = this.ysjl.jilubianhao
        if (
          this.ysjl.jilubianhao &&
            this.ysjl.jilubianhao.indexOf('COPY') > -1
        ) {
          this.$message({
            type: 'error',
            message: '请先修改报告编号，不允许携带COPY标志生成报告!'
          })
          return false
        }
        if (
          this.ysjl.jianyanrenyuan === null ||
            this.ysjl.jianyanrenyuan === ''
        ) {
          this.$message({
            type: 'error',
            message: '请先签名再生成报告!'
          })
          return false
        }
        this.save(operation, 'put', tableData, fubiao)
      } else if (operation === 'upd') {
        this.save(operation, 'put', tableData, fubiao)
      }
    },
    save(operation, type, jyxm, fubiao) {
      if (this.fromType !== 5 && this.fromType !== 6) { this.ysjl.imagePath = this.$refs.table1.imgPath }

      // 判断报告编号是否重复
      if (this.isRepeat) {
        this.$message({
          message: '记录编号重复，请先修改记录编号再保存',
          type: 'error'
        })
        return false
      } else {
        this.$refs['ysjl'].validate((valid) => {
          if (valid) {
            this.api({
              url: '/ysjl',
              method: type,
              data: {
                ysjl: this.ysjl,
                param: this.param,
                cyJyxm: {
                  ysjlId: this.ysjl.id,
                  fbjyxm: JSON.stringify(fubiao)
                },
                jdJyxm: jyxm,
                state: operation
              }
            }).then((data) => {
              Utils.$emit('ysjl-db-list')
              // 刷新任务列表，原始记录待办，原始记录已办，检验报告
              if (operation === 'add') {
                Utils.$emit('task-list')
                this.ysjl.id = data
                this.param.ysjlId = data
                this.$message({ message: '保存成功', type: 'success' })
                this.uploadPhxsBase64File()
                // 刷新路由网址
                this.common.reloadViewToUpdateYsjl(this.ysjl)
              } else if (operation === 'upd') {
                this.$message({ message: '更新成功', type: 'success' })
                // 替换路由中的参数
                this.$router.push({
                  query: merge(this.$route.query, {
                    jianyanrenyuan: this.ysjl.jianyanrenyuan
                  })
                })
              } else {
                // 生成pdf
                this.common.viewYsjlNoOpen(this.ysjl.id, 'YSJL')
                Utils.$emit('ysjl-list')
                Utils.$emit('ysjl-yb-list')
                Utils.$emit('bggl-daiban-list')
                this.$message({ message: '生成报告成功', type: 'success' })
                this.common.delCurrentViews()
              }
              this.state = 'update'
            })
          }
        })
      }
    },

    /**
     * 上传平衡系数表
     */
    uploadPhxsBase64File(operation) {
      if (!this.pic) {
        return false
      }
      this.uploadService
        .uploadPhxsBase64File({
          ysjlId: this.ysjl.id,
          base64File: this.pic,
          shebeizhongleidaima: this.ysjl.shebeizhongleidaima
        })
        .then(() => {
          if (operation !== 'add') {
            this.buildSaveData(operation)
          }
        })
    },
    changXh: function(val) {
      // TODO
    },
    loadPhxsImage(data) {
      this.pic = data
    }
  }
}
</script>
<style scoped>
.el-tag {
  margin: auto 5px;
}
</style>
<style lang="scss" scoped>
</style>
