中扬CRM客户关系管理系统
LSH
2023-07-24 c5356be2f4f2444ebc2fe53de3d491445ab3d045
src/main/webapp/static/js/cstmr/cstmr.js
@@ -1,6 +1,7 @@
var pageCurr;
var pageCount = 0;
var treeCond;
var admin;
layui.config({
    base: baseUrl + "/static/layui/lay/modules/"
}).extend({
@@ -11,31 +12,82 @@
    var layer = layui.layer;
    var layDate = layui.laydate;
    var form = layui.form;
    var admin = layui.admin;
    admin = layui.admin;
    var xmSelect = layui.xmSelect;
    var cascader = layui.cascader;
    var tree = layui.tree;
    var dropdown = layui.dropdown;
    $('#organization').text(localStorage.getItem('nickname'));
    $('#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: 500px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
        ,style: 'width: 370px; height: 350px; padding: 0 15px; box-shadow: 1px 1px 30px rgb(0 0 0 / 12%);'
        ,ready: function(){
            loadTree();
        }
    });
    // 数据同步
    dropdown.render({
        elem: '#data-btn'
        ,align: 'right'
        ,style: 'border-radius: 5px;'
        ,className: 'site-dropdown-demo'
        ,data: [
            {
                title: '模板下载'
                ,templet: '<i class="layui-icon layui-icon-template-1"></i>{{d.title}}'
                ,id: 1
            },
            {
                title: '导入 Excel'
                ,templet: '<i class="layui-icon layui-icon-upload"></i>{{d.title}}'
                ,id: 2
            },
            {type: '-'}, //分割线
            {
                title: '导出 Excel'
                ,templet: '<i class="layui-icon layui-icon-export"></i>{{d.title}}'
                ,id: 3
            }
        ]
        ,click: async function(item){
            switch (item.id) {
                case 1:
                    // 模板下载
                    layer.load(1, {shade: [0.1,'#fff']});
                    location.href = baseUrl + "/mould/甲方单位导入模板.xls";
                    layer.closeAll('loading');
                    break
                case 2:
                    // 导入 Excel
                    $("#importExcel").trigger("click");
                    // let arrFileHandle = await window.showOpenFilePicker()
                    // let file = await arrFileHandle[0].getFile();
                    // upload(file);
                    break
                case 3:
                    // 导出 Excel
                    layer.msg("来不及做,等等", {icon: 6});
                    break
                default:
                    break
            }
        }
    });
    // 树形图
    var organizationTree;
    window.loadTree = function(condition){
    window.loadTree = function(conditionName,condition){
        var loadIndex = layer.load(2);
        $.ajax({
            url: baseUrl+"/dept/user/tree/auth",
            headers: {'token': localStorage.getItem('token')},
            data: {
                'conditionName': conditionName,
                'condition': condition
            },
            method: 'POST',
@@ -52,7 +104,7 @@
                                key: obj.data.key,
                                val: obj.data.id
                            }
                            $('#organization').text(obj.data.title);
                            $('#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'));
@@ -76,7 +128,7 @@
    tableIns = table.render({
        elem: '#cstmr',
        headers: {token: localStorage.getItem('token')},
        url: baseUrl+'/cstmr/list/auth',
        url: baseUrl+'/cstmr/page/auth',
        page: true,
        limit: 15,
        limits: [15, 30, 50, 100, 200, 500],
@@ -88,7 +140,7 @@
            {type: 'checkbox'}
            // ,{field: 'id', align: 'center',title: 'ID'}
            // ,{field: 'hostId$', align: 'center',title: '所属商户'}
            ,{field: 'name', align: 'left',title: '客户名称', style: 'color: #1890ff;cursor:pointer', event: 'more'}
            ,{field: 'name', align: 'left',title: '客户名称', style: 'color: #1890ff;cursor:pointer', event: 'more', width: 350}
            ,{field: 'uuid', align: 'left',title: '客户代号'}
            ,{field: 'addr', align: 'left',title: '详细地址', templet:function(d){return emptyShow(d.addr)}}
            ,{field: 'tel', align: 'left',title: '电话', templet:function(d){return emptyShow(d.tel)}}
@@ -142,6 +194,14 @@
    // 添加
    $("#cstmrAddBtn").click(function () {
        form.verify({
            account: function(value, item){
                var min = item.getAttribute('lay-min');
                if(value.length < min){
                    return '客户名称不能小于'+min+'个字符的长度';
                }
            }
        });
        showEditModel();
    });
@@ -183,7 +243,7 @@
                    area: "1250px",
                    url: "cstmr_more.html",
                    end: function () {
                        $(".layui-laypage-btn")[0].click();
                        // $(".layui-laypage-btn")[0].click();
                    }
                })
                break;
@@ -204,6 +264,14 @@
            title: (mData ? '修改' : '添加') + '甲方单位',
            content: $('#editDialog').html(),
            success: function (layero, dIndex) {
                form.verify({
                    name: function(value, item){
                        var min = item.getAttribute('lay-min');
                        if(value.length < min){
                            return '客户名称不能小于'+min+'个字符的长度';
                        }
                    }
                });
                if (mData) {
                    $('#cascaderVal').val(mData.pcd);
                }
@@ -333,3 +401,46 @@
        $(".layui-laypage-btn")[0].click();
    }
}
function upload(obj){
    if(!obj.files) {
        return;
    }
    var file = obj.files[0];
    admin.confirm('确认同步 [' + file.name +'] 文件吗?', function (index) {
        layer.load(1, {shade: [0.1,'#fff']});
        var url = baseUrl + "/cstmr/excel/import/auth";
        var form = new FormData();
        form.append("file", file);
        let xhr = new XMLHttpRequest();
        xhr.open("post", url, true);
        xhr.setRequestHeader('token', localStorage.getItem('token'));
        xhr.onload = uploadComplete;
        xhr.onerror =  uploadFailed;
        xhr.onloadend = function () {
            layer.closeAll('loading');
        };
        // xhr.upload.onprogress = progressFunction;
        xhr.upload.onloadstart = function(){
            ot = new Date().getTime();
            oloaded = 0;
        };
        xhr.send(form);
    }, function(index){
    });
}
function uploadComplete(evt) {
    let res = JSON.parse(evt.target.responseText);
    if(res.code === 200) {
        layer.msg(res.msg, {icon: 1});
        tableReload();
    } else {
        alert(res.msg);
        // layer.msg(res.msg, {icon: 2});
    }
}
function uploadFailed(evt) {
    let res = JSON.parse(evt.target.responseText);
    alert(res.msg);
    // layer.msg(res.msg, {icon: 2});
}