bind-transaction-password.vue 4.6 KB

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