中扬CRM客户关系管理系统
#
Junjie
2023-09-08 3041a7d6dba13e237c4f21d3e46b88c35d376bf3
src/main/webapp/static/js/companyTarget/companyTarget.js
@@ -26,7 +26,7 @@
            {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: '#ID'}
            , {field: 'year', align: 'center', title: '年度'}
            , {field: 'target', align: 'center', title: '目标'}
            , {field: 'target', align: 'center', title: '目标',templet: '#targetTmp'}
            , {fixed: 'right', title: '操作', align: 'center', toolbar: '#operate', width: 400}
        ]],
@@ -135,22 +135,6 @@
            case "del":
                del([data.id]);
                break;
            case "generate":
                //生成合同
                generate(data)
                break
            case "sales":
                //合同明细
                sales(data);
                break
            case "upload":
                //上传合同
                upload(data)
                break
            case "download":
                //下载合同
                download(data)
                break
        }
    });
@@ -188,157 +172,6 @@
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        });
    }
    /* 生成合同 */
    function generate(mData) {
        admin.open({
            type: 1,
            area: '600px',
            title: '生成合同',
            content: $('#generateDialog').html(),
            success: function (layero, dIndex) {
                layDateRender(mData);
                form.val('detail', mData);
                form.on('submit(generateSubmit)', function (data) {
                    var loadIndex = layer.load(2);
                    $.ajax({
                        url: baseUrl + "/companyTarget/generate/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: data.field,
                        method: 'GET',
                        xhrFields: {
                            responseType: "blob" // 设置响应类型为二进制数据
                        },
                        success: function (res) {
                            // 创建一个临时的下载链接
                            const url = window.URL.createObjectURL(res);
                            // 创建一个隐藏的 <a> 元素并设置下载链接
                            const a = document.createElement("a");
                            a.style.display = "none";
                            a.href = url;
                            a.download = data.field.name + ".docx"; // 指定下载的文件名
                            document.body.appendChild(a);
                            // 触发点击事件以开始下载
                            a.click();
                            // 清理临时资源
                            setTimeout(function () {
                                window.URL.revokeObjectURL(url);
                                document.body.removeChild(a);
                            }, 100);
                            layer.close(loadIndex);
                            layer.close(dIndex);
                        }
                    })
                    return false;
                });
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                layui.form.render('select');
            }
        });
    }
    /* 合同明细 */
    function sales(mData) {
        layer.open({
            type: 2,
            title: '合同明细',
            maxmin: true,
            area: [top.detailWidth, top.detailHeight],
            shadeClose: false,
            content: '../companyTargetSales/companyTargetSales.html?companyTargetId=' + mData.id,
            success: function (layero, index) {
            }
        });
    }
    //上传合同
    function upload(data) {
        if (data.filepath == '' || data.filepath == null) {
            layer.confirm('是否上传合同?', function () {
                $("#uploadQuote").click()
            });
        } else {
            layer.confirm('已上传合同,是否继续覆盖上传?', function () {
                $("#uploadQuote").click()
            });
        }
        $("#uploadQuote").on("change", (evt) => {
            var files = evt.target.files;
            if (files == null || files.length == 0) {
                alert("No files wait for import");
                return;
            }
            let name = files[0].name;
            let suffixArr = name.split("."), suffix = suffixArr[suffixArr.length - 1];
            // if(suffix!="xlsx"){
            //     alert("Currently only supports the import of xlsx files");
            //     return;
            // }
            let formData = new FormData($("#uploadFile")[0]);
            formData.append("id", data.id);
            $.ajax({
                url: baseUrl + "/companyTarget/upload/auth",
                headers: {'token': localStorage.getItem('token')},
                data: formData,
                method: 'POST',
                cache: false,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res.code == 200) {
                        layer.msg('上传成功', {time: 1000}, () => {
                            parent.location.reload()
                        })
                    } else {
                        layer.msg(res.msg, {time: 1000}, () => {
                            parent.location.reload()
                        })
                    }
                }
            })
        })
    }
    //下载合同
    function download(data) {
        $.ajax({
            url: baseUrl + "/companyTarget/download/auth",
            headers: {'token': localStorage.getItem('token')},
            data: data,
            method: 'GET',
            xhrFields: {
                responseType: "blob" // 设置响应类型为二进制数据
            },
            success: function (res) {
                // 创建一个临时的下载链接
                const url = window.URL.createObjectURL(res);
                // 创建一个隐藏的 <a> 元素并设置下载链接
                const a = document.createElement("a");
                a.style.display = "none";
                a.href = url;
                let list = data.filepath.split(".")
                let suffix = "." + list[list.length - 1]//获取后缀名
                a.download = data.name + suffix; // 指定下载的文件名
                document.body.appendChild(a);
                // 触发点击事件以开始下载
                a.click();
                // 清理临时资源
                setTimeout(function () {
                    window.URL.revokeObjectURL(url);
                    document.body.removeChild(a);
                }, 100);
            }
        });
    }