<!--衍射时差法(TOFD)超声检测记录-->
<template>
  <div class="app-container">
    <sticky style="margin-bottom: 10px;">
      <btn ref="btn" />
    </sticky>
    <el-form ref="ysjl" :model="ysjl" class="el-form" label-position="right" label-width="130px">
      <fieldset>
        <legend>基本信息</legend>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="记录编号" prop="jilubianhao">
              <el-input v-model="ysjl.jilubianhao" disabled />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="检测仪器型号" prop="yiqixinghao">
              <el-input v-model="param.yiqixinghao" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="检测仪器编号" prop="yiqibianhao">
              <el-input v-model="param.yiqibianhao" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="探头型号" prop="tantouxinghao">
              <el-input v-model="param.tantouxinghao" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="试块型号" prop="shikuaixinghao">
              <el-input v-model="param.shikuaixinghao" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="22">
          <el-col :span="9">
            <el-form-item label="评定灵敏度" prop="pingdinglingmindu">
              <el-input v-model="param.pingdinglingmindu" :disabled="edit">
                <template slot="append">
                  (dB)
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="扫差方法/扫查面" prop="jiancefangfa">
              <el-input v-model="param.jiancefangfa" :disabled="edit" style="width:110px" /> / <el-select v-model="tempSaochamian" :disabled="edit" filterable allow-create multiple default-first-option placeholder="请选择" style="width:180px">
                <el-option label="单侧" value="单侧" />
                <el-option label="双侧" value="双侧" />
                <el-option label="单面" value="单面" />
                <el-option label="双面" value="双面" />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="耦合剂" prop="ouheji">
              <el-input v-model="param.ouheji" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="补偿" prop="buchang">
              <el-input v-model="param.buchang" :disabled="edit">
                <template slot="append">
                  (dB)
                </template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="检测标准" prop="jiancebiaozhun">
              <el-input v-model="param.jiancebiaozhun" :disabled="edit" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="检测比例" prop="jiancebili">
              <el-input v-model="param.jiancebili" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="操作指导书编号" prop="caozuozhidaoshubianhao">
              <el-input v-model="param.caozuozhidaoshubianhao" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
      </fieldset>
      <fieldset>
        <legend>检测结果评定表</legend>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="通道间距" prop="tongdaojianju">
              <el-input v-model="param.tongdaojianju" :disabled="edit" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-table ref="tableData1" :data="tableData1" class="myTable" border stripe style="width:100%;margin-top: 5px;">
          <el-table-column align="center" prop="C1" width="120px" label="通道" />
          <el-table-column align="center" label="技术参数">
            <el-table-column align="center" prop="C2" width="120px" label="探头频率（MHz）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C2" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C3" width="120px" label="晶片尺寸（mm）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C3" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C4" width="120px" label="楔块角度（°）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C4" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C5" width="120px" label="探头中心间距（mm）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C5" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C6" width="120px" label="探头延迟（μs）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C6" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C7" width="120px" label="检测范围">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C7" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
            <el-table-column align="center" prop="C8" width="120px" label="对比试块">
              <template slot-scope="scope">
                <el-input v-model="scope.row.C8" :disabled="edit" size="mini" />
              </template>
            </el-table-column>
          </el-table-column>
        </el-table>
      </fieldset>
      <fieldset>
        <legend>检测结果评定表</legend>
        <el-button type="success" icon="el-icon-download" size="mini" style="margin-right: 10px;" @click="common.downloadTemplate('压力容器衍射时差法检测记录表.xlsx')">
          下载导入模板
        </el-button>
        <el-upload
          :show-file-list="false"
          :before-upload="uploadTableData"
          style="float: left; margin-right: 10px;"
          action="123"
        >
          <el-button type="primary" size="mini" icon="el-icon-upload" :disabled="edit">
            导入数据
          </el-button>
        </el-upload>
        <el-button v-if="state !== 'bgView'" type="success" size="mini" icon="el-icon-circle-plus-outline" :disabled="edit" @click="addRow()">
          添加
        </el-button>
        <el-button v-if="state !== 'bgView'" type="danger" size="mini" icon="el-icon-remove-outline" :disabled="edit" @click="delRow()">
          删除
        </el-button>
        <el-table ref="tableData2" :data="tableData2" :row-class-name="tableRowClassName" class="myTable" border stripe style="width:100%;margin-top: 5px;" @row-click="onRowClick" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="40" />
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="center" width="100px" label="区段编号">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C1" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C2" width="140px" label="检测数据文件名称">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C2" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C3" width="120px" label="缺陷位置">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C3" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C4" width="110px" label="缺陷埋藏深度(mm)">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C4" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C5" width="110px" label="缺陷指示长度(mm)">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C5" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C6" width="120px" label="缺陷高度(mm)">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C6" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C7" width="100px" label="评定级别">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C7" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
          <el-table-column align="center" prop="C8" width="100px" label="备注">
            <template slot-scope="scope">
              <el-input v-model="scope.row.C8" :disabled="edit" size="mini" />
            </template>
          </el-table-column>
        </el-table>
      </fieldset>
      <fieldset>
        <legend>检测信息</legend>
        <el-form-item label="检测结果" prop="jiancejieguo">
          <el-input v-model="param.jiancejieguo" :disabled="edit" type="textarea" rows="5" />
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="检测人员" prop="jianyanrenyuan">
              <el-input v-model="jianyanrenyuan" disabled />
              <el-input v-show="false" v-model="ysjl.jianyanrenyuan" />
            </el-form-item>
          </el-col>
          <el-col v-if="state !== 'bgView'" :span="9">
            <sign-name :ysjl="ysjl" :jianyanrenyuan="jianyanrenyuan" :disabled="edit" @setSignValue="singNameValue" />
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="9">
            <el-form-item label="检测日期" prop="jianyanjieshuriqi">
              <el-date-picker v-model="ysjl.jianyanjieshuriqi" :disabled="edit" type="date" value-format="yyyy-MM-dd" placeholder="选择日期" style="width: 100%;" />
            </el-form-item>
          </el-col>
        </el-row>
      </fieldset>
    </el-form>
  </div>
</template>
<script>
import Sticky from '@/components/Sticky'
import SignName from '@/views/common/SignName'
import btn from '@/views/common/WsButton'
import Utils from '../../../../../utils/contact.js'
export default {
  name: 'RqZbgTofd',
  components: { SignName, Sticky, btn },
  data() {
    return {
      ysjl: {},
      param: {},
      tableData1: [{ C1: '通道一' }, { C1: '通道二' }, { C1: '通道三' }, { C1: '通道四' }],
      tableData2: [],
      delRowIndex2: [],
      edit: false,
      departmentId: this.$route.query.departmentId,
      jianyanrenyuan: '',
      ysjlId: this.$route.query.id,
      state: '',
      tempSaochamian: [],
      info: {
        ysjlId: this.$route.query.id,
        jyxm: this.$route.query.jyxm,
        limit: 1
      }
    }
  },
  created() {
    this.getInfo()
  },
  methods: {
    // 签名方法
    singNameValue(data) {
      this.jianyanrenyuan = data.name
      this.ysjl.jianyanrenyuan = data.id
      if (this.state !== 'create') {
        this.common.signName(this.ysjl.id, this.ysjl.jianyanrenyuan)
        Utils.$emit('ysjl-list')
      }
    },
    getInfo() {
      this.api({
        url: '/wusun',
        method: 'get',
        params: {
          ysjlId: this.$route.query.id,
          jyxm: this.$route.query.jyxm
        }
      }).then(data => {
        this.ysjl = data.ysjl
        this.state = 'create'
        if (this.ysjl.jianyanrenyuan !== null && this.ysjl.jianyanrenyuan.length > 0) {
          this.jianyanrenyuan = this.common.convertCnName(this.ysjl.jianyanrenyuan)
        }
        if (data.param !== null && data.param !== undefined) {
          // 有无损原始记录参数
          this.state = 'update'
          this.param = data.param
          this.tempSaochamian = this.param.saochamian ? this.param.saochamian.split(';') : []
          this.tableData1 = data.param.fubiao2 === null || data.param.fubiao2 === undefined ? [] : JSON.parse(data.param.fubiao2)
          this.tableData2 = data.param.fubiao1 === null || data.param.fubiao1 === undefined ? [] : JSON.parse(data.param.fubiao1)
        } else {
          this.param = {
            caozuozhidaoshubianhao: 'RDAE-2019'
          }
        }
        if (this.ysjl.flowstatus !== null) {
          this.state = 'finish'
          this.edit = true
        }
        this.$refs.btn.getParentInfo(this.ysjl, this.param, this.tableData, this.state, true, false)
      })
    },
    addRow: function() {
      const d = {
      }
      this.tableData2.push(d)
      setTimeout(() => {
        this.$refs.tableData2.setCurrentRow(d)
      }, 10) // 用于延时渲染后选中这行
    },
    delRow: function() {
      if (this.delRowIndex2.length === 0) {
        this.$message({
          type: 'error',
          message: '请选中需要删除的数据！'
        })
        return false
      } else {
        // 对delRowIndex进行排序，因为删除一个元素后index值会变
        this.delRowIndex2.sort(function(x, y) {
          if (x < y) {
            return 1
          }
          if (x > y) {
            return -1
          }
          return 0
        })
        for (let i = 0; i < this.delRowIndex2.length; i++) {
          this.tableData2.splice(this.delRowIndex2[i], 1)
        }
        this.$refs.tableData2.clearSelection()
        this.delRowIndex2 = []
      }
    },
    // 表格单击选中行
    onRowClick(row) {
      this.$refs.tableData2.toggleRowSelection(row)
    },
    tableRowClassName({ row, rowIndex }) {
      row.index = rowIndex
    },
    handleSelectionChange(val) {
      this.delRowIndex2 = []
      for (let i = 0; i < val.length; i++) {
        this.delRowIndex2.push(val[i].index)
      }
    },
    changed(item) {
      this.param.imagePath = item
    },
    beforeSaveBuildData() {
      this.param.ysjlId = this.$route.query.id
      this.param.fubiao1 = this.tableData2
      this.param.fubiao2 = this.tableData1
      this.param.saochamian = this.tempSaochamian.join(';')
      this.ysjl.jianyanjielun = this.param.jiancejieguo
    },
    uploadTableData(file) {
      this.common.uploadTableData(file, this.tableData2)
    }
  }
}
</script>
<style>
  .myTable .el-input__inner{
    padding: 0px 5px;
    text-align: center;
  }
</style>
