bind-transaction-password.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <template>
  2. <view class="container">
  3. <view class="login-wrap">
  4. <view class="login-form">
  5. <u--form
  6. labelPosition="left"
  7. :model="userInfo"
  8. :rules="rules"
  9. ref="form1"
  10. >
  11. <u-form-item
  12. label="账号支付密码"
  13. prop="transactionPassword"
  14. labelWidth="auto"
  15. labelAlign="right"
  16. >
  17. <u--input
  18. v-model="userInfo.transactionPassword"
  19. placeholder="请输入账号支付密码"
  20. border="bottom"
  21. maxlength="6"
  22. type="password"
  23. ></u--input>
  24. </u-form-item>
  25. <u-form-item
  26. labelWidth="auto"
  27. labelAlign="right"
  28. label="确认密码"
  29. prop="transactionPassword1"
  30. width="120"
  31. >
  32. <u--input
  33. maxlength="6"
  34. v-model="userInfo.transactionPassword1"
  35. placeholder="请再次输入账号支付密码"
  36. border="bottom"
  37. type="password"
  38. ></u--input>
  39. </u-form-item>
  40. </u--form>
  41. </view>
  42. </view>
  43. <view @click="submitData" class="op-btn-wrap">
  44. <view class="h-btn">
  45. <text>确定</text>
  46. </view>
  47. </view>
  48. <view class="h-mark-desc">
  49. <view class="h-text">
  50. <text>*账户支付密码建议输入不连续6位数密码</text>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import {wechatRegister,realNameAuthLogin} from '/src/api/login/login.js';
  57. export default {
  58. data() {
  59. return {
  60. userInfo: {
  61. phone: '',
  62. smsCode: '',
  63. openId: '',
  64. password: "",
  65. password1: '',
  66. transactionPassword: "",
  67. transactionPassword1: "",
  68. reference: ""
  69. },
  70. tips2: '',
  71. rules: {
  72. transactionPassword: {
  73. required: true,
  74. min: 6,
  75. max: 6,
  76. message: '请输入6位密码',
  77. trigger: ['blur', 'change'],
  78. },
  79. transactionPassword1: [
  80. {
  81. required: true,
  82. min: 6,
  83. max: 6,
  84. message: '请输入6位密码',
  85. trigger: ['blur', 'change'],
  86. },
  87. {
  88. validator: (rule, value, callback) => {
  89. if(this.userInfo.transactionPassword === value){
  90. return true;
  91. }
  92. return false;
  93. },
  94. message: "两次输入密码不一致",
  95. trigger: ['blur', 'change'],
  96. }
  97. ],
  98. },
  99. }
  100. },
  101. onLoad(option) {
  102. // 判断Openid是否为空
  103. if(!this.$isDataEmpty(option)){
  104. this.userInfo = JSON.parse(option.data);
  105. }
  106. },
  107. onReady() {
  108. this.$refs.form1.setRules(this.rules)
  109. },
  110. methods: {
  111. // 提交交易密码
  112. submitData(){
  113. let that = this;
  114. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  115. this.$refs.form1.validate().then(res => {
  116. console.log(that.userInfo)
  117. that.userInfo.password = that.userInfo.transactionPassword;
  118. if(that.userInfo.type == '1'){ // 新微信新手机注册
  119. // 调用注册
  120. that.wechatRegister();
  121. }
  122. if(that.userInfo.type == '2'){ // 新微信新手机注册
  123. // 调用注册
  124. that.realNameAuthLogin();
  125. }
  126. }).catch(errors => {
  127. uni.$u.toast('校验失败,请认真填写')
  128. })
  129. },
  130. // 新微信新手机注册
  131. wechatRegister(){
  132. const that = this;
  133. // 新微信新手机注册账号
  134. wechatRegister(null,{data:this.userInfo}).then((res)=>{
  135. console.log(res)
  136. console.log(res.access_token)
  137. if(!this.$isDataEmpty(res.access_token)){
  138. that.setUserData(res);
  139. } else {
  140. uni.showToast({
  141. title: "用户注册失败"
  142. })
  143. }
  144. }).catch(() =>{
  145. uni.showToast({
  146. title: "操作失败"
  147. })
  148. });
  149. },
  150. realNameAuthLogin(){
  151. // 新微信老手机注册账号
  152. realNameAuthLogin(null,{data:this.userInfo}).then((res)=>{
  153. console.log(res)
  154. console.log(res.access_token)
  155. if(!this.$isDataEmpty(res.access_token)){
  156. that.setUserData(res);
  157. } else {
  158. uni.showToast({
  159. title: "用户注册失败"
  160. })
  161. }
  162. }).catch(() =>{
  163. uni.showToast({
  164. title: "操作失败"
  165. })
  166. });
  167. },
  168. // 设置登录后的用户数据
  169. setUserData(res){
  170. let loginState = {
  171. status: 1,
  172. accessToken: ""
  173. }
  174. // 数据获取token
  175. loginState.accessToken = res.access_token;
  176. this.$store.commit('updateLoginState', loginState);
  177. this.$store.commit('updateLoginUserInfo', res.userInfo)
  178. uni.$u.route({
  179. url: '/pages/index/tabbar',
  180. params: {
  181. PageCur: 'index'
  182. }
  183. })
  184. },
  185. }
  186. }
  187. </script>
  188. <style lang="scss">
  189. page,body{
  190. background: #fff;
  191. }
  192. .container{
  193. background: #fff;
  194. height: 300px;
  195. .login-wrap {
  196. display: flex;
  197. justify-content: center;
  198. .login-form{
  199. width: 90%;
  200. }
  201. .account{
  202. display: flex;
  203. }
  204. .identifying-code{
  205. }
  206. }
  207. .op-btn-wrap{
  208. margin-top: 30px;
  209. display: flex;
  210. justify-content: center;
  211. align-items: center;
  212. .h-btn{
  213. text-align: center;
  214. width: 343px;
  215. height: 42px;
  216. background: #FFE05C;
  217. border-radius: 27px;
  218. line-height: 42px;
  219. }
  220. }
  221. }
  222. </style>