chenhaozhe
2025-11-04 9a3ea87cd2f74d61eb0c1c25a3ab0dc505e1e182
components/ZLGL/InspectValueTemplate.vue
@@ -21,7 +21,7 @@
            </view>
            <view class="form-item">
                <view class="left">检验结果</view>
                <view class="right disabled">
                <view class="right" :class="CheckResultClass">
                    <input type="text" v-model="checkData.HResult2" disabled />
                </view>
            </view>
@@ -45,7 +45,7 @@
                        {{ checkData.HStatus?"合格":"不合格" }}
                    </view>
                    <view>
                        <switch style="width: 2em; transform:scale(0.7);" :checked="checkData.HStatus?'checked':''"
                        <switch style="width: 2em; transform:scale(0.7);" :checked="checkData.HStatus"
                            @change="HStatusChange" />
                    </view>
                </view>
@@ -53,25 +53,26 @@
            <view class="form-item">
                <view class="left">比较符</view>
                <view class="right disabled">
                    <input type="text" v-model="checkData.HResult2" disabled />
                    <uni-combox :candidates="HCompareSymbolList" v-model="checkData.HCompareSymbol"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="left">单位</view>
                <view class="right disabled">
                    <input type="text" v-model="checkData.HTargetVal" disabled />
                    <uni-combox :candidates="UnitNameList" v-model="checkData.HUnitName"></uni-combox>
                    <!-- <input type="text" v-model="checkData.HTargetVal" /> -->
                </view>
            </view>
            <view class="form-item">
                <view class="left">检验值</view>
                <view class="right disabled">
                    <input type="text" v-model="checkData.HInSpectVal" disabled />
                <view class="right">
                    <input type="text" v-model="checkData.HInSpectVal" />
                </view>
            </view>
            <view class="form-item">
                <view class="left">目标值</view>
                <view class="right disabled">
                    <input type="text" v-model="checkData.HTargetVal" disabled />
                <view class="right ">
                    <input type="text" v-model="checkData.HTargetVal" />
                </view>
            </view>
            <view class="form-item">
@@ -120,7 +121,7 @@
                        </view>
                        <view>
                            <switch style="width: 3em; transform:scale(0.7);"
                                :checked="item.HInSpectResult == 1?'checked':''"
                                :checked="item.HInSpectResult == 1"
                                @change="HInSpectResultChange(index, $event)" />
                        </view>
                    </view>
@@ -128,8 +129,10 @@
                        <uni-combox v-if="checkData.HAnalysisMethod == 1" :candidates="InitInSpectValNameList"
                            v-model="item.HInSpectValueB_Text"
                            @update:modelValue="HInSpectValueBChange(index, $event)"></uni-combox>
                        <input v-else-if="checkData.HAnalysisMethod == 2" type="number" v-model="item.HInSpectValue" />
                        <input v-else type="number" v-model="item.HInSpectValueT" />
                        <input v-else-if="checkData.HAnalysisMethod == 2" type="number" v-model="item.HInSpectValue"
                            @blur="InSpectValueChange(item,index)" @confirm="InSpectValueChange(item,index)" />
                        <input v-else type="number" v-model="item.HInSpectValueT"
                            @blue="InSpectValueTChange(item, index)" @confirm="InSpectValueTChange(item, index)" />
                    </view>
                </view>
            </view>
@@ -153,10 +156,18 @@
                    HResDec: 2,
                    HResult2: '',
                    HStatus: true,
                    HCompareSymbol: "=", // 默认为=号
                    HUnitName: ''
                },
                InSpectValues: [],
                InitInSpectValNameList: [],
                InitInSpectValList: [],
                UnitNameList: [],
                UnitList: [],
                CheckResultClass: 'disable',
                HCompareSymbolList: ["=", ">", ">=", "<", "<=", "<>", "between"]
            };
        },
        props: {
@@ -175,7 +186,8 @@
                data,
                list
            } = this.bindData
            this.checkData = Object.assign(data, JSON.parse(JSON.stringify(this.bindData)))
            Object.assign(this.checkData, data, JSON.parse(JSON.stringify(this.bindData)))
            this.checkData.HStatus = this.checkData.HStatus ? true : false
            // 判断是否有缓存数据或者缓存数据是否与样本数一致
            if (!list || list.length != this.checkData.HSampleQty) {
                for (let index = 0; index < this.checkData.HSampleQty; index++) {
@@ -192,16 +204,125 @@
                this.InSpectValues = list
            }
            this.InitInSpectVal()
            this.InitUnit()
            // 实例挂载后,获取InterID 和 EntryID 对应的检验项目的检验值
            this.getValueList()
            this.$forceUpdate()
        },
        watch: {
            "checkData.HResult2"(newVal, oldVal) {
                if (newVal == '合格') {
                    this.CheckResultClass = 'pass-background'
                } else if (newVal == '不合格') {
                    this.CheckResultClass = 'unpass-background'
                } else {
                    this.CheckResultClass = 'disabled'
                }
            }
        },
        beforeDestroy() {
            // 注销前,提交数据的检验值, 并将最后一次提交的检验值同步至父模块
            // 注销前,提交数据的检验值
            this.set_SaveValue()
            this.$emit("syncCheckData", this.checkData)
        },
        methods: {
            // 其他分析 检验值变化时判断
            InSpectValueTChange(item, index) {
                console.log('item,: ', item);
                this.HInSpectResultChange(index, {
                    detail: {
                        value: this.checkValuePass(item.HInSpectValueT)
                    }
                })
            },
            // 定量分析 检验值变化时判断
            InSpectValueChange(item, index) {
                console.log('item,: ', item);
                this.HInSpectResultChange(index, {
                    detail: {
                        value: this.checkValuePass(item.HInSpectValue)
                    }
                })
            },
            checkValuePass(val) {
                console.log('val: ', val);
                console.log('this.checkData.HTargetVal: ', this.checkData.HTargetVal);
                switch (this.checkData.HCompareSymbol) {
                    case '=':
                        if (val == this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case '>':
                        if (val > this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case '>=':
                        if (val >= this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case '<':
                        if (val < this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case '<=':
                        if (val <= this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case '<>':
                        if (val != this.checkData.HTargetVal) {
                            return true
                        };
                        break;
                    case 'between':
                        if (val >= (this.checkData.HTargetVal - this.checkData.HDownLimit || 0) &&
                            val <= (this.checkData.HTargetVal + this.checkData.HUpLimit || 0)) {
                            return true
                        };
                        break;
                    default:
                        CommonUtils.showTips({
                            message: '请选择比较符'
                        })
                }
            },
            // 初始化 单位
            async InitUnit() {
                let res = await CommonUtils.doRequest2Async({
                    url: '/Gy_Unit/list1',
                    data: {
                        sWhere: ` and 禁用标记 = '' and 审核人 != ''`,
                        user: getUserInfo()['Czymc'],
                        Organization: uni.getStorageSync("Organization")
                    }
                })
                let {
                    data,
                    count,
                    Message
                } = res.data
                if (!count) {
                    CommonUtils.showTips({
                        title: '温馨提示',
                        message: `初始化单位错误: ${Message}`
                    })
                } else {
                    this.UnitNameList = Array.from(data).map(e => e["计量单位名称"])
                    this.UnitList = data
                }
            },
            // 单位 修改 监听
            UnitChange(e) {
            },
            async set_SaveValue() {
                console.log("InSpect Values: ", this.InSpectValues)
                try {
@@ -250,17 +371,16 @@
                        count
                    } = res.data
                    if (count == 1) {
         //                if (this.InSpectValues.length >= data.length) {
         //                    console.log('data: ',data);
         //                    console.log('this.InSpectValues: ',this.InSpectValues);
         //                } else {
         //                    this.InSpectValues = data.slice(0, this.InSpectValues.length)
         //                }
         this.InSpectValues = data
                        // 当前 检验值页签中 保存的数据个数和数据库中的个数大 或者相等,取数据库中的数据,多的补空
                        if (this.InSpectValues.length >= data.length) {
                            let InSpectValuesNew = this.InSpectValues.slice(data.length, this.InSpectValues.length)
                            this.InSpectValues = [...data, ...InSpectValuesNew]
                        } else {
                            // 截取当前保存的数据
                            this.InSpectValues = data.slice(0, this.InSpectValues.length)
                        }
                        // this.InSpectValues = data
                    }
                } catch (err) {
                    CommonUtils.showTips({
@@ -332,15 +452,37 @@
            },
            HInSpectResultChange(index, e) {
                console.log('e: ', e.detail.value);
                this.InSpectValues[index].HInSpectResult = e.detail.value?1:2
                this.InSpectValues[index].HInSpectResult = e.detail.value ? 1 : 2
                this.CheckPassNum()
            },
            CheckPassNum() {
                let unPassNum = this.InSpectValues.map(elem => elem.HInSpectResult).filter(elem => elem != 1).length
                this.checkData.HSampleUnRightQty = unPassNum
                let unRightQty = this.checkData.HAcceptQty
                if (this.checkData.HStatus) { // true 为 检验合格, false为检验 不合格
                    if (unPassNum > unRightQty) {
                        this.checkData.HResult2 = '不合格'
                    } else {
                        this.checkData.HResult2 = '合格'
                    }
                } else {
                    if (this.InSpectValues.length - unPassNum > unRightQty) {
                        this.checkData.HResult2 = '不合格'
                    } else {
                        this.checkData.HResult2 = '合格'
                    }
                }
            }
        },
    }
</script>
<style lang="scss">
<style lang="scss" scoped>
    input {
        height: inherit;
        width: inherit;
@@ -382,6 +524,21 @@
                display: flex;
                flex-direction: row;
                align-items: center;
                .uni-combox {
                    padding: 0;
                    height: auto;
                    .uni-input-placeholder,
                    .uni-input-input {
                        font-size: 26rpx;
                    }
                }
                .uni-combox::v-deep input {
                    height: inherit;
                    font-size: 26rpx;
                }
            }
            .disabled {
@@ -389,12 +546,24 @@
                background-color: #e4e4e4;
            }
            .pass-background {
                background-color: #CEE3F2;
                border: none;
            }
            .unpass-background {
                background-color: #F0D6E3;
                border: none;
            }
            .none-border {
                border: none;
            }
        }
    }
    .InSpect-value-list {
        box-sizing: border-box;
        display: flex;