//打開車輛操作模態框 加載開關數據 function control(id) { //通過uniqueId 獲取行數據 var rows = $('#vehicleInfoTab').bootstrapTable('getRowByUniqueId', id); $("#id").val(rows.id); $("#gpsNo").val(rows.gpsNo); //展示車輛操作模態框 $('#controlModal').modal('show'); $('#controlModal').on('shown.bs.modal', function () { //移動報警的開關switch $("#moveSwitch").bootstrapSwitch({ onText: "開", // 設置ON文本 offText: "關", // 設置OFF文本 onColor: "success",// 設置ON文本顏色 (info/success/warning/danger/primary) offColor: "danger", // 設置OFF文本顏色 (info/success/warning/danger/primary) size: "small", // 設置控件大小,從小到大 (mini/small/normal/large) handleWidth: "35",//設置控件寬度 // 當開關狀態改變時觸發 onSwitchChange: function (event, state) { if (state == true) { //開 <!--7:移位報警開; var sCmdV = 7; var gpsNo = $("#gpsNo").val(); $.post("/system/vehicle/sendCmd?gpsNo=" + gpsNo + "&cmd=" + sCmdV, function (data) { if (data) { // toastr.success("發送成功"); $('#vehicleInfoTab').bootstrapTable('refresh'); } else { toastr.error("發送失敗"); } }); } else { //關 8:移位報警關--> var sCmdV = 8; var gpsNo = $("#gpsNo").val(); $.post("/system/vehicle/sendCmd?gpsNo=" + gpsNo + "&cmd=" + sCmdV, function (data) { if (data) { // toastr.success("發送成功"); $('#vehicleInfoTab').bootstrapTable('refresh'); } else { toastr.error("發送失敗"); } }); } } }).bootstrapSwitch('state',rows.move);//必須放在最后才能初始化值 }); }
//效果圖
