succutil.js 3.6 KB

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