BaseProject.js 11.1 KB
let action = null;
layui.config({
    base: "/js/",
    version: 1
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        sendDataWhere = null,
        sendDataDescWhere = null,
        areaName = "configure",
        controllerName = "BaseProject",
        app = null;

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
                //sendDataWhere: null,
                //isAddWhereExtend: "arbitrarily",
                //mainTable: app.data.tableIns,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/DelByIds`,
                titleConfirmDelete:"确定要删除所选信息吗?项目已绑定客户,项目不能直接删除需要先解绑客户和设备再删除项目。删除项目会直接删除厂房!",
                keyId: "keys"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${controllerName}/Export`,
                isDefault: false,
                sendDataWhere:{},
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controllerName}/Export`,
                urlQuery: `/${areaName}/${controllerName}/Load`,
                sendDataWhere:{},
                mainTable: app.data.tableIns
            }
            return options;
        },
        /*rowClickOptions: function () {
            var options = {
                //是否主子表
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },*/

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },
        editSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },

        checkboxMethod: function (obj) {
            var page = "".GetUrlParam("page"),
                clientKeys = "".GetUrlParam("clientKeys");
            if (page == "BaseClientInfo") {
                var sendData = {
                    clientKeys: clientKeys,
                    checkeds: obj.checked,
                    projectKeys: obj.data.keys,
                };
                var ajaxConfig = {
                    data: sendData,
                    url: "/configure/BaseClientInfo/BindClientProject",
                    success: function (result) {
                        if (sysU.successBefore(result)) return false;
                        layer.msg(result.Message);
                    }
                };
                sysU.ajax(ajaxConfig);
            }
        },
        //所有动作成功之后
        actionSuccess: (flag) => {
            sysU.refreshTable(app, sysU, null, flag);
        },
        closeAfter: function (callBack) {
            if (callBack != null) callBack();
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id" },
                { field: "keys", width: 80, hide: true, title: "Keys" },
                { field: "projectName", width: 200, title: "项目名称" },
               
                { field: "projectManager", width: 150, title: "项目经理" },
                { field: "telephone", width: 150, title: "负责人电话" },
                { field: "projectStatus", width: 150, title: "状态", templet: function (obj) { return "".GetState(window.top.EnumProjectStatus, obj.projectStatus) } },
                { field: "projectStartTime", width: 150, title: "开始日期" },
                { field: "projectEndTime", width: 150, title: "结束日期" },
                { field: "projectAddress", width: 300, title: "地址" },
                { field: "longitude", width: 100, title: "经度" },
                { field: "latitude", width: 100, title: "纬度" },
                { field: "picture", width: 150, title: "图片" },
                { field: "projectDescribe", width: 150, title: "描述" },

                { field: "createBy", width: 150, title: "创建人" },
                { field: "createTime", width: 150, title: "创建时间" },
            ]],
            tableIns: null,
            tableElem: "mainList",

            btnGetPoint: $("#btnGetPoint"),
            txtProjectAddress: $("#modifyForm form  input[name=projectAddress]"),
            btnCopyLonLat: document.querySelector("#btnCopyLonLat"),


            //下拉框配置
            selectOptionEnum: {
                type: {
                    SelFrom: "dataSource",
                    SelValue: "value",
                    Dom: [$("select[name='projectStatus']")],
                    dataSource: window.top.EnumProjectStatus,
                },
                //返回的数据 用于后续操作
                selectData: {
                }
            },

            //下拉框配置
            selectOption: {
                projectType: {
                    SelType: "FromDict",
                    SelFrom: "projectType",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='projectType']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            },
        },
        methods: {
            initTable: function (opt) {
                var config = {};
                if (opt != undefined) $.extend(config, opt);
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${controllerName}/Load`,
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                    where: config, 
                    //height: "full-56",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {
                        var pageFlag = "".GetUrlParam("page"),
                            clientKeys = "".GetUrlParam("clientKeys");
                        //加载用户绑定的客户
                        if (pageFlag == "BaseClientInfo") {
                            let ajaxConfig = {
                                data: { clientKeys: clientKeys },
                                url: `/configure/BaseClientInfo/GetClientBindProjects`,
                                success: function (result) {
                                    if (sysU.successBefore(result)) return false;
                                    var targetArrValue = result.Result.map(function (e) { return e.projectKeys; });
                                    var selectColKey = "".GetUrlParam("selectColKeyCustom");
                                    sysU.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
                                }
                            };
                            sysU.ajax(ajaxConfig);
                        }
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            //根据地址解析经度纬度
            setLngAndlat() {
                debugger
                let address = app.data.txtProjectAddress.val();
                if (!address) {
                    app.data.txtProjectAddress.focus();
                    return;
                }
                mapApp.fn.getPointByAddress(address, (point) => {
                    var val = {  longitude: "", latitude: "", }
                    if (point) {
                        val.longitude = point.lng;
                        val.latitude = point.lat;
                    }
                    form.val("modifyForm", val);
                });
            },

            initFrom() {
                sysU.initSelecteByEnum(app.data.selectOptionEnum);
                sysU.initSelect(app.data.selectOption);
            },
            initCopy() {
                app.data.btnCopyLonLat.addEventListener("click", function (event) {
                    $("#modifyForm form  input[name=longitude]").focus();
                    // 获取剪贴板中的文本数据
                    navigator.clipboard.readText()
                        .then(text => {
                            debugger
                            const pattern = /^\d+(\.\d+)?,\d+(\.\d+)?$/;
                            if (!pattern.test(text)) {
                                layer.alert('经纬度复制的值错误,正确的是格式【x,x】x是数字!', { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                                return;
                            }
                            var tempValue = text.split(",");
                            form.val("modifyForm", { longitude: tempValue[0], latitude: tempValue[1] });
                        })
                        .catch(err => {
                            layer.alert('无法读取剪贴板数据:' + err, { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleError });
                        });
                });
            }
        },
        registerEvent: function () {
            app.data.btnGetPoint.click(function () {
                app.methods.setLngAndlat();
            })
        },
        init: function () {
            debugger
            app.methods.initTable();
            app.methods.initFrom();
            app.methods.initCopy();
            app.registerEvent();
        }
    };
    app.init();
});