/** * 注册 * @author: xuqi<qi.xu@yoho.cn> * @date: 2015/10/8 */ var $ = require('jquery'); var $phoneNum = $('#phone-num'), $countrySelect = $('#country-select'), $areaCode = $('#area-code'), $openId = $('#openId'), $nickname = $('#nickname'), $sourceType = $('#sourceType'), $btnNext = $('#btn-next'); var api = require('../api'), tip = require('../../plugin/tip'), dialog = require('../../me/dialog'); var trim = $.trim; var showErrTip = tip.show; var requesting = false; function nextStep(url, mobileNo, areaCode) { if (requesting) { return false; } requesting = true; $.ajax({ type: 'POST', url: '/passport/bind/sendBindMsg', data: { phoneNum: mobileNo, areaCode: areaCode.replace('+', '') }, success: function(res) { console.log(res.data); location.href = url; requesting = false; }, error: function() { tip.show('出错了,请重试!'); requesting = false; } }); } api.selectCssHack($('#country-select')); api.bindClearEvt(); $phoneNum.bind('input', function() { if (trim($phoneNum.val()) === '') { $btnNext.addClass('disable'); } else { $btnNext.removeClass('disable'); } }); $countrySelect.change(function() { $areaCode.text($countrySelect.val()); }); $btnNext.on('touchstart', function() { var pn = trim($phoneNum.val()), openId = trim($openId.val()), nickname = trim($nickname.val()), sourceType = trim($sourceType.val()), areaCode = $countrySelect.val(); if ($btnNext.hasClass('disable')) { return; } if (api.phoneRegx[areaCode].test(pn)) { $.ajax({ url: '/passport/bind/bindCheck', type: 'POST', data: { areaCode: areaCode.replace('+', ''), phoneNum: pn, openId: openId, sourceType: sourceType, nickname: nickname }, success: function(res) { console.log(res); //res : { // code: 'xxx', // data: { // isReg: 0, // next: 'xxxx' // }, // message: 'xxxx', //} if (res.code === 200) { if (res.data.isReg === 1) { dialog.showDialog({ dialogText: '该手机号已注册过有货\n' + pn + ',确定绑定吗?', hasFooter: { leftBtnText: '更换号码', rightBtnText: '继续绑定' } }, function() { nextStep(res.data.next, pn, areaCode); }); } else { nextStep(res.data.next, pn, areaCode); } } else { showErrTip(res.message); } } }); } else { showErrTip('手机号格式不正确,请重新输入'); } });