licp
2024-05-28 df85764203947543c0ced0a0cdf8b7299f6b40ff
src/views/quality/rawMaterial/rawMaterial-form.vue
@@ -28,16 +28,16 @@
            </el-col>
              <el-col :span="6">
                <el-form-item label="零件号" prop="code">
                <el-input v-model="dataForm.code">
                <el-input v-model="dataForm.code" :disabled="dataForm&&dataForm.id!==null&&dataForm.id!==''">
                  <el-button
                    slot="append"
                    icon="el-icon-search"
                    :disabled="(resultVal!=null && resultVal!='')"
                    :disabled="dataForm&&dataForm.id!==null&&dataForm.id!==''"
                    @click="queryCode"></el-button>
                    <el-button
                    slot="append"
                    icon="el-icon-full-screen"
                    :disabled="(resultVal!=null && resultVal!='')"
                    :disabled="dataForm&&dataForm.id!==null&&dataForm.id!==''"
                    @click="Turnonthecamera"></el-button>
                </el-input>
                </el-form-item>
@@ -86,16 +86,16 @@
                </el-col>
                <el-col :span="6">
                  <el-form-item label="数量" prop="number">
                      <el-input v-model="dataForm.number" :disabled="(resultVal!=null && resultVal!='')" />
                      <el-input v-model="dataForm.number" :disabled="dataForm&&dataForm.id!==null&&dataForm.id!==''" />
                  </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="6">
                    <el-form-item label="报检日期" prop="createTime">
                    <el-form-item label="报检日期" prop="startTime">
                        <el-date-picker
                        :disabled="dataForm.id!=null"
                        v-model="dataForm.createTime"
                        disabled
                        v-model="dataForm.startTime"
                        type="datetime"
                        format="yyyy-MM-dd HH:mm:ss"
                        value-format="yyyy-MM-dd HH:mm:ss"
@@ -103,18 +103,23 @@
                        </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item label="报检人" prop="createUser" v-if="dataForm.id!=null">
                <el-col :span="6" v-if="dataForm.id!=null">
                  <el-form-item label="报检人" prop="createUser" >
                        <el-input v-model="dataForm.createUser" disabled />
                  </el-form-item>
                </el-col>
                <el-col :span="6">
                  <el-form-item  prop="projectName" label="项目名称" v-if="dataForm.id!=null">
                <el-col :span="6" v-if="dataForm.id!=null">
                  <el-form-item  prop="projectName" label="项目名称" >
                    <el-tooltip :disabled="dataForm.projectName==null" :content="dataForm.projectName">
                      <el-input v-model="dataForm.projectName" disabled ></el-input>
                    </el-tooltip>
                  </el-form-item>
              </el-col>
              <el-col :span="6">
                    <el-form-item label="备注" prop="remark">
                        <el-input :disabled="dataForm&&dataForm.id!==null&&dataForm.id!==''" v-model="dataForm.remark" />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
      </div>
@@ -124,6 +129,9 @@
            <el-row style="width:100%;z-index: 10;height:50px;" v-if="resultVal==null">
                <el-col :span="12"></el-col>
                <el-col :span="12" style="text-align: right;">
                    <el-button v-if="dataForm.id&&resultVal==null" size="small"
                    type="primary"
                    @click="saveTable()">保存</el-button>
                  <el-button v-if="dataForm.id==null" size="small" @click="clickAddLine()">添加检验项目</el-button>
                  <el-button class="pad-addcol-btn" v-if="resultVal==null || dataForm.id==null" size="small" @click="addTeatValueColumn()">添加检测值列</el-button>
                  <el-button v-if="resultVal==null || dataForm.id==null" size="small" @click="delTeatValueColumn()">删除检测值列</el-button>
@@ -149,21 +157,30 @@
                      </el-table-column>
                      <el-table-column prop="father" label="检验项目" width="160">
                        <template slot-scope="scope">
                          <el-input v-if="scope.row.children" style="width:80%" :disabled="dataForm.id!=null" v-model="scope.row.father" placeholder="请输入检验项目"></el-input>
                          <el-input v-if="scope.row.children" style="width:80%" :disabled="dataForm.id!=null&&(resultVal!=null && resultVal!='')" v-model="scope.row.father" placeholder="请输入检验项目"
                          :ref="'inspectProject'+scope.$index"
                          :id="'inspectProject'+scope.$index"
                          @keyup.native="moveFocus($event, scope.$index, 'inspectProject')"></el-input>
                        </template>
                      </el-table-column>
                      <el-table-column prop="name" label="项目" width="160">
                        <template slot-scope="scope">
                        <div v-if="!scope.row.children">
                          <el-input class="inline-input" :disabled="dataForm.id!=null" v-model="scope.row.name"
                            placeholder="请输入项目名称"></el-input>
                          <el-input class="inline-input" :disabled="dataForm.id!=null&&(resultVal!=null && resultVal!='')" v-model="scope.row.name"
                            placeholder="请输入项目名称"
                            :ref="'project'+scope.$index"
                            :id="'project'+scope.$index"
                             @keyup.native="moveFocus($event, scope.$index, 'project')"></el-input>
                      </div>
                          </template>
                      </el-table-column>
                      <el-table-column prop="unit" label="单位" width="160">
                        <template slot-scope="scope">
                        <div v-if="!scope.row.children">
                          <el-input :disabled="dataForm.id != null" v-model="scope.row.unit" placeholder="请输入单位"></el-input>
                          <el-input :disabled="dataForm.id!=null&&(resultVal!=null && resultVal!='')" v-model="scope.row.unit" placeholder="请输入单位"
                          :ref="'unit'+scope.$index"
                          :id="'unit'+scope.$index"
                          @keyup.native="moveFocus($event, scope.$index, 'unit')"></el-input>
                        </div>
                        </template>
@@ -171,8 +188,11 @@
                      <el-table-column prop="required" label="标准值" width="160">
                        <template slot-scope="scope">
                          <div v-if="!scope.row.children">
                          <el-input :disabled="dataForm.id != null" v-model="scope.row.required"
                            placeholder="请输入标准值"></el-input>
                          <el-input :disabled="dataForm.id!=null&&(resultVal!=null && resultVal!='')" v-model="scope.row.required"
                            placeholder="请输入标准值"
                            :ref="'standard'+scope.$index"
                            :id="'standard'+scope.$index"
                             @keyup.native="moveFocus($event, scope.$index, 'standard')"></el-input>
                          </div>
                        </template>
                      </el-table-column>
@@ -185,13 +205,16 @@
                            <el-tooltip :disabled="scope.row.deviceId != null" class="item" effect="dark" content="请先选择设备!" placement="top-start">
                                <el-autocomplete clearable
                                cache="false"
                                ref="testValueInput"
                                @blur="checkTestValues(scope.row,'blur',$event)"
                                @select="checkTestValues(scope.row,'select',$event)"
                                :disabled="scope.row.deviceId == null ||  (dataForm.id!=null&&(resultVal!=null && resultVal!=''))"
                                :disabled="scope.row.deviceId == null ||  (dataForm.id!=null&&(resultVal!=null && resultVal!=''))"
                                v-model="scope.row.testValueList[index]"
                                :fetch-suggestions="querySearch"
                                placeholder="请输入或选择检测值" >
                                placeholder="请输入或选择检测值"
                                :ref="`detectionValue${index}`+scope.$index"
                                :id="`detectionValue${index}`+scope.$index"
                                @keyup.native="moveFocus($event, scope.$index, `detectionValue${index}`)"
                                popper-class="no-keyboard-events">
                                <template slot-scope="{ item }">
                                    <div>{{ item.value }}</div>
                                </template>
@@ -220,7 +243,10 @@
                      <el-table-column prop="note" label="检验描述" width="160" >
                        <template slot-scope="scope">
                          <div v-if="!scope.row.children">
                            <el-input @blur="checkTestValues(scope.row,'blur',$event)" :disabled="scope.row.deviceId == null ||  (dataForm.id!=null&&(resultVal!=null && resultVal!=''))" v-model="scope.row.note" placeholder="检验描述"></el-input>
                            <el-input @blur="checkTestValues(scope.row,'blur',$event)" :disabled="scope.row.deviceId == null ||  (dataForm.id!=null&&(resultVal!=null && resultVal!=''))" v-model="scope.row.note" placeholder="检验描述"
                            :ref="`remark`+scope.$index"
                            :id="`remark`+scope.$index"
                            @keyup.native="moveFocus($event, scope.$index, `remark`)"></el-input>
                          </div>
                        </template>
                      </el-table-column>
@@ -275,7 +301,7 @@
            </div>
            <el-table :data="processConfigFileTableData" height="260px">
              <el-table-column
                prop="rawInsNo"
                prop="no"
                align="center"
                width="120"
                label="原材料检验编号"
@@ -305,11 +331,12 @@
              ></el-table-column>
              <el-table-column align="center" label="操作">
                <template slot-scope="scope">
                    <!-- :disabled="(resultVal!=null && resultVal!='')" -->
                  <el-button
                    @click="delProcessConfigFile(scope.row)"
                    type="text"
                    size="small"
                    :disabled="(resultVal!=null && resultVal!='')"
                    >删除</el-button
                  >
                  <el-button
@@ -402,6 +429,7 @@
  getObj,
  updateRawInsProduct,
  updateRawInspectsById,
  updateRawInsProduct2,
  updateDeviceById, chooseIFS} from '@/api/quality/rawMaterial'
  import {
    getProcessConfigFiles,
@@ -460,6 +488,7 @@
                unit: '',
                number: '',
                supplier: '',
                remark:'',
                rawInsProducts: [{
                  deviceId: 0,
                  father:'',
@@ -481,9 +510,11 @@
            }],
            dataRule: {
              code:[{ required: true, message: '请扫描选择零件', trigger: 'blur' }],
              createTime: [{ required: true, message: '请选择报检日期', trigger: 'blur' }]
            //   startTime: [{ required: true, message: '请选择报检日期', trigger: 'blur' }]
            },
            deviceList: [],
            keyfield:['inspectProject','project','unit','standard','remark'],
            keyfield0:['detectionValue0']
        }
    },
    beforeUpdate(){
@@ -507,6 +538,18 @@
          this.unqualifiedNum = null
        }
      },
      empiricalValueAdd(newVal){
        if(newVal!=this.keyfield0.length){
            if(newVal>this.keyfield0.length){
                this.keyfield0 = []
                for(let i=0;i<newVal;i++){
                    this.keyfield0.push('detectionValue'+i)
                }
            }else{
                this.keyfield0.splice(this.keyfield0.length-1,1);
            }
        }
      }
    },
    methods:{
      querySearch(queryString, cb){
@@ -620,6 +663,7 @@
          this.dataForm.code = param.code
          this.dataForm.name = param.name
          this.dataForm.formTime = param.formTime
          this.dataForm.startTime = param.formTime
          this.dataForm.unit = param.unit
          this.dataForm.specs = param.specs
          this.dataForm.supplier = param.supplier
@@ -699,7 +743,9 @@
        });
      },
      addTeatValueColumn(){
        this.empiricalValueAdd = this.empiricalValueAdd + 1;
        this.$nextTick(()=>{
            this.empiricalValueAdd = this.empiricalValueAdd + 1;
        })
      },
      // 添加行
      clickAddLine(row,index) {
@@ -760,32 +806,35 @@
          if(this.list){
              this.list.forEach(e=>{
                  if(e.children){
                      e.children.forEach(i=>{
                      e.children.map(i=>{
                          if(i.testValueList.length>1){
                              let arr = i.testValue.split(",")
                              arr.splice((arr.length-1),1)
                              let obj = {
                                deviceId: i.deviceId,
                                rpId: i.rpId,
                                testValue: arr.join(","),
                                note: i.note
                              }
                              updateRawInsProduct(obj).then(res=>{
                                if(res.data.code === 0){
                                  this.init(this.dataForm.id)
                                }
                              })
                            i.testValueList = i.testValueList.splice(i.testValueList.length-1,1)
                            return i
                            //   let arr = i.testValue.split(",")
                            //   arr.splice((arr.length-1),1)
                            //   let obj = {
                            //     deviceId: i.deviceId,
                            //     rpId: i.rpId,
                            //     testValue: arr.join(","),
                            //     note: i.note
                            //   }
                            //   updateRawInsProduct(obj).then(res=>{
                            //     if(res.data.code === 0){
                            //       this.init(this.dataForm.id)
                            //     }
                            //   })
                          }
                      })
                  }
              })
              this.saveTable()
          }
      },
      delTeatValueColumn(){
        if (this.empiricalValueAdd - 1 > 0) {
          if (this.empiricalValueAddMaxNumber != this.empiricalValueAdd - 1) {
            this.empiricalValueAdd = this.empiricalValueAdd - 1;
            this.changeRowResult()
            // this.changeRowResult()
            this.list.forEach(i => {
              if(i.children){
                i.children.forEach(ele=>{
@@ -793,6 +842,7 @@
                })
              }
            });
            this.saveTable()
          }
        }
      },
@@ -803,6 +853,8 @@
            this.dataForm.rawInsNo = data.rawInsNo
            this.dataForm.name = data.name
            this.dataForm.formTime = data.formTime
            this.dataForm.startTime = data.startTime
            this.dataForm.remark = data.remark
            this.dataForm.code = data.code
            this.dataForm.specs = data.specs
            this.dataForm.unit = data.runit
@@ -915,30 +967,35 @@
              if(!isTrue){
                  return
              }
              this.changeState(row)
            //   this.changeState(row)
          }
      },
      changeState(row) {
      saveTable() {
        let rawInsProducts = [];
          this.$nextTick(()=>{
            if (row.rpId != null && row.rpId != '') {
                let val = row.testValueList.join(",")
                if (val === undefined || val === '' || val === null) {
                    return
            this.list.forEach(item=>{
                if(item.children){
                    item.children.forEach(ele=>{
                        let obj = JSON.parse(JSON.stringify(ele))
                        obj.testValue = obj.testValueList.join(",")
                        obj.id = obj.rpId
                        delete obj.testValueList;
                        obj.name = ele.name;
                        obj.father = item.father;
                        obj.unit = ele.unit;
                        rawInsProducts.push(obj)
                    })
                }
                let obj = {
                    deviceId: row.deviceId,
                    rpId: row.rpId,
                    testValue: val,
                    note: row.note
                }
              updateRawInsProduct(obj).then(res => {
                  if (res.data.code == 0) {
                      this.$message.success("更新成功")
                  } else {
                      this.$message.error("更新失败")
                  }
                  this.init(this.dataForm.id)
              })
            })
            if(rawInsProducts.length>0){
                updateRawInsProduct2(rawInsProducts).then(res => {
                    if (res.data.code == 0) {
                        this.$message.success("更新成功")
                    } else {
                        this.$message.error("更新失败")
                    }
                    this.init(this.dataForm.id)
                })
            }
        })
      },
@@ -989,12 +1046,13 @@
                this.list.forEach(item=>{
                item.children.forEach(c=>{
                    c.testValue=c.testValueList.join(",")
                    c.required = c.required.replace(',',',').replace('(','(').replace(')',')')
                })
                })
                data.rawInsProducts = this.list
                addRawInspects(data).then(res=>{
                    this.$message.success("保存成功")
                    // this.$router.go(-1)
                    this.$router.go(-1)
                }).catch(error=>{
                this.$message.error(error)
                })
@@ -1009,11 +1067,134 @@
          this.deviceList = res.data.data
        })
      },
    },
      moveFocus(event, index, key) {
        console.log(key, index,key)
        let keyfield = this.insertArrayAt(this.keyfield,4,this.keyfield0);
        // enter键
        // if (event.keyCode === 13) { // 回车
        //     if (index === this.getLen() - 1 && key === keyfield[keyfield.length - 1]) { // 最后一行最后一个
        //         console.log('最后一行最后一个无法回车')
        //     return
        //     }
        //     this.$nextTick(() => {
        //         event.target.blur()
        //     })
        //     if (key === keyfield[keyfield.length - 1]) { // 当前行最后一个,跳转下一行第一个
        //     } else { // 跳转下一个
        //     const nextkeyindex = keyfield.findIndex(k => k === key) + 1
        //     this.$nextTick(() => {
        //         document.getElementById(keyfield[nextkeyindex] + index).focus()
        //     })
        //     }
        // }
        // 向上 =38
        if (event.keyCode === 38) {
            console.log('向上')
            if (index === 0) { // 第一行
            console.log('第一行无法向上')
            return
            }
            document.getElementById(key + index).blur()
            if(key.includes('detectionValue')){
                this.$refs[key + index][0].activated = false;
            }
            let i = 0;
            while (true){
                let dom = document.getElementById(key + (index - 1-i))
                if(dom){
                    dom.focus()
                    return
                }else if((index-1-i)==0){
                    return
                }
                i++
            }
        }
        // 下 = 40
        if (event.keyCode === 40) {
            console.log('向下')
            if (index === this.getLen() - 1) { // 最后一行
            console.log('最后一行无法向下')
            return
            }
            document.getElementById(key + index).blur()
            if(key.includes('detectionValue')){
                this.$refs[key + index][0].activated = false;
            }
            this.$nextTick(() => {
            let i = 0;
            while (true){
                let dom = document.getElementById(key + (index + 1+i))
                console.log(dom,key + (index + 1+i))
                if(dom){
                    dom.focus()
                    return
                }else if((index+1+i)==this.getLen() - 1){
                    return
                }
                i++
            }
            })
        }
        // 左 = 37
        if (event.keyCode === 37) {
            console.log('向左')
            if (index === 0 && key === keyfield[0]) { // 第一行第一个
            console.log('第一行第一个无法向左')
            return
            }
            document.getElementById(key + index).blur()
            const prevkeyindex = keyfield.findIndex(k => k === key) - 1
            this.$nextTick(() => {
                let dom = document.getElementById(keyfield[prevkeyindex] + index)
                if(dom){
                    dom.focus()
                }
            })
        }
        // 右 = 39
        if (event.keyCode === 39) {
            console.log('向右')
            if (index === this.getLen() - 1 && key === keyfield[keyfield.length - 1]) { // 最后一行最后一个
            console.log('最后一行最后一个无法向右')
            return
            }
            document.getElementById(key + index).blur()
            const nextkeyindex = keyfield.findIndex(k => k === key) + 1
            this.$nextTick(() => {
                let dom = document.getElementById(keyfield[nextkeyindex] + index)
                if(dom){
                    dom.focus()
                }
            })
        }
        },
      insertArrayAt(arr1, index, arr2) {
        return arr1.slice(0, index).concat(arr2, arr1.slice(index));
        },
        getLen(){
        let arr = []
        this.list.forEach(item => {
            arr.push(item)
            item.children.forEach(child => {
                arr.push(child)
            })
        })
        return arr.length
      }
      }
}
</script>
<style>
/* .no-keyboard-events * {
  pointer-events: none;
} */
.rawMaterial-detail {
  width: 100%;
  height: 530px;