cl
2024-01-23 6dadf36ef118fbb3b2cd5aca94cde88e29fb55dc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
 * 添加或者修改页面
 */
var EquipmentMaintainPlanInfoDlg = {
    data: {
        id: "",
        equipmentNo: "",
        equipmentName: "",
        planNo: "",
        planName: "",
        planType: "",
        maintainType: "",
        intervalTime: "",
        intervalUnit: "",
        state: "",
        spareField1: "",
        spareField2: "",
        remarks: "",
        createUser: "",
        updateUser: "",
        createTime: "",
        updateTime: "",
        startTime: "",
        endTime: ""
    }
};
 
layui.use(['table','form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var table = layui.table;
    var laydate = layui.laydate;
 
 
    var dataList = new Array();
 
    laydate.render({
        elem: '#startTime' //指定元素
    });
 
    laydate.render({
        elem: '#endTime' //指定元素
    });
 
    $(document).ready(function () {
        var ajax1 = new $ax(Feng.ctxPath + "/equipmentMaintainPlan/planNumberGenerate");
        var result1 = ajax1.start();
        console.log(result1.data);
        $("#planNo").val(result1.data)
 
        $(document).ready(function () {
            $.ajax({
                type: "POST",
                contentType: "application/json;charset=UTF-8",
                url: Feng.ctxPath + '/equipmentMaintainPlan/getIntervalUnit',
                success: function (result) {
                    console.log(result);
                    $.each(result.data, function (index, value) {
                        $('#intervalUnit').append(new Option(value.name));// 下拉菜单里添加元素
                    });
                    layui.form.render("select");//重新渲染 固定写法
                },
            });
        });
    });
 
 
    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        if(dataList.length === 0){
            Feng.error("请配置保养内容!");
            return false;
        }else {
            var ajax = new $ax(Feng.ctxPath + "/equipmentMaintainPlan/addItem", function (data) {
                Feng.success("添加成功!");
                window.location.href = Feng.ctxPath + '/equipmentMaintainPlan'
            }, function (data) {
                Feng.error("添加失败!" + data.responseJSON.message)
            });
            ajax.set(data.field);
            ajax.set("dataList", JSON.stringify(dataList));
            ajax.start();
            return false;
        }
    });
 
    /**
     * 物料档案管理
     */
    var EqConfTable = {
        tableId: "eqConfTable"
    };
    table.render({
        elem: '#eqConfTable',page: true
        , cols: [[ //标题栏
            // {type: 'checkbox'},
            {field: 'maintainContentCode',  title: '编号'},
            {field: 'maintainContentName',  title: '名称'},
            {field: 'maintainContentType',  title: '类型'},
            {field: 'maintainContent',  title: '保养内容描述'},
            {align: 'center', toolbar: '#tableBar', title: '操作', minWidth: 120}
        ]]
        ,limit: 10
        , data: dataList
        , even: true
    });
 
    table.reload(EqConfTable.tableId, {
        data: dataList
    });
 
    $('#btnAdds').click(function () {
        console.log("点击保养计划配置")
        EqConfTable.btnForProcess();
    });
 
    EqConfTable.btnForProcess = function () {
        layer.open({
            type: 2,
            title: '保养内容',
            area: ['800px', '650px'],
            content: Feng.ctxPath + '/equipmentMaintainContentConf/addListConf',
            end: function () {
                var info = $("#materialList").val();
                console.log(info)
                if (info != "") {
                    var tempList = eval(info);
                    tempList.forEach(function (val, index) {
                        var obj = {
                            'maintainContentCode': val.maintainContentCode,
                            'maintainContentName': val.maintainContentName,
                            'maintainContentType': val.maintainContentType,
                            'maintainContent': val.maintainContent,
                        };
                        dataList.push(obj);
                    });
                    table.reload(EqConfTable.tableId, {
                        data: dataList
                    });
                    $("#materialList").val("");
                }
            }
        });
    };
 
    // 工具条点击事件
    table.on('tool(' + EqConfTable.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;
 
        if (layEvent === 'delete') {
            EqConfTable.onDeleteItem(data);
        }
    });
 
    /**
     * 点击删除
     *
     * @param data 点击按钮时候的行数据
     */
    EqConfTable.onDeleteItem = function (data) {
        var operation = function () {
            for (var i = 0; i < dataList.length; i++) {
                console.log(dataList[i].maintainContentCode)
                console.log(data.maintainContentCode)
                if (dataList[i].maintainContentCode == data.maintainContentCode) {
                    dataList.splice(i, 1);
                    Feng.success("删除成功!");
                }
            }
            table.reload(EqConfTable.tableId, {
                data: dataList
            });
        };
        Feng.confirm("是否删除?", operation);
    };
 
    $('#cancel').click(function(){
        window.location.href = Feng.ctxPath + '/equipmentMaintainPlan'
    });
 
    $('#equipmentNo').click(function (){
        layer.open({
            type: 2,
            area: ['1000px', '600px'],
            title: '设备列表',
            content: Feng.ctxPath + '/equipmentMaintainPlan/eqList',
            end: function () {
                let msg = JSON.parse(window.localStorage.getItem('message'));
                console.log("选择工单_id", msg.id)
                $('#equipmentNo').val(msg.equipmentNo);
                $('#equipmentName').val(msg.equipmentName);
                console.log(msg);
            }
        });
    });
 
});