index.vue 7.1 KB

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