Aucune description

exchange.html 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta content="yes" name="apple-mobile-web-app-capable">
  6. <meta name="viewport" content="width=device-width,height=device-height,inital-scale=1.0,maximum-scale=1.0,user-scalable=no;">
  7. <title>积分兑换</title>
  8. <style type="text/css">
  9. body,html{
  10. font-size: 0.16rem;
  11. height: 100vh;
  12. }
  13. body, div, button, h3, h6, span, ul, li, p, a,input{
  14. font-family: -apple-system,SF UI Text,Helvetica Neue,Helvetica,Arial,sans-serif;
  15. padding: 0;
  16. margin: 0;
  17. box-sizing: inherit;
  18. font-weight: normal;
  19. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  20. }
  21. a, a:visited{
  22. text-decoration: none;
  23. }
  24. button{
  25. outline: none;
  26. }
  27. body{
  28. width: 100%;
  29. height: 100%;
  30. background: #FFFFFF;
  31. }
  32. #body{
  33. margin:0 0.2rem;
  34. }
  35. .myExchange{
  36. color: #535353;
  37. font-size: 0.16rem;
  38. line-height: 0.22rem;
  39. padding-top: 0.2rem;
  40. margin-bottom: 0.07rem;
  41. }
  42. .myExchange text{
  43. color: #E2252F;
  44. font-weight: bold;
  45. }
  46. #teleNumber{
  47. font-size: 0.24rem;
  48. line-height: 0.33rem;
  49. color: #333333;
  50. border: none;
  51. outline: none;
  52. background: #FFFFFF;
  53. }
  54. .teleNumber{
  55. padding-top: 0.06rem;
  56. padding-bottom: 0.06rem;
  57. border-bottom: 0.005rem solid #D8D8D8;
  58. }
  59. .flowList{
  60. width: 100vw;
  61. display: -webkit-flex;
  62. display: -webkit-box;
  63. display: -moz-box;
  64. display: -ms-flexbox;
  65. display: flex;
  66. margin: 0.25rem 0.05rem 0 -0.2rem;
  67. flex-flow: wrap;
  68. }
  69. .flowList div{
  70. margin: 0 0.15rem;
  71. width: 0.92rem;
  72. border: 0.01rem solid #FFC600;
  73. border-radius: 0.04rem;
  74. margin-bottom: 0.12rem;
  75. text-align: center;
  76. line-height: 0.42rem;
  77. color: #333333;
  78. font-size: 0.16rem;
  79. }
  80. .flowList .active{
  81. background-color:#FFEFB7;
  82. border-color: #FFEFB7;
  83. color: #EA3D3D;
  84. }
  85. .needExchange{
  86. color: #535353;
  87. font-size: 0.14rem;
  88. line-height: 0.2rem;
  89. margin-top: 0.41rem;
  90. }
  91. .needExchange text{
  92. color: #E2252F;
  93. font-size: 0.2rem;
  94. font-weight: bold;
  95. }
  96. .needExchange span{
  97. color: #E2252F;
  98. font-weight: normal;
  99. font-size: 0.12rem;
  100. display: none;
  101. }
  102. button{
  103. width: 3.35rem;
  104. height: 0.44rem;
  105. background: #FFC600;
  106. border-radius: 0.04rem;
  107. text-align: center;
  108. line-height: 0.44rem;
  109. color: #FFFFFF;
  110. font-size: 0.16rem;
  111. margin-top: 0.14rem;
  112. margin-bottom: 0.2rem;
  113. border: none;
  114. outline: none;
  115. }
  116. .describe{
  117. font-size: 0.12rem;
  118. line-height: 0.17rem;
  119. color: #999999;
  120. }
  121. input::-webkit-input-placeholder { /* WebKit browsers */
  122. font-size:0.14rem;
  123. }
  124. .registerMask{
  125. display: none;
  126. width: 100%;
  127. height: 100%;
  128. position: fixed;
  129. top: 0;
  130. left: 0;
  131. background: rgba(0,0,0,0.5);
  132. }
  133. .registerTost{
  134. width: 3rem;
  135. background: #FFFFFF;
  136. position: absolute;
  137. top: 30%;
  138. left: 0;
  139. right: 0;
  140. margin: auto;
  141. border-radius: 0.04rem;
  142. }
  143. .registerTost p{
  144. padding: 0 0.18rem;
  145. padding-top: 0.44rem;
  146. padding-bottom: 0.33rem;
  147. text-align: center;
  148. color: #000000;
  149. font-size: 0.16rem;
  150. }
  151. .registerTost div{
  152. color: #16B80A;
  153. font-size: 0.18rem;
  154. line-height: 0.55rem;
  155. text-align: center;
  156. border-top: 0.01rem solid #D8D8D8;
  157. }
  158. </style>
  159. <script>
  160. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  161. window.onresize = function(){
  162. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  163. }
  164. </script>
  165. </head>
  166. <body>
  167. <div id="body">
  168. <div class="myExchange">积分: <text></text></div>
  169. <div class="teleNumber">
  170. <input type="tel" name="" id="teleNumber" placeholder="请输入手机号码" value="" oninput=""/>
  171. </div>
  172. <div class="flowList">
  173. <div>0M</div>
  174. <div>0M</div>
  175. <div>0M</div>
  176. <div>0M</div>
  177. <div>0M</div>
  178. <div>0M</div>
  179. </div>
  180. <div class="needExchange">所需积分: <text>3000</text><span>(您的积分不足)</span></div>
  181. <button onclick="goExchange()">马上兑换</button>
  182. <p class="describe">兑换流量:全国可用,当月有效。流量预计24小时到账,双休日及节假日不处理流量兑换业务</p>
  183. </div>
  184. <div class="registerMask">
  185. <div class="registerTost">
  186. <p>手机号不能为空</p>
  187. <div class="yes" onclick="yesClickEvent()">我知道了</div>
  188. </div>
  189. </div>
  190. </body>
  191. </html>
  192. <script type="text/javascript" src="../jquery-2.1.0.js"></script>
  193. <script type="text/javascript">
  194. var flag = false;
  195. var userId = null;
  196. var html = "";
  197. var time = '';
  198. var id = '';
  199. var sign = "";
  200. var myScore = '';
  201. var arr = [];
  202. var cid = '';
  203. var str=location.href; //取得整个地址栏
  204. var num=str.indexOf("?");
  205. str=str.substr(num+1); //str得到?之后的字符串
  206. var brr=str.split("&");
  207. for(var i = 0 ; i<brr.length; i++){
  208. if(brr[i].indexOf('userId') != -1){
  209. userId = brr[i].split('=')[1];//用户id
  210. }
  211. if(brr[i].indexOf('cid') != -1){
  212. cid = brr[i].split('=')[1];//cid
  213. }
  214. if(brr[i].indexOf('sign') != -1){
  215. sign = brr[i].split('=')[1];//sign
  216. }
  217. if(brr[i].indexOf('time') != -1){
  218. time = brr[i].split('=')[1];//time
  219. }
  220. }
  221. window.onload = function (){
  222. getAwards();
  223. }
  224. $("#teleNumber").blur(function(){
  225. var teleNumber = $("#teleNumber").val();
  226. var myreg=/^[0-9]{11}$/;
  227.    if (!myreg.test(teleNumber)) {
  228. //手机号码未填写及填写不正确
  229. $(".registerMask").css('display','block');
  230. $(".registerTost").find('p').html("请正确填写手机号码");
  231. localStorage.setItem('numberFlag',0);
  232. }else{
  233. localStorage.setItem('numberFlag',1);
  234. }
  235. });
  236. function exchangeActive (dataList) {
  237. arr = dataList.res.data;
  238. id = arr[0].id;
  239. myScore = dataList.res.all_score;
  240. for(var i = 0; i<arr.length; i++){
  241. html+=`<div>${arr[i].data_flow}</div>`
  242. }
  243. $(".flowList").html(html);
  244. $(".flowList").find('div').eq(0).addClass('active');
  245. $(".myExchange").find('text').html(myScore);//用户所有积分
  246. $(".needExchange").find('text').html(arr[0].score);//兑换所需积分
  247. $("#teleNumber").val(dataList.res.mobile);//用户手机号
  248. if(dataList.res.mobile == undefined || !dataList.res.mobile || dataList.res.mobile == null || dataList.res.mobile == ""){
  249. //用户没有手机号
  250. $("#teleNumber").val("");//用户手机号
  251. }
  252. if(myScore<arr[0].score){
  253. $(".needExchange").find("span").css('display','inline-block');
  254. }else{
  255. $(".needExchange").find("span").css('display','none');
  256. }
  257. $(".flowList div").click(function () {
  258. $(".flowList div").removeClass('active');
  259. $(this).addClass('active')
  260. for(var i = 0;i<arr.length;i++){
  261. if(arr[i].data_flow == $(this).html()){
  262. $(".needExchange").find('text').html(arr[i].score);//兑换所需积分
  263. id = arr[i].id;
  264. }
  265. }
  266. if(parseFloat(myScore) < parseFloat($(".needExchange").find('text').html())){
  267. $(".needExchange").find("span").css('display','inline-block');
  268. }else{
  269. $(".needExchange").find("span").css('display','none');
  270. }
  271. })
  272. }
  273. function getAwards () {
  274. $.ajax({
  275. type:"post",
  276. url:"/api/V1/getAwards",
  277. data:{
  278. userId:userId
  279. },
  280. headers: {
  281. 'time':time,
  282. "sign":sign
  283. },
  284. success: function (res) {
  285. console.log(!JSON.parse(res).res.mobile)
  286. if(JSON.parse(res).res.mobile == undefined || !JSON.parse(res).res.mobile || JSON.parse(res).res.mobile == null || JSON.parse(res).res.mobile == ""){
  287. //用户没有手机号
  288. console.log("nohave")
  289. $("#teleNumber").removeAttr("disabled");
  290. $("#teleNumber").val("");
  291. }else{
  292. $("#teleNumber").attr('disabled','disabled');
  293. }
  294. exchangeActive(JSON.parse(res));
  295. }
  296. });
  297. }
  298. function exchangeAward(){
  299. var teleNumber = $("#teleNumber").val();
  300. $.ajax({
  301. type:"post",
  302. url:"/api/V1/exchangeAward",
  303. headers: {
  304. 'cid':cid,
  305. 'time':time,
  306. 'sign':sign
  307. },
  308. data:{
  309. user_id:userId,
  310. award_id:id,
  311. mobile:teleNumber
  312. },
  313. success: function (res) {
  314. console.log(JSON.parse(res))
  315. $(".registerMask").css('display','block');
  316. $(".registerTost").find('p').html(JSON.parse(res).message);
  317. if(JSON.parse(res).code == 0){
  318. flag = true
  319. }
  320. }
  321. });
  322. }
  323. function goExchange () {
  324. if(localStorage.getItem('numberFlag') == 0){
  325. //手机号填写有误
  326. $(".registerMask").css('display','block');
  327. $(".registerTost").find('p').html("请正确填写手机号码");
  328. }else{
  329. exchangeAward();
  330. }
  331. }
  332. function yesClickEvent () {
  333. $(".registerMask").css('display','none');
  334. if(flag){
  335. window.location.reload();
  336. }
  337. }
  338. </script>