index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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. this.state.mobile = 'error'
  152. } else {
  153. if (!reg.test(this.step1.mobile)) {
  154. this.downToast('请填写正确的手机号')
  155. this.state.mobile = 'warning'
  156. } else {
  157. this.state.mobile = 'success'
  158. }
  159. }
  160. },
  161. // 验证正确的验证码
  162. validateCode () {
  163. if (!this.step1.token) {
  164. this.downToast('请先填写验证码')
  165. this.state.token = 'error'
  166. } else {
  167. if (!this.step1.mobile) {
  168. this.downToast('请先填写正确的手机号码')
  169. this.state.token = 'warning'
  170. } else {
  171. if (this.tokenCode) {
  172. let param = new FormData()
  173. param.append('mobile', this.step1.mobile)
  174. param.append('token', this.tokenCode)
  175. param.append('code', this.step1.token)
  176. let config = {
  177. headers: {'Content-Type': 'multipart/form-data'}
  178. }
  179. this.$http.post('/sso/personal/register/checkCode', param, config)
  180. .then(response => {
  181. if (response.data.success) {
  182. this.state.token = 'success'
  183. } else {
  184. this.$toast({
  185. message: response.data.errMsg,
  186. iconClass: 'el-icon-error'
  187. })
  188. }
  189. }).catch(() => {
  190. this.downToast('请检查网络是否正常或联系服务商')
  191. })
  192. } else {
  193. this.downToast('请点击先获取验证码信息')
  194. this.state.token = 'warning'
  195. }
  196. }
  197. }
  198. },
  199. // 获取验证码
  200. getCheckCode () {
  201. if (this.tokenTime > 0 && this.tokenTime < 60) {
  202. this.downToast('请稍后再点击,我在倒计时')
  203. } else {
  204. if (this.state.mobile !== 'success') {
  205. this.downToast('请先输入正确的手机号')
  206. } else {
  207. this.$indicator.open('获取中...')
  208. let _this = this
  209. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.step1.mobile}})
  210. .then(response => {
  211. this.$indicator.close()
  212. if (response.data) {
  213. this.tokenCode = response.data.token
  214. this.$toast({
  215. message: '验证码已经发送到您的手机,请注意查收',
  216. iconClass: 'el-icon-success'
  217. })
  218. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  219. let setTime = setInterval(() => {
  220. _this.tokenTime--
  221. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  222. if (this.tokenTime <= 0) {
  223. clearInterval(setTime)
  224. _this.tokenText = '获取验证码'
  225. _this.tokenTime = 60
  226. }
  227. }, 1000)
  228. }
  229. }).catch(() => {
  230. this.$indicator.close()
  231. this.downToast('请检查网络是否正常或联系服务商')
  232. })
  233. }
  234. }
  235. },
  236. // 验证手机
  237. checkPhone () {
  238. if (!this.state.mobile === 'success' && !this.state.token === 'success') {
  239. this.downToast('请确认填写部分是否有误')
  240. } else if (this.checked === false) {
  241. this.downToast('您对阅读条款未做勾选')
  242. } else {
  243. this.$indicator.open('验证手机中...')
  244. let param = new FormData()
  245. param.append('mobile', this.step1.mobile)
  246. param.append('code', this.step1.token)
  247. param.append('appId', this.$store.state.option.appId)
  248. param.append('token', this.tokenCode)
  249. let config = {
  250. headers: {'Content-Type': 'multipart/form-data'}
  251. }
  252. this.$http.post('/sso/userspace/register/checkAdminTel', param, config)
  253. .then(response => {
  254. this.$indicator.close()
  255. if (response.data.success) {
  256. response.data.content.hasEmail ? this.hasEmail = true : this.hasEmail = false
  257. response.data.content.hasRegister ? this.hasRegister = true : this.hasRegister = false
  258. this.step = 2
  259. }
  260. }).catch(() => {
  261. this.$indicator.close()
  262. this.downToast('请检查网络是否正常或联系服务商')
  263. })
  264. }
  265. },
  266. // 验证企业名
  267. validateSpaceName () {
  268. if (!this.step2.spaceName) {
  269. this.downToast('请填写企业名称')
  270. this.state.spaceName = 'error'
  271. } else {
  272. if (this.step2.spaceName.length > 20) {
  273. this.downToast('输入长度过长,限定20个字符以内')
  274. this.state.spaceName = 'warning'
  275. } else {
  276. this.$http.get(`/api/userspace/checkSpaceName`, {params: {spaceName: this.step2.spaceName}})
  277. .then(response => {
  278. if (response.data.success) {
  279. this.state.spaceName = 'success'
  280. } else {
  281. this.state.spaceName = 'warning'
  282. this.downToast(response.data.errMsg)
  283. }
  284. })
  285. }
  286. }
  287. },
  288. // 验证营业号
  289. validateBusinessCode () {
  290. let reg = /^[A-Za-z0-9]+$/
  291. if (!this.step2.businessCode) {
  292. this.downToast('请填写营业执照号')
  293. this.state.businessCode = 'error'
  294. } else {
  295. if (!reg.test(this.step2.businessCode)) {
  296. this.downToast('请填写正确的营业执照号')
  297. this.state.businessCode = 'warning'
  298. } else {
  299. this.$http.get(`/api/userspace/checkBusinessCode`, {params: {businessCode: this.step2.businessCode}})
  300. .then(response => {
  301. if (response.data.success) {
  302. this.state.businessCode = 'success'
  303. } else {
  304. this.state.businessCode = 'warning'
  305. this.downToast(response.data.errMsg)
  306. }
  307. })
  308. }
  309. }
  310. },
  311. // 验证管理员名
  312. validateVipName () {
  313. if (!this.step2.vipName) {
  314. this.downToast('请填写管理员姓名')
  315. this.state.vipName = 'error'
  316. } else {
  317. if (this.step2.vipName.length > 20) {
  318. this.downToast('输入长度请限制在20个字符以内')
  319. this.state.vipName = 'warning'
  320. } else {
  321. this.state.vipName = 'success'
  322. }
  323. }
  324. },
  325. // 验证密码强度
  326. validatePassword () {
  327. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  328. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  329. if (reg1.test(this.step2.password)) {
  330. this.progress = '强'
  331. } else if (reg2.test(this.step2.password)) {
  332. this.progress = '中'
  333. } else {
  334. this.progress = '弱'
  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. this.state.password = 'error'
  343. } else {
  344. if (!reg2.test(this.step2.password)) {
  345. this.downToast('密码须为8-20字符的英文、数字混合')
  346. this.state.password = 'warning'
  347. } else {
  348. this.state.password = 'success'
  349. if (this.step2.confirm) {
  350. this.validateConfirm()
  351. }
  352. }
  353. }
  354. },
  355. // 验证密码
  356. validatePasswordTipHas () {
  357. if (!this.step2.password) {
  358. this.downToast('请输入密码')
  359. this.state.password = 'error'
  360. } else {
  361. this.state.password = 'success'
  362. }
  363. },
  364. // 验证二次密码
  365. validateConfirm () {
  366. if (!this.step2.confirm) {
  367. this.downToast('请再次输入密码')
  368. this.state.confirm = 'error'
  369. } else {
  370. if (this.step2.confirm === this.step2.password) {
  371. this.state.confirm = 'success'
  372. } else {
  373. this.state.confirm = 'warning'
  374. this.downToast('两次输入密码不一致,请重新输入')
  375. }
  376. }
  377. },
  378. // 验证邮箱
  379. validateEmail () {
  380. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  381. if (!this.step2.email) {
  382. this.downToast('请填写联系邮箱信息')
  383. this.state.email = 'error'
  384. } else {
  385. if (!reg.test(this.step2.email)) {
  386. this.downToast('请输入正确的邮箱地址格式')
  387. this.state.email = 'warning'
  388. } else {
  389. this.state.email = 'success'
  390. }
  391. }
  392. },
  393. // 注册请求方法
  394. sbmitRegister () {
  395. this.$indicator.open('注册中...')
  396. let param = new FormData()
  397. param.append('spaceName', this.step2.spaceName)
  398. param.append('businessCode', this.step2.businessCode)
  399. param.append('vipName', this.step2.vipName || '')
  400. param.append('password', this.step2.password)
  401. param.append('email', this.step2.email || '')
  402. param.append('appId', this.$store.state.option.appId)
  403. let config = {
  404. headers: {'Content-Type': 'multipart/form-data'}
  405. }
  406. this.$http.post('/sso/userspace/register', param, config)
  407. .then(response => {
  408. this.$indicator.close()
  409. if (response.data.success) {
  410. window.location.href = '/overRegister/overEnterprise'
  411. } else {
  412. this.downToast(response.data.errMsg)
  413. }
  414. }).catch(() => {
  415. this.$indicator.close()
  416. this.downToast('请检查网络是否正常或联系服务商')
  417. })
  418. },
  419. // 企业注册
  420. sureRegister () {
  421. if (!this.hasRegister) {
  422. if (this.state.spaceName !== 'success' &&
  423. this.state.businessCode !== 'success' &&
  424. this.state.vipName !== 'success' &&
  425. this.state.password !== 'success' &&
  426. this.state.confirm !== 'success' &&
  427. this.state.email !== 'success') {
  428. this.downToast('请确认填写部分是否有误')
  429. } else {
  430. this.sbmitRegister()
  431. }
  432. } else {
  433. if (!this.hasEmail) {
  434. if (this.state.spaceName !== 'success' &&
  435. this.state.businessCode !== 'success' &&
  436. this.state.password !== 'success' &&
  437. this.state.email !== 'success') {
  438. this.downToast('请确认填写部分是否有误')
  439. } else {
  440. this.sbmitRegister()
  441. }
  442. } else {
  443. if (this.state.spaceName !== 'success' &&
  444. this.state.businessCode !== 'success' &&
  445. this.state.password !== 'success') {
  446. this.downToast('请确认填写部分是否有误')
  447. } else {
  448. this.sbmitRegister()
  449. }
  450. }
  451. }
  452. }
  453. }
  454. }
  455. </script>