bindPhone.blade.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta
  6. name="viewport"
  7. content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
  8. />
  9. <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  10. <title>绑定手机</title>
  11. <style>
  12. html,
  13. body,
  14. p {
  15. padding: 0;
  16. margin: 0;
  17. }
  18. html {
  19. background: #f7f7f7;
  20. }
  21. img {
  22. width: 100%;
  23. }
  24. i {
  25. font-style: normal;
  26. }
  27. .page-banner {
  28. position: absolute;
  29. top: 0;
  30. left: 0;
  31. width: 100%;
  32. z-index: 9;
  33. }
  34. .bind-phone__wrap {
  35. position: relative;
  36. z-index: 99;
  37. border-radius: 6px;
  38. background: #fff;
  39. padding: 20px;
  40. margin: 125px 13px 0;
  41. text-align: center;
  42. font-size: 0;
  43. }
  44. .bind-phone__wrap .wrap-banner {
  45. width: 90%;
  46. }
  47. .bind-form {
  48. margin-top: 35px;
  49. }
  50. .bind-form .form-item {
  51. display: -webkit-box;
  52. display: -ms-flexbox;
  53. display: flex;
  54. -webkit-box-pack: start;
  55. -ms-flex-pack: start;
  56. justify-content: flex-start;
  57. -webkit-box-align: center;
  58. -ms-flex-align: center;
  59. align-items: center;
  60. margin: 0 12px;
  61. border-bottom: 1px solid #f7f7f7;
  62. }
  63. .bind-form .form-item input {
  64. -webkit-box-flex: 1;
  65. -ms-flex: 1;
  66. flex: 1;
  67. padding: 10px 0;
  68. font-size: 14px;
  69. color: #333;
  70. outline: none;
  71. border: none;
  72. }
  73. .bind-form .form-item input::-webkit-input-placeholder {
  74. color: #999;
  75. font-size: 14px;
  76. }
  77. .bind-form .form-item .get-code {
  78. font-size: 13px;
  79. color: #ff7130;
  80. }
  81. .bind-form .form-item:not(:last-child) {
  82. margin-bottom: 17px;
  83. }
  84. .bind-form .submit-wrap {
  85. margin-top: 69px;
  86. margin-bottom: 18px;
  87. display: -webkit-box;
  88. display: -ms-flexbox;
  89. display: flex;
  90. -webkit-box-pack: justify;
  91. -ms-flex-pack: justify;
  92. justify-content: space-between;
  93. -webkit-box-align: center;
  94. -ms-flex-align: center;
  95. align-items: center;
  96. }
  97. .bind-form .submit-wrap button {
  98. -webkit-box-flex: 1;
  99. -ms-flex: 1;
  100. flex: 1;
  101. outline: none;
  102. border-radius: 6px;
  103. font-size: 15px;
  104. color: #fff;
  105. text-align: center;
  106. border: 1px solid transparent;
  107. line-height: 45px;
  108. background: #ff7130;
  109. white-space:nowrap;
  110. text-overflow: ellipsis;
  111. overflow: hidden;
  112. }
  113. .bind-form .submit-wrap button.to-refuse {
  114. color: #b3b3b3;
  115. background: #ecf2f7;
  116. }
  117. .bind-form .submit-wrap button.to-refuse__enable {
  118. border-color: #ff7130;
  119. color: #ff7130;
  120. background: #fff;
  121. }
  122. .bind-form .submit-wrap button:not(:last-child) {
  123. margin-right: 11px;
  124. }
  125. .dialog-wrap {
  126. position: fixed;
  127. top: 0;
  128. bottom: 0;
  129. left: 0;
  130. right: 0;
  131. background: rgba(0, 0, 0, 0.2);
  132. z-index: 999;
  133. }
  134. .dialog-wrap .dialog-content {
  135. position: absolute;
  136. width: 90%;
  137. top: 50%;
  138. left: 50%;
  139. -webkit-transform: translate(-50%, -50%);
  140. transform: translate(-50%, -50%);
  141. background: #fff;
  142. border-radius: 2px;
  143. font-size: 0;
  144. text-align: center;
  145. }
  146. .dialog-wrap .dialog-content .dialog-img {
  147. position: relative;
  148. width: 80px;
  149. top: 50%;
  150. -webkit-transform: translate(0%, -50%);
  151. transform: translate(0%, -50%);
  152. }
  153. .dialog-wrap .dialog-content .content-info {
  154. text-align: center;
  155. font-size: 16px;
  156. color: #666;
  157. line-height: 1;
  158. margin-bottom: 40px;
  159. }
  160. .dialog-wrap .dialog-content .content-info .bind-title {
  161. font-size: 30px;
  162. font-weight: bold;
  163. margin-bottom: 15px;
  164. }
  165. .dialog-wrap .dialog-content .content-info i {
  166. color: #ff7130;
  167. font-weight: bold;
  168. font-size: 20px;
  169. }
  170. .dialog-wrap .dialog-content .close {
  171. outline: none;
  172. border: none;
  173. width: 175px;
  174. line-height: 40px;
  175. font-size: 15px;
  176. color: #fff;
  177. background: #ff7130;
  178. border-radius: 6px;
  179. margin: 0 auto 26px;
  180. text-align: center;
  181. }
  182. .toast-wrap {
  183. position: fixed;
  184. background: rgba(0, 0, 0, 0.7);
  185. color: #fff;
  186. left: 50%;
  187. top: 50%;
  188. -webkit-transform: translate(-50%, -50%);
  189. transform: translate(-50%, -50%);
  190. max-width: 90%;
  191. padding: 10px 10px;
  192. border-radius: 6px;
  193. z-index: 9999;
  194. text-align: center;
  195. }
  196. .toast-wrap p{
  197. white-space:nowrap;
  198. }
  199. </style>
  200. </head>
  201. <body>
  202. <main>
  203. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/doing.jpg" alt="" class="page-banner" />
  204. <div class="bind-phone__wrap">
  205. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/title.jpg" alt="" class="wrap-banner" />
  206. <div class="bind-form">
  207. <form action="">
  208. <div class="form-item">
  209. <input
  210. type="phone"
  211. name="phone"
  212. id="phone"
  213. placeholder="请输入手机号"
  214. />
  215. </div>
  216. <div class="form-item">
  217. <input
  218. type="text"
  219. name="code"
  220. id="code"
  221. placeholder="请输入手机验证码"
  222. />
  223. <span class="get-code">获取验证码</span>
  224. </div>
  225. </form>
  226. <div class="submit-wrap">
  227. <button class="to-bind" id="bind">立即绑定</button>
  228. <!-- 可以点击的时候 多加一个class->to-refuse__enable -->
  229. @if($from == 'pay')
  230. <button class="to-refuse" id="refuse" disabled>残忍拒绝</button>
  231. @endif
  232. </div>
  233. </div>
  234. </div>
  235. </main>
  236. <div class="dialog-wrap" style="display: none">
  237. <div class="dialog-content">
  238. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/success.png" alt="" class="dialog-img" />
  239. <div class="content-info">
  240. <p class="bind-title">绑定成功</p>
  241. <p class="bind-text">手机号绑定成功,赠送您<i>100</i>书币</p>
  242. </div>
  243. <button class="close" id="close">知道了</button>
  244. </div>
  245. </div>
  246. <div class="toast-wrap" style="display: none">
  247. <p class="toast-content">我是toast内容</p>
  248. </div>
  249. </body>
  250. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  251. <script>
  252. var reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57]|19[0-9])[0-9]{8}$/;
  253. var refuseNumber = 10;
  254. var getPhoneCodeNumber = 60;
  255. var order = "{{ $order }}"
  256. var from = "{{ $from }}"
  257. // toast
  258. var toast = {
  259. show: function(content, cb,last) {
  260. $(".toast-wrap")
  261. .text(content)
  262. .fadeIn();
  263. setTimeout(function() {
  264. $(".toast-wrap").fadeOut();
  265. cb && cb();
  266. }, last);
  267. }
  268. };
  269. // 倒计时
  270. function countDown(time, cb) {
  271. var timer = null
  272. timer = setInterval(function() {
  273. if (time === 1) clearInterval(timer);
  274. time--;
  275. if (cb) cb(time);
  276. }, 1000);
  277. }
  278. // 残忍拒绝事件
  279. $("#refuse").on("click", function() {
  280. if(!$(this).attr('disabled')){
  281. toast.show('可在个人中心继续绑定',function(){
  282. location.href = "{!! $url !!}";
  283. },1000);
  284. }
  285. });
  286. function refuse(){
  287. var timer = null
  288. time = refuseNumber
  289. timer = setInterval(function() {
  290. $.ajax({
  291. url:"/api/order/issuccess",
  292. data:{
  293. order:"{{ $order }}"
  294. },
  295. success:function(res){
  296. if(res['code'] == 0){
  297. $('.page-banner').attr('src','https://cdn-novel.iycdm.com/h5/bind-phone/done.jpg')
  298. time = 1;
  299. }
  300. }
  301. });
  302. if (time === 1) clearInterval(timer);
  303. time--;
  304. if (time === 0) {
  305. $("#refuse").text("残忍拒绝");
  306. $("#refuse").attr("disabled", false);
  307. $("#refuse").addClass("to-refuse__enable");
  308. } else $("#refuse").text("残忍拒绝(" + time + "s)");
  309. }, 1000);
  310. }
  311. if(order){
  312. refuse()
  313. }
  314. // 残忍拒绝倒计时
  315. /*countDown(refuseNumber, function(time) {
  316. if (time === 0) {
  317. $("#refuse").text("残忍拒绝");
  318. $("#refuse").attr("disabled", false);
  319. $("#refuse").addClass("to-refuse__enable");
  320. } else $("#refuse").text("残忍拒绝(" + time + "s)");
  321. });*/
  322. // 获取验证码
  323. var code_getting = false;
  324. $(".get-code").on("click", function() {
  325. var phone = $("#phone").val();
  326. phone = formatPhone(phone);
  327. if (!phone) {
  328. toast.show("请输入手机号!",'',2000);
  329. return;
  330. } else if (!reg.test(phone)) {
  331. toast.show("手机号不合法!",'',2000);
  332. return;
  333. }
  334. $.ajax({
  335. url:'/api/bindphone/sendcode',
  336. type:'post',
  337. data:{phone:phone},
  338. success:function () {
  339. }
  340. });
  341. if (!code_getting) {
  342. code_getting = true;
  343. countDown(getPhoneCodeNumber, function(time) {
  344. if (time === 0) {
  345. $(".get-code").text("获取验证码");
  346. code_getting = false;
  347. } else $(".get-code").text(time + "s");
  348. });
  349. }
  350. });
  351. // 立即绑定事件
  352. $("#bind").on("click", function() {
  353. var phone = $("#phone").val();
  354. var code = $("#code").val();
  355. phone = formatPhone(phone);
  356. if (!phone || !code) toast.show("手机号或验证码不能为空",'',2000);
  357. else {
  358. // 绑定逻辑
  359. $.ajax({
  360. url:'/api/bindphone/bind',
  361. type:'post',
  362. data:{phone:phone,code:code,from:from},
  363. success:function ($res) {
  364. if($res.code == 0){
  365. $(".dialog-wrap").fadeIn();
  366. return ;
  367. }
  368. if($res.code == 10029 || $res.code == 10031){
  369. toast.show($res.msg,'',2000);
  370. return ;
  371. }
  372. if($res.code == 10030){
  373. toast.show($res.msg,'',2000);
  374. setTimeout(function(){
  375. location.href = "{!! $url !!}";
  376. },50);
  377. return ;
  378. }
  379. toast.show("系统异常",'',2000);
  380. return ;
  381. }
  382. })
  383. }
  384. });
  385. // 关闭弹窗
  386. $(".dialog-content").delegate(".close", "click", function(e) {
  387. e.stopPropagation();
  388. $(".dialog-wrap").fadeOut();
  389. setTimeout(function(){
  390. location.href = "{!! $url !!}";
  391. },50);
  392. })
  393. // 手机号码格式化
  394. var spaceOneIndex = 3;
  395. var spaceTwoIndex = 8;
  396. $("#phone").on("keyup", function() {
  397. var value = $(this).val();
  398. if (value.length === spaceOneIndex || value.length === spaceTwoIndex) $(this).val(value += " ");
  399. })
  400. // 手机去空格
  401. function formatPhone(phone) {
  402. return phone.split(" ").join("")
  403. }
  404. </script>
  405. </html>