bindPhone.blade.php 12 KB

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