common.js 55.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
/*
 * APICloud JavaScript Library
 * Copyright (c) 2019 wuyingjie
 */
// var HOST = 'http://iot.uccc.cc:9090'; //安全平台线上
var HOST = 'http://iotapps.uccc.cc:9027' //安全平台测试

var IOT_HOST = 'http://iot.uccc.cc:9090/luodian_server'

// var IOT_HOST_TEST = 'http://192.168.0.105:5006' //家
// var IOT_HOST_TEST = 'http://20.20.20.103:5006' //公司
var IOT_HOST_TEST = 'http://iot.uccc.cc:9090/luodian_server' //线上

var ERR_MSG = '服务请求失败';

//选择用户类型
function chooseUserType(type) {
  var res = 0
  switch (type) {
    case 'app':
      res = 1
      break;
    case 'enterprise':
      res = 2
      break;
    case 'agent':
      res = 3
      break;
    default:
      break;
  }
  return res
}

//枚举产品类型分类
function enumProductType(model) {
  switch (model) {
    case '1':
      return '智能短路灭弧器'
    case '2':
      return '在线监测装置'
    case '3':
      return '智慧空开'
    case '4':
      return '故障电弧探测器'
    default:
    break;
  }
}

//读取远程文本通用方法
function readRemoteUrl(url) {
  //加载中
  api.showProgress({
    style: 'default',
    animationType: 'fade',
    title: '加载中...',
    text: '',
    modal: false
  });
  return $.ajax({
    url: IOT_HOST_TEST + '/luodian/products/getRemoteHtmlStr',
    type: 'POST',
    dataType: 'json',
    async: false,
    timeout: 50000,
    data: JSON.stringify({htmlUrl: url}),
    headers: {
        'Content-Type': 'application/json;charset=utf-8',
    },
    success: function(ret) {
      api.hideProgress();
      return ret
    },
    error: function () {
      api.hideProgress();
      api.toast({msg: 'Page not found!',duration: 2000,location: 'bottom'});
    }
  })
}

function get_ty401_snkz_param_type_list() {
  var data = [{name:"总模式",value: "zms", params: [{name : '关闭',value: 0}, {name : '保持',value: 1},{name : '恢复',value: 2}], address: "0x00"},
  {name:"DI1联动使能",value: "di1ldsn", params: [{name : '关闭',value: 0}, {name : '正联动',value: 1},{name : '反联动',value: 2}], address: "0x61"},
  {name:"DI2联动使能",value: "di2ldsn", params: [{name : '关闭',value: 0}, {name : '正联动',value: 1},{name : '反联动',value: 2}], address: "0x62"},
  {name:"漏电1使能",value: "ld1sn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x01"},
  {name:"温度1使能",value: "wd1sn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x11"},
  {name:"温度2使能",value: "wd2sn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x12"},
  {name:"温度3使能",value: "wd3sn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x13"},
  {name:"温度4使能",value: "wd4sn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x14"},
  {name:"过压使能",value: "gysn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x41"},
  {name:"欠压使能",value: "qysn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x42"},
  {name:"缺相使能",value: "qxsn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x43"},
  {name:"过流使能",value: "glsn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x44"},
  {name:"过载使能",value: "gzsn", params:  [{name : '关闭',value: 0}, {name : '开启',value: 1}], address: "0x45"},
  ]
  return data
}

function get_ty401_cssz_param_type_list_get() {
  var data = [
  {name:"总模式",value: "zms",unit: "", min:0, max: 0, address: "0x00"},
  {name:"DI1联动使能",value: "di1ldsn",unit: "", min: 0,max: 0, address: "0x61"},
  {name:"DI2联动使能",value: "di2ldsn",unit: "", min: 0,max: 0, address: "0x62"},
  {name:"漏电1使能",value: "ld1sn",unit: "", min: 0,max: 0, address: "0x01"},
  {name:"温度1使能",value: "wd1sn",unit: "", min: 0,max: 0, address: "0x11"},
  {name:"温度2使能",value: "wd2sn",unit: "", min: 0,max: 0, address: "0x12"},
  {name:"温度3使能",value: "wd3sn",unit: "", min: 0,max: 0, address: "0x13"},
  {name:"温度4使能",value: "wd4sn",unit: "", min: 0,max: 0, address: "0x14"},
  {name:"过压使能",value: "gysn",unit: "", min: 0,max: 0, address: "0x41"},
  {name:"欠压使能",value: "qysn",unit: "", min: 0,max: 0, address: "0x42"},
  {name:"缺相使能",value: "qxsn",unit: "", min: 0,max: 0, address: "0x43"},
  {name:"过流使能",value: "glsn",unit: "", min: 0,max: 0, address: "0x44"},
  {name:"过载使能",value: "gzsn",unit: "", min: 0,max: 0, address: "0x45"},
  {name:"漏电1阀值",value: "ld1fz",unit: "mA" ,min: 0, max: 1000 , address: "0x21"},
  {name:"温度1阀值",value: "wd1fz",unit: "℃" ,min: 0, max: 140 , address: "0x31"},
  {name:"温度2阀值",value: "wd2fz",unit: "℃" ,min: 0, max: 140 , address: "0x32"},
  {name:"温度3阀值",value: "wd3fz",unit: "℃" ,min: 0, max: 140 , address: "0x33"},
  {name:"温度4阀值",value: "wd4fz",unit: "℃" ,min: 0, max: 140 , address: "0x34"},
  {name:"过压阀值",value: "gyfz",unit: "%Un" ,min: 0, max: 200 , address: "0x51"},
  {name:"欠压阀值",value: "qyfz",unit: "%Un" ,min: 0, max: 80 , address: "0x52"},
  {name:"缺相阀值",value: "qxfz",unit: "%Un" ,min: 0, max: 20 , address: "0x53"},
  {name:"过流阀值",value: "glfz",unit: "%In" ,min: 0, max: 140 , address: "0x54"},
  {name:"过载阀值",value: "gzfz",unit: "%UnIn" ,min: 0, max: 200 , address: "0x55"}
  ]
  return data
}

function get_ty401_cssz_param_type_list_set() {
  var data = [
  {name:"漏电1阀值",value: "ld1fz",unit: "mA" ,min: 0, max: 1000 , address: "0x21"},
  {name:"温度1阀值",value: "wd1fz",unit: "℃" ,min: 0, max: 140 , address: "0x31"},
  {name:"温度2阀值",value: "wd2fz",unit: "℃" ,min: 0, max: 140 , address: "0x32"},
  {name:"温度3阀值",value: "wd3fz",unit: "℃" ,min: 0, max: 140 , address: "0x33"},
  {name:"温度4阀值",value: "wd4fz",unit: "℃" ,min: 0, max: 140 , address: "0x34"},
  {name:"过压阀值",value: "gyfz",unit: "%Un" ,min: 0, max: 200 , address: "0x51"},
  {name:"欠压阀值",value: "qyfz",unit: "%Un" ,min: 0, max: 80 , address: "0x52"},
  {name:"缺相阀值",value: "qxfz",unit: "%Un" ,min: 0, max: 20 , address: "0x53"},
  {name:"过流阀值",value: "glfz",unit: "%In" ,min: 0, max: 140 , address: "0x54"},
  {name:"过载阀值",value: "gzfz",unit: "%UnIn" ,min: 0, max: 200 , address: "0x55"}
  ]
  return data
}

function get_ty401_sbkz_list() {
  var data = [
    {name:"复位", value: "reset"},
    {name:"自检", value: "selfcheck"},
    {name:"静音", value: "mute"},
    {name:"DO1+闭合", value: "do1open"},
    {name:"DO1+断开", value: "do1close"},
    {name:"DO2+闭合", value: "do2open"},
    {name:"DO2+断开", value: "do2close"},
    ]
    return data
}

function get_ty401_operateTypes() {
  var data = [
    {name: "设备控制", command: "ctr", value: 0, },
    {name: "写入参数", command: "set", value: 1, },
    {name: "使能控制", command: "set", value: 2, },
    {name: "读取参数", command: "get", value: 3, },
  ]
}

function filterDeviceName(storename, imei) {
  let res;
  if (storename === '' || storename === null) {
     res = imei
  }else {
    res = storename
  }
  return res
}

function cacheImg(u) {
  let path = ''
  // 缓存图片
  let pic_url_ =  api.getPrefs({sync: true,key: u})
  console.log(u + " ---->>>  " + pic_url_);
  if (!pic_url_) {
    api.imageCache({
        url: u
    }, function(ret, err) {
        let url = ret.url;
        // $api.setStorage(u, url);
        api.setPrefs({
          key: u,
          value: url
        });
        path = url
    });
  }else {
    path = pic_url_
  }
  //--------


  return path
}

//产品类型根据model分组
// function groupBymodelForProduct(list) {
//   var groupList = [{name: '智能短路灭弧器', data: []},
//                    {name: '在线监测装置', data: []},
//                    {name: '智慧空开', data: []},
//                    {name: '故障电弧探测器', data: []}
//                   ]

//   for (let i = 0; i < list.length; i++) {
//     const element = list[i];
//     const typeCn_ = enumProductType(element.model)
//     for (let j = 0; j < groupList.length; j++) {
//       const element2 = groupList[j];
//       if (typeCn_ === element2.name) {
//         groupList[j].data.push(element)
//       }
//     }

//   }
//   return groupList
// }

function returnInputDialogJSON() {
  const dialogOption = {
      keyboardType: 'default',
      texts: {
          title: '   提示: 您是否要继续该操作?\n   本设置只能由专业技术人员进行操作,\n   非专业人员不得操作。\n   误操作时,有可能造成人员伤亡或财产\n   损失!',
          placeholder: '需输入设备密码进行该操作',
          leftBtnTitle: '取消',
          rightBtnTitle: '确定'
      },
      animation: true,
      styles: {
          bg: '#fff',
          corner: 1,
          w: 260,
          h: 220,
          title: {
              h: 90,
              alignment: 'center',
              size: 14,
              color: '#F26161',
              marginT:20,
          },
          input: {
              h: 20,
              marginT:20,
              marginLeft: 15,
              marginRight:15,
              textSize: 14,
              textColor: '#000',
              corner: 2,
              borderColor:'#AEB8CE',
              borderWidth:1
          },
          dividingLine: {
              width: 0,
              color: '#696969'
          },
          left: {
              bg: 'rgba(0,0,0,0)',
              color: '#007FFF',
              size: 12,
              // h: 40,                //(可选项) 数字类型;右边按钮的高度;默认:40
              // w:60,                   //(可选项) 数字类型;左边按钮的宽度;默认:提示框的宽度的一半
              // marginB:10,            //(可选项) 数字类型;左边按离底部的边距;默认:0
              // corner:5,              //(可选项) 数字类型;左边按钮的圆角;默认:0
              widhtBorder:1,         //(可选项) 数字类型;左边按钮的边宽;默认:0
              normalBorderColor:'#F0F5FF', //(可选项) 数字类型;左边按钮的边宽颜色;默认:'rgba(0,0,0,0)'
              activeBorderColor:'#0000CD', //(可选项) 数字类型;左边按钮的高亮状态下边宽颜色;默认:'rgba(0,0,0,0)'
              activeColor:'#006400', //(可选项) 数字类型;左边按钮的高亮状态下标题颜色;默认:'rgba(0,0,0,0)'
              activeBg:'#6B8E23'   //(可选项) 数字类型;左边按钮的高亮状态下背景颜色;默认:'rgba(0,0,0,0)'
          },
          right: {
              bg: 'rgba(0,0,0,0)',
              color: '#007FFF',
              size: 12,
                      // h: 40,                //(可选项) 数字类型;右边按钮的高度;默认:40
              // w:60,                   //(可选项) 数字类型;右边按钮的宽度;默认:提示框的宽度的一半
              // marginB:10,            //(可选项) 数字类型;右边按离底部的边距;默认:0
              // corner:5,              //(可选项) 数字类型;右边按钮的圆角;默认:0
              widhtBorder:1,         //(可选项) 数字类型;右边按钮的边宽;默认:0
              normalBorderColor:'#F0F5FF', //(可选项) 数字类型;右边按钮的边宽颜色;默认:'rgba(0,0,0,0)'
              activeBorderColor:'#0000CD', //(可选项) 数字类型;右边按钮的高亮状态下边宽颜色;默认:'rgba(0,0,0,0)'
              activeColor:'#006400', //(可选项) 数字类型;右边按钮的高亮状态下标题颜色;默认:'rgba(0,0,0,0)'
              activeBg:'#6B8E23'   //(可选项) 数字类型;右边按钮的高亮状态下背景颜色;默认:'rgba(0,0,0,0)'
          }
      }
  }

  return dialogOption;
}

//验证手机格式
function checkPhone(inputed_phone) {
  var phonereg = /^1\d{10}$/;
  if (inputed_phone == "" || !phonereg.test(inputed_phone)) {
      return false;
  } else {
    return true;
  }
}

function repairTypeHtml(text) {
  var dom;
  dom  = '<div class="aui-col aui-col-span-12 margin-15" style="height: 2.5rem;" tapmode onclick="chooseType(\'' + text + '\');">';
  dom +=    '<div class="repair-type-btn">' + text + '</div>';
  dom += '</div>'
  return dom;
}

function setStatusBg(color) {
  api.setStatusBarStyle({
    style:  color
  });

}

function addAlert(content) {
  var dialogBox = api.require('dialogBox');
  dialogBox.alert({
      texts: {
          title: '提示',
          content: content,
          leftBtnTitle: '好的',
      },
      styles: {
          bg: '#fff',
          w: 300,
          corner:6,
          title: {
              marginT: 20,
              icon: '',
              iconSize: 40,
              titleSize: 18,
              titleColor: '#5B7FF8'
          },
          content: {
              color: '#000',
              size: 14
          },
          left: {
              marginB: 7,
              marginL: 85,
              w: 130,
              h: 35,
              corner: 10,
              bg: '#5B7FF8',
              color: '#FFFFFF',
              size: 12
          },
      }
  }, function(ret) {
      if (ret.eventType == 'left') {
          var dialogBox = api.require('dialogBox');
          dialogBox.close({
              dialogName: 'alert'
          });
      }
  });
}

function addAlertDIYTitle(title,content) {
  var dialogBox = api.require('dialogBox');
  var titleColor = '#5B7FF8'
  if (title === '警告') {
    titleColor = '#F26161'
  }
  dialogBox.alert({
      texts: {
          title: title,
          content: content,
          leftBtnTitle: '好的',
      },
      styles: {
          bg: '#fff',
          w: 300,
          corner:6,
          title: {
              marginT: 20,
              icon: '',
              iconSize: 40,
              titleSize: 18,
              titleColor: titleColor
          },
          content: {
              color: '#000',
              size: 14
          },
          left: {
              marginB: 7,
              marginL: 85,
              w: 130,
              h: 35,
              corner: 10,
              bg: '#5B7FF8',
              color: '#FFFFFF',
              size: 12
          },
      }
  }, function(ret) {
      if (ret.eventType == 'left') {
          var dialogBox = api.require('dialogBox');
          dialogBox.close({
              dialogName: 'alert'
          });
      }
  });
}

function alertJson(title, content) {
  return {
      texts: {
          title: title,
          content: content,
          leftBtnTitle: '好的',
      },
      styles: {
          bg: '#fff',
          w: 300,
          corner:6,
          title: {
              marginT: 20,
              icon: '',
              iconSize: 40,
              titleSize: 18,
              titleColor: '#F26161'
          },
          content: {
              color: '#000',
              size: 14
          },
          left: {
              marginB: 7,
              marginL: 85,
              w: 130,
              h: 35,
              corner: 10,
              bg: '#5B7FF8',
              color: '#FFFFFF',
              size: 12
          },
      }
  }
}

function jsonSort(jsonObj) {
  var arrs = []
  var newJsonObj = []
  if (jsonObj.length === 0) {
    return []
  }
  jsonObj.forEach(j => {
    arrs.push(j.name)
  });
  arrs = arrs.sort()
  arrs.forEach(d => {
    jsonObj.forEach(j => {
      if (d === j.name) {
        newJsonObj.push(j)
      }
    });
  })

  return newJsonObj;
}

function trim_nulls(data) {
  var y;
  for (var x in data) {
      y = data[x];
      if (y instanceof Object) y = trim_nulls(y);
      if (y === "null" || y === null || y === "" || typeof y === "undefined" || (y instanceof Object && Object.keys(y).length == 0)) {
          delete data[x];
      }
  }
  return data;
}

function timeFormater(y,m,d) {
  var year = y;
  if (m < 10) {
    var month = '0' + m;
  }else {
    var month = m;
  }
  if (d < 10) {
    var day = '0' + d;
  }else {
    var day = d;
  }
  var ret =  year + '-' + month + '-' + day;
  return ret;
}

function handleFormatTY500Alert(json) {
  let list = []
  let date2 = new Date(json.createdAt);

  let time = date2.toLocaleString();
  for(var p in json){
    let typeCn = alarmTypeList(p)
    if (typeCn != null && json[p] === "1") {
      list.push({
        type: typeCn,
        time: time
      })

      // eval('list.push({"' + typeCn + '": "' + time + '"})')
    }
  }
  return list
}

function alarmTypeList(value) {
  switch (value) {
    case 'all':
      return '全部报警';
      break;
    case 'over_current_warning':
      return '过载报警';
      break;
    case 'short_curent_warning':
      return '短路报警';
      break;
    case 'rest_current_warning':
      return '漏电报警';
      break;
    case 'over_high_voltage_warning':
      return '过压报警';
      break;
    case 'over_low_voltage_warning':
      return '欠压报警';
      break;
    case 'over_line_temp_warning':
      return '线路超温';
      break;
    case 'over_temp1_warning':
      return '内部超温';
      break;
    case 'fan_error':
      return '风扇异常';
      break;
    case 'IGBT_error':
      return '驱动异常';
      break;
    case 'param_error':
      return '参数异常';
      break;
    case 'sign_error':
      return '信号异常';
      break;
    default:
      return null;
  }
}

function formatOperateTime(param) {
  var param_ = '20' + param;
  var _param_ = '';
  var timeSpl = param_.split('');
  for (var i = 0; i < timeSpl.length; i++) {
    if (i == 3) {
        timeSpl[i] = timeSpl[i]+'-';
    }else if (i == 5) {
      timeSpl[i] = timeSpl[i]+'-';
    }else if (i == 7) {
      timeSpl[i] = timeSpl[i]+' ';
    }else if (i == 9) {
      timeSpl[i] = timeSpl[i]+':';
    }else if (i == 11) {
      timeSpl[i] = timeSpl[i]+':';
    }
    _param_ += timeSpl[i];
  }
  return _param_;
}

function reqPermission(permission) {
  var resultList = api.hasPermission({
      list: [permission]
  });
  if (resultList[0].granted) {
      // 已授权,可以继续下一步操作
      api.alert({
          msg: '已授权'
      });
  } else {
      api.confirm({
          msg: '应用需要您的授权才能访问相机',
          buttons: ['取消', '去设置']
      }, function(ret) {
          if (ret.buttonIndex == 2) {
              api.requestPermission({
                  list: [permission],
              }, function(res) {
                  if (res.list[0].granted) {
                      // 已授权,可以继续下一步操作
                      api.alert({
                          msg: '已授权'
                      });
                  }
              });
          }
      });
  }
}

function operationUnit(value,param) {
    switch (value) {
        case '&S1+':
            var format_param = formatOperateTime(param);
            return format_param;
            break;
        case '&S2+':
            return param + ' A';
            break;
        case '&S3+':
            return param + ' s';
            break;
        case '&S4+':
            return param + ' A';
            break;
        case '&S5+':
            return param + ' mA';
            break;
        case '&S6+':
            return param + ' V';
            break;
        case '&S7+':
            return param + ' V';
            break;
        case '&S8+':
            return param + ' ℃';
            break;
        default:
            return param
    }
}

function operationList(value,param) {
    switch (value) {
        case '&S1+':
            return '设置设备时间'
            break;
        case '&S2+':
            return '设置过载电流动作值';
            break;
        case '&S3+':
            return '设置过载时间动作值';
            break;
        case '&S4+':
            return '设置短路电流动作值';
            break;
        case '&S5+':
            return '设置漏电电流动作值';
            break;
        case '&S6+':
            return '设置过压报警动作值';
            break;
        case '&S7+':
            return '设置欠压报警动作值';
            break;
        case '&S8+':
            return '设置超温报警动作值';
            break;
        case '&S9+':
            if (param == '2') {
              return '远程控制-静音';
            }else if (param == '4') {
              return '远程控制-分闸';
            }else if (param == '8') {
              return '远程控制-自检';
            }else if (param == '16') {
              return '远程控制-复位';
            }
            return '远程控制';
            break;
        case '&SB+':
            return '设置心跳间隔'
            break;
        default:
            return value
    }
}
function monthAgo(month,no) {
    var date1 = new Date();
    date1.setMonth(parseInt(month)-no);
    var year1=date1.getFullYear(); 
    var month1=date1.getMonth()+1;
    month1 =(month1<10 ? "0"+month1:month1); 
    sDate = (year1.toString()+'-'+month1.toString());
    return sDate;
}
function timeList(type, time) {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    day = year + "-" + (month < 10 ? ("0" + month) : month) + "-" + (day < 10 ? ("0" + day) : day);
    var timeArrary = [];
    if (type == 'month') {
        timeArrary = [{
            status: (time == monthAgo(month,1)) ? 'selected' : 'normal',
            text: monthAgo(month,1)
        }, {
            status: (time == monthAgo(month,2)) ? 'selected' : 'normal',
            text: monthAgo(month,2)
        }, {
            status: (time == monthAgo(month,3)) ? 'selected' : 'normal',
            text: monthAgo(month,3)
        }, {
            status: (time == monthAgo(month,4)) ? 'selected' : 'normal',
            text: monthAgo(month,4)
        }, {
            status: (time == monthAgo(month,5)) ? 'selected' : 'normal',
            text: monthAgo(month,5)
        }, ]
    } else if (type == 'year') {
        timeArrary = [{
            status: (time == year) ? 'selected' : 'normal',
            text: year
        }, {
            status: (time == parseInt(year) - 1) ? 'selected' : 'normal',
            text: parseInt(year) - 1
        }, {
            status: (time == parseInt(year) - 2) ? 'selected' : 'normal',
            text: parseInt(year) - 2
        }, {
            status: (time == parseInt(year) - 3) ? 'selected' : 'normal',
            text: parseInt(year) - 3
        }, {
            status: (time == parseInt(year) - 4) ? 'selected' : 'normal',
            text: parseInt(year) - 4
        }, ]
    } else if (type == 'day') {
        timeArrary = [{
            status: 'selected',
            text: day
        }]
    }
    return timeArrary;
}

function closeWin() {
    api.closeWin({});
}

function initHeaderH() {
    // $api.setStorage('SYSTEMTYPE', api.systemType);
    api.setPrefs({key: 'SYSTEMTYPE',value: api.systemType});
    // $api.setStorage('SYSTEMVERSION', api.systemVersion);
    api.setPrefs({key: 'SYSTEMVERSION',value: api.systemVersion});
    // $api.setStorage('FULLSCREEN', api.fullScreen);
    api.setPrefs({key: 'FULLSCREEN',value: api.fullScreen});
    // $api.setStorage('IOS7STATUSBARAPPEARANCE', api.iOS7StatusBarAppearance);
    api.setPrefs({key: 'IOS7STATUSBARAPPEARANCE',value: api.iOS7StatusBarAppearance});
    // $api.setStorage('SAFEAREATOP', api.safeArea.top);
    api.setPrefs({key: 'SAFEAREATOP',value: api.safeArea.top});
    // $api.setStorage('SAFEAREABOTTOM', api.safeArea.bottom);
    api.setPrefs({key: 'SAFEAREABOTTOM',value: api.safeArea.bottom});
}

function fixIos7Bar_API(el) {
    if (!$api.isElement(el)) {
        return;
    }
    var strDM = api.getPrefs({sync: true,key: 'SYSTEMTYPE'});
    if(!strDM){
      //避免未经过常量初始化的情况
      initHeaderH();
      strDM = api.getPrefs({sync: true,key: 'SYSTEMTYPE'});
    }
    if (strDM == 'ios') {
        var strSV = api.getPrefs({sync: true,key: 'SYSTEMVERSION'});
        var numSV = parseInt(strSV, 10);
        var fullScreen = api.getPrefs({sync: true,key: 'FULLSCREEN'});
        var iOS7StatusBarAppearance = api.getPrefs({sync: true,key: 'IOS7STATUSBARAPPEARANCE'});
        if (numSV >= 7 && fullScreen == 'false' && iOS7StatusBarAppearance) {
            el.style.paddingTop = api.getPrefs({sync: true,key: 'SAFEAREATOP'})+'px';
        }
    }
}

function fixStatusBar_API(el) {
    if (!$api.isElement(el)) {
        //console.warn('$api.fixStatusBar Function need el param, el param must be DOM Element');
        return;
    }
    var sysType = api.getPrefs({sync: true,key: 'SYSTEMTYPE'});
    if (sysType == 'ios') {
        fixIos7Bar_API(el);
    } else if (sysType == 'android') {
        var ver = api.getPrefs({sync: true,key: 'SYSTEMVERSION'});
        ver = parseFloat(ver);
        if (ver >= 4.4) {
            var marginTop = api.getPrefs({sync: true,key: 'SAFEAREATOP'});
            if(!marginTop){
              initHeaderH();
              marginTop = api.getPrefs({sync: true,key: 'SAFEAREATOP'});
            }
            el.style.paddingTop = marginTop+'px';
        }
    }
}
(function(window) {

})(window);

function showPermission(perms) {
  var rets = api.hasPermission({
    list:perms
  });
  if (rets[0].granted) {
    return true
  }else {
    return false
  }
}

function openPermission(perms) {
  api.confirm({
    msg: '应用需要您的授权才能访问相机',
    buttons: ['取消', '去设置']
  }, function(ret) {
      if (ret.buttonIndex == 2) {
          api.requestPermission({
              list: perms,
          }, function(res) {
              if (res.list[0].granted) {
                  // 已授权,可以继续下一步操作
                  api.alert({
                      msg: '已授权'
                  });
              }
          });
      }
  });
}

function openCanner(isEmpty) {
  // api.showProgress({
  //     style: 'default',
  //     animationType: 'fade',
  //     title: '加载中...',
  //     text: '',
  //     modal: false
  // });
  var hasPermission = showPermission(['camera'])
  if (hasPermission) {
    api.openWin({
      name: 'scanner',
      url: '../utils/scanner.html',
      bgColor: 'rgba(0,0,0,0)',
      pageParam: {
          "isEmpty": isEmpty
      },
    });
  }else {
    openPermission(['camera'])
  }
    return false;
    //以下代码为之前版本,经修改之后暂做保存,此处直接renturn
    var FNScanner = api.require('FNScanner');
    FNScanner.openScanner({
        autorotation: true,
        isAlbum: true,
        hintText: '请扫一扫设备上的二维码获取设备编号'
    }, function(ret, err) {
        if (ret) {
            if (ret.eventType == 'cancel') {
                if (isEmpty) {
                    api.alert({
                        title: '添加设备',
                        msg: '暂无设备,请先添加设备...',
                    }, function(ret, err){
                        if( ret ){
                             openCanner(isEmpty);
                        }
                    });

                }
            } else if (ret.eventType == 'success') {
                var md5Reg = /^[a-f0-9]{32}$/;
                if (md5Reg.test(ret.content)) {
                    api.openWin({ slidBackEnabled:false,
                        name: 'perfectInfo',
                        url: 'perfectInfo.html',
                        pageParam: {
                            "code": ret.content,
                            "isEmpty": isEmpty
                        }
                    });
                } else {
                    api.alert({
                        title: '请扫描正确的设备二维码',
                        msg: '当前设备二维码不正确',
                    }, function(ret, err) {
                        openCanner(isEmpty);
                    });


                }

            }

        } else {
            //alert(JSON.stringify(err));
        }
    });
}

function check() {
  app_remain = 86400000 * 1000 //1年时间少1天这里
  var now = new Date();
  $logintime = api.getPrefs({sync: true,key: 'login_time'});
  $now = now.getTime();
  if ($now - $logintime > app_remain) { //登陆已过期
    var ajpush = api.require("ajpush");
    clearPush(ajpush, function(){
      $api.clearStorage();
      api.openWin({
          name: 'login',
          url: 'widget://html/login/login_win.html',
          slidBackEnabled:false,
          reload: true,
          bounces: false,
      });
      // api.openFrame({
      //     historyGestureEnabled:false,
      //     reload: true,
      //     name: 'login',
      //     url: 'widget://html/login/login_win.html',
      //     rect: {
      //         x: 0,
      //         y: 0,
      //         w: 'auto',
      //         h: 'auto'
      //     },
      //     allowEdit:true
      // });
      return false;
    })
  }else{
    var token = api.getPrefs({sync: true,key: 'userToken'});
    if (!token) {  //没有登陆过
      // api.openFrame({ historyGestureEnabled:false,
      //     reload: true,
      //     name: 'login',
      //     url: 'widget://html/login/login_win.html',
      //     rect: {
      //         x: 0,
      //         y: 0,
      //         w: 'auto',
      //         h: 'auto'
      //     },
      //     allowEdit:true
      // });

      api.openWin({
          name: 'login',
          url: 'widget://html/login/login_win.html',
          slidBackEnabled:false,
          reload: true,
          bounces: false,
      });
      return false;
    }

  }
    return true;

    //登陆完之后的操作
    //   api.openWin({ slidBackEnabled:false,
    //   name: 'index_public',
    //   url: '../../page/public/index_public.html',
    //   rect: {
    //           x: 0,
    //           y: 0,
    //           w: 'auto',
    //           h: 'auto'
    //   },
    //   pageParam: {
    //           name: 'test'
    //    }
    // });
    //
    // api.closeFrame({
    //      name:'login'
    // });
    //
}

function ajaxCodeCheck(code, msg, def) {
    if (parseInt(code / 10000) == 5) {
        return msg;
    }
    return def;
}

function choseDevice() {
  api.openWin({
      name: 'choseDevice',
      url: 'choseDevice.html',
      bgColor: 'rgba(0,0,0,0)'
  });
  return false;
}

function noData(obj,topval) {
    var topValue = topval;
    var dom;
    $api.html(obj, '<div style="top:' + topValue + 'rem;" class="no-data"><img src="http://iot.uccc.cc:9090/product/01001/img-nullInfo.png" /><p style="font-size:16px;font-weight:500;color:rgba(55,57,78,1);">这里还没有内容</p><p>先去别的地方看看吧~</p></div>');
}

function loadingData(obj,topval) {
    var topValue = topval;
    $api.html(obj, '<div style="top:' + topValue + 'rem;" class="no-data loading-data"><img src="../../image/loading_more.gif" /><p>加载中…</p></div>');
}

function parseTime(time, cFormat) {
  if (arguments.length === 0) {
    return null
  }
  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  var date
  if (typeof time === 'object') {
    date = time
  } else {
    if (('' + time).length === 10) time = parseInt(time) * 1000
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, function(result, key){
    var value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] }
    if (result.length > 0 && value < 10) {
      value = '0' + value
    }
    return value || 0
  })
  return time_str
}

function initPush(){
  var ajpush = api.require('ajpush');
  var strDM = api.getPrefs({sync: true,key: 'SYSTEMTYPE'});
  if(strDM=='android'){
    ajpush.init(function(ret) {
      if(ret && ret.status ==1){
        initAndListenPush(ajpush, true);
      }
    })
  }else{
    initAndListenPush(ajpush, true);
  }
}

function initAndListenPush(ajpush, needListen){
  var registrationId = api.getPrefs({sync: true,key: 'registrationId'});
  if(!registrationId){

    ajpush.getRegistrationId(function(ret) {
        if(ret && ret.id){
          var registrationId = ret.id;
          //上报reg id
          var token = api.getPrefs({sync: true,key: 'userToken'});
          var user_id = api.getPrefs({sync: true,key: 'userID'});
          var postData = {
              user_id: user_id,
              reg_id: registrationId
          }
          if(!needListen){
            postData = {
                user_id: user_id
            }
          }
          $.ajax({
              url: HOST + '/iot_api/v1/app/async_reg',
              type: 'POST',
              dataType: 'json',
              headers: {
                  'Content-Type': 'application/json;charset=utf-8',
                  'token': token
              },
              data: JSON.stringify(postData),
              success: function(ret) {
                  if (ret) {
                      if (ret.code == 0) {
                          // $api.setStorage('registrationId', registrationId);
                          api.setPrefs({key: 'registrationId',value: registrationId});
                          if(needListen){
                            api.addEventListener({name:'appintent'}, function(ret,err) {
                              notify(ret);
                          })
                          }
                      }
                  }
              },
              error: function() {

              }
          });
        }

    });
  }else{
    if(needListen){
      ajpush.setListener(
          function(ret) {
            notify(ret);
          }
      );
      if (api.systemType == 'android') {
        api.addEventListener({name:'appintent'}, function(ret,err) {
          notify(ret);
        });
      }else {
        api.addEventListener({
            name: 'noticeclicked'
        }, function(ret, err){
            if( ret ){
              notify(ret);
            }
        });
      }


    }else{
      var token = api.getPrefs({sync: true,key: 'userToken'});
      var user_id = api.getPrefs({sync: true,key: 'userID'});
      var postData = {
          user_id: user_id,
          reg_id: registrationId
      }
      if(!needListen){
        postData = {
            user_id: user_id
        }
      }
      $.ajax({
          url: HOST + '/iot_api/v1/app/async_reg',
          type: 'POST',
          dataType: 'json',
          headers:{
              'Content-Type':'application/json;charset=utf-8',
              'token': token
          },
          data: JSON.stringify(postData),
          success: function(ret) {
            if (ret.code == 0) {
              // $api.setStorage('registrationId', registrationId);
              api.setPrefs({key: 'registrationId',value: registrationId});
              if(needListen){
                api.addEventListener({name:'appintent'}, function(ret,err) {
                  notify(ret);
              })
              }
            }
          },
          error: function() {
            api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
          }
      });
      // $.ajax({
      //     url: HOST + '/iot_api/v1/app/async_reg',
      //     type: 'POST',
      //     dataType: 'json',
      //     headers: {
      //         'Content-Type': 'application/json;charset=utf-8',
      //         'token': token
      //     },
      //     data: JSON.stringify(postData),
      //     success: function(ret) {

      //     },
      //     error: function() {
      //
      //     }
      // });
    }
  }


}

function notify(info){
  var extra;
  if (api.systemType == 'android') {  //Android app后台状态
    extra = info.appParam.ajpush.extra;
  }else if (api.systemType == 'ios' && info.extra) { //ios app前台状态
    extra = info.extra;
  }else if (api.systemType == 'ios' && info.value.extra) {
    extra = info.value.extra; //ios app后台状态
  }
  console.log(JSON.stringify('----------((((-----'));
  console.log(JSON.stringify(extra));
  switch (extra.type) {
    case "warning":
      //设备告警
      var current = extra.imei;
      if(current && current != ''){
          //弹窗告警
          api.alert({
              title: extra.remark,
              msg: '编号:' + current,
              buttons: ["查看报警 >"]
          }, function(ret, err){
              if( ret ){
                //index切换为1,进入所有报警页面
                 console.log('~~~');
                 var NVTabBar = api.require('NVTabBar');
                 NVTabBar.setSelect({
                     index: 1,
                     selected: true,
                 });

                 api.openFrame({
                     name:  'alarmIndex',
                     url: './alarm/alarm.html',
                     reload: true,
                     rect: {
                         x: 0,
                         y: 0,
                         w: api.winWidth,
                         h: api.winHeight-49-api.getPrefs({sync: true,key: 'indexFooterH'})
                     },
                     bgColor: '#f4f6f9',
                     reload: true
                 });
                 //查询该用户下的所有未处理报警总数
                 var userId = api.getPrefs({sync: true,key: 'userID'});
                 var token = api.getPrefs({sync: true,key: 'userToken'});
                 $.ajax({
                     url: HOST + '/iot_api/v1/app/get_unsloved_warning_count?user_id='+userId,
                     type: 'GET',
                     dataType: 'json',
                     headers: {
                         'Content-Type': 'application/json;charset=utf-8',
                         'token': token
                     },
                     success: function(ret) {
                       if (ret.code == 0 && ret.data > 0) {
                         NVTabBar.setBadge({
                             index: 1,
                             badge: ret.data
                         });
                       }else {
                         api.toast({
                             msg: '获取所有报警总数失败'
                         });
                       }
                     },
                     error: function() {
                       api.toast({msg: ERR_MSG,duration: 2000,location: 'bottom'});
                     }
                 });
                 //---
              }
          });
      }
      break;
    default:

  }
}

function addOperaterListHtml(list,squence,isS9) {
  // console.log(JSON.stringify(list));
  var dom;
  dom =  '<div class="store01001-operate-log-protect-list">';
  dom +=   '<div class="store01001-operate-log-info-panel">';
  dom +=     '<div class="aui-row aui-row-flex store01001-operate-log-top-14">';
  dom +=        '<div class="aui-col aui-col-span-2 aui-row-flex-start">';
  dom +=          '<div class="store01001-operate-log-number-id">' + squence + '</div>';
  dom +=        '</div>';
  dom +=        '<div class="aui-col aui-col-span-12 aui-row-flex-start">';
  dom +=          '<span class="store01001-operate-log-operator" id="operator">操作者:<span style="color:#5B7FF8;">' + list.userName +'</span></span>';
  if (list.ret == '成功') {
  dom +=          '<div class="store01001-operate-log-operater-status">' + list.ret + '</div>';
  }else {
  dom +=          '<div class="store01001-operate-log-operater-status store01001-operate-err-status">失败</div>';
  }
  dom +=        '</div>';
  dom +=        '<div class="aui-col aui-col-span-10 aui-row-flex-end">';
  dom +=          '<span class="store01001-operate-log-action-time">' + parseTime(list.updatedAt,'{y}-{m}-{d} {h}:{i}:{s}') + '</span>';
  dom +=        '</div>';
  dom +=     '</div>';
  dom +=     '<div class="list-line"></div>';
  dom +=     '<div class="aui-row aui-row-flex">';
  dom +=        '<div class="aui-col aui-col-span-12 aui-row-flex-start">';
  dom +=          '<div class="store01001-operate-log-operater-dot"></div>';
  dom +=          '<div class="store01001-operate-log-operater-cmd">&nbsp;操作指令</div>';
  dom +=        '</div>';
  dom +=        '<div class="aui-col aui-col-span-12 aui-row-flex-end">';
  dom +=          '<div class="store01001-operate-log-operater-cmd-value">' + operationList(list.command,list.params) + '</div>';
  dom +=        '</div>';
  dom +=      '</div>';
  if (!isS9) {
  dom +=      '<div class="aui-row aui-row-flex" style="margin-top:0px;">';
  dom +=        '<div class="aui-col aui-col-span-12 aui-row-flex-start">';
  dom +=          '<div class="store01001-operatelog-operater-dot"></div>';
  dom +=          '<div class="store01001-operate-log-operater-cmd">&nbsp;参数</div>';
  dom +=        '</div>';
  dom +=        '<div class="aui-col aui-col-span-12 aui-row-flex-end">';
  dom +=          '<div class="store01001-operate-log-operater-cmd-value">' + operationUnit(list.command,list.params) +'</div>';
  dom +=        '</div>';
  dom +=      '</div>';
  }
  dom +=      '<div style="height:7px;"></div>';
  dom +=    '</div>';
  dom +=  '</div>';

  return dom;
}

function addWarningListHtml(list,sequence) {
  var dom;
    dom = '<div class="store01001-alarm-list-panel">';
    dom +=  '<div class="aui-flex-col">';
    dom +=    '<div class="aui-flex-item-1 aui-flex-row aui-hide store01001-alarm-choose-area">';
    dom +=      '<img src="../../../image/icon_unselected_sm.png" style="width:18px;height:18px;margin-top: 3.2rem;margin-left:0.5rem;"  tapmode onclick="chooseToHandle(this' + ',\'' + list.id + '\')"  data-id="'+ list.id +'" />';
    dom +=    '</div>';
    dom +=    '<div class="aui-flex-row aui-flex-item-12 store01001-alarm-normal-area">';
    dom +=      '<div class="store01001-alarm-info-panel">';
    dom +=       '<div class="aui-row store01001-alarm-top-14" >';
    dom +=          '<div class="aui-col-3">';
    dom +=            '<div class="store01001-alarm-number-id">' + sequence + '</div>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-10">';
    dom +=            '<span class="store01001-alarm-device-imei">报警类型</span>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-11">';
    if (list.status == '已处理') {
    dom +=            '<span class="store01001-alarm-alarm-status"">已处理</span>';
    }else if (list.status == '未解决') {
    dom +=            '<span class="store01001-alarm-alarm-status store01001-alarm-not-handle">未处理</span>';
    }
    dom +=          '</div>';
    dom +=       '</div>';
    dom +=       '<div class="store01001-alarm-list-line"></div>';
    dom +=      '</div>';
    dom +=      '<p class="store01001-alarm-warning-item-content store01001-alarm-alarms-style">';
    if (list.over_current_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">过载报警</span></em>';
    }
    if (list.short_curent_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">短路报警</span></em>';
    }
    if (list.rest_current_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">漏电报警</span></em>';
    }
    if (list.over_high_voltage_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">过压报警</span></em>';
    }
    if (list.over_low_voltage_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">欠压报警</span></em>';
    }
    if (list.over_line_temp_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">线缆超温报警</span></em>';
    }
    if (list.over_temp1_warning == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">产品内部超温</span></em>';
    }
    if (list.fan_error == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">风扇异常</span></em>';
    }
    if (list.IGBT_error == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">IGBT驱动异常</span></em>';
    }
    if (list.param_error == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">参数存储异常</span></em>';
    }
    if (list.sign_error == '1') {
    dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">信号测量异常</span></em>';
    }
    dom +=      '</p>';
    dom +=    '</div>';
    dom +=      '<div class="store01001-alarm-list-footer">';
    dom +=      '<span class="store01001-alarm-update-time">更新时间:' + parseTime(list.createdAt,'{y}-{m}-{d} {h}:{i}:{s}') + '</span>';
    dom +=     '</div>';
    dom +=  '</div>';
    dom += '</div>';
  return dom;
}

function addProtectListHtml(list,sequence) {
  var dom = '<div class="store01001-protect-protect-list">';
     dom +=  '<div class="aui-flex-col">';
     dom +=   '<div class="aui-flex-item-1 aui-flex-row aui-hide choose-area">';
     dom +=      '<img src="../../../image/icon_unselected_sm.png" style="width:18px;height:18px;margin-top: 2.6rem;margin-left:0.5rem;"  tapmode onclick="chooseToHandle(this' + ',\'' + list.id + '\')"  data-id= ' + list.id + ' />';
     dom +=   '</div>';
     dom +=  '<div class="aui-flex-row aui-flex-item-12 normal-area">';
     dom +=   '<div class="store01001-protect-info-panel">';
     dom +=     '<div class="aui-row aui-row-flex store01001-protect-top-14" style="padding-top: 0.8rem;">';
     dom +=       '<div class="aui-col aui-col-span-2 aui-row-flex-start">';
     dom +=         '<div class="store01001-protect-number-id">' + sequence + '</div>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-5 aui-row-flex-start">';
     dom +=         '<span class="store01001-protect-action-name">' + list.action_type + '动作</span>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-4 aui-row-flex-start">';
     //单独判断是否已读
     if (list.msgRead) {
     dom +=         '<div class="store01001-protect-read-state">已读</div>';
     }else {
     dom +=         '<div class="store01001-protect-read-state" style="background-color:#FEBB35">未读</div>';
     }
     //-------------
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-13 aui-row-flex-end">';
     dom +=         '<span class="store01001-protect-action-time">' + parseTime(list.createdAt,'{y}-{m}-{d} {h}:{i}:{s}') + '</span>';
     dom +=       '</div>';
     dom +=     '</div>';
     dom +=     '<div class="store01001-protect-list-line"></div>';
     dom +=     '<div class="aui-row aui-row-flex">';
     dom +=       '<div class="aui-col aui-col-span-5 aui-row-flex-center">';
     dom +=         '<span class="store01001-protect-details-value">' + list.current + '</span><span class="store01001-protect-details-value2">A</span>';
     dom +=         '<div class="store01001-protect-title-value-panel">';
     dom +=           '<p class="store01001-protect-title-value">电流</p>';
     dom +=         '</div>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-5 aui-row-flex-center">';
     dom +=         '<span class="store01001-protect-details-value">' + list.voltage + '</span><span class="store01001-protect-details-value2">V</span>';
     dom +=         '<div class="store01001-protect-title-value-panel">';
     dom +=           '<p class="store01001-protect-title-value" >电压</p>';
     dom +=         '</div>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-5 aui-row-flex-center">';
     dom +=         '<span class="store01001-protect-details-value">' + list.rest_current +'</span><span class="store01001-protect-details-value2">mA</span>';
     dom +=         '<div class="store01001-protect-title-value-panel">';
     dom +=           '<p class="store01001-protect-title-value" >漏电电流</p>';
     dom +=         '</div>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-4 aui-row-flex-center">';
     dom +=         '<span class="store01001-protect-details-value">' + list.temp + '</span><span class="store01001-protect-details-value2">℃</span>';
     dom +=         '<div class="store01001-protect-title-value-panel">';
     dom +=           '<p class="store01001-protect-title-value" >温度</p>';
     dom +=         '</div>';
     dom +=       '</div>';
     dom +=       '<div class="aui-col aui-col-span-5 aui-row-flex-center">';
     dom +=         '<span class="store01001-protect-details-value">' + changeProtectValue(list.during_time,list.action_type) + '</span><span class="store01001-protect-details-value2">' + changeProtectUnit(list.action_type) +'</span>';
     dom +=         '<div class="store01001-protect-title-value-panel">';
     dom +=           '<p class="store01001-protect-title-value" >动作时长</p>';
     dom +=         '</div>';
     dom +=       '</div>';
     dom +=     '</div>';
     dom +=     '<div class="store01001-protect-blank-area"></div>'
     dom +=   '</div>';
     dom +=  '</div>';
     dom += '</div>';

    return dom;
}

function addWarningListTY_401Html(list,sequence) {
  console.log(JSON.stringify(list));
  var dom;
    dom = '<div class="store01001-alarm-list-panel">';
    dom +=  '<div class="aui-flex-col">';
    dom +=    '<div class="aui-flex-item-1 aui-flex-row aui-hide store01001-alarm-choose-area">';
    dom +=      '<img src="../../../image/icon_unselected_sm.png" style="width:18px;height:18px;margin-top: 3.2rem;margin-left:0.5rem;"  tapmode onclick="chooseToHandle(this' + ',\'' + list.id + '\')"  data-id="'+ list.id +'" />';
    dom +=    '</div>';
    dom +=    '<div class="aui-flex-row aui-flex-item-12 store01001-alarm-normal-area">';
    dom +=      '<div class="store01001-alarm-info-panel">';
    dom +=       '<div class="aui-row store01001-alarm-top-14" >';
    dom +=          '<div class="aui-col-3">';
    dom +=            '<div class="store01001-alarm-number-id">' + sequence + '</div>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-10">';
    dom +=            '<span class="store01001-alarm-device-imei">' + list.group.name +'</span>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-11">';
    if (list.status == '已处理') {
    dom +=            '<span class="store01001-alarm-alarm-status"">已处理</span>';
    }else if (list.status == '未解决') {
    dom +=            '<span class="store01001-alarm-alarm-status store01001-alarm-not-handle">未处理</span>';
    }
    dom +=          '</div>';
    dom +=       '</div>';
    dom +=       '<div class="aui-row" >';
    dom +=          '<div class="aui-col-3">&nbsp;</div>';
    dom +=          '<div class="aui-col-10 store01001-alarm-device-name">' + list.imei + '</div>';
    dom +=       '</div>';
    dom +=       '<div class="store01001-alarm-list-line"></div>';
    dom +=      '</div>';
    dom +=      '<p class="store01001-alarm-warning-item-content store01001-alarm-alarms-style">';
    list.warning.forEach(d => {
      dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">' + d + '</span></em>';
    });
    dom +=      '</p>';
    dom +=    '</div>';
    dom +=      '<div class="store01001-alarm-list-footer">';
    dom +=      '<span class="store01001-alarm-update-time">更新时间:' + parseTime(list.createdAt,'{y}-{m}-{d} {h}:{i}:{s}') + '</span>';
    dom +=     '</div>';
    dom +=  '</div>';
    dom += '</div>';
  return dom;
}

function addFaultListTY_401Html(list,sequence) {
  var dom;
    dom = '<div class="store01001-alarm-list-panel">';
    dom +=  '<div class="aui-flex-col">';
    dom +=    '<div class="aui-flex-item-1 aui-flex-row aui-hide store01001-alarm-choose-area">';
    dom +=      '<img src="../../../image/icon_unselected_sm.png" style="width:18px;height:18px;margin-top: 3.2rem;margin-left:0.5rem;"  tapmode onclick="chooseToHandle(this' + ',\'' + list.id + '\')"  data-id="'+ list.id +'" />';
    dom +=    '</div>';
    dom +=    '<div class="aui-flex-row aui-flex-item-12 store01001-alarm-normal-area">';
    dom +=      '<div class="store01001-alarm-info-panel">';
    dom +=       '<div class="aui-row store01001-alarm-top-14" >';
    dom +=          '<div class="aui-col-3">';
    dom +=            '<div class="store01001-alarm-number-id">' + sequence + '</div>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-10">';
    dom +=            '<span class="store01001-alarm-device-imei">' + list.group.name +'</span>';
    dom +=          '</div>';
    dom +=          '<div class="aui-col-11">';
    if (list.status == '已处理') {
    dom +=            '<span class="store01001-alarm-alarm-status"">已处理</span>';
    }else if (list.status == '未解决') {
    dom +=            '<span class="store01001-alarm-alarm-status store01001-alarm-not-handle">未处理</span>';
    }
    dom +=          '</div>';
    dom +=       '</div>';
    dom +=       '<div class="aui-row" >';
    dom +=          '<div class="aui-col-3">&nbsp;</div>';
    dom +=          '<div class="aui-col-10 store01001-alarm-device-name">' + list.imei + '</div>';
    dom +=       '</div>';
    dom +=       '<div class="store01001-alarm-list-line"></div>';
    dom +=      '</div>';
    dom +=      '<p class="store01001-alarm-warning-item-content store01001-alarm-alarms-style">';
    list.fault.forEach(d => {
      dom +=      '<em class="store01001-alarm-ararm-btn"><span class="store01001-alarm-ararm-text">' + d + '</span></em>';
    });
    dom +=      '</p>';
    dom +=    '</div>';
    dom +=      '<div class="store01001-alarm-list-footer">';
    dom +=      '<span class="store01001-alarm-update-time">更新时间:' + parseTime(list.createdAt,'{y}-{m}-{d} {h}:{i}:{s}') + '</span>';
    dom +=     '</div>';
    dom +=  '</div>';
    dom += '</div>';
  return dom;
}

function changeProtectValue(time,action) {
  var value;
  if (action == '过载') {
    value = Number(time.replace("ms",''))/1000;
  }else {
    value = time.replace("ms",'');
  }
  return value;
}

function changeProtectUnit(action) {
  var unit;
  if (action == '过载') {
    unit = 's';
  }else {
    unit = 'ms';
  }
  return unit;
}

function clearPush(ajpush, func){
  var registrationId = api.getPrefs({sync: true,key: 'registrationId'});
  if(!registrationId){
    ajpush.getRegistrationId(function(ret) {
        if(ret && ret.id){
          var registrationId = ret.id;
          //同步reg id
          var token = api.getPrefs({sync: true,key: 'userToken'});
          $.ajax({
              url: HOST + '/iot_api/v1/app/async_rm_reg',
              type: 'POST',
              dataType: 'json',
              headers: {
                  'Content-Type': 'application/json;charset=utf-8',
                  'token': token
              },
              data: JSON.stringify({
                  reg_id: registrationId
              }),
              success: function(ret) {
                  if (ret) {
                      if (ret.code == 0) {
                          //$api.setStorage('registrationId', registrationId);
                      }
                  }
              },
              error: function() {

              },
              complete:function() {
                ajpush.removeListener();
                if(func){
                  func();
                }
              }
          });
        }

    });
  }else{
    var token = api.getPrefs({sync: true,key: 'userToken'});
    $.ajax({
        url: HOST + '/iot_api/v1/app/async_rm_reg',
        type: 'POST',
        dataType: 'json',
        headers: {
            'Content-Type': 'application/json;charset=utf-8',
            'token': token
        },
        data: JSON.stringify({
            reg_id: registrationId
        }),
        success: function(ret) {
            if (ret) {
                if (ret.code == 0) {
                    //$api.setStorage('registrationId', registrationId);
                }
            }
        },
        error: function() {

        },
        complete:function() {
          ajpush.removeListener();
          if(func){
            func();
          }
        }
    });
  }
  console.log('remove');
  ajpush.removeListener();

}