多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

410 lines
10 KiB

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