bindPhone.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view class="box" :class="['qn-page-' + theme]">
  3. <view class="close-view"><text class="ibonfont ibonguanbi1" @click="closePage"></text></view>
  4. <view class="top-bg"></view>
  5. <view class="welcome-title">
  6. <view>嗨~朋友</view>
  7. <view>欢迎使用{{ baseSet.shop || '' }}</view>
  8. </view>
  9. <view class="logo-img"><image :src="baseSet.images" mode="aspectFill"></image></view>
  10. <view class="login-bg">
  11. <block v-if="login_type === 1">
  12. <image src="https://onlineimg.qianniao.vip/login-img.jpg" mode="aspectFill"></image>
  13. <view class="login-btn-view"><button class="wx-Btn primary-bg" open-type="getPhoneNumber" @getphonenumber="getphonenumber">一键授权登录</button></view>
  14. <!-- <view class="wx-change-btn" @click="login_type = 2">
  15. <text class="ibonfont ibonshouji1 wxicon" style="transform: translateY(-4rpx);display: inline-block;"></text>
  16. 短信验证登录
  17. </view> -->
  18. </block>
  19. <block v-if="login_type === 2">
  20. <view class="tab-ul">
  21. <view class="tab-li" @click="login_type = 1">微信快捷登录</view>
  22. <!-- <view class="tab-on">手机验证登录</view> -->
  23. </view>
  24. <view class="input-ul">
  25. <view class="input-li">
  26. <text class="ibonfont ibonshouji1"></text>
  27. <input type="number" placeholder-class="input-pl" v-model="phoneNumber" placeholder="请输入手机号" />
  28. </view>
  29. <view class="input-li">
  30. <text class="ibonfont ibonyanzhengma"></text>
  31. <input type="number" placeholder-class="input-pl" v-model="smsCode" placeholder="请输入验证码" />
  32. <view class="yzm-view">
  33. <text v-if="is_dis_yzm">{{ num }}s后重新发送</text>
  34. <text v-else @click="getYzm()">获取验证码</text>
  35. </view>
  36. </view>
  37. </view>
  38. <view class="login-btn primary-bg" @click="appletsBindMobile()">登录</view>
  39. </block>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. is_dis_yzm: false,
  48. num: 60,
  49. source: 5,
  50. smsCode: '',
  51. phoneNumber: '',
  52. login_type: 1
  53. };
  54. },
  55. computed: {
  56. baseSet() {
  57. return this.$store.state.baseSet;
  58. },
  59. source() {
  60. return this.$common.source();
  61. },
  62. staffId() {
  63. return this.$store.state.staffId;
  64. },
  65. businessmanId() {
  66. return this.$store.state.businessmanId;
  67. }
  68. },
  69. onShow() {
  70. // #ifdef MP
  71. uni.hideHomeButton();
  72. // #endif
  73. },
  74. onLoad() {},
  75. methods: {
  76. // 拒绝跳转主页面
  77. closePage() {
  78. this.goPage('/pages/index/index', 'switchTab');
  79. },
  80. // 一键绑定
  81. getphonenumber(e) {
  82. const iv = e.detail.iv;
  83. const encryptedData = e.detail.encryptedData;
  84. this.$u.api
  85. .decryptData({
  86. openid: this.$common.getOpenid(),
  87. iv: iv,
  88. encryptedData: encryptedData
  89. })
  90. .then(data => {
  91. this.phoneNumber = data.data.phoneNumber;
  92. uni.setStorageSync('phoneNumber', this.phoneNumber);
  93. // #ifdef MP-WEIXIN
  94. this.appletsBindMobile('wx');
  95. // #endif
  96. // #ifdef MP-TOUTIAO
  97. this.appletsBindMobile('byteDance');
  98. // #endif
  99. });
  100. },
  101. // 绑定手机号
  102. appletsBindMobile(source) {
  103. if (!this.phoneNumber) {
  104. this.$api.msg('请输入手机号');
  105. return;
  106. }
  107. if (!source) {
  108. if (!this.smsCode) {
  109. this.$api.msg('请输入验证码');
  110. return;
  111. }
  112. }
  113. console.log('staffId', this.staffId);
  114. const params = {
  115. mobile: this.phoneNumber,
  116. smsCode: this.smsCode,
  117. openId: this.$common.getOpenid(),
  118. unionId: this.$common.getUnionId(),
  119. salesManId: this.staffId || '',
  120. avatar: this.$common.getAvator(),
  121. name: this.$common.getName(),
  122. source: source || 'sms',
  123. type: this.source,
  124. shopId: 0
  125. };
  126. this.$u.api.appletsBindMobile(params).then(data => {
  127. this.$api.msg('绑定成功');
  128. uni.setStorageSync('token', data.data.token);
  129. uni.setStorageSync('expireTime', data.data.expireTime);
  130. // 更新登录状态
  131. this.$store.commit('commit_hasLogin', true);
  132. // 添加分销上下级关系
  133. this.relationshipBusinessman();
  134. // this.goPage(`/pages/index/index`, 'switchTab');
  135. });
  136. },
  137. // 添加分销上下级关系 source: 1:首次点击链接 2:首次下单 3:首次付款'
  138. relationshipBusinessman() {
  139. if (!this.businessmanId) {
  140. // 是否立即去完善资料
  141. if (this.baseSet.finishDataGo) {
  142. this.goPage('/pagesT/user/editUserInfo');
  143. } else {
  144. this.goPage(`/pages/index/index`, 'switchTab');
  145. }
  146. return;
  147. }
  148. this.$u.api
  149. .relationshipBusinessman({
  150. businessmanId: this.businessmanId,
  151. source: 1
  152. })
  153. .then(data => {
  154. console.log('上下级关系绑定成功:', data.data);
  155. // 是否立即去完善资料
  156. if (this.baseSet.finishDataGo) {
  157. this.goPage('/pagesT/user/editUserInfo');
  158. } else {
  159. this.goPage(`/pages/index/index`, 'switchTab');
  160. }
  161. });
  162. },
  163. // 验证码
  164. getYzm() {
  165. const re = /^1[3456789]\d{9}$/;
  166. if (!re.test(this.phoneNumber)) {
  167. this.$api.msg('手机号格式不正确');
  168. return;
  169. }
  170. this.$u.api
  171. .sendMobileCode({
  172. mobile: this.phoneNumber,
  173. source: 6
  174. })
  175. .then(res => {
  176. this.$api.msg('发送成功');
  177. // 发送验证码
  178. this.is_dis_yzm = !this.is_dis_yzm;
  179. const secondNumIn = setInterval(() => {
  180. this.num--;
  181. if (this.num === 0) {
  182. // 清除定时器
  183. clearInterval(secondNumIn);
  184. this.is_dis_yzm = false;
  185. this.num = 60;
  186. }
  187. }, 1000);
  188. });
  189. }
  190. }
  191. };
  192. </script>
  193. <style>
  194. page {
  195. background-color: #ffffff;
  196. }
  197. </style>
  198. <style lang="scss" scoped>
  199. .input-pl {
  200. color: #b8c0c8;
  201. font-size: 28rpx;
  202. }
  203. .box {
  204. .close-view {
  205. position: fixed;
  206. left: 0;
  207. padding-left: 30upx;
  208. width: 100%;
  209. top: 70upx;
  210. z-index: 99;
  211. .ibonguanbi1 {
  212. font-size: 30upx;
  213. }
  214. }
  215. .top-bg {
  216. width: 385rpx;
  217. height: 385rpx;
  218. background: linear-gradient(315deg, #fa6400 6%, #b620e0 49%, #32c5ff 88%);
  219. opacity: 0.08;
  220. filter: blur(50px);
  221. position: fixed;
  222. top: 20rpx;
  223. left: 0;
  224. z-index: 0;
  225. }
  226. .welcome-title {
  227. position: fixed;
  228. top: 162rpx;
  229. left: 56rpx;
  230. font-weight: bold;
  231. z-index: 1;
  232. line-height: 80rpx;
  233. font-size: 46rpx;
  234. font-family: jiangxikaiti;
  235. }
  236. .logo-img {
  237. position: fixed;
  238. top: 150rpx;
  239. right: 56rpx;
  240. image {
  241. width: 120rpx;
  242. border-radius: 34rpx;
  243. height: 120rpx;
  244. display: block;
  245. box-shadow: 0px 0px 20rpx 8rpx rgba(250, 100, 0, 0.08);
  246. }
  247. }
  248. .login-bg {
  249. position: fixed;
  250. top: 370rpx;
  251. left: 0;
  252. width: 100%;
  253. image {
  254. width: 360rpx;
  255. height: 360rpx;
  256. display: block;
  257. margin: 0 auto;
  258. }
  259. .login-btn-view {
  260. width: 638rpx;
  261. margin: 40rpx auto;
  262. .wx-Btn {
  263. margin-top: 106rpx;
  264. width: 638rpx;
  265. height: 89rpx;
  266. background: #fa6400;
  267. border-radius: 11rpx;
  268. line-height: 89rpx;
  269. text-align: center;
  270. font-weight: 500;
  271. color: #ffffff;
  272. font-size: 28rpx;
  273. }
  274. .yzm-Btn {
  275. margin-top: 40rpx;
  276. text-align: center;
  277. width: 638rpx;
  278. height: 80rpx;
  279. line-height: 80rpx;
  280. border-radius: 11rpx;
  281. border: 1px solid #cad0d7;
  282. color: #2d405e;
  283. font-size: 26rpx;
  284. .ibonshouji1 {
  285. font-size: 26rpx;
  286. margin-right: 14rpx;
  287. }
  288. }
  289. }
  290. .tab-ul {
  291. display: flex;
  292. padding: 56rpx;
  293. .tab-li {
  294. width: 328rpx;
  295. height: 88rpx;
  296. line-height: 88rpx;
  297. border-radius: 16rpx;
  298. color: #fa6400;
  299. text-align: center;
  300. background: linear-gradient(-62deg, transparent 32rpx, rgba(250, 100, 0, 0.08) 0) top right;
  301. background-size: 100% 100%;
  302. background-repeat: no-repeat;
  303. margin-right: 40rpx;
  304. }
  305. .tab-on {
  306. width: 328rpx;
  307. height: 88rpx;
  308. line-height: 88rpx;
  309. border-radius: 16rpx;
  310. text-align: center;
  311. color: #ffffff;
  312. font-weight: 500;
  313. background: linear-gradient(117deg, transparent 32rpx, #fa6400 0) top left;
  314. background-size: 100% 100%;
  315. background-repeat: no-repeat;
  316. margin-left: -25px;
  317. }
  318. }
  319. .input-ul {
  320. .input-li {
  321. color: #2d405e;
  322. width: 638rpx;
  323. margin: 40rpx auto;
  324. height: 80rpx;
  325. background: #f5f5f6;
  326. border-radius: 4rpx;
  327. position: relative;
  328. padding-left: 88rpx;
  329. .ibonfont {
  330. position: absolute;
  331. font-size: 40rpx;
  332. top: 50%;
  333. transform: translateY(-50%);
  334. left: 24rpx;
  335. }
  336. input {
  337. color: #2d405e;
  338. height: 80rpx;
  339. line-height: 80rpx;
  340. width: 400rpx;
  341. }
  342. .yzm-view {
  343. position: absolute;
  344. top: 50%;
  345. transform: translateY(-50%);
  346. right: 32rpx;
  347. color: #fa6400;
  348. }
  349. }
  350. }
  351. .login-btn {
  352. margin: 56rpx auto 170rpx;
  353. width: 638rpx;
  354. height: 89rpx;
  355. background: #fa6400;
  356. border-radius: 11rpx;
  357. line-height: 89rpx;
  358. text-align: center;
  359. font-weight: 500;
  360. color: #ffffff;
  361. }
  362. .divider-text {
  363. margin: 0 27rpx;
  364. }
  365. .wx-change-btn {
  366. color: #2d405e;
  367. margin: 50rpx auto 0;
  368. width: 638rpx;
  369. font-size: 26rpx;
  370. height: 80rpx;
  371. border-radius: 11rpx;
  372. line-height: 80rpx;
  373. text-align: center;
  374. border: 1px solid #cad0d7;
  375. .wxicon {
  376. vertical-align: middle;
  377. margin-right: 10rpx;
  378. }
  379. }
  380. }
  381. }
  382. </style>