123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562 |
- mui.init();
- var CITY_CODE = "350200";
- var self,
- userRole,
- areaCode,
- areaTitle,
- initLevel,
- level,
- initDate,//记录从前一个页面跳转过来的日期
- dateType,//记录前一个页面跳转时柱状图的日期类型 1-日期,2-周,3-月
- disease, //记录从前一个页面跳转过来的疾病
- status, //从前一个页面跳转过来的状态
- expressType, //从前一个页面跳转过来的配送状态
- selectedArea, //从前一个页面带过来的区域信息
- startDate,
- endDate,
- currentYear,
- minYear = '2017', //长处方功能开始的时间2017才有这个功能
- page = 1,
- pageSize = 10,
- filterSelectedData = {
- area: {
- town: '',
- hospital: ''
- },
- filter: {
- disease: '',
- status: '',
- type: ''
- },
- date:{
- sDate: '',
- eData: '',
- year: '',
- month: ''
- }
- };
- var now = new Date();
- currentYear = now.getFullYear();
- mui.plusReady(function(){
- //获得权限
- userRole = JSON.parse(plus.storage.getItem("selectedRole"));
- areaCode = userRole.code;
- self = plus.webview.currentWebview();
- initDate = self.date;
- dateType = self.dateType;
- disease = self.disease;
- status = self.status;
- expressType = self.expressType;
- areaCode = self.area + '';
- level = areaCode == CITY_CODE ? 4 : areaCode.length==6 ? 3 : 2;
- areaTitle = self.areaTitle;
-
- $("#area").text(self.areaTitle);
- //填充帅选条件
- if(disease){
- var val = 0;
- if(disease == 'HP0047'){ //糖尿病
- val = 2;
- }else if(disease == 'HP0093'){ //高血压
- val = 1;
- }
- $(".disease[data-val="+val+"]").addClass("active");
- }
- if(status){
- $(".status[data-val="+status+"]").addClass("active");
- }
- if(expressType){
- $(".express-type[data-val="+expressType+"]").addClass("active");
- }
-
- getStartEndDate(initDate, dateType);
-
- //填充时间筛选数据
- if(dateType == 1 || dateType == 3){
- $("#date").text(initDate);
- }else if(dateType == 2){
- var str = startDate.substr(5, 5) + "~"+endDate.substr(5, 5);
- $("#date").text(str);
- //处理选中的时间
- var $inputs = $(".date-input");
- $($inputs[0]).val(startDate);
- $($inputs[1]).val(endDate);
- }
-
-
- getFilterData();
- getList(true);
-
- initListPanelScroller();
- initComminityScroller();
- initYearScroller();
- bindEvents();
- })
- function getFilterData(){
- initLevel = userRole.code == CITY_CODE ? 4 : userRole.code.length==6 ? 3 : 2;
- var areaTitle = userRole.name;
-
- if(initLevel == 4){
- getTown();
- filterSelectedData.area.town = CITY_CODE;
- }else if(initLevel == 3){
- $("#districtPanel").hide();
- filterSelectedData.area.town = userRole.code;
- //TODO 获取社区列表
- getHospital(userRole.code, userRole.name);
- }else if(initLevel == 2){
- filterSelectedData.area.hospital = userRole.code;
- $("#districtPanel").hide();
- var html = "<li data-code='"+areaCode+"' class='active'>"+areaTitle+"</li>";
- $(".community-panel").empty().append(html);
- }
-
- var dateHtml = "";
- for(i=currentYear; i>=minYear; i--){
- dateHtml += '<span class="tag mr20" data-type="date" data-val="'+i+'">'+i+'年</span>';
- }
- $("#yearPanel").empty().append(dateHtml);
- }
- //获得列表数据
- function getList(isInit){
- if(isInit){
- page = 1;
- }
- var url = "/doctor/prescriptionInfo/getPrescriptionByCondition",
- $disease = $(".disease.active"),
- disease = $disease.length > 0 ? $disease.attr("data-val") : '',
- $status = $(".status.active"),
- status = $status.length > 0 ? $status.attr("data-val") : 1,
- $type = $(".express-type.active"),
- type = $type.length > 0 ? $type.attr("data-val") : '',
- params = {
- level: level,
- area: areaCode,
- disease: disease,
- status: status,
- type: type,
- startTime: startDate,
- endTime: endDate,
- pageNo: page,
- pageSize: pageSize
- };
- plus.nativeUI.showWaiting();
- sendGet(url, params, null, function(res){
- if(res.status == 200){
- if(isInit){
- mui('#listPanel').scroll().scrollTo(0,0);
- if(res.data.length == 0){
- $("#listPanel").hide();
- $("#no_result_wrap").show();
- }else{
- $("#listPanel").show();
- $("#no_result_wrap").hide();
- $("#totalCount").text(res.data.count);
- $("#totalAmount").text(res.data.totalAmount);
- var html = template("list-tmp", res.data);
- $("#listPanel .list-panel").empty().append(html);
-
- if(res.data.length < pageSize){
- mui('#listPanel').pullRefresh().endPullupToRefresh(true);
- }else{
- mui('#listPanel').pullRefresh().refresh(true);
- page ++;
- }
- }
- }else{
- var html = template("list-tmp", res.data);
- $("#listPanel .list-panel").append(html);
-
- if(res.data.length < pageSize){
- mui('#listPanel').pullRefresh().endPullupToRefresh(true);
- }else{
- mui('#listPanel').pullRefresh().endPullupToRefresh();
- page ++;
- }
- }
- }else{
- mui.toast(res.msg);
- }
- plus.nativeUI.closeWaiting();
- }, true);
- }
- //获得市区信息
- function getTown(){
- var url = "/area/"+CITY_CODE+"/towns";
- sendGet(url, {city: CITY_CODE}, null, function(res){
- if(res.status == 200){
- console.log(res);
- var html = template("town-tmp", {list: res.data, cityCode: CITY_CODE, cityName: userRole.name});
- $("#districtPanel").empty().append(html);
-
- //判断前一个页面带过来的区域是否在此页显示
- if(level == 3){
- $(".district").removeClass("active");
- var $node = $(".district[data-code="+areaCode+"]");
- $node.addClass("active");
- getHospital(areaCode, $node.attr("data-name"));
- }else if(level == 2){
- var parentCode = areaCode.substr(0,6);
- $(".district").removeClass("active");
- var $node = $(".district[data-code="+parentCode+"]");
- $node.addClass("active");
- getHospital(parentCode, $node.attr("data-name"));
- }
- }
- }, true);
- }
- //获得服务中心的数据
- function getHospital(code, name){
- var url = "/area/getHospitals",
- params = {
- town: code
- };
- $(".mui-loading").show();
- $(".community-panel").hide();
- sendGet(url, params, null, function(res){
- if(res.status = 200){
- var html = template("community-temp", {townCode: code, townName: name, list: res.data});
- $(".community-panel").empty().append(html);
- $(".mui-loading").hide();
- $(".community-panel").show();
-
- //判断前一个页面带过来的区域是否在此页显示
- if(level == 2){
- $("li[data-level=2]").removeClass("active");
- $("li[data-code="+areaCode+"]").addClass("active");
- }
- }else{
- $(".mui-loading").hide();
- mui.toast(res.msg);
- }
- }, true);
- }
- function getStartEndDate(str, type){
- //type 1-日,2-周,3-月, 4-年
- switch(parseInt(type)){
- case 1:
- startDate = str;
- endDate = str;
- break;
- case 2:
- startDate = str;
- var d = new Date(str),
- end = new Date(str);
- end.setDate(d.getDate() + 6);
- endDate = end.format("yyyy-MM-dd");
- break;
- case 3:
- var month = str.substr(5,2);
- if(month == '12'){
- startDate = str+"-01";
- endDate = str+"-31";
- }else{
- var d = new Date(str);
- startDate = d.format("yyyy-MM-dd");
- d.setMonth(d.getMonth() + 1);
- d.setDate(d.getDate()-1);
- endDate = d.format("yyyy-MM-dd");
- }
- break;
- case 4:
- startDate = str+"-01-01";
- endDate = str+"-12-31";
- break;
- }
- }
- function bindEvents(){
- $("#area").on('click', function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- $("#showHeader").removeClass("show");
- $("#showHeader").hide();
- return false;
- }
-
- $("#tabs .j-tag").removeClass("active");
- $(this).addClass("active");
-
- $("#areaPanel").show();
- $("#filterPanel").hide();
- $("#datePanel").hide();
- $("#showHeader").show();
- $("#showHeader").addClass("show");
- });
-
- $("#filter").on('click', function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- $("#showHeader").removeClass("show");
- $("#showHeader").hide();
- return false;
- }
-
- $("#tabs .j-tag").removeClass("active");
- $(this).addClass("active");
-
- $("#areaPanel").hide();
- $("#filterPanel").show();
- $("#datePanel").hide();
- $("#showHeader").show();
- $("#showHeader").addClass("show")
- });
-
- $("#date").on('click', function(){
- if($(this).hasClass("active")){
- $(this).removeClass("active");
- $("#showHeader").removeClass("show");
- $("#showHeader").hide();
- return false;
- }
-
- $("#tabs .j-tag").removeClass("active");
- $(this).addClass("active");
-
- $("#areaPanel").hide();
- $("#filterPanel").hide();
- $("#datePanel").show();
- $("#showHeader").show();
- $("#showHeader").addClass("show")
- });
-
- $("#showHeader").on('tap', '.tag', function(){
- var $this = $(this);
- if($this.hasClass("active")){
- return false;
- }
-
- $this.siblings().removeClass("active");
- $this.addClass("active");
-
- //如果是日期选项,则清空输入框的内容
- var type = $this.attr("data-type");
- if(type == 'year'){
- $(".date-input").val("");
- }
- });
-
- $("#districtPanel").on('click', '.district', function(){
- var $this = $(this),
- code = $this.attr("data-code"),
- name = $this.attr("data-name");
- if($this.hasClass("active")){
- return false;
- }
-
- $this.siblings().removeClass("active");
- $this.addClass("active");
-
- if(code == CITY_CODE){
- $("#communityPanel .mui-loading").hide();
- $("#communityPanel .community-panel").hide();
- }
- // $("#area").text(name);
- // $("#area").attr("data-code", code);
- //TODO 获得社区服务中心列表
- getHospital(code, name);
- });
-
- $("#communityPanel").on('tap', "li", function(){
- var $this = $(this),
- code = $this.attr("data-code"),
- name = $this.attr("data-name");
- if($this.hasClass("active")){
- return false;
- }
-
- $this.siblings().removeClass("active");
- $this.addClass("active");
- // $("#area").text(name);
- // $("#area").attr("data-code", code);
- })
-
- $(".date-input").on('click', function(){
- var picker = new mui.DtPicker({
- "type": 'date',
- "beginYear": minYear,
- "endYear": currentYear
- });
- var $this = $(this);
- picker.show(function(rs){
- $this.val(rs.text);
- //将不选中选中的月份和年份
- $("#datePanel .tag").removeClass("active");
- picker.dispose();
- })
- });
-
- //重置按钮绑定事件
- $("#showHeader").on('click', ".reset-btn", function(){
- var activeTab = $("#tabs .j-tag.active").attr("id");
- if(activeTab == "area"){
- //位置的重置,直接使用默认初始的
- var areaTitle = userRole.name;
- $("#area").text(areaTitle);
- if(initLevel == 4){
- $("#districtPanel .district").removeClass("active");
- $("#districtPanel .district").eq(0).addClass("active");
- $(".community-panel").hide();
- }else if(initLevel == 3){
- $(".community-panel .district").removeClass("active");
- $(".community-panel .district").eq(0).addClass("active");
- }else if(initLevel == 2){
-
- }
- }else if(activeTab == "filter"){
- $("#filterPanel").find(".tag").removeClass("active");
- }else{
- $("#datePanel").find(".tag").removeClass("active");
- $("#datePanel").find(".date-input").val("");
- }
- });
-
- //确定按钮绑定事件
- $("#showHeader").on('click', ".confirm-btn", function(){
- //先处理地区选中的值
- if(initLevel == 4){
- var $selectTown = $("#districtPanel .district.active");
- filterSelectedData.area.town = $selectTown.attr("data-code");
- if($selectTown.attr("data-code") != CITY_CODE){
- var $hospital = $("#communityPanel li.active");
- filterSelectedData.area.hospital = $hospital.attr("data-code");
- $("#area").text($hospital.attr("data-name"));
- $("#area").attr("data-code", $hospital.attr("data-code"));
- areaCode = $hospital.attr("data-code");
- level = $hospital.attr("data-code").length > 6 ? 2 : 3;
- }else{
- $("#area").text(userRole.name);
- $("#area").attr("data-code", userRole.code);
- areaCode = userRole.code;
- level = 4;
- }
- }else if(initLevel == 3){
- var $hospital = $("#communityPanel li.active");
- filterSelectedData.area.hospital = $hospital.attr("data-code");
- $("#area").text($hospital.attr("data-name"));
- $("#area").attr("data-code", $hospital.attr("data-code"));
- areaCode = $hospital.attr("data-code");
- level = $hospital.attr("data-code").length > 6 ? 2 : 3;
- }
- //处理选中的时间
- var $inputs = $(".date-input"),
- sd = $($inputs[0]).val(),
- ed = $($inputs[1]).val();
- if(sd && ed){
- startDate = sd;
- endDate = ed;
- $("#date").text("自定义时间");
- }else if(sd || ed){
- //不改变时间值
- }else{
- var year = $("#yearPanel .tag.active").attr("data-val"),
- month = $(".month.active").attr("data-val");
- if(year && month){
- getStartEndDate(year+"-"+month, 3);
- $("#date").text(year+"年"+month+"月");
- }else if(year && !month){
- getStartEndDate(year, 4);
- $("#date").text(year+"年");
- }else if(!year && month){
- mui.toast("请选择年份");
- return false;
- }
- }
- getList(true);
- $("#showHeader").hide();
- });
-
- $("#listPanel").on('tap', ".order", function(){
- var code = $(this).attr("data-code");
- openWebview("xufangxiangqing2.html", {prescriptionCode: code});
- });
-
- $(".search-input").on('click', function(){
- openWebview("search-xufang-order.html");
- });
-
- template.helper("getStatusName", function(status){
- status = parseInt(status);
- if(status == 100){
- return "已完成";
- }else if(status == -2){
- return "居民取消";
- }else if(status == -1){
- return "审核不通过";
- }else if(status <= -3){
- return "其他原因取消";
- }else if(status >=0 && status<100){
- return "进行中";
- }
- });
-
- template.helper("getExpressName", function(type){
- switch(type){
- case 1:
- return '自取';
- break;
- case 3:
- return "健管师配送";
- break;
- case 2:
- return "快递配送";
- break;
- default:
- return "";
- break;
- }
- })
-
- template.helper("formatDate", function(str){
- if(!str){
- return "";
- }
- var timeStm = parseInt(str),
- d = new Date(timeStm);
- return d.format("yyyy-MM-dd hh:mm")
- })
- }
- function initListPanelScroller(){
- //阻尼系数
- var deceleration = mui.os.ios?0.003:0.0009;
- mui('.mui-scroll-wrapper').scroll({
- bounce: false,
- indicators: true, //是否显示滚动条
- deceleration:deceleration
- });
- mui("#listPanel").pullRefresh({
- up: {
- callback: function(){
- var self = this;
- setTimeout(function(){
- getList(false);
- // self.endPullupToRefresh();
- }, 500);
- }
- }
- })
- }
- function initComminityScroller(){
- mui("#communityPanel .mui-scroll-wrapper").pullRefresh();
- }
- function initYearScroller(){
- mui("#year-panel").scroll({
- scrollY: false, //是否竖向滚动
- scrollX: true, //是否横向滚动
- startX: 0, //初始化时滚动至x
- startY: 0, //初始化时滚动至y
- indicators: true, //是否显示滚动条
- deceleration:0.0006, //阻尼系数,系数越小滑动越灵敏
- bounce: true
- });
- }
|