StepNew.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>设置密保</p>
  5. </div>
  6. <div class="f-form">
  7. <div class="page-part">
  8. <select v-model="selectedQ1">
  9. <option disabled value=''>问题一</option>
  10. <option v-for="question1 in questionOne" v-bind:value="question1">{{question1}}</option>
  11. </select>
  12. </div>
  13. <div class="page-part">
  14. <mt-field placeholder="答案一"
  15. v-model="valid.answer1"
  16. :state="state.answer1"
  17. @blur.native.capture="validateAnswer1"
  18. ></mt-field>
  19. </div>
  20. <div class="page-part">
  21. <select v-model="selectedQ2">
  22. <option disabled value=''>问题二</option>
  23. <option v-for="question2 in questionTwo" v-bind:value="question2">{{question2}}</option>
  24. </select>
  25. </div>
  26. <div class="page-part">
  27. <mt-field placeholder="答案二"
  28. v-model="valid.answer2"
  29. :state="state.answer2"
  30. @blur.native.capture="validateAnswer2"
  31. ></mt-field>
  32. </div>
  33. <div class="page-part">
  34. <mt-button size="large" type="primary" @click="sureAccount('success')">提 交</mt-button>
  35. </div>
  36. </div>
  37. </div>
  38. </template>
  39. <script>
  40. export default {
  41. name: 'step-one',
  42. props: ['tokenId'],
  43. data () {
  44. return {
  45. state: {
  46. answer1: 'error',
  47. answer2: 'error'
  48. },
  49. valid: {
  50. answer1: '',
  51. answer2: ''
  52. },
  53. questionOne: [],
  54. questionTwo: [],
  55. selectedQ1: '',
  56. selectedQ2: ''
  57. }
  58. },
  59. mounted () {
  60. // 获取密保问题
  61. this.$http.get('/data/question.json').then(response => {
  62. this.questionOne = response.data.questionOne
  63. this.questionTwo = response.data.questionTwo
  64. })
  65. },
  66. methods: {
  67. // 弹窗处理
  68. downToast (type) {
  69. this.$toast({
  70. message: type,
  71. iconClass: 'el-icon-warning'
  72. })
  73. },
  74. // 验证密保问题1
  75. validateAnswer1 () {
  76. if (!this.selectedQ1) {
  77. this.downToast('请先选择密保问题')
  78. } else {
  79. if (!this.valid.answer1) {
  80. this.downToast('请填写密保答案')
  81. this.state.answer1 = 'error'
  82. } else {
  83. this.state.answer1 = 'success'
  84. }
  85. }
  86. },
  87. // 验证密保问题2
  88. validateAnswer2 () {
  89. if (!this.selectedQ2) {
  90. this.downToast('请先选择密保问题')
  91. } else {
  92. if (!this.valid.answer2) {
  93. this.downToast('请填写密保答案')
  94. this.state.answer2 = 'error'
  95. } else {
  96. this.state.answer2 = 'success'
  97. }
  98. }
  99. },
  100. sureAccount (type) {
  101. if (this.state.answer1 !== 'success' ||
  102. this.state.answer1 !== 'success') {
  103. this.downToast('请确认填写部分是否有误')
  104. } else {
  105. this.$indicator.open('验证过程中...')
  106. let param = new FormData()
  107. let userQuestion = []
  108. userQuestion.push({'question': this.selectedQ1, 'answer': this.valid.answer1, 'sort': '1'}, {'question': this.selectedQ2, 'answer': this.valid.answer2, 'sort': '2'})
  109. let userQuestions = JSON.stringify(userQuestion)
  110. param.append('userQuestions', userQuestions)
  111. param.append('token', this.tokenId ? this.tokenId : this.$route.query.token)
  112. let config = {
  113. headers: {'Content-Type': 'multipart/form-data'}
  114. }
  115. this.$http.post('/update/user/setQuestion', param, config)
  116. .then(response => {
  117. this.$indicator.close()
  118. if (response.data.success) {
  119. this.$emit('stepEvent', type)
  120. } else {
  121. this.downToast(response.data.errMsg)
  122. }
  123. }).catch((err) => {
  124. this.$indicator.close()
  125. this.downToast(err.errMsg)
  126. })
  127. }
  128. }
  129. }
  130. }
  131. </script>