bindPhone.blade.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 20px;
  189. border-radius: 6px;
  190. z-index: 9999;
  191. }
  192. </style>
  193. </head>
  194. <body>
  195. <main>
  196. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/doing.jpg" alt="" class="page-banner" />
  197. <div class="bind-phone__wrap">
  198. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/title.jpg" alt="" class="wrap-banner" />
  199. <div class="bind-form">
  200. <form action="">
  201. <div class="form-item">
  202. <input
  203. type="phone"
  204. name="phone"
  205. id="phone"
  206. placeholder="请输入手机号"
  207. />
  208. </div>
  209. <div class="form-item">
  210. <input
  211. type="text"
  212. name="code"
  213. id="code"
  214. placeholder="请输入手机验证码"
  215. />
  216. <span class="get-code">获取验证码</span>
  217. </div>
  218. </form>
  219. <div class="submit-wrap">
  220. <button class="to-bind" id="bind">立即绑定</button>
  221. <!-- 可以点击的时候 多加一个class->to-refuse__enable -->
  222. @if($from == 'pay')
  223. <button class="to-refuse" id="refuse" disabled>残忍拒绝</button>
  224. @endif
  225. </div>
  226. </div>
  227. </div>
  228. </main>
  229. <div class="dialog-wrap" style="display: none">
  230. <div class="dialog-content">
  231. <img src="https://cdn-novel.iycdm.com/h5/bind-phone/success.png" alt="" class="dialog-img" />
  232. <div class="content-info">
  233. <p class="bind-title">绑定成功</p>
  234. <p class="bind-text">手机号绑定成功,赠送您<i>100</i>书币</p>
  235. </div>
  236. <button class="close" id="close">知道了</button>
  237. </div>
  238. </div>
  239. <div class="toast-wrap" style="display: none">
  240. <p class="toast-content">我是toast内容</p>
  241. </div>
  242. </body>
  243. <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
  244. <script>
  245. var reg = /^(0|86|17951)?(13[0-9]|15[012356789]|166|17[3678]|18[0-9]|14[57]|19[0-9])[0-9]{8}$/;
  246. var refuseNumber = 10;
  247. var getPhoneCodeNumber = 60;
  248. var order = "{{ $order }}"
  249. var from = "{{ $from }}"
  250. // toast
  251. var toast = {
  252. show: function(content, cb,last) {
  253. $(".toast-wrap")
  254. .text(content)
  255. .fadeIn();
  256. setTimeout(function() {
  257. $(".toast-wrap").fadeOut();
  258. cb && cb();
  259. }, last);
  260. }
  261. };
  262. // 倒计时
  263. function countDown(time, cb) {
  264. var timer = null
  265. timer = setInterval(function() {
  266. if (time === 1) clearInterval(timer);
  267. time--;
  268. if (cb) cb(time);
  269. }, 1000);
  270. }
  271. // 残忍拒绝事件
  272. $("#refuse").on("click", function() {
  273. if(!$(this).attr('disabled')){
  274. toast.show('可在个人中心继续绑定',function(){
  275. location.href = "{!! $url !!}";
  276. },1000);
  277. }
  278. });
  279. function refuse(){
  280. var timer = null
  281. time = refuseNumber
  282. timer = setInterval(function() {
  283. $.ajax({
  284. url:"/api/order/issuccess",
  285. data:{
  286. order:"{{ $order }}"
  287. },
  288. success:function(res){
  289. if(res['code'] == 0){
  290. $('.page-banner').attr('src','https://cdn-novel.iycdm.com/h5/bind-phone/done.jpg')
  291. time = 1;
  292. }
  293. }
  294. });
  295. if (time === 1) clearInterval(timer);
  296. time--;
  297. if (time === 0) {
  298. $("#refuse").text("残忍拒绝");
  299. $("#refuse").attr("disabled", false);
  300. $("#refuse").addClass("to-refuse__enable");
  301. } else $("#refuse").text("残忍拒绝(" + time + "s)");
  302. }, 1000);
  303. }
  304. if(order){
  305. refuse()
  306. }
  307. // 残忍拒绝倒计时
  308. /*countDown(refuseNumber, function(time) {
  309. if (time === 0) {
  310. $("#refuse").text("残忍拒绝");
  311. $("#refuse").attr("disabled", false);
  312. $("#refuse").addClass("to-refuse__enable");
  313. } else $("#refuse").text("残忍拒绝(" + time + "s)");
  314. });*/
  315. // 获取验证码
  316. var code_getting = false;
  317. $(".get-code").on("click", function() {
  318. var phone = $("#phone").val();
  319. if (!phone) {
  320. toast.show("请输入手机号!",'',2000);
  321. return;
  322. } else if (!reg.test(phone)) {
  323. toast.show("手机号不合法!",'',2000);
  324. return;
  325. }
  326. $.ajax({
  327. url:'/api/bindphone/sendcode',
  328. type:'post',
  329. data:{phone:phone},
  330. success:function () {
  331. }
  332. });
  333. if (!code_getting) {
  334. code_getting = true;
  335. countDown(getPhoneCodeNumber, function(time) {
  336. if (time === 0) {
  337. $(".get-code").text("获取验证码");
  338. code_getting = false;
  339. } else $(".get-code").text(time + "s");
  340. });
  341. }
  342. });
  343. // 立即绑定事件
  344. $("#bind").on("click", function() {
  345. var phone = $("#phone").val();
  346. var code = $("#code").val();
  347. if (!phone || !code) toast.show("手机号或验证码不能为空",'',2000);
  348. else {
  349. // 绑定逻辑
  350. $.ajax({
  351. url:'/api/bindphone/bind',
  352. type:'post',
  353. data:{phone:phone,code:code,from:from},
  354. success:function ($res) {
  355. if($res.code == 0){
  356. $(".dialog-wrap").fadeIn();
  357. return ;
  358. }
  359. if($res.code == 10029 || $res.code == 10031){
  360. toast.show($res.msg,'',2000);
  361. return ;
  362. }
  363. if($res.code == 10030){
  364. toast.show($res.msg,'',2000);
  365. setTimeout(function(){
  366. location.href = "{!! $url !!}";
  367. },50);
  368. return ;
  369. }
  370. toast.show("系统异常",'',2000);
  371. return ;
  372. }
  373. })
  374. }
  375. });
  376. // 关闭弹窗
  377. $(".dialog-content").delegate(".close", "click", function(e) {
  378. e.stopPropagation();
  379. $(".dialog-wrap").fadeOut();
  380. setTimeout(function(){
  381. location.href = "{!! $url !!}";
  382. },50);
  383. })
  384. </script>
  385. </html>