tom
2023-12-06 9e968679ed2e6937aeb7b50a6c450d5d19251f42
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
var aProduct=[], iProduct; 
var aTerritory=[], iTerritory;
var aTerritoryHospital=[], iTerritoryHospital;
var aHospital=[], iHospital, oHospital;
var aProvince=[], aCity=[];
var aHospitalApply, iHospitalApply;
 
$(document).ready( onDocumentReady );
 
function onDocumentReady() {
    pageInit(showHospitalNew);
    loadMaster();
}
 
function loadMaster() {
    jsonRequest("sales", "load_master", {}, onMasterResponse);
}
 
function onMasterResponse(res) {
    aProduct=res.product_list;
    aHospital=res.hospital_list;
    aDealer=res.dealer_list;
}
 
function showHospitalApplyList() {
    menuSwitch("hospital_apply_list");
    loadHospitalApplyList();
}
 
function loadHospitalApplyList() {
    jsonRequest("territory", "load_hospital_apply_list", {}, onHospitalApplyListResponse, "正在获取医院申请状态信息");
}
 
function onHospitalApplyListResponse(res) {
    aHospitalApply=res.hospital_apply_list;
    var html="";
    var aStatus=["已取消", "已生效", "待审核"];
    for (var i=0; i<aHospitalApply.length; i++) {
        var hp=aHospitalApply[i];
        html+=div("div_hospital_item",
                div("div_hospital_code", hp.code)+
                div("div_hospital_name", hp.name)+
                div("div_hospital_apply_date", hp.apply_date)+
                div("div_hospital_apply_name", hp.apply_name+" 申请")+
                div("div_hospital_status_"+(hp.status==2?"on":"off"), aStatus[hp.status]),
                    "showHospitalApplyDetail("+i+")");
    }
    $("#div_hospital_apply_sheet").html(html);
}
 
function showHospitalApplyDetail(i) {
    iHospitalApply=i;
    var label=["全称", "别名", "城市", "地址", "电话", "等级", "其它信息",         
        "提交人", "提交日期"];
    var a=aHospitalApply[i];
    var content=[a.name, a.alias, a.city, a.address, a.phone, a.level, a.info,
        a.apply_employee_name, a.apply_date];
    var s=property(label, content);
    $("#div_hospital_apply_property").html(s);
    var dm=getAccount().level=="DM";
    $("#div_hospital_approve").toggle(dm);
    pageGo("hospital_apply_detail");
}
 
function confirmHospitalStatus(i) {
    var req={};
    req.status=i;
    req.hospital_uid=aHospitalApply[iHospitalApply].uid;
    jsonRequest("territory", "do_hospital_status", req, onHospitalStatusResponse);
}
 
function onHospitalStatusResponse() {
    pageBack();
    loadHospitalApplyList();
}
 
function showHospitalNew() {
    oHospital={level:""};
    $("#input_hospital_name").val("");
    $("#input_hospital_alias").val("");
    $("#input_hospital_address").val("");
    $("#input_hospital_phone").val("");
    $("#input_hospital_bed_num").val("");
    menuSwitch("hospital_new");
}
 
function setHospitalLevel(l) {
    var levels=["", "一级", "二级", "三级"];
    oHospital.level=levels[l];
    for (var i=1; i<=3; i++) {
        toggleSwitch("hospital_level", l);
    }
}
 
function loadProvince() {
    jsonRequest("territory", "load_geo", {}, onProvinceResponse, "正在获取省市信息……请稍候");
}
 
function onProvinceResponse(res) {
    aProvince=res.province_list;
    var html="";
    for (var i in aProvince) {
        html+=div("div_geo_item", aProvince[i].province, "selectProvince("+i+")");
    }
    $("#div_geo_group").html(html);
    pageGo("geo");
}
 
function selectProvince(i) {
    var req={};
    req.province_uid=aProvince[i].uid;
    jsonRequest("territory", "load_geo", req, onCityResponse, "正在获取城市信息……请稍候");
    oHospital.province=aProvince[i].province;
}
 
function onCityResponse(res) {
    aCity=res.city_list;
    var html="";
    for (var i in aCity) {
        html+=div("div_geo_item", (aCity[i].city || "(未知区域)"), "selectCity("+i+")");
    }
    $("#div_geo_group").html(html);
}
 
function selectCity(i) {
    oHospital.geo_uid=aCity[i].uid;
    oHospital.city=aCity[i].city;
    $("#prompt_hospital_geo").html(oHospital.province+" "+oHospital.city);
    $("#prompt_hospital_geo").attr("class", "div_form_content");
    pageBack();
}
 
function searchLocation() {
    var hao=oHospital.address.indexOf("号");
    if (hao==-1) {
        alertMessage("地址未包含门牌号信息");
    } else {
        pageGo("map");
        window.map = new BMap.Map("map_container");
        map.centerAndZoom(oHospital.province+oHospital.city, 16);
        map.addControl(new BMap.NavigationControl());
        var localSearch = new BMap.LocalSearch(map);
        localSearch.setSearchCompleteCallback(onSearchLocationResult);
        var address=oHospital.province + oHospital.city + oHospital.address.substr(0,hao);
        localSearch.search(address);
    }
}
    
function onSearchLocationResult(result) {
    if (result.getNumPois()==0) {
        alertMessage("无法识别地址: "+result.keyword);
    } else { 
        var poi = result.getPoi(0);
        oHospital.longitude=poi.point.lng;
        oHospital.latitude=poi.point.lat;
        map.centerAndZoom(poi.point, 16);
        var marker = new BMap.Marker(new BMap.Point(poi.point.lng, poi.point.lat));
        map.addOverlay(marker);
    }
}
 
function submitHospitalNew() {
    oHospital.name=$("#input_hospital_name").val();
    oHospital.alias=$("#input_hospital_alias").val();
    oHospital.address=$("#input_hospital_address").val();
    oHospital.phone=$("#input_hospital_phone").val();
    oHospital.info=$("#input_hospital_info").val();
    if (!oHospital.name) {
        alertMessage("请填写全称");
    } else if (!oHospital.geo_uid) {
        alertMessage("请选择城市");
    } else if (!oHospital.address) {
        alertMessage("请填写地址");
    } else if (!oHospital.phone) {
        alertMessage("请填写联系电话");
    } else {
        searchLocation();
    }
}
 
function confirmHospitalNew() {
    jsonRequest("territory", "do_hospital_new", oHospital, onNewHospitalApplyResponse, "正在提交新医院申请");
}
 
function onNewHospitalApplyResponse(res) {
    pageBack();
    pageBack();
    showHospitalApplyList();
}
 
function loadProduct() {
    jsonRequest("territory", "load_product", {}, onProductResponse, "正在获取产品信息……请稍候");
}
 
function onProductResponse(res) {
    aProduct=res.product_list;
    var html="";
    for (var i=0; i<aProduct.length; i++) {
        html+=div("div_list_item",
            div("div_list_code", aProduct[i].code)+div("div_list_name", aProduct[i].name+" ("+aProduct[i].name_en+")"), 
                "selectProduct("+i+")");
    }
    if (aProduct.length==0) {
        html+=div("div_list_item", "没有产品可以选择");
    }
    $("#div_product_group").html(html);
    pageGo("product");
}
 
function selectProduct(i) {
    iProduct=i;
    $("#div_header_product").html(aProduct[iProduct].name);
    pageBack(loadTerritory);
}
 
function showTerritory() {
    if (getAccount().level=="REP") {
        alertMessage("请切换为地区经理账户");
    } else {
        menuSwitch("territory");
        loadTerritory();
    }
}
 
function loadTerritory() {
    if (iProduct>=0) {
        var req={};
        req.product_uid=aProduct[iProduct].uid;
        jsonRequest("territory", "load_territory", req, onTerritoryResponse, "正在获取辖区信息……请稍候");
    } else {
        loadProduct();
    }
}
 
function onTerritoryResponse(res) {
    aTerritory=res.territory_list;
    var title=["地点", "辖区代码", "姓名", "医院数"];
    var width=["25%", "30%", "30%", "15%"];
    var f=field(title, width);
    $("#div_territory_field").html(f);
    
    var html="";
    for (var i=0; i<aTerritory.length; i++) {
        var it=aTerritory[i];
        html+=div("div_row",
            cell(it.geo, "25%")+
            cell(it.code, "30%")+
            cell(it.name, "30%")+
            cell(it.hospital_num, "15%"),
                "iTerritory="+i+"; showTerritoryHospital()");
    }
    $("#div_territory_sheet").html(html);
}
 
function showTerritoryHospital() {
    pageGo("territory_hospital", loadTerritoryHospital);
}
 
function loadTerritoryHospital() {
    var req={};
    req.product_uid=aProduct[iProduct].uid;
    req.territory_uid=aTerritory[iTerritory].uid;
    jsonRequest("territory", "load_territory_hospital", req, onTerritoryHospitalResponse, "正在获取辖区医院列表信息");
}
 
function onTerritoryHospitalResponse(res) {
    aTerritoryHospital=res.hospital_list;
    var html="";
    for (var i=0; i<aTerritoryHospital.length; i++) {
        html+=div("div_list_item",
            div("div_list_code", aTerritoryHospital[i].code)+
            div("div_list_name", aTerritoryHospital[i].name)+
            div("div_list_del", "", "promptTerritoryHospital("+i+")")); 
    }
    if (aTerritoryHospital.length==0) {
        html+=div("div_list_item", "没有目标医院,点右上角添加");
    }
    $("#div_territory_hospital_sheet").html(html);
}
 
function hideTerritoryHospital() {
    pageBack(loadTerritory);
}
 
function addTerritoryHospital(i) {
    var req={};
    req.product_uid=aProduct[iProduct].uid;
    req.territory_uid=aTerritory[iTerritory].uid;
    req.hospital_uid=aHospital[i].uid;
    jsonRequest("territory", "add_territory_hospital", req, hideHospital);
}    
 
function promptTerritoryHospital(i) {
    var name=aTerritoryHospital[i].name;
    showConfirm("是否去除目标医院<br>"+name, "removeTerritoryHospital("+i+")");
}
 
function removeTerritoryHospital(i) {
    var req={};
    req.product_uid=aProduct[iProduct].uid;
    req.territory_uid=aTerritory[iTerritory].uid;
    req.hospital_uid=aTerritoryHospital[i].uid;
    jsonRequest("territory", "remove_territory_hospital", req, loadTerritoryHospital);
}
 
function loadHospital() {
    var req={};
    req.product_uid=aProduct[iProduct].uid;
    req.territory_uid=aTerritory[iTerritory].uid;
    jsonRequest("territory", "load_hospital", req, onHospitalResponse, "正在获取医院列表");
}
 
function onHospitalResponse(res) {
    aHospital=res.hospital_list;
    var html="";
    for (var i=0; i<aHospital.length; i++) {
        html+=div("div_list_item",
            div("div_list_code", aHospital[i].code)+
            div("div_list_name", aHospital[i].name),
                "addTerritoryHospital("+i+")");
    }
    $("#div_hospital_group").html(html);
    pageGo("hospital");
}
 
function hideHospital() {
    pageBack(loadTerritoryHospital);
}
 
function showMine() {
    menuSwitch("mine", loadMine());
}
 
function loadMine() {
    jsonRequest("territory", "load_mine", {}, onMineResponse, "正在获取我的辖区医院列表");
}
 
function onMineResponse(res) {
    var title=["代码", "医院"];
    var width=["30%", "70%"];
    var f=field(title, width);
    $("#div_mine_field").html(f);
    
    var html="";
    for (var i=0; i<res.product_list.length; i++) {
        var product=res.product_list[i];
        html+=div("div_row_blue",
            cell(product.code, "30%")+cell(product.name, "70%"));
        for (var j=0; j<product.hospital_list.length; j++) {
            var hospital=product.hospital_list[j];
            html+=div("div_row",
                cell(hospital.code, "30%")+cell(hospital.name, "70%", "left"));
        }
    }
    $("#div_mine_sheet").html(html);
}