index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  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" style="text-align:right;"><a href="/reset/forgetPasswordValidationAccount">忘记密码?</a></p>
  75. </template>
  76. <template v-if="step2.password">
  77. <p class="pwd">手机号已注册,请输入原密码</p>
  78. </template>
  79. </div>
  80. <div class="page-part" v-if="!hasRegister">
  81. <mt-field placeholder="密码确认"
  82. v-model="step2.confirm"
  83. :state="state.confirm"
  84. type="password"
  85. @blur.native.capture="validateConfirm"></mt-field>
  86. </div>
  87. <div class="page-part" v-if="!hasEmail">
  88. <mt-field placeholder="联系邮箱"
  89. v-model="step2.email"
  90. :state="state.email"
  91. type="email"
  92. @blur.native.capture="validateEmail"></mt-field>
  93. </div>
  94. </div>
  95. <div class="form-btn">
  96. <mt-button type="primary" size="large" @click.native="sureRegister">完成注册</mt-button>
  97. </div>
  98. </template>
  99. </div>
  100. </template>
  101. <script>
  102. export default {
  103. name: 'registerEnterprise',
  104. data () {
  105. return {
  106. step: 1,
  107. state: {
  108. mobile: 'error',
  109. token: 'error',
  110. spaceName: 'error',
  111. businessCode: 'error',
  112. vipName: 'error',
  113. password: 'error',
  114. confirm: 'error',
  115. email: 'error'
  116. },
  117. step1: {
  118. mobile: '',
  119. token: ''
  120. },
  121. step2: {
  122. spaceName: '',
  123. businessCode: '',
  124. vipName: '',
  125. password: '',
  126. confirm: '',
  127. email: ''
  128. },
  129. checked: true,
  130. tokenCode: '',
  131. tokenTime: 60,
  132. tokenText: '获取验证码',
  133. hasRegister: false,
  134. hasEmail: false,
  135. progress: '弱'
  136. }
  137. },
  138. methods: {
  139. // 弹窗处理
  140. downToast (type) {
  141. this.$toast({
  142. message: type,
  143. iconClass: 'el-icon-warning'
  144. })
  145. },
  146. // 验证手机号
  147. validateMobile () {
  148. let reg = /^1[0-9]{10}$/
  149. if (!this.step1.mobile) {
  150. this.downToast('请先填写手机号')
  151. } else {
  152. if (!reg.test(this.step1.mobile)) {
  153. this.downToast('请填写正确的手机号')
  154. this.state.mobile = 'warning'
  155. } else {
  156. this.state.mobile = 'success'
  157. }
  158. }
  159. },
  160. // 验证正确的验证码
  161. validateCode () {
  162. if (!this.step1.token) {
  163. this.downToast('请先填写验证码')
  164. } else {
  165. if (!this.step1.mobile) {
  166. this.downToast('请先填写正确的手机号码')
  167. this.state.token = 'warning'
  168. } else {
  169. if (this.tokenCode) {
  170. let param = new FormData()
  171. param.append('mobile', this.step1.mobile)
  172. param.append('token', this.tokenCode)
  173. param.append('code', this.step1.token)
  174. let config = {
  175. headers: {'Content-Type': 'multipart/form-data'}
  176. }
  177. this.$http.post('/sso/personal/register/checkCode', param, config)
  178. .then(response => {
  179. if (response.data.success) {
  180. this.state.token = 'success'
  181. } else {
  182. this.$toast({
  183. message: response.data.errMsg,
  184. iconClass: 'el-icon-error'
  185. })
  186. }
  187. }).catch(() => {
  188. this.downToast('请检查网络是否正常或联系服务商')
  189. })
  190. } else {
  191. this.downToast('请点击先获取验证码信息')
  192. this.state.token = 'warning'
  193. }
  194. }
  195. }
  196. },
  197. // 获取验证码
  198. getCheckCode () {
  199. if (this.tokenTime > 0 && this.tokenTime < 60) {
  200. this.downToast('请稍后再点击,我在倒计时')
  201. } else {
  202. if (this.state.mobile !== 'success') {
  203. this.downToast('请先输入正确的手机号')
  204. } else {
  205. this.$indicator.open('获取中...')
  206. let _this = this
  207. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile}})
  208. .then(response => {
  209. this.$indicator.close()
  210. if (response.data) {
  211. this.tokenCode = response.data.token
  212. this.$toast({
  213. message: '验证码已经发送到您的手机,请注意查收',
  214. iconClass: 'el-icon-success'
  215. })
  216. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  217. let setTime = setInterval(() => {
  218. _this.tokenTime--
  219. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  220. if (this.tokenTime <= 0) {
  221. clearInterval(setTime)
  222. _this.tokenText = '获取验证码'
  223. _this.tokenTime = 60
  224. }
  225. }, 1000)
  226. }
  227. }).catch(() => {
  228. this.$indicator.close()
  229. this.downToast('请检查网络是否正常或联系服务商')
  230. })
  231. }
  232. }
  233. },
  234. // 验证手机
  235. checkPhone () {
  236. if (!this.state.mobile === 'success' && !this.state.token === 'success') {
  237. this.downToast('请确认填写部分是否有误')
  238. } else if (this.checked === false) {
  239. this.downToast('您对阅读条款未做勾选')
  240. } else {
  241. this.$indicator.open('验证手机中...')
  242. let param = new FormData()
  243. param.append('mobile', this.step1.mobile)
  244. param.append('code', this.step1.token)
  245. param.append('appId', this.$store.state.option.appId)
  246. param.append('token', this.tokenCode)
  247. let config = {
  248. headers: {'Content-Type': 'multipart/form-data'}
  249. }
  250. this.$http.post('/sso/userspace/register/checkAdminTel', param, config)
  251. .then(response => {
  252. this.$indicator.close()
  253. if (response.data.success) {
  254. response.data.content.hasEmail ? this.hasEmail = true : this.hasEmail = false
  255. response.data.content.hasRegister ? this.hasRegister = true : this.hasRegister = false
  256. this.step = 2
  257. }
  258. }).catch(() => {
  259. this.$indicator.close()
  260. this.downToast('请检查网络是否正常或联系服务商')
  261. })
  262. }
  263. },
  264. // 验证企业名
  265. validateSpaceName () {
  266. if (!this.step2.spaceName) {
  267. this.downToast('请填写企业名称')
  268. } else {
  269. if (this.step2.spaceName.length > 20) {
  270. this.downToast('输入长度过长,限定20个字符以内')
  271. this.state.spaceName = 'warning'
  272. } else {
  273. this.$http.get(`/api/userspace/checkSpaceName`, {params: {spaceName: this.step2.spaceName}})
  274. .then(response => {
  275. if (response.data.success) {
  276. this.state.spaceName = 'success'
  277. } else {
  278. this.state.spaceName = 'warning'
  279. this.downToast(response.data.errMsg)
  280. }
  281. })
  282. }
  283. }
  284. },
  285. // 验证营业号
  286. validateBusinessCode () {
  287. let reg = /^[A-Za-z0-9]+$/
  288. if (!this.step2.businessCode) {
  289. this.downToast('请填写营业执照号')
  290. } else {
  291. if (!reg.test(this.step2.businessCode)) {
  292. this.downToast('请填写正确的营业执照号')
  293. this.state.businessCode = 'warning'
  294. } else {
  295. this.$http.get(`/api/userspace/checkBusinessCode`, {params: {businessCode: this.step2.businessCode}})
  296. .then(response => {
  297. if (response.data.success) {
  298. this.state.businessCode = 'success'
  299. } else {
  300. this.state.businessCode = 'warning'
  301. this.downToast(response.data.errMsg)
  302. }
  303. })
  304. }
  305. }
  306. },
  307. // 验证管理员名
  308. validateVipName () {
  309. if (!this.step2.vipName) {
  310. this.downToast('请填写管理员姓名')
  311. } else {
  312. if (this.step2.vipName.length > 20) {
  313. this.downToast('输入长度请限制在20个字符以内')
  314. this.state.vipName = 'warning'
  315. } else {
  316. this.state.vipName = 'success'
  317. }
  318. }
  319. },
  320. // 验证密码强度
  321. validatePassword () {
  322. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  323. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  324. let count = this.step2.password.length
  325. if (count >= 20) {
  326. this.downToast('密码须为8-20字符的英文、数字混合')
  327. } else {
  328. if (reg1.test(this.step2.password)) {
  329. this.progress = '强'
  330. } else if (reg2.test(this.step2.password)) {
  331. this.progress = '中'
  332. } else {
  333. this.progress = '弱'
  334. }
  335. }
  336. },
  337. // 验证密码
  338. validatePasswordTip () {
  339. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  340. if (!this.step2.password) {
  341. this.downToast('请输入密码')
  342. } else {
  343. if (!reg2.test(this.step2.password)) {
  344. this.downToast('密码须为8-20字符的英文、数字混合')
  345. this.state.password = 'warning'
  346. } else {
  347. this.state.password = 'success'
  348. }
  349. }
  350. },
  351. // 验证密码
  352. validatePasswordTipHas () {
  353. if (!this.step2.password) {
  354. this.downToast('请输入密码')
  355. } else {
  356. this.state.password = 'success'
  357. }
  358. },
  359. // 验证二次密码
  360. validateConfirm () {
  361. if (!this.step2.confirm) {
  362. this.downToast('请再次输入密码')
  363. } else {
  364. if (this.step2.confirm === this.step2.password) {
  365. this.state.confirm = 'success'
  366. } else {
  367. this.state.confirm = 'warning'
  368. this.downToast('两次输入密码不一致,请重新输入')
  369. }
  370. }
  371. },
  372. // 验证邮箱
  373. validateEmail () {
  374. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  375. if (!this.step2.email) {
  376. this.downToast('请填写联系邮箱信息')
  377. } else {
  378. if (!reg.test(this.step2.email)) {
  379. this.downToast('请输入正确的邮箱地址格式')
  380. this.state.email = 'warning'
  381. } else {
  382. this.state.email = 'success'
  383. }
  384. }
  385. },
  386. // 注册请求方法
  387. sbmitRegister () {
  388. this.$indicator.open('注册中...')
  389. let param = new FormData()
  390. param.append('spaceName', this.step2.spaceName)
  391. param.append('businessCode', this.step2.businessCode)
  392. param.append('vipName', this.step2.vipName || '')
  393. param.append('password', this.step2.password)
  394. param.append('email', this.step2.email || '')
  395. param.append('appId', this.$store.state.option.appId)
  396. let config = {
  397. headers: {'Content-Type': 'multipart/form-data'}
  398. }
  399. this.$http.post('/sso/userspace/register', param, config)
  400. .then(response => {
  401. this.$indicator.close()
  402. if (response.data.success) {
  403. window.location.href = '/overRegister/overEnterprise'
  404. } else {
  405. this.downToast(response.data.errMsg)
  406. }
  407. }).catch(() => {
  408. this.$indicator.close()
  409. this.downToast('请检查网络是否正常或联系服务商')
  410. })
  411. },
  412. // 企业注册
  413. sureRegister () {
  414. if (!this.hasRegister) {
  415. if (!this.state.spaceName === 'success' &&
  416. !this.state.businessCode === 'success' &&
  417. !this.state.vipName === 'success' &&
  418. !this.state.password === 'success' &&
  419. !this.state.confirm === 'success' &&
  420. !this.state.email === 'success') {
  421. this.downToast('请确认填写部分是否有误')
  422. } else {
  423. this.sbmitRegister()
  424. }
  425. } else {
  426. if (!this.hasEmail) {
  427. if (!this.state.spaceName === 'success' &&
  428. !this.state.businessCode === 'success' &&
  429. !this.state.password === 'success' &&
  430. !this.state.email === 'success') {
  431. this.downToast('请确认填写部分是否有误')
  432. } else {
  433. this.sbmitRegister()
  434. }
  435. } else {
  436. if (!this.state.spaceName === 'success' &&
  437. !this.state.businessCode === 'success' &&
  438. !this.state.password === 'success') {
  439. this.downToast('请确认填写部分是否有误')
  440. } else {
  441. this.sbmitRegister()
  442. }
  443. }
  444. }
  445. }
  446. }
  447. }
  448. </script>