succutil.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. $(function () {
  2. fog = getUrlParam("fog"),
  3. phone = getUrlParam("phone"),
  4. go('tt');
  5. $("#useraccount_tt").attr("value", getUrlParam("use"));
  6. });
  7. var fog;
  8. var phone;
  9. //环形图
  10. var fw = $('.header1').width();
  11. $('.header1').height(fw);
  12. var c = document.getElementById('myCanvas');
  13. var ctx = c.getContext('2d');
  14. var process = 0;
  15. var w = parseInt($('#myCanvas').css('width'));
  16. var mW = c.width = w;
  17. var mH = c.height = w;
  18. var lineWidth = 5;
  19. var r = mW / 2;
  20. var cR = r - 4 * lineWidth; //圆半径
  21. var startAngle = -(1 / 2 * Math.PI); //开始角度
  22. var endAngle = startAngle + 2 * Math.PI; //结束角度
  23. var xAngle = 1 * (Math.PI / 180); //偏移角度量
  24. var fontSize = 35; //字号大小
  25. var tmpAngle = startAngle; //临时角度变量
  26. //渲染函数
  27. var rander = function (ctx, prs) {
  28. ctx.clearRect(0, 0, mW, mH);
  29. ctx.beginPath();
  30. ctx.lineWidth = 25;
  31. ctx.strokeStyle = '#F86A5C';
  32. ctx.arc(r, r, cR, 0, Math.PI * 2);
  33. ctx.stroke();
  34. ctx.closePath();
  35. ctx.beginPath();
  36. ctx.lineWidth = 15;
  37. ctx.lineCap = 'round';
  38. ctx.strokeStyle = '#fff';
  39. ctx.arc(r, r, cR, Math.PI * (1.5 + 2 * prs / 100), Math.PI * 1.5);
  40. ctx.stroke();
  41. ctx.closePath();
  42. };
  43. function animate(i) {
  44. requestAnimationFrame(function () {
  45. process = process + 1;
  46. rander(ctx, process);
  47. if (process < i) {
  48. animate(i);
  49. }
  50. });
  51. }
  52. var usedf;
  53. var sta = 0;
  54. //弹窗
  55. function go(product) {
  56. $(".shuaxin").text("刷新中");
  57. if (sta == 0) {
  58. //当用户访问过流量查询页面时加入标记
  59. var rl = null;
  60. var e = null;
  61. $("#go").removeAttr("onclick");
  62. $.ajax({
  63. type: "POST",
  64. contentType: "application/json; charset=utf-8",
  65. dataType: "Json",
  66. url: getRootPath() + "-s1api" + '/com/queryl',//目标地址
  67. data: JSON.stringify(GetFlowJsonData(product)),
  68. success: function (msg) {
  69. var resCode = eval(msg["resultCode"]);
  70. if (resCode == "0000") {
  71. $(".shuaxin").text("点击刷新");
  72. var data = msg["date"];
  73. var usermob = data["phone"];
  74. $("#phone").text(usermob);
  75. var stu = data["stu"];
  76. if (stu == 0) {
  77. $("title").text("订购成功");//修改页面标题
  78. $("#sta").text("订购");
  79. } else {
  80. $("title").text("退订成功");//修改页面标题
  81. $("#sta").text("退订");
  82. $("#cancel").remove();
  83. $("#yuyueys").remove();
  84. }
  85. var productid = data["productid"];
  86. if (productid == '2017060802') {//页面为15元
  87. $("#ys").text("15/6G");
  88. }
  89. if (productid == '2018072301') {//页面为10元
  90. $("#ys").text("9/10G");
  91. $("#yuyueys").remove();
  92. }
  93. var flow = msg["queryflow"];
  94. var usedFlow = (flow["usedFlow"] / 1024 / 1024).toFixed(2);//用户使用流量
  95. $("#usedFlow").text(usedFlow + "GB");
  96. var lodFlow = (flow["surplusFlow"] / 1024 / 1024).toFixed(2);//剩余流量
  97. $("#lodFlow").text(lodFlow + "GB");
  98. var totalFlow = (flow["totalFlow"] / 1024 / 1024).toFixed(2);//总流量
  99. $("#totalFlow").text(lodFlow + "GB");
  100. var couflow = totalFlow / 100;//1%为多少kb
  101. usedf = usedFlow / couflow;
  102. animate(usedf);
  103. sta = 1;//说明查询成功
  104. $("#go").attr("onclick", "go('tt')"); //查询成功后不给与用户重新查询
  105. rl = {stac: 1};
  106. } else {
  107. $("#cancel").remove();
  108. $("#yuyueys").remove();
  109. if (resCode == "4015") {//本地未查询到用户订购关系
  110. rl = {stac: 2};
  111. gotorder();
  112. } else {
  113. rl = {stac: 3};
  114. $(".shuaxin").text("刷新失败");
  115. animate(0);
  116. $("#go").attr("onclick", "go('tt')");
  117. }
  118. }
  119. e = JSON.stringify(rl);
  120. sessionStorage.setItem("sd", e);
  121. },
  122. error: function (XMLHttpRequest, textStatus, errorThrown) {
  123. animate(0);
  124. $("#go").attr("onclick", "go('tt')");
  125. rl = {stac: 3};
  126. e = JSON.stringify(rl);
  127. sessionStorage.setItem("sd", e);
  128. },
  129. });
  130. } else {
  131. $(".shuaxin").text("点击刷新");
  132. process = 0;
  133. animate(usedf);
  134. }
  135. }