bind.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. var bindPage = new Vue({
  2. el: "#bindPage",
  3. data: {
  4. rule:{
  5. mobileOrEmail: '(^([\\w-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([\\w-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$)|(^\\d{6,12}$)',
  6. name: '^[a-zA-Z\\u4e00-\\u9fa5]{2,}$',
  7. phone: '^\\d{6,12}$',
  8. code: '^\\d{6}$',
  9. password: "^[^\\u4e00-\\u9fa5]{8,16}$",
  10. mobile:'^1[1-9][0-9]{9}$'
  11. },
  12. loginLoading:false,
  13. mobilCount:0,
  14. mobileCodeText:'获取验证码',
  15. mobilTime:null,
  16. isMobileDisabled:false,
  17. isCodeModel:false,
  18. codeImagePath:'',
  19. codeImageToken:'',
  20. imageCode:'',
  21. activeNum:0,
  22. loginTabs:1,
  23. isDisabled:true,
  24. isSubDisabled:true,
  25. mobilCount1:0,
  26. mobileCodeText1:'获取验证码',
  27. mobilTime1:null,
  28. isMobileDisabled1:false,
  29. userParams: {
  30. mobileOrEmail :'',
  31. password : '',
  32. mobile : '',
  33. linkName :'',
  34. smsCode :'',
  35. unionId:'',
  36. companyMobile:'',
  37. passOrNote:1
  38. },
  39. codeParams:{
  40. mobile:'',
  41. code:''
  42. },
  43. smsCodeParams:{// 获取手机短信验证码
  44. mobile: '', //用户登录手机号
  45. },
  46. bindCodeParams:{// 获取运营人员手机验证码
  47. mobile: '',
  48. bindMobile: '',
  49. platformType:0,
  50. isCheckCaptcha:0,
  51. imgCode:'',
  52. token:''
  53. },
  54. verifiParams:{
  55. mobileOrEmail :'',
  56. password : '',
  57. mobile:'',
  58. code:'',
  59. codeType:1
  60. }
  61. },
  62. computed: {
  63. },
  64. methods: {
  65. handleTabsClick(index){// tabs切换
  66. this.loginTabs = this.userParams.passOrNote = this.verifiParams.codeType = index;
  67. this.isDisabled = true;
  68. if(this.loginTabs === 1){
  69. this.userParams.mobileOrEmail = '';
  70. this.userParams.password = '';
  71. }else{
  72. this.userParams.companyMobile = '';
  73. this.codeParams.mobile = '';
  74. this.codeParams.code = '';
  75. }
  76. },
  77. handleStepNext(){// 账号密码 下一步
  78. if(this.isDisabled){ return }
  79. this.userLoginVerification();
  80. },
  81. userLoginVerification(){// 校验短信验证码
  82. const _self = this;
  83. UserApi.userLoginVerification(this.verifiParams,function(response){
  84. if(response.code === 0){
  85. _self.activeNum = 1;
  86. }else{
  87. CAIMEI.Alert(response.msg,'确定',false);
  88. }
  89. });
  90. },
  91. handleInputMobileOrEmail(e){// 账号输入
  92. this.userParams.mobileOrEmail = this.verifiParams.mobileOrEmail = e.target.value;
  93. this.handldeCheckInput();
  94. },
  95. handleInputPassword(e){// 密码输入
  96. this.userParams.password = this.verifiParams.password = e.target.value;
  97. this.handldeCheckInput();
  98. },
  99. handleInputPhone(e){// 已注册手机号输入
  100. this.codeParams.mobile = this.smsCodeParams.mobile = this.verifiParams.mobile = this.userParams.companyMobile = e.target.value;
  101. this.handldeCheckInput();
  102. },
  103. handleInputSmsCode(e){// 短信验证码输入
  104. this.codeParams.code = this.verifiParams.code = e.target.value;
  105. this.handldeCheckInput();
  106. },
  107. handleInputLinkName(e){// 运营人员输入
  108. this.userParams.linkName = e.target.value;
  109. this.handldeCheckInput();
  110. },
  111. handleInputMobile(e){// 运营人员手机号输入
  112. this.userParams.mobile = e.target.value;
  113. this.handldeCheckInput();
  114. },
  115. handleInputSmsCodee(e){// 运营人员手机验证码输入
  116. this.userParams.smsCode = e.target.value;
  117. this.handldeCheckInput();
  118. },
  119. handldeCheckInput(){// 控制按钮高亮
  120. if(this.activeNum === 1){
  121. this.isSubDisabled = !(this.userParams.linkName !== '' && this.userParams.mobile !== '' && this.userParams.smsCode !== '');
  122. }else{
  123. if(this.loginTabs === 0){
  124. this.isDisabled = !(this.userParams.mobileOrEmail !== '' && this.userParams.password !== '');
  125. }else{
  126. this.isDisabled = !(this.codeParams.mobile !== '' && this.codeParams.code !== '');
  127. }
  128. }
  129. },
  130. handleMobileCode(){// 点击获取短信验证码
  131. const _self = this;
  132. if( this.isMobileDisabled1){ return }
  133. this.$nextTick(function() {
  134. if (!verifyCheack('.codeParamsMobile')) { return false; }
  135. UserApi.userOperateCode(_self.smsCodeParams,function (response) {
  136. if(response.code === 0){
  137. CAIMEI.dialog('获取验证码成功~',false,function () {});
  138. _self.genereateMobileCodeText()
  139. }else{
  140. CAIMEI.Alert(response.msg,'确定',false);
  141. _self.isMobileDisabled1 = false;
  142. }
  143. })
  144. })
  145. },
  146. handleBindConfirm(){ //绑定运营人员
  147. const _self = this;
  148. if(this.isSubDisabled){ return }
  149. if (this.loginLoading) { return false; }
  150. if (!verifyForm()) {return false;}
  151. _self.loginLoading = true;
  152. UserApi.BindOrganization(_self.userParams,function (response) {
  153. if(response.code === 0){
  154. var _userIdentity = response.data.userIdentity;
  155. CAIMEI.dialog('绑定成功!',true,function () {
  156. _self.userData = {
  157. account: response.data.account,
  158. email: response.data.email,
  159. phone: response.data.bindMobile,
  160. name: response.data.name ? response.data.name : response.data.userName,
  161. userName: response.data.userName,
  162. userId: response.data.userId,
  163. spId: response.data.serviceProviderId,
  164. clubId: response.data.clubId,
  165. shopId: response.data.shopId,
  166. userIdentity: response.data.userIdentity,
  167. firstClubType: response.data.firstClubType,
  168. permission: response.data.userPermission,
  169. token: response.data.token
  170. };
  171. _self.setStorages( _self.userData);
  172. _self.loginLoading = false;
  173. // 绑定成功后跳转
  174. if(_userIdentity === 4 || _userIdentity ===2){
  175. window.location.href = '/user/dashboard.html';
  176. }else if(_userIdentity === 3){
  177. window.location.href = '/supplier/dashboard.html';
  178. }
  179. });
  180. } else {
  181. CAIMEI.Alert(response.msg,'确定',false);
  182. _self.loginLoading = false;
  183. }
  184. });
  185. },
  186. handleShowImage:function() { //获取图形验证码
  187. const _self = this;
  188. if (!verifyCheack('.mobileOrEmail')) { return false; }
  189. if (!verifyCheack('.massageBtn')) { return false; }
  190. if (this.isMobileDisabled) { return false; }
  191. PublicApi.getImgVerifyCode({platformType: 0},function(response){
  192. if(response.code === 0){
  193. _self.bindCodeParams.imgCode = '';
  194. _self.codeImagePath = response.data.baseImage;
  195. _self.bindCodeParams.token = response.data.token;
  196. _self.isCodeModel = true;
  197. }else{
  198. CAIMEI.Alert(response.msg,'确定',false);
  199. }
  200. })
  201. },
  202. getMobileCodeFn:function(){//机构注册获取注册短信验证码
  203. const _self = this;
  204. if(this.loginTabs === 0){
  205. this.bindCodeParams.bindMobile = this.userParams.mobileOrEmail
  206. }else{
  207. this.bindCodeParams.bindMobile = this.codeParams.mobile
  208. }
  209. if(this.activeNum === 0){
  210. this.bindCodeParams.mobile = this.codeParams.mobile
  211. }else{
  212. this.bindCodeParams.mobile = this.userParams.mobile
  213. }
  214. if( this.isMobileDisabled){ return }
  215. this.$nextTick(function() {
  216. if (!verifyCheack('.codeMsgButton')) {return false; }
  217. UserApi.getNoteSMScode(this.bindCodeParams,function (response) {
  218. if(response.code === 0){
  219. _self.isCodeModel = false;
  220. CAIMEI.dialog('验证短信已发送',false,function () {});
  221. _self.genereateMobileCodeText()
  222. }else{
  223. _self.handleShowImage();
  224. _self.isMobileDisabled = false;
  225. setErrorTxt($('.codeMsgButton'),response.msg);
  226. }
  227. })
  228. })
  229. },
  230. genereateMobileCodeText: function(){
  231. const TIME_COUNT = 60;
  232. const _self = this
  233. if(this.activeNum === 0 && !_self.mobilTime1){
  234. _self.mobilCount1 = TIME_COUNT;
  235. _self.isMobileDisabled1 = true;
  236. _self.mobilTime1 = setInterval(function(){
  237. if (_self.mobilCount1 > 1 && _self.mobilCount1 <= TIME_COUNT) {
  238. _self.mobilCount1--;
  239. _self.mobileCodeText1 = _self.mobilCount1 +'s';
  240. } else {
  241. _self.isMobileDisabled1 = false;
  242. clearInterval(this.mobilTime1);
  243. _self.mobilTime1 = null;
  244. _self.mobileCodeText1 = '获取验证码';
  245. }
  246. },1000)
  247. }else if(this.activeNum === 1 && !_self.mobilTime){
  248. _self.mobilCount = TIME_COUNT;
  249. _self.isMobileDisabled = true;
  250. _self.mobilTime = setInterval(function(){
  251. if (_self.mobilCount > 1 && _self.mobilCount <= TIME_COUNT) {
  252. _self.mobilCount--;
  253. _self.mobileCodeText = _self.mobilCount +'s重新发送';
  254. } else {
  255. _self.isMobileDisabled = false;
  256. clearInterval(_self.mobilTime);
  257. _self.mobilTime = null;
  258. _self.mobileCodeText = '获取验证码';
  259. }
  260. },1000)
  261. }
  262. },
  263. setStorages:function(data){//存储本地数据
  264. localStorage.setItem('userInfo',JSON.stringify(data));
  265. },
  266. handleRefreshCodeImage:function(){
  267. this.handleShowImage()
  268. },
  269. closeCodeModel:function(){
  270. this.isCodeModel = false;
  271. },
  272. blurHandle: function(event) { // 失去焦点校验
  273. var el = event.currentTarget;
  274. verifyHandle(el);
  275. }
  276. },
  277. created: function () {
  278. },
  279. mounted: function () {
  280. if(globalUserData){
  281. this.userParams.unionId = globalUserData.unionId;
  282. }
  283. }
  284. });