陈婷婷
1 天以前 567148901a4af91560c3bdc6c0ee14beddfac1fa
运单编辑,源单选择数据回填
2个文件已修改
519 ■■■■ 已修改文件
src/views/logistics/transportGPS/Add_Edit_WL_YayBill.vue 215 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/logistics/transportGPS/WL_YayBill.vue 304 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/logistics/transportGPS/Add_Edit_WL_YayBill.vue
@@ -194,7 +194,7 @@
                                </el-col>
                            </el-row>
                        </div>
                        <div class="form-group">
                        <!-- <div class="form-group">
                            <el-form-item label="附件" prop="fujian">
                                <el-upload class="upload-demo" ref="upload" action="" :on-preview="handleFilePreview"
                                    :on-remove="handleFileRemove" :on-change="handleFileChange" :file-list="fileList"
@@ -205,7 +205,7 @@
                                        支持上传jpg/png/jpeg/pdf/doc/docx/xls/xlsx/zip/rar格式文件,最多10个</div>
                                </el-upload>
                            </el-form-item>
                        </div>
                        </div> -->
                    </el-tab-pane>
                    <el-tab-pane label="承运商信息" name="second">
                        <div class="form-group">
@@ -1302,7 +1302,7 @@
                    if (ListMaterial) ListMaterial += ";";
                    ListMaterial += materialId;
                }
                 if (!ListMaterial) {
                if (!ListMaterial) {
                    this.$modal.msgError("没有找到物料信息,请检查选择的源单是否包含有效的物料数据!");
                    this.sourceDataLoading = false;
                    return;
@@ -1318,164 +1318,91 @@
                        "hmainid": hmainidVal.join(',')
                    },
                });
                console.log('源单详情', response)
                console.log('源单详情', response.data.data)
                let result = response.data;
                if (result.count == 1) {
                    let res = result.data;
                    console.log(res)
                    var newRows = [];
                    // 为每个源单行创建对应的子表行
                    for (var materialId in materialMap) {
                        var sourceInfos = materialMap[materialId];
                        if (res.length === 0) {
                            // 为每个源单行创建一条记录
                            for (var j = 0; j < sourceInfos.length; j++) {
                                var sourceInfo = sourceInfos[j];
                                // 再次检查是否已存在(双重保险)
                                var isExist = false;
                                for (var k = 0; k < existingData.length; k++) {
                                    if (existingData[k].HSourceInterID == sourceInfo.hmainid &&
                                        existingData[k].HSourceEntryID == sourceInfo.hsubid) {
                                        isExist = true;
                                        break;
                                    }
                                }
                                if (isExist) {
                                    this.$modal.msgError(`源单${sourceInfo.单据号}已存在,跳过`);
                                    continue;
                                }
                                // 计算相关数量
                                var qty = orginHQTY || 0;
                                var snp = 0;
                                var mouldQty = 0;
                                var HPackQTY = 0;
                                var rowVolume = 0;
                                // if
                                newRows.push({
                                    "HSourceInterID": sourceInfo.hmainid,
                                    "HSourceEntryID": sourceInfo.hsubid,
                                    "HSourceBillNo": sourceInfo.单据号,
                                    "HCusID": dataArray[j].HCusID,
                                    "HCusName": dataArray[j].客户,
                                    "HMaterID": dataArray[j].HMaterID,
                                    "HMaterNumber": dataArray[j].物料代码,
                                    "HMaterName": dataArray[j].物料名称,
                                    "HUnitID": dataArray[j].HUnitID,
                                    // "HPackV": dataArray[j].托单位体积,
                                    // "HStandardQtyForMouldInPack": dataArray[j].容器数量 / 托,
                                    "HMouldID": 0,
                                    "HMouldNumber": '',
                                    "HMouldName": '',
                                    "HMouldLength": 0,
                                    "HMouldWidth": 0,
                                    "HMouldHeight": 0,
                                    "HMouldFoldHeight": 0,
                                    "HQty": orginHQTY,
                                    "HQty_origin": orginHQTY,
                                    "HMouldQty": mouldQty,
                                    "HVolume": rowVolume,
                                    "HSNP": 0,
                                    HScatteredVolume: 0,
                                });
                            }
                        } else {
                            // 查找该物料ID对应的包装容器信息
                            var materialInfo = null;
                            for (var i = 0; i < res.length; i++) {
                                if (res[i].HMaterID == materialId) {
                                    materialInfo = res[i];
                                    break;
                                }
                            }
                            if (materialInfo) {
                                // 为每个源单行创建一条记录
                                for (var j = 0; j < sourceInfos.length; j++) {
                                    var sourceInfo = sourceInfos[j];
                                    // 再次检查是否已存在(双重保险)
                                    var isExist = false;
                                    for (var k = 0; k < existingData.length; k++) {
                                        if (existingData[k].HSourceInterID == sourceInfo.hmainid &&
                                            existingData[k].HSourceEntryID == sourceInfo.hsubid) {
                                            isExist = true;
                                            break;
                                        }
                                    }
                                    if (isExist) {
                                        this.$modal.msgError(`源单${sourceInfo.单据号}已存在,跳过`);
                                        continue;
                                    }
                                    // 计算相关数量
                                    var qty = orginHQTY || 0;
                                    var snp = materialInfo.HSNP || 0;
                                    var mouldQty = 0;
                                    if (snp > 0) {
                                        mouldQty = Math.ceil(qty / snp);
                                    }
                                    var HPackQTY = 0;
                                    if (materialInfo.HStandardQtyForMouldInPack > 0 && mouldQty > 0) {
                                        HPackQTY = Math.ceil(mouldQty / materialInfo.HStandardQtyForMouldInPack);
                                    }
                                    var rowVolume = (HPackQTY * materialInfo.HPackV).toFixed(2);
                                    newRows.push({
                                        "HSourceInterID": sourceInfo.hmainid,
                                        "HSourceEntryID": sourceInfo.hsubid,
                                        "HSourceBillNo": sourceInfo.单据号,
                                        "HCusID": materialInfo.HCusID,
                                        "HCusName": materialInfo.客户,
                                        "HMaterID": materialInfo.HMaterID,
                                        "HMaterNumber": materialInfo.物料代码,
                                        "HMaterName": materialInfo.物料名称,
                                        "HUnitID": materialInfo.HUnitID,
                                        "HMouldID": materialInfo.HMouldID,
                                        // "HPackV": materialInfo.托单位体积,
                                        // "HStandardQtyForMouldInPack": materialInfo.容器数量 / 托,
                                        "HMouldNumber": materialInfo.HMouldNumber,
                                        "HMouldName": materialInfo.HMouldName,
                                        "HMouldLength": materialInfo.长度,
                                        "HMouldWidth": materialInfo.宽度,
                                        "HMouldHeight": materialInfo.高度,
                                        "HMouldFoldHeight": materialInfo.折叠高度,
                                        "HQty": orginHQTY,
                                        "HQty_origin": orginHQTY,
                                        "HMouldQty": mouldQty,
                                        "HVolume": rowVolume,
                                        "HSNP": materialInfo.HSNP,
                                        HScatteredVolume: 0,
                                        "HPackV": materialInfo.HPackV,
                                        "HStandardQtyForMouldInPack": materialInfo.HStandardQtyForMouldInPack,
                                        "HPackQTY": HPackQTY,
                                    });
                                    this.form.HTotalVolume = this.form.HTotalVolume * 1 + rowVolume * 1
                                }
                    // for (var materialId in materialMap) {
                    // var sourceInfos = materialMap[materialId];
                    // // 查找该物料ID对应的包装容器信息
                    // var materialInfo = null;
                    // for (var i = 0; i < res.length; i++) {
                    //     if (res[i].HMaterID == materialId) {
                    //         materialInfo = res[i];
                    //         break;
                    //     }
                    // }
                    // if (materialInfo) {
                    // 为每个源单行创建一条记录
                    for (var j = 0; j < res.length; j++) {
                        var sourceInfo = res[j];
                        // 再次检查是否已存在(双重保险)
                        var isExist = false;
                        for (var k = 0; k < existingData.length; k++) {
                            if (existingData[k].HSourceInterID == sourceInfo.hmainid &&
                                existingData[k].HSourceEntryID == sourceInfo.hsubid) {
                                isExist = true;
                                break;
                            }
                        }
                        if (isExist) {
                            this.$modal.msgError(`源单${sourceInfo.单据号}已存在,跳过`);
                            continue;
                        }
                        // 计算相关数量
                        var qty = orginHQTY || 0;
                        var snp = res[j].托标准容器数量 || 0;
                        var mouldQty = 0;
                        if (snp > 0) {
                            mouldQty = Math.ceil(qty / snp);
                        }
                        var HPackQTY = 0;
                        if (res[j].托数量 > 0 && mouldQty > 0) {
                            HPackQTY = Math.ceil(mouldQty / res[j].托数量);
                        }
                        var rowVolume = (HPackQTY * res[j].托体积).toFixed(2);
                        newRows.push({
                            "HSourceInterID": res[j].hmainid,
                            "HSourceEntryID": res[j].hsubid,
                            "HSourceBillNo": res[j].单据号,
                            "HCusID": res[j].HCusID,
                            "HCusName": res[j].客户,
                            "HMaterID": res[j].HMaterID,
                            "HMaterNumber": res[j].物料代码,
                            "HMaterName": res[j].物料名称,
                            "HMouldNumber": res[j].容器代码,
                            "HMouldName": res[j].容器名称,
                            "HUnitID": res[j].HUnitID,
                            "HMouldID": res[j].HMouldID,
                            "HPackV": res[j].托体积,
                            "HStandardQtyForMouldInPack": res[j].托数量,
                            "HMouldLength": res[j].长度,
                            "HMouldWidth": res[j].宽度,
                            "HMouldHeight": res[j].高度,
                            "HMouldFoldHeight": res[j].折叠高度,
                            "HQty": orginHQTY,
                            "HQty_origin": orginHQTY,
                            "HMouldQty": mouldQty,
                            "HVolume": rowVolume,
                            "HSNP": res[j].托标准容器数量,
                            "HScatteredVolume": 0,
                            "HPackQTY": HPackQTY,
                        });
                        this.form.HTotalVolume = this.form.HTotalVolume * 1 + rowVolume * 1
                    }
                    // }
                    // }
                    if (newRows.length === 0) {
                        this.$modal.msgError("没有可添加的新记录,可能是源单数据已存在或物料信息不完整!");
                        this.sourceDataLoading = false;
                        return;
                    }
                    // 合并现有数据和新数据
                    var allData = existingData.concat(newRows);
                    // 渲染表格
                    this.editData = allData;
                    this.$modal.msgSuccess(`成功添加${newRows.length}条记录`);
                } else {
src/views/logistics/transportGPS/WL_YayBill.vue
@@ -221,6 +221,14 @@
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-date" size="mini" @click="handleRowHide">隐藏列设置</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-upload" size="mini" :disabled="single"
                    @click="handleFileUpload">附件上传</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="primary" icon="el-icon-download" size="mini" :disabled="multiple"
                    @click="handleBatchFileDownload">附件下载</el-button>
            </el-col>
        </el-row>
        <div class="tableBox" v-loading="loading">
            <el-table :data="tableData" ref="tableData" max-height="710" :summary-method="getSummaries"
@@ -322,6 +330,65 @@
                    <el-button @click="openCarDriver = false">取 消</el-button>
                </div>
            </el-dialog>
            <!-- 附件上传 -->
            <el-dialog title="附件上传" :visible.sync="openFileUpload" width="600px" append-to-body>
                <el-form ref="fileUploadForm" label-width="100px">
                    <el-form-item label="单据号">
                        <el-input v-model="fileUploadForm.billNo" disabled />
                    </el-form-item>
                    <el-form-item label="附件">
                        <el-upload class="upload-demo" ref="fileUpload" action="" :on-preview="handleFilePreview"
                            :on-remove="handleFileRemove" :on-change="handleFileChange" :file-list="fileList"
                            :auto-upload="false" :limit="10" :on-exceed="handleFileExceed"
                            accept=".jpg,.png,.jpeg,.pdf,.doc,.docx,.xls,.xlsx,.zip,.rar">
                            <el-button size="small" type="primary">点击上传</el-button>
                            <div slot="tip" class="el-upload__tip">
                                支持上传jpg/png/jpeg/pdf/doc/docx/xls/xlsx/zip/rar格式文件,最多10个</div>
                        </el-upload>
                    </el-form-item>
                    <el-form-item label="已上传附件" v-if="uploadedFileList.length > 0">
                        <el-table :data="uploadedFileList" border size="small" max-height="200">
                            <el-table-column label="文件名" prop="name" align="center" show-overflow-tooltip />
                            <el-table-column label="上传时间" prop="uploadTime" align="center" width="150" />
                            <el-table-column label="操作" align="center" width="100">
                                <template slot-scope="scope">
                                    <el-button type="text" size="small" @click="downloadFile(scope.row)">下载</el-button>
                                    <el-button type="text" size="small" style="color: red;"
                                        @click="deleteUploadedFile(scope.row, scope.$index)">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitFileUpload" :loading="fileUploadLoading">上传</el-button>
                    <el-button @click="openFileUpload = false">关 闭</el-button>
                </div>
            </el-dialog>
            <!-- 附件批量下载 -->
            <el-dialog title="附件批量下载" :visible.sync="openBatchDownload" width="900px" append-to-body>
                <div style="margin-bottom: 10px;">
                    <el-alert :title="`已选择 ${selectedBillCount} 条单据,共 ${batchFileList.length} 个附件`" type="info" show-icon :closable="false" />
                </div>
                <el-table :data="batchFileList" border v-loading="batchDownloadLoading" max-height="400"
                    @selection-change="handleBatchFileSelectionChange">
                    <el-table-column type="selection" width="55" align="center" />
                    <el-table-column label="单据号" prop="billNo" align="center" width="150" show-overflow-tooltip />
                    <el-table-column label="文件名" prop="name" align="center" show-overflow-tooltip />
                    <el-table-column label="文件类型" prop="fileType" align="center" width="100" />
                    <el-table-column label="上传时间" prop="uploadTime" align="center" width="150" />
                    <el-table-column label="操作" align="center" width="80">
                        <template slot-scope="scope">
                            <el-button type="text" size="small" @click="downloadSingleFile(scope.row)">下载</el-button>
                        </template>
                    </el-table-column>
                </el-table>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="batchDownloadFiles" :loading="batchDownloadLoading" :disabled="selectedBatchFiles.length === 0">批量下载选中</el-button>
                    <el-button type="primary" @click="downloadAllFiles" :loading="batchDownloadLoading">下载全部</el-button>
                    <el-button @click="openBatchDownload = false">关 闭</el-button>
                </div>
            </el-dialog>
        </div>
    </div>
</template>
@@ -413,6 +480,20 @@
                DriverHName: [{ required: true, message: '请输入驾驶员', trigger: 'blur' }],
                DriverHIDCard: [{ required: true, message: '请输入身份证号', trigger: 'blur' }],
            },
            openFileUpload: false,                                                     //附件上传弹窗标记
            fileUploadForm: {                                                          //附件上传表单
                billNo: '',
                hInterID: 0
            },
            fileList: [],                                                              //待上传文件列表
            uploadFiles: [],                                                           //待上传文件数据
            fileUploadLoading: false,                                                  //上传加载状态
            uploadedFileList: [],                                                      //已上传文件列表
            openBatchDownload: false,                                                  //批量下载弹窗标记
            batchFileList: [],                                                         //批量下载文件列表
            selectedBatchFiles: [],                                                    //选中的批量下载文件
            batchDownloadLoading: false,                                               //批量下载加载状态
            selectedBillCount: 0,                                                      //选中的单据数量
            dialogTypeNum: null,                                                       //部门弹窗1,仓库弹窗2
            gyCarShow: false,                                                          //车辆数据组件显示标记
            gyDriverShow: false,                                                       //司机数据组件显示标记
@@ -467,6 +548,7 @@
    },
    methods: {
        //#region 设置表头
        renderHeader(h, { column, $index }) {// 新建一个 span
            let span = document.createElement(span)// 设置表头名称
@@ -1367,6 +1449,227 @@
            })
        },
        //#endregion
        //#region 附件上传
        handleFileUpload() {
            this.fileUploadForm = {
                billNo: this.rowForm.单据号,
                hInterID: this.rowForm.HInterID
            }
            this.fileList = []
            this.uploadFiles = []
            this.uploadedFileList = []
            this.getUploadedFileList()
            this.openFileUpload = true
        },
        handleFileChange(file, fileList) {
            this.uploadFiles = fileList
        },
        handleFileRemove(file, fileList) {
            this.uploadFiles = fileList
        },
        handleFilePreview(file) {
            if (file.url) {
                window.open(file.url, '_blank')
            } else if (file.raw) {
                const url = URL.createObjectURL(file.raw)
                window.open(url, '_blank')
            } else {
                this.$modal.msgWarning('无法预览该文件')
            }
        },
        handleFileExceed(files, fileList) {
            this.$modal.msgWarning(`当前限制选择 10 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
        },
        submitFileUpload() {
            if (this.uploadFiles.length === 0) {
                this.$modal.msgWarning('请先选择要上传的文件')
                return
            }
            this.fileUploadLoading = true
            const formData = new FormData()
            this.uploadFiles.forEach(file => {
                formData.append('files', file.raw)
            })
            formData.append('HBillNo', this.fileUploadForm.billNo)
            formData.append('HInterID', this.fileUploadForm.hInterID)
            formData.append('HUserName', sessionStorage["HUserName"] || '')
            axios.post(this.$baseUrl + '/WLYayBillController/UploadFile', formData, {
                headers: {
                    'Content-Type': 'multipart/form-data'
                }
            }).then(response => {
                this.fileUploadLoading = false
                if (response.data.code == 1) {
                    this.$modal.msgSuccess(response.data.Message || '文件上传成功')
                    this.fileList = []
                    this.uploadFiles = []
                    this.getUploadedFileList()
                } else {
                    this.$modal.msgError(response.data.code + response.data.Message || '上传失败')
                }
            }).catch(error => {
                this.fileUploadLoading = false
                this.$modal.msgError('上传请求失败')
                console.error('上传错误:', error)
            })
        },
        getUploadedFileList() {
            axios.get(this.$baseUrl + '/WLYayBillController/GetFileList', {
                params: {
                    HInterID: this.fileUploadForm.hInterID
                }
            }).then(response => {
                if (response.data.code == 1) {
                    this.uploadedFileList = response.data.data || []
                }
            }).catch(error => {
                console.error('获取文件列表失败:', error)
            })
        },
        downloadFile(row) {
            if (row.url) {
                window.open(row.url, '_blank')
            } else {
                axios.get(this.$baseUrl + '/WLYayBillController/DownloadFile', {
                    params: {
                        fileId: row.id || row.fileId
                    },
                    responseType: 'blob'
                }).then(response => {
                    const blob = new Blob([response.data])
                    const url = window.URL.createObjectURL(blob)
                    const link = document.createElement('a')
                    link.href = url
                    link.download = row.name || row.fileName
                    link.click()
                    window.URL.revokeObjectURL(url)
                }).catch(error => {
                    this.$modal.msgError('下载失败')
                    console.error('下载错误:', error)
                })
            }
        },
        deleteUploadedFile(row, index) {
            this.$modal.confirm('确认要删除该文件吗?').then(() => {
                axios.get(this.$baseUrl + '/WLYayBillController/DeleteFile', {
                    params: {
                        fileId: row.id || row.fileId,
                        HInterID: this.fileUploadForm.hInterID,
                        HUserName: sessionStorage["HUserName"]
                    }
                }).then(response => {
                    if (response.data.code == 1) {
                        this.$modal.msgSuccess('删除成功')
                        this.uploadedFileList.splice(index, 1)
                    } else {
                        this.$modal.msgError(response.data.Message || '删除失败')
                    }
                }).catch(error => {
                    this.$modal.msgError('删除请求失败')
                    console.error('删除错误:', error)
                })
            }).catch(() => { })
        },
        //#endregion
        //#region 附件批量下载
        handleBatchFileDownload() {
            if (this.rowList.length === 0) {
                this.$modal.msgWarning('请先选择要下载附件的单据')
                return
            }
            this.selectedBillCount = this.rowList.length
            this.batchFileList = []
            this.selectedBatchFiles = []
            this.getBatchFileList()
            this.openBatchDownload = true
        },
        getBatchFileList() {
            this.batchDownloadLoading = true
            const interIds = this.rowList.map(item => item.HInterID).join(',')
            axios.get(this.$baseUrl + '/WLYayBillController/GetBatchFileList', {
                params: {
                    HInterIDs: interIds
                }
            }).then(response => {
                this.batchDownloadLoading = false
                if (response.data.code == 1) {
                    this.batchFileList = response.data.data || []
                } else {
                    this.$modal.msgError(response.data.Message || '获取文件列表失败')
                }
            }).catch(error => {
                this.batchDownloadLoading = false
                this.$modal.msgError('获取文件列表失败')
                console.error('获取文件列表错误:', error)
            })
        },
        handleBatchFileSelectionChange(selection) {
            this.selectedBatchFiles = selection
        },
        downloadSingleFile(row) {
            if (row.url) {
                window.open(row.url, '_blank')
            } else {
                axios.get(this.$baseUrl + '/WLYayBillController/DownloadFile', {
                    params: {
                        fileId: row.id || row.fileId
                    },
                    responseType: 'blob'
                }).then(response => {
                    const blob = new Blob([response.data])
                    const url = window.URL.createObjectURL(blob)
                    const link = document.createElement('a')
                    link.href = url
                    link.download = row.name || row.fileName
                    link.click()
                    window.URL.revokeObjectURL(url)
                }).catch(error => {
                    this.$modal.msgError('下载失败')
                    console.error('下载错误:', error)
                })
            }
        },
        batchDownloadFiles() {
            if (this.selectedBatchFiles.length === 0) {
                this.$modal.msgWarning('请先选择要下载的文件')
                return
            }
            this.downloadFiles(this.selectedBatchFiles)
        },
        downloadAllFiles() {
            if (this.batchFileList.length === 0) {
                this.$modal.msgWarning('没有可下载的文件')
                return
            }
            this.downloadFiles(this.batchFileList)
        },
        downloadFiles(fileList) {
            this.batchDownloadLoading = true
            const fileIds = fileList.map(item => item.id || item.fileId).join(',')
            axios.get(this.$baseUrl + '/WLYayBillController/BatchDownloadFiles', {
                params: {
                    fileIds: fileIds
                },
                responseType: 'blob'
            }).then(response => {
                this.batchDownloadLoading = false
                const blob = new Blob([response.data], { type: 'application/zip' })
                const url = window.URL.createObjectURL(blob)
                const link = document.createElement('a')
                link.href = url
                const now = new Date()
                const timestamp = `${now.getFullYear()}${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}_${now.getHours().toString().padStart(2, '0')}${now.getMinutes().toString().padStart(2, '0')}${now.getSeconds().toString().padStart(2, '0')}`
                link.download = `附件下载_${timestamp}.zip`
                link.click()
                window.URL.revokeObjectURL(url)
                this.$modal.msgSuccess('下载成功')
            }).catch(error => {
                this.batchDownloadLoading = false
                this.$modal.msgError('批量下载失败')
                console.error('批量下载错误:', error)
            })
        },
        //#endregion
        //清除选中数据的缓存
        clearData() {
            this.ids = []
@@ -1375,7 +1678,6 @@
            this.OperationType = 0
            this.copyType = 0
        },
    }
};
</script>