index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>企业注册</p>
  5. <a class="go" href="/register/personalRegistration"><i class="fa fa-long-arrow-right"></i>个人注册</a>
  6. </div>
  7. <template v-if="step === 1">
  8. <div class="f-form">
  9. <div class="page-part">
  10. <mt-field placeholder="手机号码"
  11. v-model="step1.mobile"
  12. :state="state.mobile"
  13. type="tel"
  14. @blur.native.capture="validateMobile"
  15. ></mt-field>
  16. </div>
  17. <div class="page-part">
  18. <mt-field auto-complete="off"
  19. placeholder="短信验证码"
  20. v-model="step1.token"
  21. :state="state.token"
  22. @blur.native.capture="validateCode">
  23. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  24. </mt-field>
  25. </div>
  26. </div>
  27. <div class="form-btn">
  28. <div class="page-part">
  29. <el-checkbox v-model="checked">我已阅读并同意 <a href="/common/agreement" class="rgba">《优软云服务条款》</a></el-checkbox>
  30. </div>
  31. <mt-button type="primary" size="large" @click.native="checkPhone">验证手机</mt-button>
  32. </div>
  33. </template>
  34. <template v-if="step === 2">
  35. <div class="f-form">
  36. <div class="page-part">
  37. <mt-field placeholder="企业名称"
  38. v-model="step2.spaceName"
  39. :state="state.spaceName"
  40. @blur.native.capture="validateSpaceName"></mt-field>
  41. </div>
  42. <div class="page-part">
  43. <mt-field placeholder="营业护照号"
  44. v-model="step2.businessCode"
  45. :state="state.businessCode"
  46. @blur.native.capture="validateBusinessCode"></mt-field>
  47. </div>
  48. <div class="page-part" v-if="!hasRegister">
  49. <mt-field placeholder="管理员号码"
  50. v-model="step2.vipName"
  51. :state="state.vipName"
  52. @blur.native.capture="validateVipName"></mt-field>
  53. </div>
  54. <div class="page-part" v-if="!hasRegister">
  55. <mt-field placeholder="登录密码"
  56. :attr="{ maxlength: 20 }"
  57. v-model="step2.password"
  58. :state="state.password"
  59. type="password"
  60. @input.native="validatePassword"
  61. @blur.native.capture="validatePasswordTip"></mt-field>
  62. <template v-if="step2.password">
  63. <p class="pwd">密码强度 <em :class="{sm:progress === '弱', md: progress === '中', ld:progress === '强'}"></em> <em :class="{md: progress === '中', ld:progress === '强'}"></em> <em :class="{ld:progress === '强'}"></em> <span :class="{smstep:progress === '弱', mdstep: progress === '中', ldstep:progress === '强'}" v-text="progress">强</span></p>
  64. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  65. </template>
  66. </div>
  67. <div class="page-part" v-if="hasRegister">
  68. <mt-field placeholder="登录密码"
  69. v-model="step2.password"
  70. :state="state.password"
  71. type="password"
  72. @blur.native.capture="validatePasswordTipHas"></mt-field>
  73. <template v-if="step2.password">
  74. <p class="pwd">手机号已注册,请输入原密码</p>
  75. </template>
  76. </div>
  77. <div class="page-part" v-if="!hasRegister">
  78. <mt-field placeholder="密码确认"
  79. v-model="step2.confirm"
  80. :state="state.confirm"
  81. type="password"
  82. @blur.native.capture="validateConfirm"></mt-field>
  83. </div>
  84. <div class="page-part" v-if="!hasEmail">
  85. <mt-field placeholder="联系邮箱"
  86. v-model="step2.email"
  87. :state="state.email"
  88. type="email"
  89. @blur.native.capture="validateEmail"></mt-field>
  90. </div>
  91. </div>
  92. <div class="form-btn">
  93. <mt-button type="primary" size="large" @click.native="sureRegister">完成注册</mt-button>
  94. </div>
  95. </template>
  96. </div>
  97. </template>
  98. <script>
  99. export default {
  100. name: 'registerEnterprise',
  101. data () {
  102. return {
  103. step: 1,
  104. state: {
  105. mobile: 'error',
  106. token: 'error',
  107. spaceName: 'error',
  108. businessCode: 'error',
  109. vipName: 'error',
  110. password: 'error',
  111. confirm: 'error',
  112. email: 'error'
  113. },
  114. step1: {
  115. mobile: '',
  116. token: ''
  117. },
  118. step2: {
  119. spaceName: '',
  120. businessCode: '',
  121. vipName: '',
  122. password: '',
  123. confirm: '',
  124. email: ''
  125. },
  126. checked: true,
  127. tokenCode: '',
  128. tokenTime: 60,
  129. tokenText: '获取验证码',
  130. hasRegister: false,
  131. hasEmail: false,
  132. progress: '弱'
  133. }
  134. },
  135. methods: {
  136. // 弹窗处理
  137. downToast (type) {
  138. this.$toast({
  139. message: type,
  140. iconClass: 'el-icon-warning'
  141. })
  142. },
  143. // 验证手机号
  144. validateMobile () {
  145. let reg = /^1[0-9]{10}$/
  146. if (!this.step1.mobile) {
  147. this.downToast('请先填写手机号')
  148. } else {
  149. if (!reg.test(this.step1.mobile)) {
  150. this.downToast('请填写正确的手机号')
  151. this.state.mobile = 'warning'
  152. } else {
  153. this.state.mobile = 'success'
  154. }
  155. }
  156. },
  157. // 验证正确的验证码
  158. validateCode () {
  159. if (!this.step1.token) {
  160. this.downToast('请先填写验证码')
  161. } else {
  162. if (!this.step1.mobile) {
  163. this.downToast('请先填写正确的手机号码')
  164. this.state.token = 'warning'
  165. } else {
  166. if (this.tokenCode) {
  167. let param = new FormData()
  168. param.append('mobile', this.step1.mobile)
  169. param.append('token', this.tokenCode)
  170. param.append('code', this.step1.token)
  171. let config = {
  172. headers: {'Content-Type': 'multipart/form-data'}
  173. }
  174. this.$http.post('/sso/personal/register/checkCode', param, config)
  175. .then(response => {
  176. if (response.data.success) {
  177. this.state.token = 'success'
  178. } else {
  179. this.$toast({
  180. message: response.data.errMsg,
  181. iconClass: 'el-icon-error'
  182. })
  183. }
  184. }).catch(() => {
  185. this.downToast('请检查网络是否正常或联系服务商')
  186. })
  187. } else {
  188. this.downToast('请点击先获取验证码信息')
  189. this.state.token = 'warning'
  190. }
  191. }
  192. }
  193. },
  194. // 获取验证码
  195. getCheckCode () {
  196. if (this.tokenTime > 0 && this.tokenTime < 60) {
  197. this.downToast('请稍后再点击,我在倒计时')
  198. } else {
  199. if (this.state.mobile !== 'success') {
  200. this.downToast('请先输入正确的手机号')
  201. } else {
  202. this.$indicator.open('获取中...')
  203. let _this = this
  204. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile}})
  205. .then(response => {
  206. this.$indicator.close()
  207. if (response.data) {
  208. this.tokenCode = response.data.token
  209. this.$toast({
  210. message: '验证码已经发送到您的手机,请注意查收',
  211. iconClass: 'el-icon-success'
  212. })
  213. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  214. let setTime = setInterval(() => {
  215. _this.tokenTime--
  216. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  217. if (this.tokenTime <= 0) {
  218. clearInterval(setTime)
  219. _this.tokenText = '获取验证码'
  220. _this.tokenTime = 60
  221. }
  222. }, 1000)
  223. }
  224. }).catch(() => {
  225. this.$indicator.close()
  226. this.downToast('请检查网络是否正常或联系服务商')
  227. })
  228. }
  229. }
  230. },
  231. // 验证手机
  232. checkPhone () {
  233. if (!this.state.mobile === 'success' && !this.state.token === 'success') {
  234. this.downToast('请确认填写部分是否有误')
  235. } else if (this.checked === false) {
  236. this.downToast('您对阅读条款未做勾选')
  237. } else {
  238. this.$indicator.open('验证手机中...')
  239. let param = new FormData()
  240. param.append('mobile', this.step1.mobile)
  241. param.append('code', this.step1.token)
  242. param.append('appId', this.$store.state.option.appId)
  243. param.append('token', this.tokenCode)
  244. let config = {
  245. headers: {'Content-Type': 'multipart/form-data'}
  246. }
  247. this.$http.post('/sso/userspace/register/checkAdminTel', param, config)
  248. .then(response => {
  249. this.$indicator.close()
  250. if (response.data.success) {
  251. response.data.content.hasEmail ? this.hasEmail = true : this.hasEmail = false
  252. response.data.content.hasRegister ? this.hasRegister = true : this.hasRegister = false
  253. this.step = 2
  254. }
  255. }).catch(() => {
  256. this.$indicator.close()
  257. this.downToast('请检查网络是否正常或联系服务商')
  258. })
  259. }
  260. },
  261. // 验证企业名
  262. validateSpaceName () {
  263. if (!this.step2.spaceName) {
  264. this.downToast('请填写企业名称')
  265. } else {
  266. if (this.step2.spaceName.length > 20) {
  267. this.downToast('输入长度过长,限定20个字符以内')
  268. this.state.spaceName = 'warning'
  269. } else {
  270. this.$http.get(`/api/userspace/checkSpaceName`, {params: {spaceName: this.step2.spaceName}})
  271. .then(response => {
  272. if (response.data.success) {
  273. this.state.spaceName = 'success'
  274. } else {
  275. this.state.spaceName = 'warning'
  276. this.downToast(response.data.errMsg)
  277. }
  278. })
  279. }
  280. }
  281. },
  282. // 验证营业号
  283. validateBusinessCode () {
  284. let reg = /^[A-Za-z0-9]+$/
  285. if (!this.step2.businessCode) {
  286. this.downToast('请填写营业执照号')
  287. } else {
  288. if (!reg.test(this.step2.businessCode)) {
  289. this.downToast('请填写正确的营业执照号')
  290. this.state.businessCode = 'warning'
  291. } else {
  292. this.$http.get(`/api/userspace/checkBusinessCode`, {params: {businessCode: this.step2.businessCode}})
  293. .then(response => {
  294. if (response.data.success) {
  295. this.state.businessCode = 'success'
  296. } else {
  297. this.state.businessCode = 'warning'
  298. this.downToast(response.data.errMsg)
  299. }
  300. })
  301. }
  302. }
  303. },
  304. // 验证管理员名
  305. validateVipName () {
  306. if (!this.step2.vipName) {
  307. this.downToast('请填写管理员姓名')
  308. } else {
  309. if (this.step2.vipName.length > 20) {
  310. this.downToast('输入长度请限制在20个字符以内')
  311. this.state.vipName = 'warning'
  312. } else {
  313. this.state.vipName = 'success'
  314. }
  315. }
  316. },
  317. // 验证密码强度
  318. validatePassword () {
  319. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  320. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  321. let count = this.step2.password.length
  322. if (count >= 20) {
  323. this.downToast('密码须为8-20字符的英文、数字混合')
  324. } else {
  325. if (reg1.test(this.step2.password)) {
  326. this.progress = '强'
  327. } else if (reg2.test(this.step2.password)) {
  328. this.progress = '中'
  329. } else {
  330. this.progress = '弱'
  331. }
  332. }
  333. },
  334. // 验证密码
  335. validatePasswordTip () {
  336. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  337. if (!this.step2.password) {
  338. this.downToast('请输入密码')
  339. } else {
  340. if (!reg2.test(this.step2.password)) {
  341. this.downToast('密码须为8-20字符的英文、数字混合')
  342. this.state.password = 'warning'
  343. } else {
  344. this.state.password = 'success'
  345. }
  346. }
  347. },
  348. // 验证密码
  349. validatePasswordTipHas () {
  350. if (!this.step2.password) {
  351. this.downToast('请输入密码')
  352. } else {
  353. this.state.password = 'success'
  354. }
  355. },
  356. // 验证二次密码
  357. validateConfirm () {
  358. if (!this.step2.confirm) {
  359. this.downToast('请再次输入密码')
  360. } else {
  361. if (this.step2.confirm === this.step2.password) {
  362. this.state.confirm = 'success'
  363. } else {
  364. this.state.confirm = 'warning'
  365. this.downToast('两次输入密码不一致,请重新输入')
  366. }
  367. }
  368. },
  369. // 验证邮箱
  370. validateEmail () {
  371. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  372. if (!this.step2.email) {
  373. this.downToast('请填写联系邮箱信息')
  374. } else {
  375. if (!reg.test(this.step2.email)) {
  376. this.downToast('请输入正确的邮箱地址格式')
  377. this.state.email = 'warning'
  378. } else {
  379. this.state.email = 'success'
  380. }
  381. }
  382. },
  383. // 注册请求方法
  384. sbmitRegister () {
  385. this.$indicator.open('注册中...')
  386. let param = new FormData()
  387. param.append('spaceName', this.step2.spaceName)
  388. param.append('businessCode', this.step2.businessCode)
  389. param.append('vipName', this.step2.vipName || '')
  390. param.append('password', this.step2.password)
  391. param.append('email', this.step2.email || '')
  392. param.append('appId', this.$store.state.option.appId)
  393. let config = {
  394. headers: {'Content-Type': 'multipart/form-data'}
  395. }
  396. this.$http.post('/sso/userspace/register', param, config)
  397. .then(response => {
  398. this.$indicator.close()
  399. if (response.data.success) {
  400. window.location.href = '/overRegister/overEnterprise'
  401. } else {
  402. this.downToast(response.data.errMsg)
  403. }
  404. }).catch(() => {
  405. this.$indicator.close()
  406. this.downToast('请检查网络是否正常或联系服务商')
  407. })
  408. },
  409. // 企业注册
  410. sureRegister () {
  411. if (!this.hasRegister) {
  412. if (!this.state.spaceName === 'success' &&
  413. !this.state.businessCode === 'success' &&
  414. !this.state.vipName === 'success' &&
  415. !this.state.password === 'success' &&
  416. !this.state.confirm === 'success' &&
  417. !this.state.email === 'success') {
  418. this.downToast('请确认填写部分是否有误')
  419. } else {
  420. this.sbmitRegister()
  421. }
  422. } else {
  423. if (!this.hasEmail) {
  424. if (!this.state.spaceName === 'success' &&
  425. !this.state.businessCode === 'success' &&
  426. !this.state.password === 'success' &&
  427. !this.state.email === 'success') {
  428. this.downToast('请确认填写部分是否有误')
  429. } else {
  430. this.sbmitRegister()
  431. }
  432. } else {
  433. if (!this.state.spaceName === 'success' &&
  434. !this.state.businessCode === 'success' &&
  435. !this.state.password === 'success') {
  436. this.downToast('请确认填写部分是否有误')
  437. } else {
  438. this.sbmitRegister()
  439. }
  440. }
  441. }
  442. }
  443. }
  444. }
  445. </script>
  446. <style scoped type="text/scss" lang="scss">
  447. .f-main{
  448. background: #fff;
  449. padding:0.55rem .3rem 1.1rem;
  450. .content-top{
  451. position:relative;
  452. p{
  453. font-size: .4rem;
  454. color:#787878;
  455. margin-bottom:.35rem;
  456. }
  457. a.go{
  458. position: absolute;
  459. top: 0;
  460. right: 0;
  461. font-size: .28rem;
  462. i{
  463. margin-right: .06rem;
  464. }
  465. }
  466. }
  467. .f-form{
  468. border-top:1px solid #b5b5b5;
  469. padding-top:.6rem;
  470. .pwd{
  471. font-size: .14rem;
  472. color:#a0a0a0;
  473. margin: .2rem auto;
  474. em{
  475. display: inline-block;
  476. line-height: .14rem;
  477. margin:.05rem .2rem;
  478. width: .45rem;
  479. height: .1rem;
  480. }
  481. .sm{background:#ff4e00}
  482. .md{background: #22ac38}
  483. .ld{background: #00a0e9}
  484. .smstep{color:#ff4e00}
  485. .mdstep{color: #22ac38}
  486. .ldstep{color: #00a0e9}
  487. }
  488. .token{
  489. display:inline-block;
  490. padding: 0 .5rem;
  491. text-align: center;
  492. border-left:1px solid #b5b5b5;
  493. color:#2d8cf0;
  494. margin-left: .1rem;
  495. }
  496. }
  497. }
  498. </style>