Blame view

web/WebMvc/wwwroot/productjs/configure/baseproject.js 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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",
唐召明 authored
16
        xmSelectObj = null,
17
18
19
20
21
22
23
        app = null;

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
唐召明 authored
24
                area: ["750px", "550px"],
25
26
27
28
29
30
31
32
33
34
35
36
                //sendDataWhere: null,
                //isAddWhereExtend: "arbitrarily",
                //mainTable: app.data.tableIns,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Upd`,
37
                area: ["750px", "550px"],
38
39
40
41
42
43
44
45
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/DelByIds`,
唐召明 authored
46
                titleConfirmDelete: "确定要删除所选信息吗?项目已绑定客户,项目不能直接删除需要先解绑客户和设备再删除项目。删除项目会直接删除厂房!",
47
                keyId: "keys",
唐召明 authored
48
                deleteCount: 1
49
50
51
52
53
54
55
56
57
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${controllerName}/Export`,
                isDefault: false,
唐召明 authored
58
                sendDataWhere: {},
59
60
61
62
63
64
65
66
67
68
69
70
71
72
                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`,
唐召明 authored
73
                sendDataWhere: {},
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                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;
        },
98
        addBefore: function (callBack, flagKey) {
99
100
101
102
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },
103
        addSaveBefore: function (data, callBack, flagKey) {
104
            debugger
105
106
107
            if (flagKey == "btnCopyAdd") {
                data.field.eqCount = "0"
            }
108
109
110
111
            if (new Date(data.field.projectStartTime) > new Date(data.field.projectEndTime)) {
                layer.alert("开始时间不能大于结束时间", { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                return
            }
112
113
114
115
116
117
            var projectRoles = "".XmSelectGetValue(xmSelectObj);
            if (!projectRoles) {
                layer.alert("请选择项目角色!", { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                return;
            }
            data.field["projectRoles"] = projectRoles;
118
119
120
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
121
            debugger
122
            form.val("modifyForm", data);
123
124
125
126
            var projectRoles = data.projectRoles;
            var projectRolesArr = projectRoles.split(",");
            //先清空项目角色,在设置项目的值
            "".XmSelectSetValue(xmSelectObj);
唐召明 authored
127
128
            "".XmSelectSetValue(xmSelectObj, projectRolesArr);
129
130
131
            if (callBack != null) callBack();
        },
        editSaveBefore: function (data, callBack) {
132
133
134
135
            if (new Date(data.field.projectStartTime) > new Date(data.field.projectEndTime)) {
                layer.alert("开始时间不能大于结束时间", { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                return
            }
136
137
138
139
140
141
142
            var projectRoles = "".XmSelectGetValue(xmSelectObj);
            if (!projectRoles) {
                layer.alert("请选择项目角色!", { icon: sysU.config.iconoError, shadeClose: true, title: sysU.config.titleOpen });
                return;
            }
            data.field["projectRoles"] = projectRoles;
143
144
145
146
            if (callBack != null) callBack();
        },

        checkboxMethod: function (obj) {
147
            //用户绑定项目
148
            var page = "".GetUrlParam("page"),
唐召明 authored
149
150
151
                projectRoleKey = "".GetUrlParam("projectRoleKey");
            if (page != "sysuser") {
                return;
152
            }
唐召明 authored
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
            var sendData = {
                projectRoleKey: projectRoleKey,
                checkeds: obj.checked,
                projectKeys: obj.data.keys
            };

            console.log(sysU.getTableAllData(app.data.tableElem));
            if (obj.type == "all") {
                sendData.projectKeys = sysU.getTableAllData(app.data.tableElem).map(x => x.keys);//.GetArrValue("keys");
            }
            if (sendData.projectKeys == null || sendData.projectKeys == "") {
                layer.alert("checkboxMethod:工位标识【projectKeys】为空,请重新关闭后再操作,反复出现请联系管理员", { icon: 2, shadeClose: true, title: "提示" });
                return false;
            }
            var ajaxConfig = {
                data: sendData,
                url: "/base/SysUser/RoleBindProjectRel",
                success: function (result) {
                    if (sysU.successBefore(result)) return false;
                    layer.msg(result.Message);
                    sysU.refreshTable(app, sysU, null, "main");
                }
            };
            sysU.ajax(ajaxConfig);
177
        },
178
        //项目客户信息链接
179
180
        btnUserProjectLink: function (sU, toolbarId, obj) {
            sU.getParentElemId("SysUser").click();
181
        },
182
183
184
        //地图默认定位(本地) 
        btnMapPosition: function (sU, toolbarId, obj) {
            var dataCheckObj = table.checkStatus(toolbarId);
唐召明 authored
185
            if (dataCheckObj.data.length != 1) {
186
187
188
                layer.alert(sU.config.titleSelectOneRowData, { icon: sU.config.iconoError, shadeClose: true, title: sU.config.titleSelectOneRowData });
                return;
            }
赖素文 authored
189
            localStorage.setItem("defaultSelectProjectId", dataCheckObj.data[0].id);
190
            layer.msg(sU.config.titleActionSuccess, { icon: sU.config.iconoOk, shade: 0.4, time: 2000 });
191
192
        },
193
194
        //所有动作成功之后
        actionSuccess: (flag) => {
HuXiYu authored
195
            sysU.refreshTable(app, sysU, null, flag);
196
197
198
199
200
201
202
203
204
205
206
207
        },
        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" },
208
                { field: "projectCode", width: 200, title: "项目编码", hide: true, },
209
                { field: "projectName", width: 200, title: "项目名称" },
210
211

                { field: "eqCount", width: 100, title: "设备总数" },
唐召明 authored
212
                /*   { field: "projectUsers", width: 200, title: "用户账号登入" },*/
213
                { field: "projectManager", width: 150, title: "项目负责人" },
214
                { field: "telephone", width: 150, title: "负责人电话" },
215
216
                { field: "projectClientName", width: 150, title: "工商信息" },
                { field: "projectAddress", width: 300, title: "项目地址" },
217
218
                {
                    field: "projectStatus", width: 120, title: "状态", templet: function (obj) {
219
                        var state = "".GetState(sysU.sysEnumData.EnumProjectStatus, obj.projectStatus)
220
                        var nowTime = new Date();
221
                        if (nowTime > new Date(obj.projectEndTime) && state != sysU.sysEnumData.EnumProjectStatus["已完成"]) {
222
223
224
225
226
                            return `<span   style='color:red;' >${state}</span>`;
                        }
                        return state;
                    }
                },
227
228
229
230
231
232
233
234
235
236
                {
                    field: "projectStartTime", width: 150, title: "开始日期", templet: function (obj) {
                        return new Date(obj.projectStartTime).format("yyyy-MM-dd")
                    }
                },
                {
                    field: "projectEndTime", width: 150, title: "结束日期", templet: function (obj) {
                        return new Date(obj.projectEndTime).format("yyyy-MM-dd")
                    }
                },
237
238
                { field: "longitude", width: 100, title: "经度" },
                { field: "latitude", width: 100, title: "纬度" },
239
                { field: "picture", width: 150, title: "图片" },
240
241
                { field: "projectDescribe", width: 150, title: "描述" },
唐召明 authored
242
                { field: "projectRoles", hide: true, width: 150, title: "项目对应的角色" },
243
244
                { field: "createBy", width: 150, title: "创建人" },
                { field: "createTime", width: 150, title: "创建时间" },
245
246
247
            ]],
            tableIns: null,
            tableElem: "mainList",
248
249
250

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

            //下拉框配置
255
            selectOptionEnum: {
赖素文 authored
256
257
                type: {
                    SelFrom: "dataSource",
258
                    SelValue: "value",
赖素文 authored
259
                    Dom: [$("select[name='projectStatus']")],
260
                    dataSource: sysU.sysEnumData.EnumProjectStatus,
赖素文 authored
261
                },
262
263
264
                //返回的数据 用于后续操作
                selectData: {
                }
265
266
267
268
269
270
271
272
273
274
275
            },

            //下拉框配置
            selectOption: {
                projectType: {
                    SelType: "FromDict",
                    SelFrom: "projectType",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='projectType']")]
                },
276
277
278
279
280
281
282
                lineCode: {
                    SelType: "FromUrl",
                    SelFrom: "/configure/BaseClientInfo/Load",
                    SelLabel: "clientName",
                    SelValue: "keys",
                    Dom: [$("[name='projectClientInfoKeys']")]
                },
283
284
285
286
287
                //返回的数据 用于后续操作
                selectData: {

                }
            },
288
289
290
291
292
293
294
295
296
297
        },
        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',
唐召明 authored
298
                    where: config,
299
300
                    //height: "full-56",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {
HuXiYu authored
301
                        var pageFlag = "".GetUrlParam("page"),
唐召明 authored
302
                            projectRoleKey = "".GetUrlParam("projectRoleKey");
303
                        //加载用户绑定的项目
唐召明 authored
304
305
                        if (pageFlag != "sysuser") {
                            return;
HuXiYu authored
306
                        }
唐召明 authored
307
308
309
310
311
312
313
314
315
316
317
                        let ajaxConfig = {
                            data: { projectRoleKey: projectRoleKey },
                            url: `/base/SysUser/GetUserBindClient`,
                            success: function (result) {
                                if (sysU.successBefore(result)) return false;
                                var targetArrValue = result.Result;//.map(e.clientKeys);
                                var selectColKey = "".GetUrlParam("selectColKeyCustom");
                                sysU.SetTableCheck(targetArrValue, res, selectColKey, app.data.tableElem);
                            }
                        };
                        sysU.ajax(ajaxConfig);
318
319
320
321
322
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },
323
324
325
326
327
328
329
330
            //根据地址解析经度纬度
            setLngAndlat() {
                let address = app.data.txtProjectAddress.val();
                if (!address) {
                    app.data.txtProjectAddress.focus();
                    return;
                }
                mapApp.fn.getPointByAddress(address, (point) => {
唐召明 authored
331
                    var val = { longitude: "", latitude: "", }
332
333
334
335
336
337
                    if (point) {
                        val.longitude = point.lng;
                        val.latitude = point.lat;
                    }
                    form.val("modifyForm", val);
                });
338
339
340
            },

            initFrom() {
341
342
                sysU.initSelecteByEnum(app.data.selectOptionEnum);
                sysU.initSelect(app.data.selectOption);
343
344
345
346
347
348
349
350
351
352
353

                //初始化项目角色
                "".XmSelectInit({
                    el: '#projectRose',
                    url: `/base/SysProjectRoles/Load`,
                    paramData: { page: 1, limit: 500 },
                    keylabel: "roles_name",
                    keyValue: "keys",
                }, sysU, (obj) => {
                    xmSelectObj = obj
                });
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
            },
            initCopy() {
                app.data.btnCopyLonLat.addEventListener("click", function (event) {
                    $("#modifyForm form  input[name=longitude]").focus();
                    // 获取剪贴板中的文本数据
                    navigator.clipboard.readText()
                        .then(text => {
                            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 });
                        });
                });
373
374
375
            }
        },
        registerEvent: function () {
376
377
378
            app.data.btnGetPoint.click(function () {
                app.methods.setLngAndlat();
            })
379
380
381
382
        },
        init: function () {
            app.methods.initTable();
            app.methods.initFrom();
383
            app.methods.initCopy();
384
385
386
387
            app.registerEvent();
        }
    };
    app.init();
唐召明 authored
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
});


// 更新datalist的函数
function updateDataList() {
    $.ajax({
        url: "GetProjecInfo", // 请求的URL
        type: "GET", // 请求类型,默认为GET
        dataType: "json", // 预期服务器返回的数据类型
        success: function (response) { // 请求成功时的回调函数
            const dataList = document.getElementById('projectCodeList');
            // 清空现有的选项
            if (response.Code != 200) {
                dataList.innerHTML = '';
                layer.msg(`获取数据失败:${response.Message}`, { icon: 2 });
                return;
            }

            if (response.Result == null || response.Result.length == 0) {
                dataList.innerHTML = '';
                layer.msg('暂无可用的项目编号', { icon: 0 });
                return;
            }

            // 移除失效项
            Array.from(dataList.options).forEach(item => {
                if (!response.Result.some(x => x == item.value)) {
                    dataList.removeChild(item);
                }
            });

            // 添加新的选项
            response.Result.forEach(item => {
                // 检查当前选项是否已存在
                let exists = Array.from(dataList.options).some(option => option.value === item);
                // 如果选项不存在,则添加
                if (!exists) {
                    const option = document.createElement('option');
                    option.value = item;
                    dataList.appendChild(option);
                }
            });
        },
        error: function (xhr, status, error) { // 请求失败时的回调函数
            layer.msg(`请求失败${error}`, { icon: 2 });
        }
    });
}