<!--工业锅炉内部检验-->
<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 === 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:85px" @blur="judgeRepeat(jlbh1 + jlbh2 + '-' + jlbh3 , ysjl.id)" />
                </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="车辆牌号">
                  <el-input v-model="chepai" style="width:80px" disabled />
                  <el-input v-model="ysjl.cheliangpaihao" :disabled="edit" style="width:80px" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="设备注册代码（使用登记证编号）" prop="zhucedaima" label-width="240px">
                  <el-input v-model="ysjl.zhucedaima" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item label="使用单位" prop="shiyongdanwei">
                  <el-input v-model="ysjl.shiyongdanwei" :disabled="edit" 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="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="9">
                <el-form-item label="联系人" prop="shiyongdanweiLianxiren">
                  <el-input v-model="ysjl.shiyongdanweiLianxiren" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="联系电话" prop="shiyongdanweiDianhua">
                  <el-input v-model="ysjl.shiyongdanweiDianhua" :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="guigexinghao">
                  <el-input v-model="ysjl.guigexinghao" :disabled="edit" />
                </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="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="zhizaodanwei">
                  <el-input v-model="ysjl.zhizaodanwei" :disabled="edit" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="制造日期" prop="zhizaoriqi">
                  <el-date-picker v-model="ysjl.zhizaoriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="改造单位" prop="gaizaodanwei">
                  <el-input v-model="ysjl.gaizaodanwei" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="改造日期" prop="gaizaoriqi">
                  <el-date-picker v-model="ysjl.gaizaoriqi" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="发动机（电机）编号" prop="fadongjibianhao">
                  <el-input v-model="param.fadongjibianhao" :disabled="edit" type="text" />
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="燃料种类" prop="ranliaozhonglei">
                  <el-input v-model="param.ranliaozhonglei" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="6">
                <el-form-item label="额定起重量" prop="edingqizhongliang">
                  <el-input v-model="param.edingqizhongliang" :disabled="edit">
                    <span slot="suffix">/kg</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="自重" prop="kongchezhongliang">
                  <el-input v-model="param.kongchezhongliang" :disabled="edit">
                    <span slot="suffix">/kg</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="防爆功能" prop="fangbaogongneng">
                  <el-input v-model="param.fangbaogongneng" :disabled="edit" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="9">
                <el-form-item label="空载最大起升高度" prop="kongzaigaodu">
                  <el-input v-model="param.kongzaigaodu" :disabled="edit">
                    <span slot="suffix">mm</span>
                  </el-input>
                </el-form-item>
              </el-col>
              <el-col :span="9">
                <el-form-item label="空载最大运行速度" prop="sudukongzai">
                  <el-input v-model="param.sudukongzai" :disabled="edit">
                    <span slot="suffix">km/h</span>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row :gutter="20">
              <el-col :span="18">
                <el-form-item
                  label="使用区域"
                  prop="shiyongquyu"
                >
                  <el-radio-group v-model="param.shiyongquyu">
                    <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="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="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>
            <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="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-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="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="center" prop="jianyanmu" 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.D1" :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 },
  data() {
    return {
      jlbh1: 'GN',
      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: [],
      tree: [],
      tableData: [],
      checkedTab: 'first',
      ysjlId: this.$route.query.id,
      // 表格合并相关
      // 参与列合并的字段，在这里增加即可
      cols: [
        {
          name: 'jianyanxiang', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanxiang
          }
        },
        {
          name: 'jianyanmu', // 参与计算的列名，必须和el-table-column prop=''值一致
          getValue(row) { // 该列用于比较的值的获取方法
            return row.jianyanmu
          }
        }
      ],
      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
      })
    },
    /**
     * 签名方法
     * @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.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.param.jiezhi = '水'
        this.ysjl.jigouhezhunzhenghao = process.env.VUE_APP_HZZBH
        this.ysjl.beizhu = '/'
        this.ysjl.xiacijianyanriqishuoming = '/'
        this.ysjl.anzhuangdidian = this.ysjl.shiyongdanweiDizhi
        this.$set(this.param, 'qita', '/')
        this.departmentId = this.ysjl.departmentId
        // 制造日期、投用日期、上次检验日期设置成正确的日期格式
        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)
      })
    },
    handleChange(v) {
      this.ysjl.departmentId = v[1]
    },
    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) {
      let url = ''
      let data = {}
      if (this.state === 'create') {
        url = '/jyxm/getCyJyxm'
        data = {
          templateId: this.$route.query.templateId,
          order: sort
        }
      } else {
        url = '/jyxm/getCyJyxmByYsjl'
        data = {
          ysjlId: this.ysjlId,
          isReport: false,
          templateId: this.$route.query.templateId,
          order: sort
        }
      }
      this.api({
        url: url,
        method: 'get',
        params: data
      }).then(data => {
        if (this.state === 'create') {
          data.forEach(row => {
            this.sybjSData.push({
              id: row.id,
              jianyanxiang: row.jianyanxiang,
              jianyanneirong: row.jianyanneirong,
              D1: row.jianyanjieguo
            })
          })
        } else {
          data.forEach(row => {
            this.sybjSData.push({
              id: row.id,
              jianyanxiang: row.jianyanxiang,
              jianyanneirong: row.jianyanneirong,
              D1: row.D1
            })
          })
        }
        this.tableJs.getData(this.cols, this.rows, 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,
          beizhu: row.beizhu,
          dicJyxmId: row.dicJyxmId,
          jianyanjieguo: row.jianyanjieguo ? row.jianyanjieguo : '',
          jianyanjielun: row.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>
