中扬CRM客户关系管理系统
#
LSH
2023-11-21 29cfba4aa2e41fb15cacb500c3e2d9ae7c652d08
src/main/webapp/static/js/businessTrip/businessTrip.js
@@ -3,7 +3,7 @@
    base: baseUrl + "/static/layui/lay/modules/"
}).extend({
    cascader: 'cascader/cascader',
}).use(['table','laydate', 'form', 'admin', 'cascader'], function(){
}).use(['table','laydate', 'form', 'admin', 'xmSelect', 'cascader', 'tree', 'dropdown'], function(){
    var table = layui.table;
    var $ = layui.jquery;
    var layer = layui.layer;
@@ -11,6 +11,64 @@
    var form = layui.form;
    var admin = layui.admin;
    var cascader = layui.cascader;
    var tree = layui.tree;
    var dropdown = layui.dropdown;
    $('#organization').html(localStorage.getItem('nickname') + ' <i class="layui-icon">&#xe61a;</i>');
    // 部门人员 筛选
    dropdown.render({
        elem: '#organization'
        ,content: ['<div id="organizationTree" style="height: calc(100vh - 525px);border: none"></div>'].join('')
        ,style: 'width: 370px; height: 350px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
        ,ready: function(){
            loadTree();
        }
    });
    // 树形图
    var organizationTree;
    window.loadTree = function(condition){
        var loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl+"/dept/user/tree/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                'condition': condition
            },
            method: 'POST',
            success: function (res) {
                layer.close(loadIndex);
                if (res.code === 200){
                    organizationTree = tree.render({
                        elem: '#organizationTree',
                        id: 'organizationTree',
                        onlyIconControl: true,
                        data: res.data,
                        click: function (obj) {
                            treeCond = {
                                key: obj.data.key,
                                val: obj.data.id
                            }
                            $('#organization').html(obj.data.title + ' <i class="layui-icon">&#xe61a;</i>');
                            $('#organizationTree').find('.ew-tree-click').removeClass('ew-tree-click');
                            $(obj.elem).children('.layui-tree-entry').addClass('ew-tree-click');
                            clearFormVal($('#search-box'));
                            tableIns.reload({
                                where: {[obj.data.key]: obj.data.id},
                                page: {curr: 1}
                            });
                        }
                    });
                    treeData = res.data;
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg)
                }
            }
        })
    }
    // 数据渲染
    tableIns = table.render({
@@ -28,31 +86,32 @@
            {field: 'id', align: 'center',title: 'ID',hide: true}
            ,{field: 'businessTripReasons', align: 'center',title: '出差事由',hide: false}
            ,{field: 'businessTransportation$', align: 'center',title: '交通工具',hide: false}
            ,{field: 'businessReturn$', align: 'center',title: '单程往返',hide: false}
            ,{field: 'businessReturn$', align: 'center',title: '单程往返',hide: true}
            ,{field: 'businessStartAddr', align: 'center',title: '出发地', templet:function(d){return emptyShow(d.businessStartAddr)},hide: true}
            ,{field: 'businessStartAddr$', align: 'center',title: '出发地',hide: false}
            ,{field: 'businessEndAddr', align: 'center',title: '目的地', templet:function(d){return emptyShow(d.businessEndAddr)},hide: true}
            ,{field: 'businessEndAddr$', align: 'center',title: '目的地',hide: false}
            ,{field: 'businessStartTimeDay$', align: 'center',title: '出发日期',hide: false,width: 165}
            ,{field: 'businessEndTimeDay$', align: 'center',title: '结束日期',hide: false,width: 165}
            ,{field: 'businessDuration', align: 'center',title: '出差时长',hide: false}
            ,{field: 'businessTripDays', align: 'center',title: '出差天数',hide: false}
            ,{field: 'businessPeers', align: 'center',title: '出行人',hide: false}
            ,{field: 'businessPeersId', align: 'center',title: '同行人ID',hide: true}
            ,{field: 'carNumber', align: 'center',title: '自驾私家车车牌号',hide: false}
            ,{field: 'kilometers', align: 'center',title: '自驾私家车行程明细及公里数',hide: false}
            ,{field: 'businessDuration$', align: 'center',title: '出差时长',hide: false}
            ,{field: 'businessTripDays$', align: 'center',title: '出差天数',hide: false}
            ,{field: 'businessPeers', align: 'center',title: '同行人',hide: false}
            ,{field: 'businessPeersId', align: 'center',title: '时间戳',hide: true}
            ,{field: 'carNumber', align: 'center',title: '自驾私家车车牌号',hide: true}
            ,{field: 'kilometers', align: 'center',title: '自驾私家车行程明细及公里数',hide: true}
            ,{field: 'userId$', align: 'center',title: '申请人',hide: false}
            ,{field: 'deptId$', align: 'center',title: '所属部门',hide: false}
            ,{field: 'deptId$', align: 'center',title: '所属部门',hide: true}
            ,{field: 'hostId', align: 'center',title: 'hostId',hide: true}
            ,{field: 'createTime$', align: 'center',title: '创建时间',hide: false,width: 125}
            ,{field: 'orderId', align: 'center',title: '跟踪项目',hide: false}
            ,{field: 'createTime$', align: 'center',title: '创建时间',hide: true,width: 125}
            ,{field: 'updateTime$', align: 'center',title: '更新时间',hide: false,width: 125}
            ,{field: 'updateId$', align: 'center',title: '更新人员',hide: false}
            ,{field: 'settle$', align: 'center',title: '进度',hide: false}
            ,{field: 'status$', align: 'center',title: '状态',hide: false}
            ,{field: 'settle$', align: 'center',title: '进度', style: 'color: #1890ff;cursor:pointer', event: 'more',hide: false}
            ,{field: 'status$', align: 'center',title: '状态',hide: true}
            ,{field: 'businessTripType', align: 'center',title: '类型',hide: true}
            ,{field: 'businessNotes', align: 'center',title: '出差备注',hide: false}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:120}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:240}
        ]],
        request: {
            pageName: 'curr',
@@ -153,6 +212,32 @@
    table.on('tool(businessTrip)', function(obj){
        var data = obj.data;
        switch (obj.event) {
            case 'addBlank':
                showEditModelBlank(data.id);
                break;
            case 'approval':
                layer.confirm('审批通过?', {
                    skin: 'layui-layer-admin',
                    shade: .1,
                    offset: '200px',
                    title: data.name
                }, function (i) {
                    layer.close(i);
                    approval(data.id);
                });
                break;
            case 'more':
                top.businessTripByMore = data.id;
                admin.popupRight({
                    type: 1,
                    window: "top",
                    area: "1250px",
                    url: "businessTrip_more.html",
                    end: function () {
                        // $(".layui-laypage-btn")[0].click();
                    }
                })
                break;
            case 'edit':
                showEditModel(data);
                break;
@@ -166,8 +251,8 @@
    function showEditModel(mData) {
        admin.open({
            type: 1,
            area: ["95%", "90%"],
            title: (mData ? '修改' : '添加') + '订单状态',
            area: ["95%", "75%"],
            title: (mData ? '修改' : '添加') + '出差申请',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                if (mData) {
@@ -236,6 +321,267 @@
        });
    }
    // 显示表单弹窗
    function showEditModelBlank(businessId) {
        admin.open({
            type: 1,
            title: '添加报销审批',
            content: $('#editDialog2').html(),
            area: '2200px',
            success: function (layero, dIndex) {
                $(layero).children('.layui-layer-content').css('overflow', 'visible');
                var isExpAdd = true;
                // 回显数据
                form.val('editForm', false);
                // console.log(expTpe)
                // if (expTpe) {
                //     // $('#orderNo').attr("disabled", "disabled");
                // }
                // 表单提交事件
                form.on('submit(orderEditSubmit)', function (data) {
                    // 组装数据
                    if (xxDataList.length <= 0) {
                        layer.tips('请添加报销明细', '#matAddBtnComment', {tips: [1, '#ff4c4c']});
                        return false;
                    }
                    let nList = admin.util.deepClone(xxDataList);
                    for (let xi = 0; xi < nList.length; xi++) {
                        // if (nList[xi].anfme <= 0){
                        //     layer.msg('明细修改数量不合法', {icon: 2});
                        //     return false;
                        // }
                    }
                    layer.load(2);
                    $.ajax({
                        url: baseUrl+"/reimburseOnline/from/" + (isExpAdd?"add":"modify") + "/auth",
                        headers: {'token': localStorage.getItem('token')},
                        data: JSON.stringify({
                            reimburseId: Number(data.field.id),
                            docType: Number(data.field.docType),
                            businessId: businessId,
                            templateName: data.field.templateName,
                            checkData: data.field.checkData,
                            reimburseOnlineDetls: nList
                        }),
                        contentType:'application/json;charset=UTF-8',
                        method: 'POST',
                        success: function (res) {
                            console.log(data)
                            layer.closeAll('loading');
                            if (res.code === 200){
                                layer.close(dIndex);
                                $(".layui-laypage-btn")[0].click();
                                layer.msg(res.msg, {icon: 1});
                            } else if (res.code === 403){
                                top.location.href = baseUrl+"/";
                            }else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }
                    })
                    return false;
                });
                // 明细表格
                var xxDataList = [];
                var tbOptions = {
                    elem: '#formSSXMTable',
                    headers: {token: localStorage.getItem('token')},
                    data: xxDataList,
                    page: true,
                    height: '350px;',
                    cellMinWidth: 100,
                    cols: [[
                        {type: 'numbers', title: '#'},
                        {field: 'occupation', title: '事由', width: 100, style: 'color: blue;font-weight: bold', edit:true},
                        // {field: 'expenseType', title: '费用类型', width: 100},
                        {field: 'expenseType$', title: '费用类型', width: 100},
                        {field: 'taxRate', title: '税率', width: 60, edit: true},
                        {field: 'untaxedAmountInLocalCurrency', title: '未税本币金额', width: 120, edit: true},
                        {field: 'untaxedAmount', title: '未税金额', width: 100, edit: true},
                        {field: 'taxAmount', title: '税额', width: 60, edit: true},
                        {field: 'invoiceValue', title: '发票金额', width: 100, edit: true},
                        {field: 'invoiceAmountInLocalCurrency', title: '发票本币金额', width: 120, edit: true},
                        {field: 'reimbursementRatio', title: '报销比例', width: 100, edit: true},
                        {field: 'reimbursementAmount', title: '报销金额', width: 100, edit: true},
                        {field: 'reimbursementAmountInLocalCurrency', title: '报销本币金额', width: 120, edit: true},
                        {field: 'cashierConfirmationAmount', title: '出纳确认金额', width: 120, edit: true},
                        {field: 'cashierCurrency', title: '出纳币种', width: 100, edit: true},
                        {field: 'departureTime', title: '出发日期', width: 100},
                        {field: 'cashierConfirmationAmount', title: '出纳确认金额', width: 120, edit: true},
                        {field: 'userId', title: '列支人员', width: 120},
                        {field: 'deptId', title: '列支部门', width: 120},
                        {field: 'updateTime', title: '更新日期', width: 100},
                        // {field: 'updateUserId', title: '更新人员ID', width: 160},
                        {field: 'updateUserName', title: '更新人员名字'},
                        // {field: 'creationTime', title: '创建日期', width: 160}
                        {align: 'center', title: '操作', toolbar: '#formSSXMTableBar', minWidth: 80, width: 80, fixed: 'right'}
                    ]],
                    done: function (res, curr, count) {
                        $(layero).find('.layui-table-view').css('margin', '0');
                        var options = this;
                        // 获取当前行数据
                        table.getRowData = function(elem){
                            var index = $(elem).closest('tr').data('index');
                            return table.cache[options.id][index] || {};
                        };
                        $('.input-occupation').on('text', function(){
                            var value = this.value; // 获取选中项 value
                            var data = table.getRowData(this);
                            console.log(value);
                            console.log("value------===");
                            xxDataList.forEach(res => {
                                if (data.id === res.id){
                                    console.log(res)
                                    res.occupation = value;
                                }
                            })
                        });
                    },
                    size: ''
                };
                var insTbSSXM = table.render(tbOptions);
                // 工具条点击事件
                table.on('tool(formSSXMTable)', function (obj) {
                    var data = obj.data;
                    var layEvent = obj.event;
                    if (layEvent === 'edit') {
                        showEditModel2(data);
                    } else if (layEvent === 'del') {
                        layer.confirm('确定要删除吗?', {
                            shade: .1,
                            skin: 'layui-layer-admin'
                        }, function (i) {
                            layer.close(i);
                            for (var j = 0; j < xxDataList.length; j++) {
                                if (xxDataList[j].matnr === data.matnr && xxDataList[j].batch === data.batch) {
                                    xxDataList.splice(j, 1);
                                    break;
                                }
                            }
                            insTbSSXM.reload({data: xxDataList, page: {curr: 1}});
                        });
                    }
                });
                // 明细数据修改
                table.on('edit(formSSXMTable)', function (obj) {
                    let index = obj.tr.attr("data-index");
                    let data = xxDataList[index];
                    if (obj.field === 'anfme'){
                        let vle = Number(obj.value);
                        if (isNaN(vle)) {
                            layer.msg("请输入数字", {icon: 2});
                            return false;
                        } else {
                            if (vle <= 0) {
                                layer.msg("数量必须大于零", {icon: 2});
                                return false;
                            }
                        }
                    }
                    data[obj.field] = obj.value;
                    insTbSSXM.reload({data: xxDataList});
                });
                $('#matAddBtnComment').click(function () {
                    showEditModel2();
                });
                // 显示添加明细表单弹窗
                function showEditModel2(exp) {
                    admin.open({
                        type: 1,
                        offset: '150px',
                        area: '680px',
                        title: (exp ? '修改' : '添加') + '明细',
                        content: $('#matEditDialog').html(),
                        success: function (layero, dIndex) {
                            console.log("exp")
                            console.log(exp)
                            // 回显数据
                            form.val('matEditForm', exp);
                            // 表单提交事件
                            form.on('submit(matEditSubmit)', function (data) {
                                let selectList = matXmSelect.getValue();
                                console.log("selectList")
                                console.log(selectList)
                                console.log(selectList)
                                for (let i = 0; i<selectList.length; i++) {
                                    let item = selectList[i];
                                    // 查询物料详情
                                    $.ajax({
                                        url: baseUrl+"/reimburseCostTypes/covert/"+item.value+"/auth",
                                        headers: {'token': localStorage.getItem('token')},
                                        method: 'GET',
                                        async: false,
                                        success: function (res) {
                                            if (res.code === 200){
                                                var bige=true;
                                                // console.log("-------2.1-------")
                                                // for (var j = 0; j < xxDataList.length; j++) {
                                                //     if (xxDataList[j].expenseType === res.data.expenseType && xxDataList[j].batch === res.data.batch) {
                                                //         bige=false;
                                                //         console.log("-------2.2-------")
                                                //         break;
                                                //     }
                                                // }
                                                if (bige){
                                                    // console.log("-------2.3-------")
                                                    xxDataList.push(res.data);
                                                    insTbSSXM.reload({data: xxDataList, page: {curr: 1}});
                                                }
                                            } else if (res.code === 403){
                                                top.location.href = baseUrl+"/";
                                            }else {
                                                layer.msg(res.msg, {icon: 2})
                                            }
                                        }
                                    })
                                }
                                layer.close(dIndex);
                                return false;
                            });
                            // 渲染物料选择
                            var matXmSelect = xmSelect.render({
                                el: '#reimburseCostTypes',
                                style: {
                                    width: '340px',
                                },
                                autoRow: true,
                                toolbar: { show: true },
                                filterable: true,
                                remoteSearch: true,
                                remoteMethod: function(val, cb, show){
                                    $.ajax({
                                        url: baseUrl+"/reimburseCostTypes/all/get/kv",
                                        headers: {'token': localStorage.getItem('token')},
                                        data: {
                                            condition: val
                                        },
                                        method: 'POST',
                                        success: function (res) {
                                            if (res.code === 200){
                                                cb(res.data)
                                            } else {
                                                cb([]);
                                                layer.msg(res.msg, {icon: 2});
                                            }
                                        }
                                    });
                                }
                            })
                            // 弹窗不出现滚动条
                            $(layero).children('.layui-layer-content').css('overflow', 'visible');
                            layui.form.render('select');
                        }
                    });
                }
            }
        });
    }
    // 搜索
    form.on('submit(search)', function (data) {
        pageCurr = 1;
@@ -303,6 +649,33 @@
        });
    }
    function approval(planId, plannerId, dIdx) {
        let loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl+"/businessTrip/approval/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                planId: planId,
                plannerId: plannerId
            },
            method: 'POST',
            success: function (res) {
                if (dIdx) {
                    layer.close(dIdx);
                }
                layer.close(loadIndex);
                if (res.code === 200){
                    layer.msg(res.msg, {icon: 1});
                    tableReload();
                } else if (res.code === 403){
                    top.location.href = baseUrl+"/";
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }
        })
    }
});
// 关闭动作