puzhibing
2023-02-15 2811bab657aab4145b65a45a824fb63e93b58e30
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**
 * 初始化调度管理详情对话框
 */
var TDispatchInfoDlg = {
    tDispatchInfoData : {},
    validateFields: {
        name: {
            validators: {
                notEmpty: {
                    message: '调度名称不能为空'
                }
            }
        },
        /*oneId: {
            validators: {
                notEmpty: {
                    message: '请选择所属分公司'
                }
            }
        },
        twoId: {
            validators: {
                notEmpty: {
                    message: '请选择所属加盟商'
                }
            }
        },
        franchiseeId: {
            validators: {
                notEmpty: {
                    message: '请选择所属加盟商'
                }
            }
        },*/
        phone: {
            validators: {
                notEmpty: {
                    message: '联系电话不能为空'
                },
                regexp: {
                    regexp: /^1\d{10}$/,
                    message: '联系电话格式不正确'
                }
            }
        },
        account: {
            validators: {
                notEmpty: {
                    message: '登录账号不能为空'
                },
                regexp: {
                    regexp: /^1\d{10}$/,
                    message: '登录账号格式不正确'
                }
            }
        },
        password: {
            validators: {
                notEmpty: {
                    message: '密码不能为空'
                },
                identical: {
                    field: 'rePassword',
                    message: '两次密码不一致'
                },
            }
        },
        rePassword: {
            validators: {
                notEmpty: {
                    message: '密码不能为空'
                },
                identical: {
                    field: 'password',
                    message: '两次密码不一致'
                },
            }
        }
    }
};
 
/**
 * 验证数据是否为空
 */
TDispatchInfoDlg.validate = function () {
    $('#dispatchInfoForm').data("bootstrapValidator").resetForm();
    $('#dispatchInfoForm').bootstrapValidator('validate');
    return $("#dispatchInfoForm").data('bootstrapValidator').isValid();
};
 
/**
 * 清除数据
 */
TDispatchInfoDlg.clearData = function() {
    this.tDispatchInfoData = {};
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TDispatchInfoDlg.set = function(key, val) {
    this.tDispatchInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}
 
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
TDispatchInfoDlg.get = function(key) {
    return $("#" + key).val();
}
 
/**
 * 关闭此对话框
 */
TDispatchInfoDlg.close = function() {
    parent.layer.close(window.parent.TDispatch.layerIndex);
}
 
/**
 * 收集数据
 */
TDispatchInfoDlg.collectData = function() {
    this
    .set('id')
    .set('insertTime')
    .set('name')
    .set('companyId')
    .set('franchiseeId')
    .set('phone')
    .set('account')
    .set('password')
    .set('insertUserId')
    .set('insertUserRole')
    .set('state');
}
 
/**
 * 提交添加
 */
TDispatchInfoDlg.addSubmit = function() {
 
    this.clearData();
    this.collectData();
    if(!this.validate()){
        return ;
    }
    var roleType = $("#roleType").val();  //1=平台  2=分公司 3=加盟商
 
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tDispatch/add", function(data){
        if (data.code == 500){
            Feng.error(data.message);
            return ;
        } else {
            Feng.success("添加成功!");
            window.parent.TDispatch.table.refresh();
            TDispatchInfoDlg.close();
        }
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tDispatchInfoData);
    if (1 == roleType){
        var companyId = $("#oneId").val();
        if ("" != companyId && null != companyId && undefined != companyId){
            ajax.set("companyId",companyId);
        }
        var franchiseeId = $("#twoId").val();
        if ("" != franchiseeId && null != franchiseeId && undefined != franchiseeId){
            ajax.set("franchiseeId",franchiseeId);
        }
    }else if (2 == roleType) {
        var franchiseeId = $("#franchiseeId").val();
        if ("" != franchiseeId && null != franchiseeId && undefined != franchiseeId){
            ajax.set("franchiseeId",franchiseeId);
        }
    }
    ajax.start();
}
 
/**
 * 提交修改
 */
TDispatchInfoDlg.editSubmit = function() {
 
    this.clearData();
    this.collectData();
    if(!this.validate()){
        return ;
    }
    var roleType = $("#roleType").val();  //1=平台  2=分公司 3=加盟商
    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/tDispatch/update", function(data){
        if (data.code == 500){
            Feng.error(data.message);
            return ;
        } else {
            Feng.success("修改成功!");
            window.parent.TDispatch.table.refresh();
            TDispatchInfoDlg.close();
        }
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.tDispatchInfoData);
    if (1 == roleType){
        var companyId = $("#oneId").val();
        if ("" != companyId && null != companyId && undefined != companyId){
            ajax.set("companyId",companyId);
        }
        var franchiseeId = $("#twoId").val();
        if ("" != franchiseeId && null != franchiseeId && undefined != franchiseeId){
            ajax.set("franchiseeId",franchiseeId);
        }
    }else if (2 == roleType) {
        var franchiseeId = $("#franchiseeId").val();
        if ("" != franchiseeId && null != franchiseeId && undefined != franchiseeId){
            ajax.set("franchiseeId",franchiseeId);
        }
    }
    ajax.start();
}
 
$(function() {
    Feng.initValidator("dispatchInfoForm", TDispatchInfoDlg.validateFields);
});
 
/**
 * 公司改变执行
 */
TDispatchInfoDlg.companyChange = function (e) {
    var oneId=$(e).val();
    var ajax = new $ax(Feng.ctxPath + "/tDispatch/companyChange", function(data){
        if(data!=null){
            var content='<option value="">选择所属加盟商</option>';
            $.each(data, function(k,v) {
                content += "<option value='"+v.id+"'>"+v.name+"</option>";
            });
            $("#twoId").empty().append(content);
        }
    });
    ajax.set("oneId",oneId);
    ajax.start();
}