addRemind.js 14.1 KB
Newer Older
hanpeng committed
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
define(['zepto', 'medtap', 'mui', 'mui.picker'], function($, medtap, mui) {
	var add = {
		userPicker: [],
		showUserPickerButton: [],
		userResult: [],
		dPicker: null,
		remindId: medtap.getRequest('remindId'),
		remind_typeData: [{
				text: '用药提醒',
				value: '1'
			},
			{
				text: '检查提醒',
				value: '2'
			},
			{
				text: '就诊提醒',
				value: '3'
			}
		],
		remind_frequency: [{
				text: '每天一次',
				value: '1'
			},
			{
				text: '每周一次',
				value: '2'
			},
			{
				text: '每两周一次',
				value: '3'
			},
			{
				text: '每三周一次',
				value: '4'
			},
			{
				text: '每四周一次',
				value: '5'
			}
		],
		remind_repeat: [{
			text: '重复提醒',
			value: '1'
		}, {
			text: '不重复提醒',
			value: '0'
		}],
		remind_status: [{
			text: '开启',
			value: '1'
		}, {
			text: '关闭',
			value: '0'
		}],
hanpeng committed
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
		checkItem_Data: [{
			'text': '血液检查',
			'value': '11'
		}, {
			'text': '肿瘤标志物检查',
			'value': '12'
		}, {
			'text': 'X线检查',
			'value': '13'
		}, {
			'text': 'B超',
			'value': '14'
		}, {
			'text': 'CT',
			'value': '15'
		}, {
			'text': '磁共振(MRI)',
			'value': '16'
		}, {
			'text': 'PET-CT',
			'value': '17'
		}, {
			'text': '内镜',
			'value': '18'
		}, {
			'text': '病理',
			'value': '19'
hanpeng committed
83
		}],
hanpeng committed
84 85 86 87 88 89 90 91 92 93 94 95
		medicalType_Data: [{
			'text': '门诊',
			'value': '1'
		}, {
			'text': '化疗',
			'value': '2'
		}, {
			'text': '放疗',
			'value': '3'
		}, {
			'text': '其他治疗',
			'value': '4'
hanpeng committed
96 97 98 99 100 101 102 103 104 105 106
		}],
		init: function() {
			add.initRemind_typeData();
			add.initRemind_frequency();
			add.initRemind_status();
			add.initRemind_repeat();
			add.initDate();
			add.initTime();
			if (!add.remindId) {
				$('.saveBtn').show();
			} else {
hanpeng committed
107

hanpeng committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
			}
			add.bindEve();
		},
		bindEve: function() {
			$('.saveBtn').unbind().bind('click', function() {
				var keyT = add.checkValue();
				if (keyT == true) {
					add.addNewRemind();
				}
			})
		},
		checkValue: function() {
			var flag = false;
			if (!$('#remind_status').val()) {
				medtap.toast({
					message: '请选择提醒状态'
				})
				flag = false;
			} else if (!$('#remind_type').val()) {
				medtap.toast({
					message: '请选择提醒类型'
				})
				flag = false;
hanpeng committed
131 132
			} else if ($('#remind_type').attr('sendkey') == 1) {
				if (!$('#drug_name').val()) {
hanpeng committed
133
					medtap.toast({
hanpeng committed
134
						message: '请输入药品名称'
hanpeng committed
135 136
					})
					flag = false;
hanpeng committed
137
				} else if (!$('#remind_repeat').val()) {
hanpeng committed
138
					medtap.toast({
hanpeng committed
139
						message: '请选择是否重复提醒'
hanpeng committed
140 141
					})
					flag = false;
hanpeng committed
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
				} else if ($('#remind_repeat').attr('sendkey') == 0) {
					if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
				} else if ($('#remind_repeat').attr('sendkey') == 1) {
					if (!$('#remind_frequency').val()) {
						medtap.toast({
							message: '请选择提醒频率'
						})
						flag = false;
					} else if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
hanpeng committed
187
				}
hanpeng committed
188 189
			} else if ($('#remind_type').attr('sendkey') == 2) {
				if (!$('#remind_checkItem').val()) {
hanpeng committed
190
					medtap.toast({
hanpeng committed
191
						message: '请选择检查项目'
hanpeng committed
192 193
					})
					flag = false;
hanpeng committed
194
				} else if (!$('#remind_repeat').val()) {
hanpeng committed
195
					medtap.toast({
hanpeng committed
196
						message: '请选择是否重复提醒'
hanpeng committed
197 198
					})
					flag = false;
hanpeng committed
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
				} else if ($('#remind_repeat').attr('sendkey') == 0) {
					if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
				} else if ($('#remind_repeat').attr('sendkey') == 1) {
					if (!$('#remind_frequency').val()) {
						medtap.toast({
							message: '请选择提醒频率'
						})
						flag = false;
					} else if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
				}
			} else if ($('#remind_type').attr('sendkey') == 3) {
				if (!$('#remind_medicalType').val()) {
hanpeng committed
247
					medtap.toast({
hanpeng committed
248
						message: '请选择就诊类型'
hanpeng committed
249 250
					})
					flag = false;
hanpeng committed
251
				} else if (!$('#remind_repeat').val()) {
hanpeng committed
252
					medtap.toast({
hanpeng committed
253
						message: '请选择是否重复提醒'
hanpeng committed
254 255
					})
					flag = false;
hanpeng committed
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
				} else if ($('#remind_repeat').attr('sendkey') == 0) {
					if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
				} else if ($('#remind_repeat').attr('sendkey') == 1) {
					if (!$('#remind_frequency').val()) {
						medtap.toast({
							message: '请选择提醒频率'
						})
						flag = false;
					} else if (!$('#remind_date').val()) {
						medtap.toast({
							message: '请选择提醒日期'
						})
						flag = false;
					} else if (!$('#remind_time').val()) {
						medtap.toast({
							message: '请选择提醒时间'
						})
						flag = false;
					} else if (!$('.remind_content').val()) {

						medtap.toast({
							message: '请输入提醒内容'
						})
						flag = false;
					} else {
						flag = true;
					}
hanpeng committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
				}
			}
			return flag;
		},
		initRemind_typeData: function() {
			add.initPickers(1, 'remind_type_typeBox', 'remind_type', add.remind_typeData, 1);
		},
		initRemind_frequency: function() {
			add.initPickers(2, 'remind_frequency_typeBox', 'remind_frequency', add.remind_frequency, 1)
		},
		initRemind_status: function() {
			add.initPickers(3, 'remind_status_typeBox', 'remind_status', add.remind_status, 1)
		},
		initRemind_repeat: function() {
			add.initPickers(4, 'remind_repeat_typeBox', 'remind_repeat', add.remind_repeat, 1)
		},
hanpeng committed
317 318
		initCheckItem: function() {
			add.initPickers(5, 'remind_checkItem_typeBox', 'remind_checkItem', add.checkItem_Data, 1);
hanpeng committed
319
		},
hanpeng committed
320 321
		initMedicalType: function() {
			add.initPickers(6, 'remind_medicalType_typeBox', 'remind_medicalType', add.medicalType_Data, 1);
hanpeng committed
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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372
		},
		initDate: function() {
			$('#remind_date_typeBox').on('click', function() {
				var year = new Date().getFullYear();
				var month = new Date().getMonth();
				var day = new Date().getDate();
				add.dPicker = new mui.DtPicker({
					"type": "date",
					"beginYear": 1900,
					"endDate": year
				});
				add.dPicker.show(function(rs) {
					$('#remind_date').val(rs.text);
				});
			});
		},
		initTime: function() {
			$('#remind_time_typeBox').on('click', function() {
				var year = new Date().getFullYear();
				var month = new Date().getMonth();
				var day = new Date().getDate();
				add.dPicker = new mui.DtPicker({
					"type": "time",
					"beginYear": 1900
				});
				add.dPicker.show(function(rs) {
					$('#remind_time').val(rs.text);
				});
			});
		},
		addNewRemind: function() {
			var notifyType = '';
			if ($('#remind_repeat').attr('sendkey') == 0) {
				notifyType = '';
			} else {
				notifyType = $('#remind_type').attr('sendkey');
			}
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/operation/notify/addNotify',
				type: 'POST',
				async: false,
				contentType: 'application/json',
				data: {
					repeatePeriod: $('#remind_frequency').attr('sendkey'), //提醒周期
					repeateFlag: $('#remind_repeat').attr('sendkey'), //是否重复
					notifyType: $('#remind_type').attr('sendkey'), //提醒类型
					startTime: $('#remind_time').val(), //提醒时间
					startDate: $('#remind_date').val(), //提醒日期
					content: $('.remind_content').val(), //提醒内容
					status: $('#remind_status').attr('sendkey'), //提醒状态,
hanpeng committed
373 374 375
					drugName: $('#drug_name').val() || '',
					checkItem: $('#remind_checkItem').attr('sendkey') || '',
					medicalType: $('#remind_medicalType').attr('sendkey') || ''
hanpeng committed
376 377 378 379 380 381 382 383 384 385 386
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {
						medtap.toast({
							message: '保存成功',
							time: 1500
						});
						setTimeout(function() {
							window.location.replace('myRemind.html');
						}, 1500);
hanpeng committed
387 388 389 390 391
					} else {
						medtap.toast({
							message: res.resultDesc,
							time: 1500
						});
hanpeng committed
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 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461
					}
				}
			})
		},
		upDateRemind: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: 'https://testdevgw.medtap.cn/operation/notify/updateNotify',
				type: 'POST',
				async: false,
				contentType: 'application/json',
				data: {
					repeatePeriod: '', //提醒周期
					repeateFlag: '', //是否重复
					notifyType: '', //提醒类型
					startTime: '', //提醒时间
					startDate: '', //提醒日期
					content: '', //提醒内容
					status: '', //提醒状态,
					id: add.remindId
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {

					}
				}
			})
		},
		getRemindDetail: function() {
			medtap.loading(1);
			medtap.submitAjax({
				url: "https://testdevgw.medtap.cn/operation/notify/getNotify",
				type: "post",
				async: false,
				contentType: 'application/json',
				data: {
					id: add.remindId
				},
				success: function(res) {
					medtap.loading(0);
					if (res.success == true) {

					}
				}
			})
		},
		initPickers: function(index, el, tarEl, vals, layer) {
			var _this = this;
			_this.userPicker[index] = new mui.PopPicker({
				layer: layer
			});
			_this.userPicker[index].setData(vals);
			_this.showUserPickerButton[index] = document.getElementById(el);
			_this.userResult[index] = document.getElementById(tarEl);
			_this.showUserPickerButton[index].addEventListener('tap', function(event) {
				_this.userPicker[index].show(function(items) {
					if (layer == 1) {
						document.getElementById(tarEl).nodeName === 'INPUT' || document.getElementById(tarEl).nodeName ===
							'TEXTAREA' ?
							(_this.userResult[index].value = items[0]['text']) :
							(_this.userResult[index].innerHTML = items[0]['text']);
						_this.userResult[index].setAttribute("sendKey", items[0]['value']);
						if (tarEl == 'remind_repeat') {
							if (items[0]['value'] == 0) {
								$('#needFre').hide()
							} else if (items[0]['value'] == 1) {
								$('#needFre').show()
							}
						}
hanpeng committed
462 463
						if (tarEl == 'remind_type') {
							if (items[0]['value'] == 1) {
hanpeng committed
464 465 466 467
								$('#drug_box').show();
								$('#medicalType_box').hide();
								$('#checkItem_box').hide();
								//$('#drug_name').val() || '';
hanpeng committed
468 469 470
								$('#remind_checkItem').attr('sendkey', '');
								$('#remind_medicalType').attr('sendkey', '');
							} else if (items[0]['value'] == 2) {
hanpeng committed
471 472 473 474 475
								$('#drug_box').hide();
								$('#medicalType_box').hide();
								$('#checkItem_box').show();
								$('#drug_name').val('');
								//$('#remind_checkItem').attr('sendkey','');
hanpeng committed
476
								$('#remind_medicalType').attr('sendkey', '');
hanpeng committed
477
								add.initCheckItem();
hanpeng committed
478
							} else if (items[0]['value'] == 3) {
hanpeng committed
479 480 481 482
								$('#drug_box').hide();
								$('#checkItem_box').hide();
								$('#medicalType_box').show();
								$('#drug_name').val('');
hanpeng committed
483
								$('#remind_checkItem').attr('sendkey', '');
hanpeng committed
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
								//$('#remind_medicalType').attr('sendkey','');
								add.initMedicalType();
							}
						}
					} else if (layer == 2) {
						//只显示第二级的数据
						document.getElementById(tarEl).nodeName === 'INPUT' || document.getElementById(tarEl).nodeName ===
							'TEXTAREA' ?
							(_this.userResult[index].value = items[0]['text'] + items[1]['text']) :
							(_this.userResult[index].innerHTML = items[0]['text'] + ' ' + items[1]['text']);
						_this.userResult[index].setAttribute("sendKey", items[0]['value']);
						if (tarEl == 'disease') {
							document.getElementById(tarEl).setAttribute('diseaseid', items[1]['value']);
							_this.userResult[index].setAttribute("sendKey", items[1]['value']);
						} else if (tarEl == 'location') {
							document.getElementById(tarEl).setAttribute('locationid', items[1]['value']);
							_this.userResult[index].setAttribute("sendKey", items[1]['value']);
						} else if (tarEl == 'pathology') {
							document.getElementById(tarEl).setAttribute('pathologyId', items[1]['value']);
							if (items[1].showText != '') {
								_this.userResult[index].innerHTML = items[1]['showText'];
								_this.userResult[index].value = items[1]['showText'];
							} else {
								_this.userResult[index].innerHTML = items[0]['text'];
								_this.userResult[index].value = items[0]['text']
							}
							_this.userResult[index].setAttribute("sendKey", items[1]['value']);
						}
					} else if (layer == 3) {
						document.getElementById(tarEl).nodeName === 'INPUT' || document.getElementById(tarEl).nodeName ===
							'TEXTAREA' ?
							(_this.userResult[index].value = items[0]['text'] + items[1]['text'] + items[2]['text']) :
							(_this.userResult[index].innerHTML = items[0]['text'] + ' ' + items[1]['text'] + '' + items[2]['text']);
						_this.userResult[index].setAttribute("sendKey", items[0]['value']);
					}

				});
			}, false);
		}
	}
	add.init();
})