bind.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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:0,
  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:0
  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:0
  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. const TIME_COUNT = 60;
  139. if (!_self.mobilTime1) {
  140. _self.mobilCount1 = TIME_COUNT;
  141. _self.isMobileDisabled1 = true;
  142. _self.mobilTime1 = setInterval(function(){
  143. if (_self.mobilCount1 > 1 && _self.mobilCount1 <= TIME_COUNT) {
  144. _self.mobilCount1--;
  145. _self.mobileCodeText1 = _self.mobilCount1 +'s';
  146. } else {
  147. _self.isMobileDisabled1 = false;
  148. clearInterval(_self.mobilTime1);
  149. _self.mobilTime1 = null;
  150. _self.mobileCodeText1 = '获取验证码';
  151. }
  152. },1000)
  153. }
  154. }else{
  155. CAIMEI.Alert(response.msg,'确定',false);
  156. _self.isMobileDisabled1 = false;
  157. }
  158. })
  159. })
  160. },
  161. handleBindConfirm(){ //绑定运营人员
  162. const _self = this;
  163. if(this.isSubDisabled){ return }
  164. if (this.loginLoading) { return false; }
  165. if (!verifyForm()) {return false;}
  166. _self.loginLoading = true;
  167. UserApi.BindOrganization(_self.userParams,function (response) {
  168. if(response.code === 0){
  169. var _userIdentity = response.data.userIdentity;
  170. CAIMEI.dialog('绑定成功!',true,function () {
  171. _self.userData = {
  172. account: response.data.account,
  173. email: response.data.email,
  174. phone: response.data.bindMobile,
  175. name: response.data.name ? response.data.name : response.data.userName,
  176. userName: response.data.userName,
  177. userId: response.data.userId,
  178. spId: response.data.serviceProviderId,
  179. clubId: response.data.clubId,
  180. shopId: response.data.shopId,
  181. userIdentity: response.data.userIdentity,
  182. firstClubType: response.data.firstClubType,
  183. permission: response.data.userPermission,
  184. token: response.data.token
  185. };
  186. _self.setStorages( _self.userData);
  187. _self.loginLoading = false;
  188. // 绑定成功后跳转
  189. if(_userIdentity === 4 || _userIdentity ===2){
  190. window.location.href = '/user/dashboard.html';
  191. }else if(_userIdentity === 3){
  192. window.location.href = '/supplier/dashboard.html';
  193. }
  194. });
  195. } else {
  196. CAIMEI.Alert(response.msg,'确定',false);
  197. _self.loginLoading = false;
  198. }
  199. });
  200. },
  201. handleShowImage:function() { //获取图形验证码
  202. const _self = this;
  203. if (!verifyCheack('.mobileOrEmail')) { return false; }
  204. if (!verifyCheack('.massageBtn')) { return false; }
  205. if (this.isMobileDisabled) { return false; }
  206. PublicApi.getImgVerifyCode({platformType: 0},function(response){
  207. if(response.code === 0){
  208. _self.bindCodeParams.imgCode = '';
  209. _self.codeImagePath = response.data.baseImage;
  210. _self.bindCodeParams.token = response.data.token;
  211. _self.isCodeModel = true;
  212. }else{
  213. CAIMEI.Alert(response.msg,'确定',false);
  214. }
  215. })
  216. },
  217. getMobileCodeFn:function(){//机构注册获取注册短信验证码
  218. const _self = this;
  219. if(this.loginTabs === 0){
  220. this.bindCodeParams.bindMobile = this.userParams.mobileOrEmail
  221. }else{
  222. this.bindCodeParams.bindMobile = this.codeParams.mobile
  223. }
  224. this.bindCodeParams.mobile = this.userParams.mobile
  225. if( this.isMobileDisabled){ return }
  226. this.$nextTick(function() {
  227. if (!verifyCheack('.codeMsgButton')) {return false; }
  228. UserApi.getNoteSMScode(this.bindCodeParams,function (response) {
  229. if(response.code === 0){
  230. _self.isCodeModel = false;
  231. CAIMEI.dialog('验证短信已发送',false,function () {});
  232. var TIME_COUNT = 60;
  233. if (!_self.mobilTime) {
  234. _self.mobilCount = TIME_COUNT;
  235. _self.isMobileDisabled = true;
  236. _self.mobilTime = setInterval(function(){
  237. if (_self.mobilCount > 1 && _self.mobilCount <= TIME_COUNT) {
  238. _self.mobilCount--;
  239. _self.mobileCodeText = _self.mobilCount +'s重新发送';
  240. } else {
  241. _self.isMobileDisabled = false;
  242. clearInterval(_self.mobilTime);
  243. _self.mobilTime = null;
  244. _self.mobileCodeText = '获取验证码';
  245. }
  246. },1000)
  247. }
  248. }else{
  249. _self.handleShowImage();
  250. _self.isMobileDisabled = false;
  251. setErrorTxt($('.codeMsgButton'),response.msg);
  252. }
  253. })
  254. })
  255. },
  256. setStorages:function(data){//存储本地数据
  257. localStorage.setItem('userInfo',JSON.stringify(data));
  258. },
  259. handleRefreshCodeImage:function(){
  260. this.handleShowImage()
  261. },
  262. closeCodeModel:function(){
  263. this.isCodeModel = false;
  264. },
  265. blurHandle: function(event) { // 失去焦点校验
  266. var el = event.currentTarget;
  267. verifyHandle(el);
  268. }
  269. },
  270. created: function () {
  271. },
  272. mounted: function () {
  273. if(globalUserData){
  274. this.userParams.unionId = globalUserData.unionId;
  275. }
  276. }
  277. });