licp
2024-05-22 ef4e46f182aee6253805e66286dee847c573cbde
src/views/quality/processInspect/processInspect-form.vue
@@ -146,7 +146,9 @@
                                                    class="item" effect="dark" content="请先选择设备!" placement="top-start">
                                                    <el-input :disabled="scope.row.eId == null"
                                                        v-model="scope.row.empiricalValueAddss[index]"
                                                        @blur="changeState(scope.row,true)" placeholder="请输入检测值"></el-input>
                                                        @blur="changeState(scope.row,true)" placeholder="请输入检测值"
                                                        :id="`detectionValue${index}`+scope.$index"
                                @keyup.native="moveFocus($event, scope.$index, `detectionValue${index}`)"></el-input>
                                                    <span v-if="resultVal != null && processInspectVo.id != null"
                                                        v-text="scope.row.empiricalValueAddss[index]"></span>
                                                </el-tooltip>
@@ -192,7 +194,9 @@
                                                    class="item" effect="dark" content="请先选择设备!" placement="top-start">
                                                    <el-input :disabled="scope.row.eId == null"
                                                        v-model="scope.row.inote"
                                                        @blur="changeState(scope.row)" placeholder="请输入检验描述"></el-input>
                                                        @blur="changeState(scope.row)" placeholder="请输入检验描述"
                                                        :id="`remark`+scope.$index"
                            @keyup.native="moveFocus($event, scope.$index, `remark`)"></el-input>
                                                    <span v-if="resultVal != null && processInspectVo.id != null"
                                                        v-text="scope.row.inote"></span>
                                                </el-tooltip>
@@ -516,10 +520,24 @@
            inspectionItems: [], // 新增检验项目表格
            inspectionResultForm: [],
            configFileTableData:[],
            dataForm:null
            dataForm:null,
            keyfield:['remark'],
            keyfield0:['detectionValue0']
        }
    },
    watch: {
        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);
            }
        }
      }
    },
    beforeUpdate() {
        this.$nextTick(() => {
@@ -1022,7 +1040,121 @@
        // 添加检验值列
        clickAddInspectionColumn() {
            this.empiricalValueAdd = this.empiricalValueAdd + 1;
        },
        moveFocus(event, index, key) {
        console.log(key, index,key)
        let keyfield = this.insertArrayAt(this.keyfield,0,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()
            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()
            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.inspectionItems.forEach(item => {
            arr.push(item)
            item.children.forEach(child => {
                arr.push(child)
            })
        })
        return arr.length
      }
    },
}
</script>