index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. <template>
  2. <view class="bind-phone-container">
  3. <BeeBack>
  4. <view style="display: flex;align-items: center;justify-content: space-between;">
  5. <BeeIcon name="arrowleft" :size="34" color="#222229" style="width: fit-content;">
  6. </BeeIcon>
  7. <text style="flex: 1;margin-left: -40rpx;text-align: center;line-height: 2.5;">绑定手机号</text>
  8. </view>
  9. </BeeBack>
  10. <view class="loginInfo fs26 font-color-999">
  11. <p>共建真实、安全的交易环境</p>
  12. <p>本平台承诺不会滥用您授权的信息</p>
  13. </view>
  14. <view v-if="verifyType === 0" class="verifyTypeBox">
  15. <view class="verifyItem" @click="verifyType = 1">
  16. 短信验证码
  17. </view>
  18. <view class="verifyItem verify-checked" @click="verifyType = 2">
  19. 小程序授权
  20. </view>
  21. </view>
  22. <view v-else-if="verifyType === 1" class="phoneVerify">
  23. <view class="iphoneNum-box flex-row-plus flex-items">
  24. <tui-icon :size="50" color="#cccccc" name="mobile" unit="rpx" margin="0 30rpx 0 0"></tui-icon>
  25. <view>
  26. <input v-model="phone" maxlength="11" type="number" placeholder="请输入您的手机号" />
  27. </view>
  28. </view>
  29. <view class="mar-top-20">
  30. <view class="code-box">
  31. <tui-icon :size="50" color="#cccccc" name="shield" unit="rpx" margin="0 30rpx 0 0"></tui-icon>
  32. <tui-input
  33. v-model="code" padding="26rpx 20rpx 26rpx 0" background-color="transparent" label-color="#ffffff"
  34. placeholder="请输入验证码"
  35. >
  36. <template #right>
  37. <tui-countdown-verify
  38. ref="refBindPhoneVerify" width="188rpx" height="48rpx" border-width="0"
  39. text="获取验证码"
  40. :size="30" color="#dddddd" @send="handleSendVerify"
  41. ></tui-countdown-verify>
  42. </template>
  43. </tui-input>
  44. </view>
  45. </view>
  46. <view class="mar-top-60">
  47. <view
  48. class="registerBut mar-top-100" :class="{ bindCls: (phone !== '') && (code !== '') }"
  49. @click="handleBindPhone"
  50. >
  51. 确认
  52. </view>
  53. </view>
  54. </view>
  55. <view v-else-if="verifyType === 2" class="mpVerify">
  56. <button
  57. v-if="[ 4 ].includes(terminal)" class="verifyPhone" open-type="getAuthorize" scope="phoneNumber"
  58. @getAuthorize="onGetAuthorize" @error="() => { }"
  59. >
  60. 授权手机号验证
  61. </button>
  62. <button
  63. v-if="[ 2 ].includes(terminal)" class="verifyPhone fs28 mar-top-100" open-type="getPhoneNumber"
  64. @getphonenumber="getWxPhoneNumber"
  65. >
  66. 微信手机号授权
  67. </button>
  68. </view>
  69. <view v-if="(verifyType !== 0) && [2, 4].includes(terminal)" class="backBtn" @click="verifyType = 0">
  70. 返回
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import { mapGetters } from 'vuex'
  76. import { getVerifyCodeApi, updateAliPhoneAppApi, getSessionKeyAppApi, updateSetWxPhoneAppApi, updateWxPhoneAppApi } from '../../../api/anotherTFInterface'
  77. export default {
  78. name: 'BindPhone',
  79. data() {
  80. return {
  81. phone: '',
  82. code: '',
  83. wechatOpenId: '',
  84. headImage: '',
  85. wechatName: '',
  86. verifyType: 0,
  87. buyerUserId: 0
  88. }
  89. },
  90. onLoad(options) {
  91. this.wechatOpenId = options.wechatOpenId
  92. this.headImage = options.headImage
  93. this.wechatName = options.wechatName
  94. this.buyerUserId = options.buyerUserId
  95. if (![2, 4].includes(this.$store.state.app.terminal)) this.verifyType = 1
  96. },
  97. computed: {
  98. ...mapGetters([ 'terminal' ])
  99. },
  100. methods: {
  101. // 获取验证码
  102. handleSendVerify() {
  103. if (!this.phone) {
  104. this.$refs.refBindPhoneVerify.reset()
  105. return this.$showToast('请填写手机号')
  106. }
  107. if (!/^1[3-9]\d{9}$/.test(this.phone)) {
  108. this.$refs.refBindPhoneVerify.reset()
  109. return this.$showToast('请输入正确的手机号')
  110. }
  111. getVerifyCodeApi({ phone: this.phone })
  112. .then((res) => {
  113. this.$refs.refBindPhoneVerify.success()
  114. this.$showToast('发送成功,请注意查看手机短信')
  115. })
  116. .catch(() => {
  117. this.$refs.refBindPhoneVerify.reset()
  118. })
  119. },
  120. handleBindPhone() {
  121. if ([ 4 ].includes(this.$store.state.app.terminal)) {
  122. this.updateAliPhone(this.phone, false)
  123. } else if ([2, 3].includes(this.$store.state.app.terminal)) {
  124. this.updateWxPhone()
  125. }
  126. },
  127. updateWxPhone() {
  128. updateWxPhoneAppApi({
  129. phone: this.phone,
  130. wechatOpenId: this.wechatOpenId,
  131. headImage: this.headImage,
  132. wechatName: this.wechatName,
  133. verificationCode: this.code,
  134. channelCode: '',
  135. terminal: 3
  136. }).then((res) => {
  137. this.$showToast('绑定成功')
  138. this.$store.dispatch('auth/LoginAfterAction', { type: 'wx', data: res.data })
  139. })
  140. },
  141. getWxPhoneNumber(e) {
  142. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  143. uni.login({
  144. provider: 'weixin',
  145. success: (res) => {
  146. getSessionKeyAppApi({
  147. code: res.code
  148. }).then((result) => {
  149. updateSetWxPhoneAppApi({
  150. wechatOpenId: result.data.wechatOpenId,
  151. sessionKey: result.data.sessionKey,
  152. encryptedData: e.detail.encryptedData,
  153. iv: e.detail.iv,
  154. headImage: this.headImage,
  155. wechatName: this.wechatName
  156. }).then((res) => {
  157. this.$showToast('绑定成功')
  158. this.$store.dispatch('auth/LoginAfterAction', { type: 'wx', data: res.data })
  159. })
  160. })
  161. },
  162. fail: () => {
  163. this.$showToast('微信登录授权失败')
  164. }
  165. })
  166. } else {
  167. this.$showToast('获取手机授权失败')
  168. }
  169. },
  170. onGetAuthorize() {
  171. const that = this
  172. uni.showLoading({
  173. mask: true,
  174. title: '验证中...'
  175. })
  176. my.getPhoneNumber({
  177. success: (res) => {
  178. uni.hideLoading()
  179. that.updateAliPhone(res.response, true)
  180. },
  181. fail: (res) => {
  182. uni.hideLoading()
  183. this.$showToast('验证失败')
  184. }
  185. })
  186. },
  187. updateAliPhone(encryptedData, encrypted) {
  188. uni.showLoading()
  189. updateAliPhoneAppApi({
  190. 'phone': encryptedData,
  191. 'buyerUserId': this.buyerUserId,
  192. encrypted
  193. }).then((res) => {
  194. uni.hideLoading()
  195. this.$showToast('绑定成功')
  196. this.$store.dispatch('auth/LoginAfterAction', { type: 'alipay', data: res.data })
  197. })
  198. .catch((e) => {
  199. uni.hideLoading()
  200. })
  201. }
  202. }
  203. }
  204. </script>
  205. <style lang="less" scoped>
  206. .bind-phone-container {
  207. min-height: 100vh;
  208. box-sizing: border-box;
  209. .loginInfo {
  210. margin: 130rpx 0 50rpx 0;
  211. text-align: center;
  212. }
  213. .verifyTypeBox {
  214. width: 98%;
  215. .verifyItem {
  216. width: 80%;
  217. display: block;
  218. text-align: center;
  219. border: 2rpx solid #F3F4F5;
  220. padding: 30rpx;
  221. font-size: 34rpx;
  222. margin: 0 auto 30rpx auto;
  223. color: #C5AA7B;
  224. }
  225. .verify-checked {
  226. color: white;
  227. background: #C5AA7B;
  228. }
  229. }
  230. .phoneVerify {
  231. padding: 20rpx 30rpx;
  232. .iphoneNum-box {
  233. border-bottom: 1rpx solid #DDDDDD;
  234. }
  235. .code-box {
  236. border-bottom: 1rpx solid #DDDDDD;
  237. display: flex;
  238. flex-direction: row;
  239. justify-content: space-between;
  240. align-items: center;
  241. /deep/ .tui-input__wrap {
  242. flex: 1;
  243. border-bottom: 2rpx solid #ffffff;
  244. }
  245. }
  246. .registerBut {
  247. background: #F3F4F5;
  248. color: #999999;
  249. height: 100rpx;
  250. width: 600rpx;
  251. text-align: center;
  252. line-height: 100rpx;
  253. margin: 30rpx auto;
  254. }
  255. .bindCls {
  256. background: #333333;
  257. color: #F5DEB2;
  258. }
  259. }
  260. .mpVerify {
  261. height: 300rpx;
  262. .verifyPhone {
  263. background: #333333;
  264. color: #FFEBC4;
  265. height: 100rpx;
  266. width: 600rpx;
  267. text-align: center;
  268. line-height: 100rpx;
  269. margin-top: 88rpx;
  270. border-radius: 0;
  271. }
  272. }
  273. .backBtn {
  274. color: #C5AA7B;
  275. text-align: center;
  276. text-decoration: underline;
  277. }
  278. }
  279. </style>