choseDoctorByName.js 4.17 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 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
define(['zepto', 'vue', 'Utils'], function($, Vue, Utils) {
	//搜索按钮
	var jzz = $(".load");
	var btn = $("#btn");
	var doctorBg = $(".doctorBg");
	var body = $("body");
	var windowH = $(window).height();
	var cishu = 0;
	var other = true;
	var qudao = Utils.getRequest("linkType");
	var subQudao = Utils.getRequest('sub');
	if (qudao == "wx") {
		other = false;
	}
	if (subQudao == 'dd' || subQudao == 'hz') {
		other = true;
	}
	var chose = {
		doctorName: '',
		doctorList: [],
		max: "LAST",
		hasMore: false,
		noMore: true,
		scrollTopBefore: "0",
		windowH: $(window).height(),
		isScroll: true,
		isScroll01: true,
		scrollTopBefore01: 0,
		doctorListHeight: 0,
		doctorHeightHasChange: true,
		other: other,
		offset: 1,

		renderDoctorList: function(opts) {
			if (chose.doctorName == "") {
				return;
			}
			jzz.addClass("on");
			$.ajax({
				url: 'https://testdevgw.medtap.cn/doctor/listDoctor',
				contentType: "application/json",
				type: 'post',
				async: true,
				dataType: 'json',
				headers: Utils.getHeaders(),
				data: JSON.stringify(Utils.setToken({
					offset: chose.offset, //当前页
					limit: 10, //每页显示数量
					doctorName: chose.doctorName //医生姓名
				})),
				success: function(data) {
					if (!data.success) {
						Utils.pop(data.resultDesc);
						jzz.removeClass("on");
						return;
					}
					var docLen = data.content.doctorResults.length;
					if (docLen > 0) {
						chose.offset++;
					}
					if (opts.more) {
						chose.doctorList = chose.doctorList.concat(data.content.doctorResults);
					} else {
						chose.doctorList = data.content.doctorResults;
						chose.scrollTopBefore01 = 0;
					}
					chose.hasMore = docLen > 0;
					chose.noMore = docLen <= 0;
					chose.scrollTopBefore = 0;
					chose.doctorHeightHasChange = true;
					chose.isScroll = true;
					chose.isScroll01 = true;
					jzz.removeClass("on");
				},
				error: function() {
					jzz.removeClass("on");
				}
			}, true);

		},
		showImg: function() {

			var scrollTop = $(window).scrollTop();
			var liList = doctorBg.find(".has");
			if (liList.length < 1) {
				return;
			}
			$.each(liList, function() {
				var li = $(this).offset().top;
				if ((chose.windowH + 300) > li - scrollTop && li > scrollTop) {
					var img = $(this).find('img');
					if (!img.attr("src")) {
						var imgUrl = $(this).attr("data_src");
						$(this).removeClass("has");
						img.attr("src", imgUrl);
					}
				}
			});
			chose.isScroll = true;
		},
		eventBind: function() {
			btn.on("click", function() {
				chose.max = "LAST";
				body.scrollTop("0");
				chose.offset = 1;
				chose.renderDoctorList({
					more: false
				});
			});
			doctorBg.on("click", ".more", function() {
				chose.renderDoctorList({
					more: true
				});
			});
			doctorBg.on("click", 'li', function() {
				var type = Utils.getRequest("linkType");
				var doctorId = $(this).attr("doctorId");
				var doctorName = $(this).attr("doctorName");
				if (type == "wx") {
					Utils.pushNewWindow(
						"https://review-formal.iplusmed.com/wechatForLungCancer/dev/wechat_lung_push_doctor/pages/doctorHomePage.html?v=1.0.0&doctorId=" +
						doctorId + '&wechatId=' + Utils.getRequest('wechatId'));
					return;
				}
				window.selectDoctorBean = {
					doctorId: doctorId,
					doctorName: doctorName
				}

			});

			$(window).on("scroll", function() {
				if (chose.isScroll01) {
					chose.isScroll01 = false;
					setTimeout(function() {
						chose.isScroll01 = true;
						var ddd = $(window).scrollTop();
						if (chose.scrollTopBefore01 >= ddd) {
							return;
						}
						chose.scrollTopBefore01 = ddd;
						var docH;
						if (chose.doctorHeightHasChange) {
							docH = doctorBg.height();
							chose.doctorListHeight = docH;
							chose.doctorHeightHasChange = false;
						} else {
							docH = chose.doctorListHeight;

						}
						if (docH - (ddd + windowH) < 200) {
							chose.isScroll01 = false;
							if (!chose.hasMore) {
								return;
							}
							chose.renderDoctorList({
								more: true
							});
						}
					}, 1000);
				}
			});
		},

		init: function() {
			new Vue({
				el: "#app",
				data: chose
			});
			chose.eventBind();
			$("body").css("opacity", "1");

		}
	}
	chose.init();

});