function showSuccessMessage(msg) {
	layer.msg(msg, {
		icon: 1
	})
}

function showErrorMessage(msg) {
	layer.msg(msg, {
		icon: 5
	})
}

function showWarningMessage(msg) {
	layer.msg(msg, {
		icon: 2
	})
}

function showInfoMessage(msg) {
	layer.msg(msg, {
		icon: 6
	})
}
new Vue({
	el: '#app',
	data: {
		modal: "",
		type: "",
		status: "",
		name: "",
		isDanger: "1",
		pagesize: 10,
		total: "",
		pagetotal: '', //总页数
		currentPage: 1, //当前页数
		tablelist: [],
		types: [],
		Statics: {},
		wujilu: false,
		datamodelshow: true,
	},
	mounted: function() {
		var vm = this
		vm.getModal()
		vm.getDatas()
		vm.gettypes()
	},
	methods: {
		//获取筛查数据模型
		getModal: function() {
			var vm = this
			jbscAPI.screenStatics().then(function(res) {
				if(res.status == 200) {
					vm.Statics = res.data;
				} else {
					showErrorMessage(res.msg);
				}
			})
		},
		//获取数据
		getDatas: function() {
			var vm = this
			var params = {
				diseaseType: vm.type, //疾病类型
				dealType: vm.status, //处理方式(全部为空 1已预约 2已跟踪 3已接诊4待处理)
				patientName: vm.name, //搜索居民的姓名
				isDanger: vm.isDanger, //是否高危预警(0否 1是)
				pageNo: vm.currentPage,
				pageSize: vm.pagesize
			}
			jbscAPI.getResultList(params).then(function(res) {
				if(res.status == 200) {
					vm.wujilu = false
					vm.total = res.data.num
					vm.pagetotal = Math.ceil(res.data.num / vm.pagesize)
					vm.tablelist = res.data.data;
					if(vm.tablelist.length == 0) {
						vm.wujilu = true
					}
				} else {
					showErrorMessage(res.msg);
				}
			})
		},
		gettypes: function() {
			var vm = this
			var search = true
			$("#Status").bsSuggest({
				data: {
					value: [{
							code: "",
							name: "全部"
						},
						{
							code: "1",
							name: "已预约"
						},
						{
							code: "2",
							name: "已跟踪"
						},
						{
							code: "3",
							name: "已接诊"
						},
						{
							code: "4",
							name: "待处理"
						},
						{
							code: "5",
							name: "日常健康管理"
						}
					]
				},
				getDataMethod: "data",
				effectiveFields: ["name"],
				idField: "code",
				keyField: "name"
			});
			jbscAPI.getSpecialDisease().then(function(res) {
				if(res.status == 200) {
					var data = {}
					data.value = _.map(res.data, function(v) {
						return {
							code: v.code,
							name: v.name
						}
					})
					if(search) {
						data.value = [{
							code: "",
							name: "全部"
						}].concat(data.value)
					}
					$("#Type").bsSuggest({
						data: data,
						getDataMethod: "data",
						effectiveFields: ["name"],
						idField: "code",
						keyField: "name"
					});
					vm.types = res.data;
				} else {
					showErrorMessage(res.msg);
				}
			})
		},
		gettable: function(type) {
			var vm = this
			if(type == "1") {
				if(vm.status == "") {
					$("#Status").attr({
						"data-id": "",
						"value": "全部"
					})
					$("#Status").val("全部")
				}
			} else {
				if(vm.status != "") {
					vm.status = ""
					$("#Status").attr({
						"data-id": "",
						"value": "全部"
					})
					$("#Status").val("全部")
				}
			}
			vm.isDanger = type
			vm.search(1)
		},
		//页面跳转
		search: function(page) {
			var vm = this
			vm.type = $("#Type").attr("data-id");
			var status = $("#Status").attr("data-id");
			if(status == "5") {
				vm.status = "";
				vm.isDanger = "0";
			} else if(status == "" || status == undefined) {
				if(vm.isDanger == "0") {
					vm.isDanger = ""
				}
				vm.status = status;
			} else {
				vm.isDanger = "1";
				vm.status = status;
			}
			vm.currentPage = page
			vm.getDatas()
		},
		//转诊
		zhuanzhen: function() {
			showInfoMessage("PC上暂不支持，请打开手机端疑似高危记录进行转诊预约!")
		},
		//健康教育
		jkjy: function(data) {
			//			sessionStorage.setItem("jbsc-jkwzreceiver", JSON.stringify(receiver))
			//			sessionStorage.setItem("jbsc-jkroler", 1)
			layer.open({
				type: 2,
				//				  offset: ['100px'], //右下角弹出
				area: ['80%', '648px'],
				shade: 0.5,
				title: '健康教育',
				fixed: true, //不固定
				maxmin: true,
				closeBtn: 1,
				shift: 5,
				shadeClose: false, //点击遮罩关闭层
				content: "../../article/html/article.html?code=" + data.patientCode + '&resultCode=' + data.code
			});
			//		location.href="../../../../health-education/login.html?origin=jbsc"
		},
		view: function(data) {
			layer.open({
				type: 2,
				//				  offset: ['100px'], //右下角弹出
				area: ['568px', '100%'],
				shade: 0.5,
				title: '查看筛选结果',
				fixed: true, //不固定
				maxmin: true,
				closeBtn: 1,
				shift: 5,
				shadeClose: false, //点击遮罩关闭层
				content: '../../jbsc/html/view_screening_results.html?isView=true&resultCode=' + data.code
			});
		},
		//筛查
		shaicha: function(data, isNew) {
			var vm = this
			if(isNew) {
				//再次筛查数+1
				layer.open({
					type: 2,
					area: ['820px', '648px'],
					shade: 0.5,
					id: "questionnaire",
					title: '筛选统计',
					fixed: true, //不固定
					maxmin: true,
					closeBtn: 1,
					shift: 5,
					shadeClose: false, //点击遮罩关闭层
					content: '../../jbsc/html/questionnaire.html?fliter_code=' + data.templateCode + '&fliter_title=' + data.templateTitle + '&resident_code=' + data.patientCode + '&resident_name=' + data.patientName
				});
				return;
			}
			layer.open({
				type: 2,
				offset: 'rb', //右下角弹出
				id: "filter_type",
				area: ['280px', '100%'],
				shade: 0.5,
				title: false,
				fixed: true, //不固定
				maxmin: false,
				closeBtn: 0,
				shift: 5,
				shadeClose: true, //点击遮罩关闭层
				content: '../../jbsc/html/filter_type.html'
			});
		},
		//健康跟踪
		jkgz: function(data) {

			var vm = this
			//跳转到筛查结果页面
			var index = layer.open({
				type: 2,
				area: ['500px', '550px'],
				shade: 0.5,
				title: '家医建议',
				fixed: true, //不固定
				maxmin: false,
				closeBtn: 1,
				shift: 5,
				shadeClose: false, //点击遮罩关闭层
				content: '../../jbsc/html/advice.html?resultCode=' + data.code + '&filter_code=' + data.templateCode
			});
			console.log(index)
		},
		datamodeltap: function() {
			var vm = this
			$("#sc_datamodel").toggle("normal", function() {
				if(vm.datamodelshow) {
					vm.datamodelshow = false
					$("#datamodeltap").removeClass("up_datamodel").addClass("down_datamodel")
					$("#datamodeltap span").text("展开")
				} else {
					vm.datamodelshow = true
					$("#datamodeltap").removeClass("down_datamodel").addClass("up_datamodel")
					$("#datamodeltap span").text("收起")
				}
			});
		}
	}
})