bindPhone.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. <template>
  2. <view class="container flex-items-plus flex-column">
  3. <global-loading />
  4. <view class="login-logoBox">
  5. <image class="login-logo" src="../../static/images/origin/loginLogo.png"></image>
  6. </view>
  7. <view class="loginInfo fs26 font-color-999">
  8. <p>共建真实、安全的交易环境</p>
  9. <p>本平台承诺不会滥用您授权的信息</p>
  10. </view>
  11. <view v-show="verifyType === 0" class="verifyTypeBox">
  12. <view class="verifyItem" @click="verifyType = 1">
  13. 短信验证码
  14. </view>
  15. <view class="verifyItem verify-checked" @click="verifyType = 2">
  16. 小程序授权
  17. </view>
  18. </view>
  19. <view v-if="verifyType == 1" class="phoneVerify">
  20. <view class="iphoneNum-box flex-row-plus flex-items">
  21. <view style="margin-right: 30rpx">
  22. <image class="loginIcon" src="../../static/images/origin/phone.png"></image>
  23. </view>
  24. <view>
  25. <input
  26. v-model="phone" maxlength="11" placeholder-class="iphoneNum-input" type="number"
  27. placeholder="请输入您的手机号"
  28. />
  29. </view>
  30. </view>
  31. <view class="flex-row-plus mar-top-20">
  32. <view class="code-box">
  33. <view style="margin-right: 30rpx">
  34. <image class="loginIcon" src="../../static/images/origin/code.png"></image>
  35. </view>
  36. <view>
  37. <input v-model="code" maxlength="6" placeholder-class="codeNum-input" placeholder="请输入验证码" />
  38. </view>
  39. </view>
  40. <view :class="disabled === true ? 'on' : ''" :disabled="disabled" class="getcode" @click="codede">
  41. {{ text }}
  42. </view>
  43. </view>
  44. <view class="mar-top-60">
  45. <view class="registerBut mar-top-100" :class="{ bindCls: phone !== '' && code !== '' }" @click="bindPhone">
  46. 确认
  47. </view>
  48. </view>
  49. <!-- <u-popup v-model="bindPhoneShow" class="popupbind" mode="center" border-radius="14" @close="closepopupbind"
  50. :closeable="true" close-icon-pos="top-right" close-icon-size="20">
  51. <view class="popupbind-box flex-items-plus">
  52. <view class="flex-column flex-items-plus" style="width: 95%;">
  53. <view class="fa38 font-color-C5AA7B">提示</view>
  54. <view class="mar-top-50" style="width: 90%;">此手机号已经绑定其他微信号,暂时无法与您的微信账号进行绑定。</view>
  55. </view>
  56. </view>
  57. </u-popup> -->
  58. </view>
  59. <view v-if="verifyType == 2" class="mpVerify">
  60. <button
  61. v-if="mpAlipay" class="verifyPhone" open-type="getAuthorize" scope="phoneNumber"
  62. @getAuthorize="onGetAuthorize" @error="onAuthError"
  63. >
  64. 授权手机号验证
  65. </button>
  66. <button class="verifyPhone fs28 mar-top-100" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
  67. 微信手机号授权
  68. </button>
  69. </view>
  70. <view v-if="verifyType !== 0" class="backBtn" @click="verifyType = 0">返回</view>
  71. </view>
  72. </template>
  73. <script>
  74. import sendVerifyCode from '@/mixins/SendVerifyCode'
  75. const NET = require('../../utils/request')
  76. const API = require('../../config/api')
  77. export default {
  78. mixins: [ sendVerifyCode ],
  79. data() {
  80. return {
  81. disabled: false,
  82. phone: '',
  83. code: '',
  84. wechatOpenId: '',
  85. headImage: '',
  86. bindPhoneShow: false,
  87. verifyType: 0,
  88. buyerUserId: 0,
  89. isMp: false,
  90. mpAlipay: false,
  91. mpWechat: false
  92. }
  93. },
  94. onLoad(options) {
  95. if (options.data) {
  96. const bindPhoneData = JSON.parse(options.data)
  97. this.wechatOpenId = bindPhoneData.wechatOpenId
  98. this.headImage = bindPhoneData.headImage
  99. this.buyerUserId = bindPhoneData.buyerUserId
  100. }
  101. // #ifdef MP
  102. this.isMp = true
  103. // #endif
  104. // #ifdef MP-ALIPAY
  105. this.mpAlipay = true
  106. // #endif
  107. // #ifdef MP-WEIXIN
  108. this.mpWechat = true
  109. // #endif
  110. },
  111. methods: {
  112. closepopupbind() {
  113. this.bindPhoneShow = false
  114. },
  115. codede() {
  116. const phoneCodeVerification = /^[1][3-9][0-9]{9}$/
  117. if (this.phone == '') {
  118. uni.showToast({
  119. title: '请输入手机号!',
  120. duration: 2000,
  121. icon: 'none'
  122. })
  123. } else if (!phoneCodeVerification.test(this.phone)) {
  124. uni.showToast({
  125. title: '请输入正确的手机号!',
  126. duration: 2000,
  127. icon: 'none'
  128. })
  129. } else {
  130. NET.request(API.Verify, {
  131. phone: this.phone
  132. }, 'GET').then((res) => {
  133. this.sendCode()
  134. })
  135. .catch((res) => {
  136. uni.showToast({
  137. title: res.data.message,
  138. duration: 2000,
  139. icon: 'none'
  140. })
  141. })
  142. }
  143. },
  144. bindPhone() {
  145. // #ifdef MP-ALIPAY
  146. this.updateAliPhone(this.phone, false)
  147. // #endif
  148. // #ifdef MP-WEIXIN
  149. this.updateWxPhone()
  150. // #endif
  151. },
  152. onGetAuthorize() {
  153. const that = this
  154. // uni.showLoading({
  155. // mask: true,
  156. // title: '验证中...',
  157. // })
  158. this.$showLoading()
  159. my.getPhoneNumber({
  160. success: (res) => {
  161. this.$hideLoading()
  162. const encryptedData = res.response
  163. that.updateAliPhone(encryptedData, true)
  164. },
  165. fail: (res) => {
  166. this.$hideLoading()
  167. uni.hideLoading()
  168. uni.showToast({
  169. title: '验证失败',
  170. icon: 'none'
  171. })
  172. }
  173. })
  174. },
  175. onAuthError() {
  176. },
  177. getPhoneNumber(e) {
  178. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  179. uni.login({
  180. provider: 'weixin',
  181. success: (res) => {
  182. NET.request(API.GetSessionKey, {
  183. code: res.code
  184. }, 'POST').then((res1) => {
  185. NET.request(API.SetWxPhone, {
  186. wechatOpenId: res1.data.wechatOpenId,
  187. sessionKey: res1.data.sessionKey,
  188. encryptedData: e.detail.encryptedData,
  189. iv: e.detail.iv,
  190. headImage: this.headImage
  191. }, 'POST').then((res2) => {
  192. const item = res2.data
  193. uni.setStorageSync('storage_key', item)
  194. this.bindSalesCustomer()
  195. this.gotoHome()
  196. })
  197. .catch((res) => { })
  198. })
  199. .catch((err) => {
  200. })
  201. },
  202. fail: () => {
  203. uni.showToast({
  204. title: '微信登录授权失败',
  205. icon: 'none'
  206. })
  207. }
  208. })
  209. } else {
  210. uni.showToast({
  211. title: '获取手机授权失败',
  212. icon: 'none'
  213. })
  214. }
  215. },
  216. updateWxPhone() {
  217. NET.request(API.UpdateWxPhone, {
  218. phone: this.phone,
  219. wechatOpenId: this.wechatOpenId,
  220. headImage: this.headImage,
  221. verificationCode: this.code,
  222. channelCode: this.channelCode
  223. }, 'POST').then((res) => {
  224. const item = res.data
  225. uni.setStorageSync('storage_key', item)
  226. this.bindSalesCustomer()
  227. uni.showToast({
  228. title: '绑定成功',
  229. duration: 2000,
  230. icon: 'none'
  231. })
  232. this.gotoHome()
  233. })
  234. .catch((res) => {
  235. this.bindPhoneShow = true
  236. })
  237. },
  238. updateAliPhone(encryptedData, encrypted) {
  239. NET.request(API.UpdateAliPhone, {
  240. 'phone': encryptedData,
  241. 'buyerUserId': this.buyerUserId,
  242. encrypted
  243. }, 'POST').then((res) => {
  244. const item = res.data
  245. uni.setStorageSync('storage_key', item)
  246. this.bindSalesCustomer()
  247. this.phone = item.phone
  248. uni.showToast({
  249. title: '绑定成功',
  250. duration: 2000,
  251. icon: 'none'
  252. })
  253. this.gotoHome()
  254. })
  255. .finally((res) => {
  256. uni.hideLoading()
  257. })
  258. },
  259. bindSalesCustomer() {
  260. const shopId = uni.getStorageSync('shopId')
  261. const salesId = uni.getStorageSync('salesId')
  262. if (shopId && salesId) {
  263. // 多次调用绑定方法,不提示任何信息即可
  264. NET.request(API.BindSalesCustomer, {
  265. shopId,
  266. distributorId: salesId
  267. }, 'POST').then((res) => {
  268. uni.removeStorageSync('salesId')
  269. uni.removeStorageSync('shopId')
  270. })
  271. .catch((res) => {
  272. console.dir(res)
  273. })
  274. }
  275. },
  276. gotoHome() {
  277. // #ifdef MP-ALIPAY
  278. uni.navigateTo({
  279. url: '/pages/tabbar/user/index'
  280. })
  281. // #endif
  282. // #ifndef MP-ALIPAY
  283. uni.switchTab({
  284. url: '/pages/tabbar/user/index'
  285. })
  286. // #endif
  287. }
  288. }
  289. }
  290. </script>
  291. <style lang="scss">
  292. .container {
  293. background-color: #FFFFFF;
  294. height: 100vh;
  295. .login-logoBox {
  296. margin-top: 100upx;
  297. .login-logo {
  298. width: 234upx;
  299. height: 193upx;
  300. }
  301. }
  302. .loginInfo {
  303. margin: 130rpx 0 50rpx 0;
  304. text-align: center;
  305. }
  306. .verifyTypeBox {
  307. width: 98%;
  308. .verifyItem {
  309. width: 80%;
  310. display: block;
  311. text-align: center;
  312. border: 2upx solid #F3F4F5;
  313. padding: 30upx;
  314. font-size: 34upx;
  315. margin: 0 auto 30rpx auto;
  316. color: #C5AA7B;
  317. }
  318. .verify-checked {
  319. color: white;
  320. background: #C5AA7B;
  321. }
  322. }
  323. .phoneVerify {
  324. height: 450upx;
  325. .iphoneNum-box {
  326. border-bottom: 1rpx solid #DDDDDD;
  327. height: 100rpx;
  328. width: 600rpx;
  329. .loginIcon {
  330. width: 40rpx;
  331. height: 53rpx;
  332. }
  333. .iphoneNum-input {
  334. color: #999999;
  335. font-size: 28rpx;
  336. font-weight: 400;
  337. }
  338. }
  339. .passwordNum-box {
  340. border-bottom: 1rpx solid #DDDDDD;
  341. height: 100rpx;
  342. width: 600rpx;
  343. .passwordNum-input {
  344. color: #999999;
  345. font-size: 28rpx;
  346. font-weight: 400;
  347. width: 346rpx;
  348. }
  349. }
  350. .code-box {
  351. border-bottom: 1rpx solid #DDDDDD;
  352. height: 100rpx;
  353. width: 360rpx;
  354. display: flex;
  355. flex-direction: row;
  356. justify-content: space-between;
  357. align-items: center;
  358. .loginIcon {
  359. width: 44rpx;
  360. height: 50rpx;
  361. }
  362. .code-lab {
  363. width: 200rpx;
  364. }
  365. .codeNum-input {
  366. color: #999999;
  367. font-size: 28rpx;
  368. font-weight: 400;
  369. }
  370. }
  371. .getcode {
  372. background-color: #C5AA7B;
  373. height: 100rpx;
  374. width: 230rpx;
  375. display: flex;
  376. flex-direction: row;
  377. justify-content: center;
  378. align-items: center;
  379. margin-left: 20rpx;
  380. color: #FFFFFF;
  381. }
  382. .registerBut {
  383. background: #F3F4F5;
  384. color: #999999;
  385. height: 100rpx;
  386. width: 600rpx;
  387. text-align: center;
  388. line-height: 100rpx;
  389. margin-top: 30rpx;
  390. }
  391. .bindCls {
  392. background: #333333;
  393. color: #F5DEB2;
  394. }
  395. }
  396. .mpVerify {
  397. height: 300upx;
  398. .verifyPhone {
  399. background: #333333;
  400. color: #FFEBC4;
  401. height: 100upx;
  402. width: 600upx;
  403. text-align: center;
  404. line-height: 100upx;
  405. margin-top: 88upx;
  406. border-radius: 0;
  407. }
  408. }
  409. .backBtn {
  410. color: #C5AA7B;
  411. text-decoration: underline;
  412. }
  413. }
  414. </style>