123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679 |
- 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 showDateDom1 = null;
- var showDateDom2 = null;
- var showDateDom3 = null;
- var showDateDom4 = null;
- var showDateDom5 = null;
- var showDateDom6 = null;
- var showDateDom7 = null;
- 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("保存");
- showDateDom1 = $('#mobIn1');
- showDateDom2 = $('#mobIn2');
- showDateDom3 = $('#mobIn3');
- showDateDom4 = $('#mobIn4');
- showDateDom5 = $('#mobIn5');
- showDateDom6 = $('#mobIn6');
- showDateDom7 = $('#mobIn7');
- } else {
- $(document).attr("title", "新增血糖仪");
- }
- $("#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;
- console.log(rowData);
- 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('-');
-
- showDateDom1.val(fasting[0].substring(0,5) + '-' + fasting[1].substring(0,5));
- showDateDom2.val(afterBreakFast[0].substring(0,5) + '-' + afterBreakFast[1].substring(0,5));
- showDateDom3.val(beforeLunch[0].substring(0,5) + '-' + beforeLunch[1].substring(0,5));
- showDateDom4.val(afterLunch[0].substring(0,5) + '-' + afterLunch[1].substring(0,5));
- showDateDom5.val(beforeDinner[0].substring(0,5) + '-' + beforeDinner[1].substring(0,5));
- showDateDom6.val(afterDinner[0].substring(0,5) + '-' + afterDinner[1].substring(0,5));
- showDateDom7.val(beforeSleep[0].substring(0,5) + '-' + beforeSleep[1].substring(0,5));
- loadTime();
- } 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(",");//因为微信扫描条形码的时候,会带上这个码的类型,所以取数组后的码显示
-
- $("#sncode").val(arr[1]);
- },
- error: function(res){
- if(res.errMsg.indexOf('function_not_exist') > 0){
- alert('版本过低请升级')
- }
- }
- });
- })
- }
- 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(v, index) {
- if(v == '') {
- switch(index) {
- case 0:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 1:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 2:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 3:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 4:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 5:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- case 6:
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: tips[index]
- }).show();
- break;
- }
- d.close();
- return true;
- }
- return false;
- }
- 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 = false,
- isGo = false;
- o.deviceSN = snCode;
- o.userType = "-1"; //是否多用户
- o.categoryCode = categoryCode;
- $.each($szTime, function(index) {
- var tArr = ($(this).val()).split('-');
- if(!isTrue) {
- isTrue = checkDate($(this).val(), index);
- isGo = checkDate($(this).val(), index);
- switch(index) {
- case 0:
- o.fastingStart = tArr[0] + ':00';
- o.fastingEnd = tArr[1] + ':59';
- break;
- case 1:
- o.afterBreakfastStart = tArr[0] + ':00';
- o.afterBreakfastEnd = tArr[1] + ':59';
- break;
- case 2:
- o.beforeLunchStart = tArr[0] + ':00';
- o.beforeLunchEnd = tArr[1] + ':59';
- break;
- case 3:
- o.afterLunchStart = tArr[0] + ':00';
- o.afterLunchEnd = tArr[1] + ':59';
- break;
- case 4:
- o.beforeDinnerStart = tArr[0] + ':00';
- o.beforeDinnerEnd = tArr[1] + ':59';
- break;
- case 5:
- o.afterDinnerStart = tArr[0] + ':00';
- o.afterDinnerEnd = tArr[1] + ':59';
- break;
- case 6:
- o.beforeSleepStart = tArr[0] + ':00';
- o.beforeSleepEnd = tArr[1] + ':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 loadTime() {
- var iosSelect1 = null;
- var iosSelect2 = null;
- var iosSelect3 = null;
- var iosSelect4 = null;
- var iosSelect5 = null;
- var iosSelect6 = null;
- var iosSelect7 = null;
- var starNum1 = 0;
- var starNum2 = 0;
- // 初始化时间
- var now = new Date();
- var nowHours = now.getHours();
- var nowSeconds = now.getMinutes();
- for(var i = 1; i <= 7; i++) {
- var d = $('#mobIn' + i),
- // d2 = $('#mobIn' + (i - 1)),
- aArr = (d.val()).split('-');
- d.attr('data-hours', (aArr[0].split(':'))[0]);
- d.attr('data-seconds', (aArr[0].split(':'))[1]);
- d.attr('data-thours', (aArr[1].split(':'))[0]);
- d.attr('data-tseconds', (aArr[1].split(':'))[1]);
- }
- // 数据初始化
- function cN(v) {
- return v < 10 ? '0' + v : v;
- }
- function formatHours(s) {
- var arr = [];
- for(var i = s; i <= 23; i++) {
- arr.push({
- id: cN(i) + '',
- value: cN(i)
- });
- }
- return arr;
- }
- function formatSeconds(s) {
- var arr = [];
- for(var i = s; i <= 59; i++) {
- arr.push({
- id: cN(i) + '',
- value: cN(i)
- });
- }
- return arr;
- }
- var hoursData = function(callback) {
- callback(formatHours(starNum1));
- };
- var secondData = function(h, callback) {
- callback(formatSeconds(starNum2))
- };
- var hoursTData = function(h, s, callback) {
- h = parseInt(h);
- callback(formatHours(h));
- };
- var secondTData = function(h, s, h1, callback) {
- s = parseInt(s);
- callback(formatSeconds(0))
- };
- for(var i = 1; i <= 7; i++) {
- $('#mobIn' + i).on('click', function() {
- var $me = $(this),
- aArr = ($me.val()).split('-');
- // d.attr('data-hours', (aArr[0].split(':'))[0]);
- // d.attr('data-seconds', (aArr[0].split(':'))[1]);
- // d.attr('data-thours', (aArr[1].split(':'))[0]);
- // d.attr('data-tseconds', (aArr[1].split(':'))[1]);
- var oneLevelId = parseInt(aArr[0].split(':')[0]);
- var twoLevelId = parseInt(aArr[0].split(':')[1]);
- var threeLevelId = parseInt(aArr[1].split(':')[0]);
- var fourLevelId = parseInt(aArr[1].split(':')[1]);
- var st = parseInt($me.attr('data-thours'));
- var $n = $me.closest('.time-item').next(),
- $p = $me.closest('.time-item').prev(),
- ind = $me.closest('.time-item').index();
- if($p.length) {
- if(!$p.find('input').val()) {
- dialog({
- contentType: 'tipsbox',
- skin: 'bk-popup',
- bottom: true,
- content: '请先选择上一个时间段!'
- }).show();
- return;
- }
- }
- if(ind == 0) {
- starNum1 = 0;
- starNum2 = 0;
- } else {
- var $p = $me.closest('.time-item').prev().find('input'),
- pArr = ($p.val()).split('-');
- starNum1 = parseInt(pArr[1].split(':')[0]);
- starNum2 = parseInt('00');
- }
- new IosSelect(4, [hoursData, secondData, hoursTData, secondTData], {
- title: '',
- itemHeight: 35,
- relation: [1, 1, 1, 1],
- oneLevelId: oneLevelId,
- twoLevelId: twoLevelId,
- threeLevelId: threeLevelId,
- fourLevelId: fourLevelId,
- showLoading: true,
- callback: function(selectOneObj, selectTwoObj, selectThreeObj, selectFourObj) {
- $n.find('input').attr('data-hours', selectThreeObj.id);
- $n.find('input').attr('data-seconds', selectFourObj.id);
- $n.find('input').attr('data-thours', selectThreeObj.id);
- $n.find('input').attr('data-tseconds', selectFourObj.id);
- $me.attr('data-hours', selectOneObj.id);
- $me.attr('data-seconds', selectTwoObj.id);
- $me.attr('data-thours', selectThreeObj.id);
- $me.attr('data-tseconds', selectFourObj.id);
- starNum1 = parseInt(selectThreeObj.id);
- starNum2 = parseInt(selectFourObj.id);
- $me.val(selectOneObj.value + ':' + selectTwoObj.value + '-' + selectThreeObj.value + ':' + selectFourObj.value);
- }
- });
- });
- }
- }
- 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
- }
- });
- });
- }
- }
- });
- }
|