123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- var $deviceCategory = $('#device_category'),
- $deviceVersion = $('#device_version'),
- $deviceSn = $('#device_sn'),
- $unbingBtn = $('#bind_btn'),
- $endPointMsg = $('#end_point_msg');
- /**
- * 获取设备类型列表
- * */
- function deviceCategoryPromise() {
- return getReqPromise('common/device/DeviceCategory',null,'GET')
- .then(function(res) {
- if(res.status == 200) {
- var codes = _.pluck(res.data, 'code');
- var names = _.pluck(res.data, 'name');
- initDeviceCategory(codes, names);
- } else {
- mui.toast(res.msg);
- Promise.reject();
- }
- });
- }
- /**
- * 获取设备型号列表
- * */
- function deviceListPromise(code) {
- return getReqPromise('common/device/DeviceList',{
- category_code: code
- },'GET')
- .then(function(res) {
- if(res.status == 200) {
- var codes = _.pluck(res.data, 'id');
- var names = _.pluck(res.data, 'name');
- initDeviceVersion(codes, names);
- } else {
- mui.toast(res.msg);
- Promise.reject();
- }
- })
- }
- /**
- * 通过sn码获取设备绑定情况
- * */
- function getListByDeviceSnPromise(type,deviceSn) {
- return getReqPromise('doctor/device/getListByDeviceSn',{
- type: type,
- deviceSn: deviceSn
- },'GET')
- .then(function(res) {
- if(res.status == 200) {
- if(!res.data || !res.data.length) {
- $endPointMsg.text("该设备未绑定居民");
- } else {
- var names = _.pluck(res.data, 'userName').join('、');
- mui.confirm("当前设备已绑定至"+names+"账户,解绑设备后,将无法自动从设备获取相关数据,是否确认解绑?", "提示", ["立即解绑","不了,谢谢"], function(e) {
- if(e.index==0){
- unbindDevicePromise(type,deviceSn).then(function(res) {
- mui.toast(res.msg);
- });
- return;
- }else{
- return;
- }
- });
- }
- } else {
- $endPointMsg.text(res.msg);
- Promise.reject();
- }
- }).catch(function(e) {
- console&& console.error(e)
- })
- }
- /**
- * 解绑设备请求
- * */
- function unbindDevicePromise(type, deviceSn) {
-
- return getReqPromise('doctor/device/unbindDevice',{
- type: type,
- deviceSn: deviceSn
- },'GET')
- }
- function initMobiscroll($el,codes,names,opts) {
- $el.mobiscroll({
- theme: 'ios',
- lang: 'zh',
- customWheels: true,
- wheels: [
- [{
- keys: codes,
- values: names
- }]
- ],
- onSelect: function(valueText, inst) {
- var dd = eval("[" + valueText + "]");
- $(this).val(dd[0].values);
- $(this).attr('data-code',dd[0].keys);
- if(opts && opts.onselect) {
- opts.onselect(dd[0].keys);
- }
- $endPointMsg.text('');
- }
- });
- }
- /*
- * 设备类型下拉列表初始化
- * */
- function initDeviceCategory(codes,names) {
- initMobiscroll($deviceCategory,codes,names,{
- onselect: function(code) {
- deviceListPromise(code)
- }
- })
- }
- /*
- * 设备类型型号下拉列表初始化
- * */
- function initDeviceVersion(codes,names) {
- initMobiscroll($deviceVersion,codes,names)
- }
- /*
- * 必输校验
- * */
- function validRequiredPromise() {
- return new Promise(function(resolve, reject) {
- var category = $deviceCategory.attr('data-code'),
- version = $deviceVersion.attr('data-code'),
- sn = $.trim($deviceSn.val());
- if(!category) {
- reject("请选择设备类型");
- } else if(!version){
- reject("请选择设备型号");
- } else if(!sn) {
- reject("请输入SN码");
- } else {
- resolve({
- category: category,
- version: version,
- sn: sn
- });
- }
- })
- }
- // 页面业务处理流程开始
- new Promise(function(resolve, reject) {
- mui.plusReady(function() {
- // plus已经准备好,可以往下执行
- resolve(true);
- })
- }).then(function() {
-
- return deviceCategoryPromise()
- .then(function() {
- $unbingBtn.on('click',function() {
- validRequiredPromise().then(function(data) {
- return getListByDeviceSnPromise(data.category, data.sn)
- },function(msg) {
- mui.toast(msg);
- }
- ).then(function(res) {
- if(res.status == 200) {
- mui.toast(res.msg);
- } else if(res.status == -1){
- $endPointMsg.text("未查询到设备或设备未绑定居民");
- } else {
- mui.toast(res.msg);
- }
-
- })
- });
-
- $deviceSn.on('input',function() {
- $endPointMsg.text('');
- })
- }).catch(function(e) {
- console && console.error(e);
- })
- })
|