BindNew.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="div container">
  3. <view class="div top-wrapper">
  4. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" v-model="username" placeholder="用户名" maxlength="25" /><label v-if="!username" class="tips">用户名为3-25位,可以包含英文与数字</label></view></flex-line>
  5. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="password" placeholder="设置密码" maxlength="20" /></view></flex-line>
  6. <flex-line class="field-line input-wrapper" :show-border="true"><view class="div field-line-right" slot="right"><input class="field-input" type="password" v-model="confirmPassword" placeholder="确认密码" maxlength="20" /><label v-if="!confirmPassword" class="tips">6-20位数字/字母/符号</label></view></flex-line>
  7. </view>
  8. <view class="div common-btn ds-button-large mt-10 mb-10" @click="onSubmit">绑定</view>
  9. <view class="div link-wrapper">
  10. <text class="span left-text">点击绑定表示同意</text>
  11. <text class="span right-text" @click="onAgreement">《用户协议》</text>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. import { urlencode } from '@/util/common'
  17. import { mapState, mapMutations } from 'vuex'
  18. import { bind, getThirdLogin } from '../../../api/memberLogin'
  19. import flexLine from '../../flexLine'
  20. export default {
  21. name: 'BindNew',
  22. data () {
  23. return {
  24. query:{},
  25. username: '',
  26. password: '',
  27. confirmPassword: '',
  28. aggrementUrl: '',
  29. wxinfo: false
  30. }
  31. },
  32. components: { flexLine },
  33. mounted(){
  34. var pages = getCurrentPages()
  35. var page = pages[pages.length - 1]
  36. this.query = page.options
  37. getThirdLogin(this.query.id).then(res => {
  38. let wxinfo = res.result.wxinfo
  39. if (!wxinfo) {
  40. uni.showToast({icon:'none',title: '绑定信息不存在'})
  41. uni.navigateTo({url: '/pages/home/memberlogin/Login' })
  42. } else {
  43. this.wxinfo = wxinfo
  44. }
  45. })
  46. },
  47. computed: {
  48. ...mapState({
  49. inviter_id: state => state.member.inviterId
  50. })
  51. },
  52. methods: {
  53. ...mapMutations({
  54. saveAuthInfo: 'memberLogin'
  55. }),
  56. goBack () {
  57. uni.navigateBack({delta:1})
  58. },
  59. goProfile () {
  60. uni.navigateBack({delta:2})
  61. },
  62. goProfileAdd () {
  63. uni.navigateTo({url: 'profileAdd' })
  64. },
  65. check () {
  66. let username = this.username
  67. let password = this.password
  68. let confirmPassword = this.confirmPassword
  69. if (username.length === 0) {
  70. uni.showToast({icon:'none',title: '请输入3-25个字符的用户名'})
  71. return false
  72. }
  73. if (username.length < 3 || username.length > 25) {
  74. uni.showToast({icon:'none',title: '请输入3-25个字符的用户名'})
  75. return false
  76. }
  77. if (password.length === 0) {
  78. uni.showToast({icon:'none',title: '请输入密码'})
  79. return false
  80. }
  81. if (password.length < 6 || password.length > 20) {
  82. uni.showToast({icon:'none',title: '请输入6-20个字符的密码'})
  83. return false
  84. }
  85. if (confirmPassword.length === 0) {
  86. uni.showToast({icon:'none',title: '请输入确认密码'})
  87. return false
  88. }
  89. if (password.length !== confirmPassword.length) {
  90. uni.showToast({icon:'none',title: '确认密码与输入密码不一致'})
  91. return false
  92. }
  93. if (password !== confirmPassword) {
  94. uni.showToast({icon:'none',title: '确认密码与输入密码不一致'})
  95. return false
  96. }
  97. return true
  98. },
  99. signup () {
  100. if (!this.check()) {
  101. return
  102. }
  103. uni.showLoading({ title: '加载中' })
  104. bind(1, 'wx', this.wxinfo.openid, this.wxinfo.unionid, this.wxinfo.nickname, this.wxinfo.headimgurl, this.username, this.password, this.confirmPassword, this.inviter_id).then(
  105. response => {
  106. uni.hideLoading()
  107. this.saveAuthInfo({ token: response.result.token, info: response.result.info })
  108. uni.navigateTo({url: '/pages/member/index/Index' })
  109. },
  110. error => {
  111. uni.hideLoading()
  112. uni.showToast({icon:'none',title: error.message})
  113. }
  114. )
  115. },
  116. onSubmit () {
  117. this.signup()
  118. },
  119. onAgreement () {
  120. uni.navigateTo({url: '/pages/home/article/Document'+'?'+urlencode( { type: '' })})
  121. }
  122. }
  123. }
  124. </script>
  125. <style scoped lang="scss">
  126. .ds-button-large{margin:0 $pageSpace}
  127. .container {
  128. display: flex;
  129. flex-direction: column;
  130. justify-content: flex-start;
  131. align-items: stretch;
  132. //background-color: $primaryColor;
  133. .input-wrapper {
  134. font-size:$subFontSize;
  135. display: flex;
  136. flex-direction: row;
  137. align-content: flex-start;
  138. align-items: center;
  139. background-color: #fff;
  140. height:2.2rem;
  141. padding-left:0.5rem;
  142. input {
  143. flex: 1;
  144. }
  145. .bottom-input {
  146. border-bottom-width: 0;
  147. }
  148. }
  149. .link-wrapper {
  150. display: flex;
  151. flex-direction: row;
  152. justify-content: center;
  153. align-items: stretch;
  154. .span {
  155. font-size:$subFontSize;
  156. display: flex;
  157. flex-direction: row;
  158. justify-content: center;
  159. align-items: center;
  160. }
  161. .left-text {
  162. color: $descTextColor;
  163. }
  164. .right-text {
  165. color: $primaryColor;
  166. }
  167. }
  168. }
  169. .top-wrapper {
  170. margin:0 $pageSpace;
  171. }
  172. .bottom-wrapper {
  173. margin-top:0.5rem;
  174. }
  175. .tips {
  176. color: $descTextColor;
  177. font-size:$fontSize;
  178. white-space: nowrap;
  179. position: absolute;
  180. right: 0;
  181. top:50%;
  182. margin-top:-.3rem;
  183. }
  184. .field-line-right{position: relative;
  185. .field-input{
  186. text-align: left !important;
  187. }
  188. }
  189. </style>