chenhaozhe
2025-09-09 87668fec3d068f91aedc0585f7ba98eadffbc142
pages/quyangdan/form.vue
@@ -1,22 +1,833 @@
<template>
    <view>
        <scroll-view scroll-y id="scroll-content" class="scroll-content" :style="{height: scrollContentHeight + 'px'}">
            <view class="form-item">
                <view class="title">条形码:</view>
                <view class="right">
                    <input type="text" name="HBarCode" id="HBarCode" v-model="HBarCode"
                        @confirm="getCode(HBarCode)" />
                </view>
                <view class="right-icon" @click="toScanCode">
                    <uni-icons color="#fff" type="scan" size="24"></uni-icons>
                </view>
            </view>
            <view class="form-item">
                <view class="title">工序:</view>
                <view class="right">
                    <uni-combox :candidates="HProcNameArray" name="HProcName" id="HProcName" placeholder="请选择工序号"
                        v-model="hform.HProcName" @input="onHProcNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">取样数量:</view>
                <view class="right">
                    <input type="number" name="HQty" id="HQty" v-model="hform.HQty" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">破坏性实验数量:</view>
                <view class="right">
                    <input type="number" name="HSampleDamageQty" id="HSampleDamageQty"
                        v-model="hform.HSampleDamageQty" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">送测类型:</view>
                <view class="right">
                    <uni-combox :candidates="TestTypeArray" v-model="hform.TestType"
                        @input="TestTypeChange"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">送测内容:</view>
                <view class="right">
                    <input type="text" name="HBadNote" id="HBadNote" v-model="hform.HBadNote" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">部门:</view>
                <view class="right">
                    <uni-combox :candidates="HDeptNameArray" name="HDeptName" id="HDeptName" placeholder="请选择部门"
                        v-model="hform.HDeptName" @input="HDeptNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">生产班次:</view>
                <view class="right">
                    <uni-combox :candidates="HShiftsNameArray" name="HShiftsName" id="HShiftsName" placeholder="请选择生产班次"
                        v-model="hform.HShiftsName" @input="HShiftsNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">生产班组:</view>
                <view class="right">
                    <uni-combox :candidates="HGroupNameArray" name="HShiftsName" id="HShiftsName" placeholder="请选择生产班组"
                        v-model="hform.HGroupName" @input="HGroupNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">取样员:</view>
                <view class="right">
                    <uni-combox :candidates="HCheckEmpNameArray" name="HCheckEmpName" id="HCheckEmpName"
                        placeholder="请选择取样员" v-model="hform.HCheckEmpName"
                        @input="HCheckEmpNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">生产资源:</view>
                <view class="right">
                    <uni-combox :candidates="HSourceNameArray" name="HSourceName" id="HSourceName" placeholder="请选择生产资料"
                        v-model="hform.HSourceName" @input="HSourceNameChangeHandler"></uni-combox>
                </view>
            </view>
            <view class="form-item">
                <view class="title">单据日期:</view>
                <view class="right disabled">
                    <input disabled type="text" name="HDate" id="HDate" v-model="hform.HDate" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">单据号:</view>
                <view class="right disabled">
                    <input disabled type="text" name="HBillNo" id="HBillNo" v-model="hform.HBillNo" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">生产订单:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HICMOBillNo" name="HICMOBillNo" id="HICMOBillNo" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">流转卡:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HProcExchBillNo" name="HProcExchBillNo"
                        id="HProcExchBillNo" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">物料代码:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HMaterCode" name="HMaterCode" id="HMaterCode" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">物料名称:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HMaterName" name="HMaterName" id="HMaterName" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">规格型号:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HMaterSpec" name="HMaterSpec" id="HMaterSpec" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">计量单位:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HUnitName" name="HUnitName" id="HUnitName" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">流转卡批号:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HBatchNo" name="HBatchNo" id="HBatchNo" />
                </view>
            </view>
            <view class="form-item">
                <view class="title">流转卡数量:</view>
                <view class="right disabled">
                    <input disabled type="text" v-model="hform.HProcExchQty" name="HProcExchQty" id="HProcExchQty" />
                </view>
            </view>
        </scroll-view>
        <view class="bottom-btn" id="bottom-btn">
            <view><button class="btn-a" size="mini" @tap="submit">提交</button></view>
            <view><button class="btn-b" size="mini" @tap="onAddNewHandler">新增</button></view>
            <view class="placeholder__view"></view>
            <view><button class="btn-c" size="mini" @tap="goBack">退出</button></view>
        </view>
    </view>
</template>
<script>
    import dayjs from 'dayjs'
    import {
        getUserInfo
    } from '../../utils/auth'
    import {
        CommonUtils
    } from '../../utils/common'
    export default {
        data() {
            return {
                pageMeta: {
                    scrollContentTop: 0,
                    bottomBtnTop: 0,
                },
                refSav: 'Add',
                showMask: true,
                TestTypeArray: ["首检", "巡检", "未检", "实验"],
                HBillType: '7521',
                HProcNameArray: [],
                HProcNameArraySource: [],
                HDeptNameArray: [],
                HDeptNameArraySource: [],
                HShiftsNameArray: [],
                HShiftsNameArraySource: [],
                HGroupNameArray: [],
                HGroupNameArraySource: [],
                HCheckEmpNameArray: [],
                HCheckEmpNameSource: [],
                HSourceNameArray: [],
                HSourceNameSource: [],
                HBarCode: '',
                hform: {
                    HBarCode: '',
                    HProcName: '',
                    HProcID: 0,
                    HQty: '',
                    HSampleDamageQty: 0,
                    TestType: '首检',
                    HBadNote: '',
                    HDeptName: '',
                    HDeptID: 0,
                    HCenterID: 0,
                    HShiftsName: '',
                    HShiftsID: 0,
                    HGroupName: '',
                    HGroupID: 0,
                    HCheckEmpName: '',
                    HCheckEmp: '',
                    HSourceName: '',
                    HSourceID: 0,
                    HDate: dayjs(new Date()).format("YYYY-MM-DD"),
                    HBillNo: '',
                    HInterID: 0,
                    HICMOBillNo: '',
                    HICMOInterID: 0,
                    HICMOEntryID: 0,
                    HProcExchBillNo: '',
                    HProcExchInterID: 0,
                    HProcExchEntryID: 0,
                    HMainSourceBillNo: '',
                    HMainSourceInterID: 0,
                    HMainSourceBillType: '',
                    HMainSourceEntryID: 0,
                    HMaterCode: '',
                    HMaterID: 0,
                    HMaterName: '',
                    HMaterSpec: '',
                    HUnitName: '',
                    HUnitID: 0,
                    HBatchNo: '',
                    HProcExchQty: '',
                    HMaker: getUserInfo()['Czymc'],
                    HMakeDate: dayjs(new Date()).format("YYYY-MM-DD hh:mm:ss"),
                    HUpDater: '',
                    HUpDateDate: '',
                    HChecker: '',
                    HCheckDate: '',
                    HDeleteMan: '',
                    HDeleteDate: '',
                }
            }
        },
        methods: {
        computed: {
            scrollContentHeight: {
                get() {
                    return this.pageMeta.bottomBtnTop - this.pageMeta.scrollContentTop
                }
            }
        },
        onReady() {
            // #ifndef MP-WEIXIN
            let query = uni.createSelectorQuery().in(this)
            query.select("#scroll-content").boundingClientRect((data) => {
                this.pageMeta.scrollContentTop = data.top
            }).exec()
            query.select("#bottom-btn").boundingClientRect((data) => {
                this.pageMeta.bottomBtnTop = data.top
            }).exec()
            // #endif
            // #ifdef MP-WEIXIN
            // 微信不支持 uni.createSelectorQuery().in(this)
            // #endif
        },
        async onLoad(e) {
            let {
                operationType
            } = e
            if (operationType == 0) {
                this.getMaxNum()
                this.refSav = 'Add'
            } else {
                this.refSav = 'Update'
            }
            this.getProcessList()
            this.get_Gy_WorkShiftList()
            this.GetGroupList()
            this.GetEmployeeList()
            this.getSourceList()
            this.GetDepartmentList()
        },
        methods: {
            HDeptNameChangeHandler(){
                let index = this.HDeptNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HDeptID = this.HDeptNameArraySource[index]["HItemID"]
                    this.hform.HDeptName = this.HDeptNameArraySource[index]["HName"]
                }
            },
            GetDepartmentList() {
                CommonUtils.doRequest2({
                    url: '/Web/GetDepartmentList_Json',
                    data: {
                        Department: '',
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message,
                            code
                        } = res.data
                        if (count == 1) {
                            this.HDeptNameArray = Array.from(data).map(item => item['HName'])
                            this.HDeptNameArraySource = data
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            HSourceNameChangeHandler(e) {
                let index = this.HSourceNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HSourceID = this.HSourceNameArraySource[index]["HItemID"]
                    this.hform.HSourceName = this.HSourceNameArraySource[index]["生产资源"]
                }
                console.log('this.hform: ',this.hform);
            },
            // 获取生产资源
            getSourceList() {
                CommonUtils.doRequest2({
                    url: '/api/newBill/getSourceList',
                    data: {
                        sWhere: '',
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            msg,
                            code
                        } = res.data
                        if (code == 1) {
                            let data1 = data.Gy_Source
                            this.HSourceNameArray = Array.from(data1).map(item => item['生产资源'])
                            this.HSourceNameArraySource = data1
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            HCheckEmpNameChangeHandler(e) {
                let index = this.HCheckEmpNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HCheckEmp = this.HCheckEmpNameArraySource[index]["HItemID"]
                    this.hform.HCheckEmpName = this.HCheckEmpNameArraySource[index]["HName"]
                }
            },
            // 获取职员信息
            GetEmployeeList() {
                CommonUtils.doRequest2({
                    url: '/Web/GetEmployeeList_Json',
                    data: {
                        Employee: '',
                        HGroupID: this.hform.HGroupID
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.HCheckEmpNameArray = Array.from(data).map(item => item['HName'])
                            this.HCheckEmpNameArraySource = data
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            HGroupNameChangeHandler(e) {
                let index = this.HGroupNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HGroupID = this.HGroupNameArraySource[index]["HItemID"]
                    this.hform.HGroupName = this.HGroupNameArraySource[index]["HName"]
                }
            },
            // 获取生产班组
            GetGroupList() {
                CommonUtils.doRequest2({
                    url: '/WEBSController/GetGroupList_Json',
                    data: {
                        Group: '',
                        HStockOrgID: uni.getStorageSync('OrganizationID')
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.HGroupNameArray = Array.from(data).map(item => item['HName'])
                            this.HGroupNameArraySource = data
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            // 获取最新单据号和HInterID
            getMaxNum() {
                CommonUtils.doRequest2({
                    url: '/Web/GetMAXNum',
                    data: {
                        HBillType: this.HBillType
                    },
                    resFunction: (res) => {
                        let {
                            count,
                            data,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.hform.HBillNo = data[0].HBillNo
                            this.hform.HInterID = data[0].HInterID
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            HShiftsNameChangeHandler(e) {
                let index = this.HShiftsNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HShiftsID = this.HShiftsNameArraySource[index]['HInterID']
                    this.hform.HShiftsName = this.HShiftsNameArraySource[index]['班次名称']
                }
            },
            // 初始化班次信息
            get_Gy_WorkShiftList() {
                CommonUtils.doRequest2({
                    url: '/Gy_ShiftsController/Get_Gy_WorkShiftList',
                    data: {
                        sWhere: ` and 使用组织名称 = '${uni.getStorageSync('Organization')}' and 禁用标记='' and ISNULL(审核人 ,'') !=''`,
                        HMaker: getUserInfo()['Czymc']
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.HShiftsNameArray = Array.from(data).map(item => item['班次名称'])
                            this.HShiftsNameArraySource = data
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            // 获取班次
            get_HWorkShift() {
                CommonUtils.doRequest2({
                    url: '/Gy_ShiftsController/Get_HWorkShift',
                    data: {
                        "HDeptID": this.hform.HDeptID,
                        "HCenterID": this.hform.HCenterID
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            Message,
                            count
                        } = res.data
                        this.hform.HShiftsID = data[0]['HInterID']
                        this.hform.HShiftsName = data[0]['班次']
                    }
                })
            },
            ProcessExchangeBillQuerySub() {
                let HProcID = this.hform.HProcID
                let HBarCode = this.hform.HProcExchInterID
                let sWhere = ` ${HBarCode} and HProcID = ${HProcID} `
                CommonUtils.doRequest2({
                    url: '/LEMS/MES_Sc_ProcessExchangeBillQuerySub_Json',
                    data: {
                        sWhere: sWhere
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            Message,
                            count
                        } = res.data
                        if (count == 1 && data.length > 0) {
                            this.hform = Object.assign(this.hform, {
                                HProcID: data[0]['HProcID'],
                                HProcName: data[0]['工序名称'],
                                HSourceID: data[0]['HSourceID'] || 0,
                                HSourceName: data[0]['生产资源'] || '',
                                HMainSourceEntryID: data[0]['hsubid'],
                                HProcExchEntryID: data[0]['hsubid'],
                                HProcExchQty: data[0]['流转卡数量'],
                                HCenterID: data[0]['HCenterID'] || getUserInfo()['HWorkCenterID'],
                            })
                        }
                    }
                })
            },
            onHProcNameChangeHandler(e) {
                let index = this.HProcNameArray.findIndex(item => item == e)
                if (index != -1) {
                    this.hform.HProcName = this.HProcNameArraySource[index]['HName']
                    this.hform.HProcID = this.HProcNameArraySource[index]['HItemID']
                    this.ProcessExchangeBillQuerySub()
                }
            },
            getProcessList() {
                CommonUtils.doRequest2({
                    url: '/WEBSController/GetProcessList_Json',
                    data: {
                        Process: '',
                        HStockOrgID: uni.getStorageSync("OrganizationID")
                    },
                    resFunction: (res) => {
                        let {
                            data,
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            this.HProcNameArray = Array.from(data).map(item => item.HName)
                            this.HProcNameArraySource = data
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            TestTypeChange(e) {
                console.log('e: ', e);
            },
            toScanCode() {
                var mpaasScanModule = uni.requireNativePlugin("Mpaas-Scan-Module")
                mpaasScanModule.mpaasScan({
                    'hideAlbum': true,
                    'timeoutInterval': '10', //超时时间
                    'timeoutText': '未识别到二维码' //超时提醒
                }, (ret) => {
                    console.log(ret.resp_result)
                    if (this.hform.HBarCode == '*') {
                        this.hform.HBarCode = this.hform.HBarCode + ret.resp_result
                    } else {
                        this.HBarCode = ret.resp_result
                        this.hform.HBarCode = ret.resp_result
                    }
                    this.getCode(this.hform.HBarCode)
                })
            },
            getCode(HBarCode) {
                if (!HBarCode) {
                    return uni.showToast({
                        icon: 'none',
                        title: '条形码不能为空'
                    })
                }
                let sWhere = " and 单据号='" + HBarCode + "'";
                CommonUtils.doRequest2({
                    url: '/QC_TakeSampleCheckBill/Get_BackSampleList',
                    data: {
                        "sWhere": sWhere
                    },
                    resFunction: (res) => {
                        let {
                            code,
                            msg,
                            count,
                            data
                        } = res.data
                        if (code == 1) {
                            this.HBarCode = ''
                            let data1 = data.h_v_Sc_ProcessExchangeBillList
                            this.hform = Object.assign(this.hform, {
                                "HMaterID": data1[0].HMaterID, //产品ID
                                "HMaterCode": data1[0].产品代码, //产品代码
                                "HMaterName": data1[0].产品, //产品名称
                                "HMaterSpec": data1[0].规格型号, //产品规格
                                "HUnitID": data1[0].HUnitID, //计量单位id
                                "HUnitName": data1[0].单位, //计量单位
                                "HMainSourceBillNo": data1[0].单据号, //源单单号
                                "HMainSourceInterID": data1[0].hmainid, //源单主内码
                                "HMainSourceBillType": 3772, //源单类型
                                "HProcExchBillNo": data1[0].单据号, //流转卡号
                                "HProcExchInterID": data1[0].hmainid, //流转卡主内码(取值HInterID)
                                "HBatchNo": data1[0].批号, //流转卡批次
                                "HICMOInterID": data1[0].hicmointerid, //生产订单ID
                                "HICMOEntryID": data1[0].HICMOEntryID, //生产订单子ID
                                "HICMOBillNo": data1[0].任务单号, //生产订单
                                "HDeptID": data1[0].HWorkShopID, //车间ID
                                "HDeptName": data1[0].生产车间, //车间
                            })
                            uni.showToast({
                                icon: 'none',
                                title: msg
                            })
                        } else {
                            uni.showToast({
                                icon: 'none',
                                title: msg
                            })
                        }
                    }
                })
            },
            submit() {
                if (this.hform.HProcID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '工序没有选择'
                    })
                }
                if (this.hform.HQty == '') {
                    return uni.showToast({
                        icon: 'none',
                        title: '取样数量为空'
                    })
                }
                if (this.hform.HProcID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '工序没有选择'
                    })
                }
                if (this.hform.HDeptID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '部门没有选择'
                    })
                }
                if (this.hform.HShiftsID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '班次未选择'
                    })
                }
                if (this.hform.HGroupID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '生产班组未选择'
                    })
                }
                if (this.hform.HCheckEmp == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '取样员未选择'
                    })
                }
                if (this.hform.HSourceID == 0) {
                    return uni.showToast({
                        icon: 'none',
                        title: '生产资源未选择'
                    })
                }
                console.log('this.hform: ',this.hform);
                let sMainStr = JSON.stringify(this.hform)
                console.log('sMainStr: ',sMainStr);
                let sMainSub = sMainStr + ';' + this.refSav + ';' + getUserInfo()['Czymc'];
                CommonUtils.doRequest2({
                    method: 'POST',
                    url: '/QC_TakeSampleCheckBill/SaveQC_TakeSampleCheckBillMain',
                    data: {
                        msg: sMainSub
                    },
                    resFunction: (res) => {
                        let {
                            count,
                            Message
                        } = res.data
                        if (count == 1) {
                            return uni.showToast({
                                icon: 'none',
                                title: "提交成功!"
                            })
                        } else {
                            return uni.showToast({
                                icon: 'none',
                                title: Message
                            })
                        }
                    }
                })
            },
            onAddNewHandler() {
                uni.redirectTo({
                    url: "/pages/quyangdan/form?operationType=0"
                })
            },
            goBack() {
                uni.navigateBack()
            },
        }
    }
</script>
<style>
<style lang="scss" scoped>
    .scroll-content {
        box-sizing: border-box;
        padding: 20rpx;
        ::v-deep .uni-scroll-view-content {
            box-sizing: border-box;
            padding: 0 40rpx;
            display: flex;
            flex-direction: column;
            gap: 20rpx;
        }
        .form-item {
            display: flex;
            flex-direction: row;
            align-items: center;
            gap: 20rpx;
            input {
                width: inherit;
                padding: 8rpx 20rpx;
                font-size: 30rpx;
            }
            .title {
                width: 5em;
                font-size: 30rpx;
                flex-shrink: 0;
                text-align: right;
            }
            .right {
                flex: 1;
                border-radius: 22rpx;
                border: 1px solid #acacac;
            }
            .right-icon {
                width: 54rpx;
                height: 54rpx;
                border-radius: 50%;
                background-color: #3A78FF;
                display: flex;
                align-items: center;
                justify-content: center;
                flex-shrink: 0;
            }
            .disabled {
                border: 1px solid #e4e4e4;
                background-color: #e4e4e4;
            }
        }
    }
    .bottom-btn {
        position: fixed;
        bottom: 0;
        box-sizing: border-box;
        background-color: #fff;
        box-shadow: 0 2rpx 10rpx 2rpx rgba(0, 0, 0, 0.4);
        padding: 30rpx 40rpx 40rpx 40rpx;
        display: flex;
        flex-direction: row;
        gap: 20rpx;
        justify-content: space-between;
        width: 100%;
        button {
            border-radius: 50rpx;
            width: 180rpx;
            height: 66rpx;
            line-height: 66rpx;
            font-size: 28rpx;
        }
        .btn-a {
            background-color: #3A78FF;
            color: #fff;
        }
        .btn-b {
            background-color: #41a863;
            color: #fff;
        }
        .btn-c {
            background-color: #acacac;
            color: #fff;
        }
    }
    .placeholder__view {
        flex: 1;
    }
</style>