zrg
2025-11-05 530ce8217f9828e1fbbe31a4d3d06b4a85c5383c
components/ZLGL/InspectValueTemplate.vue
@@ -1,6 +1,6 @@
<template>
    <view>
        <view class="inspect-value-content">
        <view class="InSpect-value-content">
            <view class="form-item">
                <view class="left">项目序号</view>
                <view class="right disabled">
@@ -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">
@@ -99,10 +100,10 @@
                </view>
            </view>
            <view style="width: 100%;border-bottom: 1px solid #e3e3e3;"></view>
            <view class="inspect-value-list">
                <view style="width: 100%;text-align: right;">
                    <button type="default" size="mini" class="btn-a" @click="storeInspectValue">缓存检验值</button>
                </view>
            <view class="InSpect-value-list">
                <!-- <view style="width: 100%;text-align: right;">
                    <button type="default" size="mini" class="btn-a" @click="storeInSpectValue">缓存检验值</button>
                </view> -->
                <view class="item" style="border-top: 2px solid #e3e3e3 ;">
                    <view class="th1">序号</view>
                    <view class="th2" style="display: flex; flex-direction: row; align-items: center;">
@@ -112,19 +113,26 @@
                        检验值({{getAnalysisMethodTitle(checkData.HAnalysisMethod)}})
                    </view>
                </view>
                <view class="item" v-for="(item, index) in inspectValues">
                <view class="item" v-for="(item, index) in InSpectValues">
                    <view class="th1">{{item.HSEQ}}</view>
                    <view class="th2" style="display: flex; flex-direction: row; align-items: center;">
                        <view style="width: 3em; ">
                            {{ item.HInspectResult?"合格":"不合格" }}
                            {{ item.HInSpectResult == 1?"合格":"不合格" }}
                        </view>
                        <view>
                            <switch style="width: 3em; transform:scale(0.7);" :checked="item.HInspectResult?'checked':''"
                                @change="HInspectResultChange(index, $event)" />
                            <switch style="width: 3em; transform:scale(0.7);"
                                :checked="item.HInSpectResult == 1"
                                @change="HInSpectResultChange(index, $event)" />
                        </view>
                    </view>
                    <view class="th3">
                        <input type="number" v-model="item.HInspectValue" />
                        <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"
                            @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>
@@ -133,17 +141,33 @@
</template>
<script>
    import {
        getUserInfo
    } from '../../utils/auth';
    import {
        CommonUtils
    } from '../../utils/common';
    // 检验值模板
    export default {
        name: "InspectValueTemplate",
        name: "InSpectValueTemplate",
        data() {
            return {
                checkData: {
                    HResDec: 2,
                    HResult2: '',
                    HStatus: true,
                    HCompareSymbol: "=", // 默认为=号
                    HUnitName: ''
                },
                inspectValues: []
                InSpectValues: [],
                InitInSpectValNameList: [],
                InitInSpectValList: [],
                UnitNameList: [],
                UnitList: [],
                CheckResultClass: 'disable',
                HCompareSymbolList: ["=", ">", ">=", "<", "<=", "<>", "between"]
            };
        },
        props: {
@@ -158,34 +182,267 @@
        },
        mounted() {
            console.log('bingData: ', this.bindData);
            let {data, list} = this.bindData
            this.checkData = Object.assign(data, JSON.parse(JSON.stringify(this.bindData)))
            let {
                data,
                list
            } = 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 ){
            if (!list || list.length != this.checkData.HSampleQty) {
                for (let index = 0; index < this.checkData.HSampleQty; index++) {
                    this.inspectValues.push({
                    this.InSpectValues.push({
                        HSEQ: index + 1,
                        HInspectResult: true,
                        HInspectValue: 0,
                        HInSpectResult: 1,
                        HInSpectValue: 0, // 定量检测值
                        HInSpectValueB: 0, // 定性检测ID
                        HInSpectValueB_Text: '', // 定性检测(内容)
                        HInSpectValueT: 0, // 其他检测值
                    })
                }
            }else {
                this.inspectValues = list
            } else {
                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: {
            storeInspectValue(){
                this.$emit("update", {
                    data: this.checkData,
                    list: this.inspectValues
            // 其他分析 检验值变化时判断
            InSpectValueTChange(item, index) {
                console.log('item,: ', item);
                this.HInSpectResultChange(index, {
                    detail: {
                        value: this.checkValuePass(item.HInSpectValueT)
                    }
                })
            },
            getAnalysisMethodTitle(type){
                if(type == 1) {
            // 定量分析 检验值变化时判断
            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 {
                    let res = await CommonUtils.doRequest2Sync({
                        url: '/QC_FirstPieceCheckBill/set_SaveValue',
                        data: {
                            msg: `${JSON.stringify(this.InSpectValues)};${this.checkData.HInterID};${this.checkData.num}`
                        },
                        method: "POST"
                    })
                    if (res) {
                        return
                    }
                    let {
                        Message,
                        count
                    } = res.data
                    if (count != 1) {
                        CommonUtils.showTips({
                            title: '温馨提示',
                            message: `保存检验值错误: ${Message}`
                        })
                    }
                } catch (err) {
                    CommonUtils.showTips({
                        title: '温馨提示',
                        message: `保存检验值错误: ${err}`
                    })
                }
            },
            async getValueList() {
                console.log('checkData: ', this.checkData);
                try {
                    let res = await CommonUtils.doRequest2Async({
                        url: "/QC_ValueTable/getValueList",
                        data: {
                            HInterID: this.checkData.HInterID,
                            HEntryID: this.checkData.num,
                            user: getUserInfo()['Czymc']
                        }
                    })
                    let {
                        data,
                        count
                    } = res.data
                    if (count == 1) {
                        // 当前 检验值页签中 保存的数据个数和数据库中的个数大 或者相等,取数据库中的数据,多的补空
                        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({
                        tite: '温馨提示',
                        message: `获取检测值错误: ${err}`
                    })
                }
            },
            async InitInSpectVal() { // 初始化定性检测内容
                try {
                    let res = await CommonUtils.doRequest2Async({
                        url: '/Gy_BadReason/Gy_InSpectValueList',
                        data: {
                            sWhere: ` and 使用组织名称 = '${uni.getStorageSync("Organization")}' and 禁用标志 = '否' and 审核人 !='' `,
                            user: getUserInfo()['Czymc']
                        }
                    })
                    let {
                        count,
                        Message,
                        data
                    } = res.data
                    if (count == 1) {
                        this.InitInSpectValNameList = Array.from(data).map(e => e["检测值名称"])
                        this.InitInSpectValList = data
                    } else {
                        CommonUtils.showTips({
                            title: "温馨提示",
                            message: `检测值初始化错误: ${Message}`
                        })
                    }
                } catch (err) {
                    CommonUtils.showTips({
                        title: "温馨提示",
                        message: `检测值初始化错误: ${err}`
                    })
                }
            },
            // 检测值修改
            HInSpectValueBChange(index, e) {
                let InSpectVal = this.InitInSpectValList.find(elem => elem["检测值名称"] == e)
                if (!InSpectVal) {
                    this.InSpectValues[index].HInSpectValueB = 0
                    this.InSpectValues[index].HInSpectValueB_Text = ''
                    return
                }
                this.InSpectValues[index].HInSpectValueB = InSpectVal["HItemID"]
                this.InSpectValues[index].HInSpectValueB_Text = InSpectVal["检测值名称"]
            },
            storeInSpectValue() {
                this.$emit("update", {
                    data: this.checkData,
                    list: this.InSpectValues
                })
            },
            getAnalysisMethodTitle(type) {
                if (type == 1) {
                    return '定性分析'
                }else if(type == 2){
                } else if (type == 2) {
                    return '定量分析'
                }
                return '其他分析'
@@ -193,23 +450,46 @@
            HStatusChange(e) {
                this.checkData.HStatus = e.detail.value
            },
            HInspectResultChange(index, e) {
                console.log('e: ',e.detail.value);
                this.inspectValues[index].HInspectResult = e.detail.value
            },
            HInSpectResultChange(index, e) {
                console.log('e: ', e.detail.value);
                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;
        font-size: 26rpx;
    }
    .inspect-value-content {
    .InSpect-value-content {
        box-sizing: border-box;
        padding: 20rpx 10rpx;
        display: flex;
@@ -244,11 +524,36 @@
                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 {
                border: 1px solid #e4e4e4;
                background-color: #e4e4e4;
            }
            .pass-background {
                background-color: #CEE3F2;
                border: none;
            }
            .unpass-background {
                background-color: #F0D6E3;
                border: none;
            }
            .none-border {
@@ -257,7 +562,9 @@
        }
    }
    .inspect-value-list {
    .InSpect-value-list {
        box-sizing: border-box;
        display: flex;
        flex-direction: column;