stepAppeal.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>密码重置</p>
  5. <a href="javascript:void(0)" class="back" @click="jump('select')"><i class="el-icon-back"></i></a>
  6. </div>
  7. <div class="f-form">
  8. <div class="page-part">
  9. <mt-field placeholder="新手机号码"
  10. v-model="valid.mobile"
  11. :state="state.mobile"
  12. type="tel"
  13. @blur.native.capture="validateMobile"
  14. ></mt-field>
  15. </div>
  16. <div class="page-part">
  17. <mt-field auto-complete="off"
  18. placeholder="短信验证码"
  19. v-model="valid.token"
  20. :state="state.token"
  21. @blur.native.capture="validateCode">
  22. <span class="token" @click="getCheckCode" v-text="tokenText">获取验证码</span>
  23. </mt-field>
  24. </div>
  25. <div class="page-part">
  26. <mt-field placeholder="新密码"
  27. type="password"
  28. v-model="valid.password"
  29. :attr="{maxlength: 20}"
  30. :state="state.password"
  31. @input.native="validatePassword"
  32. @blur.native.capture="validatePasswordTip"></mt-field>
  33. <template v-if="valid.password">
  34. <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>
  35. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  36. </template>
  37. </div>
  38. <div class="page-part">
  39. <mt-field placeholder="确认密码"
  40. type="password"
  41. v-model="valid.confirm"
  42. auto-complete="off"
  43. :state="state.confirm"
  44. @blur.native.capture="validateConfirm"
  45. ></mt-field>
  46. </div>
  47. <div class="page-part">
  48. <mt-field placeholder="申诉说明"
  49. type="textarea"
  50. rows="4"
  51. v-model="valid.description"></mt-field>
  52. <p class="pwd">请描述您申诉的原因,并尽可能多地列举出证明此 账号为您所有的证据</p>
  53. </div>
  54. <div class="page-part">
  55. <mt-field placeholder="姓名"
  56. v-model="valid.contactName"
  57. :state="state.contactName"
  58. @blur.native.capture="validateContactName"
  59. ></mt-field>
  60. </div>
  61. <div class="page-part">
  62. <mt-field placeholder="联系电话"
  63. v-model="valid.contactTel"
  64. :state="state.contactTel"
  65. type="tel"
  66. @blur.native.capture="validateContactTel"
  67. ></mt-field>
  68. </div>
  69. <div class="page-part">
  70. <mt-field placeholder="电子邮箱"
  71. v-model="valid.contactEmail"
  72. :state="state.contactEmail"
  73. type="email"
  74. @blur.native.capture="validateContactEmail"
  75. ></mt-field>
  76. </div>
  77. <div class="page-part">
  78. <mt-button size="large" type="primary" @click="sureAccount('last')">提 交</mt-button>
  79. </div>
  80. </div>
  81. </div>
  82. </template>
  83. <script>
  84. export default {
  85. name: 'step-one',
  86. data () {
  87. return {
  88. state: {
  89. mobile: 'error',
  90. token: 'error',
  91. password: 'error',
  92. confirm: 'error',
  93. contactName: 'error',
  94. contactTel: 'error',
  95. contactEmail: 'error'
  96. },
  97. valid: {
  98. mobile: '',
  99. token: '',
  100. password: '',
  101. confirm: '',
  102. description: '',
  103. contactName: '',
  104. contactTel: '',
  105. contactEmail: ''
  106. },
  107. tokenCode: '',
  108. tokenTime: 60,
  109. tokenText: '获取验证码',
  110. progress: '弱'
  111. }
  112. },
  113. methods: {
  114. jump (type) {
  115. this.$emit('stepEvent', type)
  116. },
  117. // 弹窗处理
  118. downToast (type) {
  119. this.$toast({
  120. message: type,
  121. iconClass: 'el-icon-warning'
  122. })
  123. },
  124. // 验证手机号
  125. validateMobile () {
  126. let reg = /^1[0-9]{10}$/
  127. if (!this.valid.mobile) {
  128. this.downToast('请先填写手机号')
  129. this.state.mobile = 'error'
  130. } else {
  131. if (!reg.test(this.valid.mobile)) {
  132. this.downToast('请填写正确的手机号')
  133. this.state.mobile = 'warning'
  134. } else {
  135. this.state.mobile = 'success'
  136. }
  137. }
  138. },
  139. // 验证正确的验证码
  140. validateCode () {
  141. if (!this.valid.token) {
  142. this.downToast('请先填写验证码')
  143. this.state.token = 'error'
  144. } else {
  145. if (!this.valid.mobile) {
  146. this.downToast('请先填写正确的手机号码')
  147. this.state.token = 'warning'
  148. } else {
  149. if (this.tokenCode) {
  150. let param = new FormData()
  151. param.append('mobile', this.valid.mobile)
  152. param.append('token', this.tokenCode)
  153. param.append('code', this.valid.token)
  154. let config = {
  155. headers: {'Content-Type': 'multipart/form-data'}
  156. }
  157. this.$http.post('/appeal/check/mobile', param, config)
  158. .then(response => {
  159. if (response.data.success) {
  160. this.state.token = 'success'
  161. } else {
  162. this.$toast({
  163. message: response.data.errMsg,
  164. iconClass: 'el-icon-error'
  165. })
  166. }
  167. }).catch(() => {
  168. this.downToast('请检查网络是否正常或联系服务商')
  169. })
  170. } else {
  171. this.downToast('请点击先获取验证码信息')
  172. this.state.token = 'warning'
  173. }
  174. }
  175. }
  176. },
  177. // 获取验证码
  178. getCheckCode () {
  179. if (this.tokenTime > 0 && this.tokenTime < 60) {
  180. this.downToast('请稍后再点击,我在倒计时')
  181. } else {
  182. if (this.state.mobile !== 'success') {
  183. this.downToast('请先输入正确的手机号')
  184. } else {
  185. this.$indicator.open('获取中...')
  186. let _this = this
  187. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.valid.mobile}})
  188. .then(response => {
  189. this.$indicator.close()
  190. if (response.data) {
  191. this.tokenCode = response.data.token
  192. this.$toast({
  193. message: '验证码已经发送到您的手机,请注意查收',
  194. iconClass: 'el-icon-success'
  195. })
  196. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  197. let setTime = setInterval(() => {
  198. _this.tokenTime--
  199. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  200. if (this.tokenTime <= 0) {
  201. clearInterval(setTime)
  202. _this.tokenText = '获取验证码'
  203. _this.tokenTime = 60
  204. }
  205. }, 1000)
  206. }
  207. }).catch(() => {
  208. this.$indicator.close()
  209. this.downToast('请检查网络是否正常或联系服务商')
  210. })
  211. }
  212. }
  213. },
  214. // 验证密码强度
  215. validatePassword () {
  216. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  217. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  218. if (reg1.test(this.valid.password)) {
  219. this.progress = '强'
  220. } else if (reg2.test(this.valid.password)) {
  221. this.progress = '中'
  222. } else {
  223. this.progress = '弱'
  224. }
  225. },
  226. // 验证密码
  227. validatePasswordTip () {
  228. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  229. if (!this.valid.password) {
  230. this.downToast('请输入密码')
  231. this.state.password = 'error'
  232. } else {
  233. if (!reg2.test(this.valid.password)) {
  234. this.downToast('密码须为8-20字符的英文、数字混合')
  235. this.state.password = 'warning'
  236. } else {
  237. this.state.password = 'success'
  238. if (this.valid.confirm) {
  239. this.validateConfirm()
  240. }
  241. }
  242. }
  243. },
  244. // 验证二次密码
  245. validateConfirm () {
  246. if (!this.valid.confirm) {
  247. this.downToast('请再次输入密码')
  248. this.state.confirm = 'error'
  249. } else {
  250. if (this.valid.confirm === this.valid.password) {
  251. this.state.confirm = 'success'
  252. } else {
  253. this.state.confirm = 'warning'
  254. this.downToast('两次输入密码不一致,请重新输入')
  255. }
  256. }
  257. },
  258. // 验证姓名
  259. validateContactName () {
  260. if (!this.valid.contactName) {
  261. this.downToast('请填写您的姓名')
  262. this.state.contactName = 'error'
  263. } else {
  264. if (this.valid.contactName.length > 20) {
  265. this.downToast('输入长度过长,限定20个字符以内')
  266. this.state.contactName = 'warning'
  267. } else {
  268. this.state.contactName = 'success'
  269. }
  270. }
  271. },
  272. // 验证电话
  273. validateContactTel () {
  274. let reg = /^1[0-9]{10}$/
  275. if (!this.valid.contactTel) {
  276. this.downToast('请填写联系电话')
  277. this.state.contactTel = 'error'
  278. } else {
  279. if (!reg.test(this.valid.contactTel)) {
  280. this.downToast('请填写正确的联系电话')
  281. this.state.contactTel = 'warning'
  282. } else {
  283. this.state.contactTel = 'success'
  284. }
  285. }
  286. },
  287. // 验证邮箱
  288. validateContactEmail () {
  289. let reg = /^([\w-])+(\.\w+)*@([\w-])+((\.\w{2,3}){1,3})$/
  290. if (!this.valid.contactEmail) {
  291. this.downToast('请填写联系电子邮箱')
  292. this.state.contactEmail = 'error'
  293. } else {
  294. if (!reg.test(this.valid.contactEmail)) {
  295. this.downToast('请输入正确的邮箱地址格式')
  296. this.state.contactEmail = 'warning'
  297. } else {
  298. this.state.contactEmail = 'success'
  299. }
  300. }
  301. },
  302. sureAccount (type) {
  303. if (this.state.mobile !== 'success' &&
  304. this.state.token !== 'success' &&
  305. this.state.password !== 'success' &&
  306. this.state.confirm !== 'success' &&
  307. this.state.contactName !== 'success' &&
  308. this.state.contactTel !== 'success' &&
  309. this.state.contactEmail !== 'success') {
  310. this.downToast('请确认填写部分是否有误')
  311. } else {
  312. this.$indicator.open('验证过程中...')
  313. let param = new FormData()
  314. param.append('mobile', this.valid.mobile)
  315. param.append('code', this.valid.token)
  316. param.append('password', this.valid.password)
  317. param.append('description', this.valid.description)
  318. param.append('contactName', this.valid.contactName)
  319. param.append('contactTel', this.valid.contactTel)
  320. param.append('contactEmail', this.valid.contactEmail)
  321. param.append('token', this.tokenCode)
  322. let config = {
  323. headers: {'Content-Type': 'multipart/form-data'}
  324. }
  325. this.$http.post('/appeal/resetPwd', param, config)
  326. .then(response => {
  327. this.$indicator.close()
  328. if (response.data.success) {
  329. this.$emit('stepEvent', type)
  330. this.$emit('lastEvent', 'appeal')
  331. } else {
  332. this.downToast(response.data.errMsg)
  333. }
  334. }).catch(() => {
  335. this.$indicator.close()
  336. this.downToast('请检查网络是否正常或联系服务商')
  337. })
  338. }
  339. }
  340. }
  341. }
  342. </script>