blob: f8da8032be40166bb592de31fc5fad91b626f849 [file] [log] [blame]
guangchao.xuc43cf972021-01-18 13:37:55 +08001<template>
2 <view>
3 <view class="setQuestion" v-if="show_question && !show_pwd">
4 <view class="setQuestion-container">
5 <view class="setQuestion-item" v-for="(v,i) in list_select" :key='i'>
6 <u-field :disabled="true" :label="v.q_title" :field-style="field_style" v-model="v.q_value" input-align='right'
7 @click="choose_list(i,'confirm'+i)"></u-field>
8 <u-field :label="v.a_title" :field-style="field_style" v-model="v.a_value" input-align='right' placeholder="请输入您的答案"
9 maxlength="20"></u-field>
guangchao.xu6cdd45e2021-04-16 17:44:30 +080010 <!-- #ifdef APP-PLUS -->
11 <u-picker mode="selector" v-model="v.isShow" :default-selector="[i]" :range="list" range-key="question" @confirm="v.func"></u-picker>
12 <!-- #endif -->
13 <!-- <u-picker mode="selector" v-model="v.isShow" :default-selector="[i]" :range="list" range-key="question" @confirm="v.func"></u-picker> -->
14 <!-- #ifdef MP-WEIXIN -->
15 <u-picker mode="selector" v-model="list_select[0].isShow" :default-selector="[i]" :range="list" range-key="question" @confirm="confirm0"></u-picker>
16 <u-picker mode="selector" v-model="list_select[1].isShow" :default-selector="[i]" :range="list" range-key="question" @confirm="confirm1"></u-picker>
17 <u-picker mode="selector" v-model="list_select[2].isShow" :default-selector="[i]" :range="list" range-key="question" @confirm="confirm2"></u-picker>
18 <!-- #endif -->
guangchao.xuc43cf972021-01-18 13:37:55 +080019 </view>
20 </view>
21 <u-button @click="submit" :custom-style="submit_btn">验证密保</u-button>
22 </view>
23 <view class="setQuestion" v-if="!show_question && !show_pwd">
24 <view class="setQuestion-container">
25 <u-field label="手机号" :field-style="field_style" v-model="phone" input-align='right' placeholder="请输入您设置密保时关联的手机号"></u-field>
26 </view>
27 <u-button @click="check_phone" :custom-style="submit_btn">确认手机号</u-button>
28 </view>
29 <view class="setQuestion" v-if="show_pwd">
30 <view class="setQuestion-container">
31 <u-field label="新密码" :field-style="field_style" v-model="pwd" input-align='right' placeholder="请输入您的新密码" password></u-field>
32 </view>
33 <view class="setQuestion-container">
34 <u-field label="确认密码" :field-style="field_style" v-model="repwd" input-align='right' placeholder="请确认您的新密码"
35 password></u-field>
36 </view>
37 <u-button @click="change_pwd" :custom-style="submit_btn">修改密码</u-button>
38 </view>
39 </view>
40
41</template>
42
43<script>
44 export default {
45 data() {
46 return {
47 phone: '',
48 field_style: {
49 'font-size': '30rpx',
50 'color': '#6a6a6a'
51 },
52 submit_btn: {
53 width: '600rpx',
54 backgroundColor: '#2FA8E1',
55 color: '#FFFFFF',
56 fontFamily: "PingFang-SC-Medium",
57 fontSize: '30rpx',
58 marginTop: '100rpx',
59 padding: '50rpx 0'
60 },
61 show_question: false,
62 show_pwd: false,
63 list: [],
64 list_select: [{
65 q_title: 'Q1:',
66 q_value: '请选择您的密保问题',
67 a_value: '',
68 a_title: 'A1:',
69 isShow: false,
guangchao.xu6cdd45e2021-04-16 17:44:30 +080070 func: function(){}
guangchao.xuc43cf972021-01-18 13:37:55 +080071 },
72 {
73 q_title: 'Q2:',
74 q_value: '请选择您的密保问题',
75 a_value: '',
76 a_title: 'A2:',
77 isShow: false,
guangchao.xu6cdd45e2021-04-16 17:44:30 +080078 func: function(){}
guangchao.xuc43cf972021-01-18 13:37:55 +080079 },
80 {
81 q_title: 'Q3:',
82 q_value: '请选择您的密保问题',
83 a_value: '',
84 a_title: 'A3:',
85 isShow: false,
guangchao.xu6cdd45e2021-04-16 17:44:30 +080086 func: function(){}
guangchao.xuc43cf972021-01-18 13:37:55 +080087 },
88 ],
89 answers: [{
90 "ssid": "",
91 "answer": ""
92 },
93 {
94 "ssid": "",
95 "answer": ""
96 },
97 {
98 "ssid": "",
99 "answer": ""
100 }
101 ],
102 pass: false,
103 pwd: '',
104 repwd: ''
105 }
106 },
107 onLoad(optins) {
108 // this.get_list()
109 },
110 methods: {
111 choose_list(e, fun_name) {
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800112 // console.log(e,fun_name)
guangchao.xuc43cf972021-01-18 13:37:55 +0800113 this.list_select[e].isShow = true
114 this.list_select[e].func = this[fun_name]
115 },
116 check_phone() {
117 let that = this
118 let phone = that.phone
119 that.$u.get('/i/security/list?phone=' + phone).then(res => {
120 let list = res.data
121 if (list.length == 0) {
122 uni.showModal({
123 title: '提示',
124 content: '您还未设置过密保',
125 })
126 return
127 }
128 uni.setStorageSync("phone", phone)
129 that.list = list
130 that.show_question = true
131 })
132 },
133 confirm0(e) {
134 this.list_select[0].q_value = this.list[e[0]].question
135 this.list_select[0].ssid = this.list[e[0]].ssid
136 },
137 confirm1(e) {
138 this.list_select[1].q_value = this.list[e[0]].question
139 this.list_select[1].ssid = this.list[e[0]].ssid
140 },
141 confirm2(e) {
142 this.list_select[2].q_value = this.list[e[0]].question
143 this.list_select[2].ssid = this.list[e[0]].ssid
144 },
145 submit() {
146 let that = this
147 let list = that.list_select
148 let answer = that.answers
149 list.map((item, index, arr) => {
150 let ssid = item.ssid
151 let length = item.a_value.length
152 answer[index].ssid = ssid
153 answer[index].answer = item.a_value
154 })
155 let str = ''
156 answer.forEach(item => {
157 str = str + item.ssid
158 })
159 for (let i = 0; i < answer.length; i++) {
160 let item = answer[i]
161 let ssid = item.ssid
162 if (!ssid) {
163 uni.showModal({
164 title: '提示',
165 content: '请选择密保问题',
166 })
167 that.pass = false
168 break;
169 } else {
170 that.pass = true
171 }
172 let reg = new RegExp(item.ssid, "g")
173 let length = str.match(reg).length
174 if (length >= 2) {
175 uni.showModal({
176 title: '提示',
177 content: '请选择不同的密保问题',
178 })
179 that.pass = false
180 break;
181 } else {
182 that.pass = true
183 }
184
185 let value_length = item.answer.length
186 if (value_length < 2) {
187 uni.showModal({
188 title: '提示',
189 content: '未填写问题或问题答案长度小于2个字符',
190 })
191 that.pass = false
192 break;
193 } else {
194 that.pass = true
195 }
196 }
197 if (!that.pass) return
198 let phone = that.phone
199 let param = {
200 answers: answer,
201 phone
202 }
203 that.$u.post('/i/security/check', param).then(res => {
204 //console.log(res)
205 if (res.error == null) {
206 that.show_question = false
207 that.show_pwd = true
208 } else {
209 uni.showModal({
210 title: '提示',
211 content: '密保错误,请确认后重新验证'
212 })
213 }
214
215 })
216 },
217 change_pwd() {
218 let that = this
219 let pwd = that.pwd
220 let repwd = that.repwd
221 if (!!!pwd || !!!repwd) {
222 uni.showModal({
223 title: '提示',
224 content: '请输入密码'
225 })
226 return
227 }
228 if (pwd != repwd) {
229 uni.showModal({
230 title: '提示',
231 content: '两次密码不一致,请确认后重新输入'
232 })
233 return
234 }
235 let answers = that.answers
236 let phone = that.phone
237 //console.log(answers)
238 let params = {
239 pwd,
240 repwd,
241 answers,
242 phone
243 }
244 that.$u.post('/i/security/pwdset', params).then(res => {
245 uni.showToast({
246 title: "密码修改成功",
247 icon: "none",
248 duration: 800,
249 complete(res) {
250 setTimeout(() => {
251 uni.reLaunch({
guangchao.xu6cdd45e2021-04-16 17:44:30 +0800252 url: "/pages/sub_basic/login"
guangchao.xuc43cf972021-01-18 13:37:55 +0800253 })
254 }, 1500)
255 }
256 })
257 })
258 }
259 }
260 }
261</script>
262
263<style scoped lang="scss">
264 .setQuestion {
265 margin-top: 30rpx;
266
267 &-container {
268 background-color: #FFFFFF;
269 }
270
271 &-item {
272 margin-bottom: 30rpx;
273 }
274 }
275</style>