index.vue 17 KB

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