Açıklama Yok

exchange.html 8.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. </head>
  160. <body>
  161. <div id="body">
  162. <div class="myExchange">积分: <text></text></div>
  163. <div class="teleNumber">
  164. <input type="tel" name="" id="teleNumber" placeholder="请输入手机号码" value="" oninput=""/>
  165. </div>
  166. <div class="flowList">
  167. <div>0M</div>
  168. <div>0M</div>
  169. <div>0M</div>
  170. <div>0M</div>
  171. <div>0M</div>
  172. <div>0M</div>
  173. </div>
  174. <div class="needExchange">所需积分: <text>3000</text><span>(您的积分不足)</span></div>
  175. <button onclick="goExchange()">马上兑换</button>
  176. <p class="describe">兑换流量:全国可用,当月有效。流量预计24小时到账,双休日及节假日不处理流量兑换业务</p>
  177. </div>
  178. <div class="registerMask">
  179. <div class="registerTost">
  180. <p>手机号不能为空</p>
  181. <div class="yes" onclick="yesClickEvent()">我知道了</div>
  182. </div>
  183. </div>
  184. </body>
  185. </html>
  186. <script type="text/javascript" src="../jquery-2.1.0.js"></script>
  187. <script type="text/javascript">
  188. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  189. window.onresize = function(){
  190. document.documentElement.style.fontSize = 100 * (document.documentElement.clientWidth/375) + "px";
  191. }
  192. var flag = false;
  193. var userId = null;
  194. var html = "";
  195. var time = '';
  196. var id = '';
  197. var sign = "";
  198. var myScore = '';
  199. var arr = [];
  200. var cid = '';
  201. var str=location.href; //取得整个地址栏
  202. var num=str.indexOf("?");
  203. str=str.substr(num+1); //str得到?之后的字符串
  204. var brr=str.split("&");
  205. for(var i = 0 ; i<brr.length; i++){
  206. if(brr[i].indexOf('userId') != -1){
  207. userId = brr[i].split('=')[1];//用户id
  208. }
  209. if(brr[i].indexOf('cid') != -1){
  210. cid = brr[i].split('=')[1];//cid
  211. }
  212. if(brr[i].indexOf('sign') != -1){
  213. sign = brr[i].split('=')[1];//sign
  214. }
  215. if(brr[i].indexOf('time') != -1){
  216. time = brr[i].split('=')[1];//time
  217. }
  218. }
  219. window.onload = function (){
  220. getAwards();
  221. }
  222. $("#teleNumber").blur(function(){
  223. var teleNumber = $("#teleNumber").val();
  224. var myreg=/^[0-9]{11}$/;
  225.    if (!myreg.test(teleNumber)) {
  226. //手机号码未填写及填写不正确
  227. $(".registerMask").css('display','block');
  228. $(".registerTost").find('p').html("请正确填写手机号码");
  229. localStorage.setItem('numberFlag',0);
  230. }else{
  231. localStorage.setItem('numberFlag',1);
  232. }
  233. });
  234. function exchangeActive (dataList) {
  235. arr = dataList.res.data;
  236. id = arr[0].id;
  237. myScore = dataList.res.all_score;
  238. for(var i = 0; i<arr.length; i++){
  239. html+=`<div>${arr[i].data_flow}</div>`
  240. }
  241. $(".flowList").html(html);
  242. $(".flowList").find('div').eq(0).addClass('active');
  243. $(".myExchange").find('text').html(myScore);//用户所有积分
  244. $(".needExchange").find('text').html(arr[0].score);//兑换所需积分
  245. $("#teleNumber").val(dataList.res.mobile);//用户手机号
  246. if(dataList.res.mobile == undefined || !dataList.res.mobile || dataList.res.mobile == null || dataList.res.mobile == ""){
  247. //用户没有手机号
  248. $("#teleNumber").val("");//用户手机号
  249. }
  250. if(myScore<arr[0].score){
  251. $(".needExchange").find("span").css('display','inline-block');
  252. }else{
  253. $(".needExchange").find("span").css('display','none');
  254. }
  255. $(".flowList div").click(function () {
  256. $(".flowList div").removeClass('active');
  257. $(this).addClass('active')
  258. for(var i = 0;i<arr.length;i++){
  259. if(arr[i].data_flow == $(this).html()){
  260. $(".needExchange").find('text').html(arr[i].score);//兑换所需积分
  261. id = arr[i].id;
  262. }
  263. }
  264. if(parseFloat(myScore) < parseFloat($(".needExchange").find('text').html())){
  265. $(".needExchange").find("span").css('display','inline-block');
  266. }else{
  267. $(".needExchange").find("span").css('display','none');
  268. }
  269. })
  270. }
  271. function getAwards () {
  272. $.ajax({
  273. type:"post",
  274. url:"/api/V1/getAwards",
  275. data:{
  276. userId:userId
  277. },
  278. headers: {
  279. 'time':time,
  280. "sign":sign
  281. },
  282. success: function (res) {
  283. console.log(!JSON.parse(res).res.mobile)
  284. if(JSON.parse(res).res.mobile == undefined || !JSON.parse(res).res.mobile || JSON.parse(res).res.mobile == null || JSON.parse(res).res.mobile == ""){
  285. //用户没有手机号
  286. console.log("nohave")
  287. $("#teleNumber").removeAttr("disabled");
  288. $("#teleNumber").val("");
  289. }else{
  290. $("#teleNumber").attr('disabled','disabled');
  291. }
  292. exchangeActive(JSON.parse(res));
  293. }
  294. });
  295. }
  296. function exchangeAward(){
  297. var teleNumber = $("#teleNumber").val();
  298. $.ajax({
  299. type:"post",
  300. url:"/api/V1/exchangeAward",
  301. headers: {
  302. 'cid':cid,
  303. 'time':time,
  304. 'sign':sign
  305. },
  306. data:{
  307. user_id:userId,
  308. award_id:id,
  309. mobile:teleNumber
  310. },
  311. success: function (res) {
  312. console.log(JSON.parse(res))
  313. $(".registerMask").css('display','block');
  314. $(".registerTost").find('p').html(JSON.parse(res).message);
  315. if(JSON.parse(res).code == 0){
  316. flag = true
  317. }
  318. }
  319. });
  320. }
  321. function goExchange () {
  322. if(localStorage.getItem('numberFlag') == 0){
  323. //手机号填写有误
  324. $(".registerMask").css('display','block');
  325. $(".registerTost").find('p').html("请正确填写手机号码");
  326. }else{
  327. exchangeAward();
  328. }
  329. }
  330. function yesClickEvent () {
  331. $(".registerMask").css('display','none');
  332. if(flag){
  333. window.location.reload();
  334. }
  335. }
  336. </script>