123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587 |
- var rowData = {};
- var sn = ""; //记录sn码
- var dataId = null;
- var type = null;
- var name = null;
- var type = null;
- var photoUrl = null;
- var deviceId = null;
- var oldSn = ""; //旧sn
- var sncode = '';
- var categoryCode = '';
- var prescriptionCode;
- var $szTime = $('.sz-time');
- var d = dialog({
- contentType: 'load',
- skin: 'bk-popup'
- }),
- tips = ['早餐前血糖', '早餐后血糖', '午餐前血糖', '午餐后血糖', '晚餐前血糖', '晚餐后血糖', '睡前血糖'];
- $(function() {
- Request = GetRequest();
- dataId = Request["id"];
- deviceId = Request["deviceId"];
- prescriptionCode = Request["prescriptionCode"];
- categoryCode = Request["categoryCode"];
-
- $('#member').val(window.localStorage.getItem('nowPatientName'));
- getDeviceInfo(deviceId);
- bindEvents();
- if(dataId) {
- $(document).attr("title", "编辑血糖仪");
- initData(dataId);
- $('.xt-time-list').show();
- $("#bang-btn").html("保存");
- } else {
- $(document).attr("title", "新增血糖仪");
- }
- if(deviceId == 5){
- //三诺亲智的设备,建议扫描设备背面的条形码获取SN码。(因为厂家提供的二维码不好扫)
- $("#device5Msg").show();
- }else{
- $("#device5Msg").hide();
- }
- $("#bang-btn").addClass("active");
-
- weixinSign();
- });
- function initData(dataId) {
- var params = {};
- params.id = dataId;
- sendPost("patient/device/PatientDeviceInfo", params, "JSON", "GET",
- function(res) {
- if(res.msg) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- content: res.msg
- }).show();
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备信息初始化失败!'
- }).show();
- }
- },
- function(res) {
- if(res.status == 200) {
- rowData = res.data;
- oldSn = rowData.device.deviceSn;
- $("#sncode").val(rowData.device.deviceSn);
- sncode = rowData.device.deviceSn;
- var fasting = (rowData.time['fasting'].replace(/ /g, '')).split('-'),
- afterBreakFast = (rowData.time['afterBreakFast'].replace(/ /g, '')).split('-'),
- beforeLunch = (rowData.time['beforeLunch'].replace(/ /g, '')).split('-'),
- afterLunch = (rowData.time['afterLunch'].replace(/ /g, '')).split('-'),
- beforeDinner = (rowData.time['beforeDinner'].replace(/ /g, '')).split('-'),
- afterDinner = (rowData.time['afterDinner'].replace(/ /g, '')).split('-'),
- beforeSleep = (rowData.time['beforeSleep'].replace(/ /g, '')).split('-');
-
- var list = [{
- name: '早餐前血糖',
- value1: fasting[0].substring(0,5),
- value2: fasting[1].substring(0,5)
- },{
- name: '早餐后血糖',
- value1: afterBreakFast[0].substring(0,5),
- value2: afterBreakFast[1].substring(0,5)
- },{
- name: '午餐前血糖',
- value1: beforeLunch[0].substring(0,5),
- value2: beforeLunch[1].substring(0,5)
- },{
- name: '午餐后血糖',
- value1: afterLunch[0].substring(0,5),
- value2: afterLunch[1].substring(0,5)
- },{
- name: '晚餐前血糖',
- value1: beforeDinner[0].substring(0,5),
- value2: beforeDinner[1].substring(0,5)
- },{
- name: '晚餐后血糖',
- value1: afterDinner[0].substring(0,5),
- value2: afterDinner[1].substring(0,5)
- },{
- name: '睡前血糖',
- value1: beforeSleep[0].substring(0,5),
- value2: beforeSleep[1].substring(0,5)
- }];
- var html = template('time-tmp', {list: list});
- $(".time-list").empty().append(html);
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备信息初始化失败!'
- }).show();
- }
- }
- )
- }
- //判断值是否改变过
- function isValueChange() {
- var changeTagStr = $("#sncode").val();
- if(oldSn != changeTagStr) {
- }
- }
- //绑定事件
- function bindEvents() {
- $('#sncode').on('click', function() {
- $(this).focus();
- });
- //保存方法
- $("#bang-btn").bind("click", function() {
- if($(this).hasClass("active")) {
- var snCode = $("#sncode").val();
- if(snCode == null || snCode == "") {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '请输入设备的SN码进行绑定!'
- }).show();
- } else {
- if(!dataId) {
- $("#bang-btn").html("正在绑定").css("pointer-events", "none");
- }
- d.show();
- checkSnBind(snCode, checkSuccess);
- }
- }
- })
- $(".scanText").on('click', function(){
- wx.scanQRCode({
- desc: 'scanQRCode desc',
- needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
- scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码,默认二者都有
- success: function (res) {
- // 回调
- var code = res.resultStr,
- arr = code.split(",");//因为微信扫描条形码的时候,会带上这个码的类型,所以取数组后的码显示
-
- if(arr.length > 1){
- $("#sncode").val(arr[1]);
- }else{
- $("#sncode").val(arr[0]);
- }
-
- },
- error: function(res){
- if(res.errMsg.indexOf('function_not_exist') > 0){
- alert('版本过低请升级')
- }
- }
- });
- });
-
- //绑定时间控件弹出
- $(".time-list").on('click', '.change-date', function(){
- var $this = $(this),
- $parent = $this.closest(".time-item"),
- $next = $parent.next();
- var picker = new mui.DtPicker({type: 'time'});
- picker.show(function(rs) {
- /*
- * rs.value 拼合后的 value
- * rs.text 拼合后的 text
- * rs.y 年,可以通过 rs.y.vaue 和 rs.y.text 获取值和文本
- * rs.m 月,用法同年
- * rs.d 日,用法同年
- * rs.h 时,用法同年
- * rs.i 分(minutes 的第二个字母),用法同年
- */
- $this.val(rs.text);
- if($next && !$this.hasClass("first")){
- var h = rs.h.text,
- i = rs.i.text;
- if(parseInt(i)+1 == 60){
- i = 0;
- h = parseInt(h) + 1;
- if(parseInt(h) < 10){
- h = '0' + h;
- }
- }else{
- i = parseInt(i)+1;
- }
- if(i < 10){
- i = '0'+ i;
- }
-
- $next.find(".sz-time").eq(0).val(h+":"+i);
- }
- // picker.dispose();
- });
- })
- }
- function checkSnBind(snCode, checkSuccess) {
- if (dataId && snCode == oldSn) {
- addData(snCode);
- } else {
- var b = /^[0-9a-zA-Z]*$/g;
- if(!b.test(snCode)) {
- setTimeout(function() {
- $("#bang-btn").html("立即绑定").css("pointer-events", "");
- }, 3000);
- d.close();
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '对不起,您输入的SN有误,请重新输入!'
- }).show();
- return false;
- }
- var params = {};
- params.type = type;
- params.device_sn = snCode;
- $.ajax(server + "patient/device/PatientDeviceIdcard", {
- data: params,
- dataType: "JSON",
- async: false,
- type: "get",
- timeout: 10000,
- beforeSend: function(request) {
- var userAgent = window.localStorage.getItem(agentName);
- request.setRequestHeader("userAgent", userAgent);
- },
- error: function(res) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备SN校验失败!'
- }).show();
- setTimeout(function() {
- $("#bang-btn").html("立即绑定").css("pointer-events", "");
- d.close();
- }, 3000);
- },
- success: function(res) {
- setTimeout(function() {
- $("#bang-btn").html("立即绑定").css("pointer-events", "");
- d.close();
- }, 3000);
- if(res.status == 200) {
- var name = "";
- var others = null;
- for(var j in res.data) {
- name = res.data[j].name;
- others = res.data[j].others
- }
- //没被绑定
- if(name == "") {
- $("#bang-btn").addClass("active");
- if(dataId){
- editSN(snCode);
- } else {
- if(checkSuccess != null) {
- checkSuccess(snCode);
- }
- }
- } else if(others != null && others == 1) {
- // $("#bang-btn").removeClass("active");
- //被绑定而且被别人绑定
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '该设备已被他人绑定,设备解绑后,方可再次绑定!'
- }).show();
- } else if(others != null && others == 0) {
- // $("#bang-btn").removeClass("active");
- if(deviceId == null || !deviceId || deviceId == "") {
- //新增,编辑/被自己绑定
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '对不起,您已绑定过该设备,解绑后方可继续绑定!'
- }).show();
- } else {
- if(dataId){
- editSN(snCode);
- } else {
- if(checkSuccess != null) {
- checkSuccess(snCode);
- }
- }
- }
- }
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '该设备已被他人绑定,设备解绑后,方可再次绑定!'
- }).show();
- }
- }
- });
- }
- }
- function getDeviceInfo(deviceId) {
- sendPost("/common/device/DeviceInfo?id=" + deviceId, {}, "JSON", "GET",
- function(res) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备信息获取失败!'
- }).show();
- },
- function(res) {
- if(res.status == 200) {
- var rowData1 = res.data;
- type = rowData1.categoryCode;
- name = rowData1.name;
- photoUrl = getImgUrl(rowData1.photo);
- $(".deviceName").html(name);
- $(".div-xuetangyi-img img").attr("src", photoUrl);
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备信息获取失败!'
- }).show();
- }
- }
- )
- }
- function checkSuccess(snCode) {
- var name1 = "血糖仪-" + name;
- var params = {};
- params.deviceId = deviceId; //设备ID
- params.deviceName = name1; //设备名称
- params.deviceSn = snCode; //设备SN码
- params.categoryCode = type; //设备分类 血糖仪1 血压计 2
- params.userType = "-1"; //是否多用户
- if(rowData.id) {
- params.id = rowData.id;
- }
- sendPost("/patient/device/SavePatientDevice", {
- "json": JSON.stringify(params)
- }, "JSON", "post",
- function(res) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备绑定失败!'
- }).show();
- },
- function(res) {
- if(res.status == 200) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '设备绑定成功!'
- }).show();
- setTimeout(function() {
- window.location.href = 'view-shezhishijianduan.html?type=1&sncode=' + $('#sncode').val()+'&categoryCode='+type;
- }, 500);
- } else {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: res.msg
- }).show();
- return false;
- }
- }
- )
- }
- function checkDate(v1, v2, index) {
- if(v1 == '' || v2 == '') {
- var content = "请选择"+tips[index]+"检测时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }else{
- var v1 = v1.split(":"),
- v2 = v2.split(":"),
- v1_h = v1[0],
- v1_m = v1[1],
- v2_h = v2[0],
- v2_m = v2[1];
- if(v1_h == v2_h){
- if(v1_m > v2_m){
- var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }
- }else if(v1_h > v2_h){
- var content = tips[index]+"设置的检测时间,结束时间必须大于开始时间";
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: content
- }).show();
- d.close();
- return false;
- }
- }
- return true;
- }
- function editSN (snCode) {
- var o = {};
- o.deviceSN = oldSn;
- o.newDeviceSN = snCode;
- o.categoryCode = categoryCode;
- o.userType = "-1"; //是否多用户
- sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
- d.close();
- if(res.status == 200) {
- addData(snCode);
- } else {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: res.msg
- }).show();
- }
- });
- }
- //添加数据
- function addData(snCode) {
- d.show();
- var o = {},
- isTrue = true,
- isGo = true;
- o.deviceSN = snCode;
- o.userType = "-1"; //是否多用户
- o.categoryCode = categoryCode;
- $.each($(".time-item"), function(index) {
- var value1 = $(this).find(".sz-time:eq(0)").val(),
- value2 = $(this).find(".sz-time:eq(1)").val();
- if(isTrue) {
- isTrue = checkDate(value1, value2, index);
- isGo = checkDate(value1, value2, index);
- switch(index) {
- case 0:
- o.fastingStart = value1 + ':00';
- o.fastingEnd = value2 + ':59';
- break;
- case 1:
- o.afterBreakfastStart = value1 + ':00';
- o.afterBreakfastEnd = value2 + ':59';
- break;
- case 2:
- o.beforeLunchStart = value1 + ':00';
- o.beforeLunchEnd = value2 + ':59';
- break;
- case 3:
- o.afterLunchStart = value1 + ':00';
- o.afterLunchEnd = value2 + ':59';
- break;
- case 4:
- o.beforeDinnerStart = value1 + ':00';
- o.beforeDinnerEnd = value2 + ':59';
- break;
- case 5:
- o.afterDinnerStart = value1 + ':00';
- o.afterDinnerEnd = value2 + ':59';
- break;
- case 6:
- o.beforeSleepStart = value1 + ':00';
- o.beforeSleepEnd = value2 + ':59';
- break;
- }
- }
- });
- if(isGo) {
- sendPost("patient/device/setBloodTime", o, "json", "get", null, function(res) {
- d.close();
- if(res.status == 200) {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: res.msg
- }).show();
- setTimeout(function() {
- if(prescriptionCode){
- window.history.go(-3);
- }else{
- window.location.href='my-equipments.html';
- }
- }, 500);
- } else {
- dialog({
- contentType: 'tipsbox',
- bottom: true,
- skin: 'bk-popup',
- content: '保存失败'
- }).show();
- }
- });
- }
- }
- function weixinSign(){
- //从后台那边获取签名等信息
- var params = {};
- var url1 = window.location.href;
- params.pageUrl = url1;
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'chooseImage',
- 'uploadImage',
- 'scanQRCode'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
-
- // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。
- wx.ready(function(){
- wx.getNetworkType({
- success: function (res) {
- networkStatus = res.networkType; // 返回网络类型2g,3g,4g,wifi
- }
- });
- });
- }
- }
- });
- }
|