scan2.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. var isManage;
  2. // 扩展API加载完毕后调用onPlusReady回调函数
  3. document.addEventListener("plusready", onPlusReady, false);
  4. // 扩展API加载完毕,现在可以正常调用扩展API
  5. function onPlusReady() {
  6. var self = plus.webview.currentWebview();
  7. isManage = self.isManage;
  8. setTimeout(function() {
  9. startRecognize();//创建扫描控件
  10. startScan();//开始扫描
  11. }, 300);
  12. bindEvents();
  13. }
  14. var scan = null;
  15. function onmarked(type, result) {
  16. // 扫码成功后的结果
  17. if(result) {
  18. var arr = result.split(" ");
  19. //判断设备是否已经绑定了其他用户
  20. if(arr.length > 1){
  21. //云湃血压计 sim + sn
  22. checkSnBind(arr[1]);
  23. }else{
  24. checkSnBind(arr[0]);
  25. }
  26. } else {
  27. mui.toast("扫码失败")
  28. }
  29. }
  30. function startRecognize() {
  31. scan = new plus.barcode.Barcode('bcid', [plus.barcode.QR, plus.barcode.CODE128, plus.barcode.EAN13, plus.barcode.EAN8], {
  32. frameColor: '#4dcd70',
  33. scanbarColor: '#4dcd70'
  34. });
  35. scan.onmarked = onmarked;
  36. }
  37. function startScan() {
  38. scan.start();
  39. }
  40. function cancelScan() {
  41. scan.cancel();
  42. }
  43. function setFlash() {
  44. scan.setFlash();
  45. }
  46. function bindEvents(){
  47. $(".input-btn").on('click', function(){
  48. openWebview("keydown-SN.html", {isManage: isManage});
  49. });
  50. $(".header-link").on('click', function(){
  51. openWebview("../../device/html/device-management.html");
  52. })
  53. }
  54. function checkSnBind(code){
  55. console.log(code);
  56. plus.nativeUI.showWaiting();
  57. var url = "doctor/device/getDeviceInfoByDeviceSn",
  58. params = {
  59. deviceSn: code,
  60. };
  61. sendGet(url, params, null, function(res){
  62. plus.nativeUI.closeWaiting();
  63. console.log(JSON.stringify(res));
  64. if(res.status == 200){
  65. var isMultiUser = res.data.isMultiUser, //0-只有一个键,1-多个键
  66. bindLength = res.data.bindingInfo.length; //获取绑定信息的长度
  67. if((!isMultiUser && bindLength == 1) || (isMultiUser && bindLength > 1)){
  68. //默认最多只有两个键
  69. mui.confirm("设备已被绑定,是否更换绑定居民?", "识别提示", ["是", "否"], function(e){
  70. if(e.index == 0){
  71. openWebview("device-bind-info.html", {info: res.data, sn: code, isManage: isManage});
  72. }else{
  73. plus.webview.currentWebview().reload();
  74. }
  75. });
  76. }else{
  77. openWebview("device-bind-info.html", {info: res.data, sn: code, isManage: isManage});
  78. }
  79. }else{
  80. console.log(res.msg);
  81. // mui.toast(res.msg);
  82. mui.alert(res.msg, "识别提示", "我知道了", function(){
  83. plus.webview.currentWebview().reload();
  84. })
  85. }
  86. }, true);
  87. }
  88. window.addEventListener("reload", function(e){
  89. plus.webview.currentWebview().reload();
  90. })