From d9a89d83c2048a964f16ca179feb2b7f21b9d33a Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期一, 29 七月 2024 16:28:47 +0800
Subject: [PATCH] 提交

---
 wechat_staff/pages/login/index.js |  193 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 181 insertions(+), 12 deletions(-)

diff --git a/wechat_staff/pages/login/index.js b/wechat_staff/pages/login/index.js
index a578bb5..90f7f48 100644
--- a/wechat_staff/pages/login/index.js
+++ b/wechat_staff/pages/login/index.js
@@ -1,4 +1,10 @@
-// pages/auth/auth.js
+import {
+  sendSms,
+  getDictData,
+  getWxMiniPhone,
+  loginByPhone,
+  bindingOpenid
+} from '../../api/index'
 Page({
 
   /**
@@ -10,20 +16,97 @@
     status: '0', // 鏍囪瘑
     countDown: 0,
     phone: '',
-    password: '',
+    code: '',
+    showModal: false,
+    activeHtml: '',
   },
   getCode() {
     let countDown = this.data.countDown
-    if(countDown > 0) return
-    this.setData({ countDown: 60 })
-    let timer = setInterval(() => {
-      let countDown = this.data.countDown
-      if(countDown === 0){
-        return clearInterval(timer)
+    if (countDown > 0) return
+    const {
+      phone
+    } = this.data
+    if (!phone || phone.length != 11) {
+      return wx.showToast({
+        title: '璇疯緭鍏ユ纭殑鎵嬫満鍙�',
+        icon: 'none'
+      })
+    }
+    sendSms({
+      phone
+    }).then(res => {
+      wx.showToast({
+        title: '楠岃瘉鐮佸彂閫佹垚鍔�',
+        icon: 'none'
+      })
+      this.setData({
+        countDown: 60
+      })
+      let timer = setInterval(() => {
+        let countDown = this.data.countDown
+        if (countDown === 0) {
+          return clearInterval(timer)
+        }
+        countDown--
+        this.setData({
+          countDown
+        })
+      }, 1000)
+    })
+  },
+  handleJudge(e) {
+    const flag = e.currentTarget.dataset.flag
+    console.log(e);
+    this.setData({ agreementFalg: flag, showModal: false })
+  },
+  loginPhone() {
+    const {
+      code,
+      phone
+    } = this.data
+    loginByPhone({
+      code,
+      phone
+    }).then(res => {
+      if (res.data && res.data.token) {
+        wx.login({
+          timeout: 5000,
+          success: (loginRes) =>  {
+            if (loginRes.code) {
+              this.bindingOpenid(loginRes.code, res.data.token)
+            }
+          }
+        })
+        if(res.data.phone){
+          res.data.users.phone = res.data.phone || res.data.users.phone
+        }
+        wx.setStorageSync('member', res.data.users)
+        wx.setStorageSync('token', res.data.token)
+        wx.showToast({
+          title: '鐧诲綍鎴愬姛',
+        })
+        setTimeout(() => {
+          wx.switchTab({
+            url: '/pages/index/index',
+          })
+        }, 300)
+      }else{
+        wx.showToast({
+          title: '浣犺繕涓嶆槸璇ョ郴缁熺敤鎴凤紝璇疯仈绯荤浉鍏崇鐞嗗憳娉ㄥ唽',
+        })
       }
-      countDown --
-      this.setData({ countDown })
-    }, 1000)
+    })
+  },
+  changeStatus() {
+    if (!this.data.agreementFalg) {
+      return wx.showToast({
+        title: '璇峰厛闃呰骞跺悓鎰忕浉鍏冲崗璁�',
+        icon: 'none'
+      })
+    }
+    this.setData({
+      status: '1'
+    })
   },
   agreementChange(e) {
     this.setData({
@@ -33,7 +116,93 @@
   onLoad(options) {
     var app = getApp().globalData
     this.setData({
-      primary: app.primary
+      primary: app.primary,
+      bottomLift: app.bottomLift
+    })
+    this.initData()
+  },
+  getPhoneNumber(e) {
+    const data = {
+      ...e.detail
+    }
+    getWxMiniPhone({
+      encryptedData: data.encryptedData,
+      iv: data.iv,
+      sessionKey: wx.getStorageSync('sessionKey'),
+    }).then(res => {
+      if (res.data && res.data.token) {
+        wx.login({
+          timeout: 5000,
+          success: (loginRes) =>  {
+            if (loginRes.code) {
+              this.bindingOpenid(loginRes.code, res.data.token)
+            }
+          }
+        })
+        if(res.data.phone){
+          res.data.users.phone = res.data.phone || res.data.users.phone
+        }
+        wx.setStorageSync('member', res.data.users)
+        wx.setStorageSync('token', res.data.token)
+        wx.switchTab({
+          url: '/pages/index/index',
+        })
+      }else{
+        wx.showToast({
+          title: '浣犺繕涓嶆槸璇ョ郴缁熺敤鎴凤紝璇疯仈绯荤浉鍏崇鐞嗗憳娉ㄥ唽',
+        })
+      }
+
+    })
+  },
+  bindingOpenid(code, token) {
+    bindingOpenid({code, token})
+  },
+  loginIn() {
+    const {
+      agreementFalg
+    } = this.data
+    if (!agreementFalg) return wx.showToast({
+      title: '璇峰厛闃呰骞跺悓鎰忕浉鍏冲崗璁�',
+      icon: 'none',
+      duration: 2000
+    })
+  },
+  onOpen(e) {
+    const {
+      serviceHtml,
+      privacyHtml
+    } = this.data
+    const {
+      index
+    } = e.target.dataset
+    let activeHtml = index == '0' ? serviceHtml : privacyHtml
+    this.setData({
+      activeHtml,
+      showModal: true
+    })
+  },
+  onClose() {
+    this.setData({
+      showModal: false
+    })
+  },
+  initData() {
+    getDictData({
+      code: 'ZBOM_CUSTOMIZED',
+      label: 'SERVER_AGREEMENT'
+    }).then(res => {
+      this.setData({
+        serviceHtml: res.data.code
+      })
+    })
+    getDictData({
+      code: 'ZBOM_CUSTOMIZED',
+      label: 'PRIVACY_AGREEMENT'
+    }).then(res => {
+      this.setData({
+        privacyHtml: res.data.code
+      })
     })
   },
 

--
Gitblit v1.9.3