doum
9 小时以前 fa6202debd1e940f9f779c86d9d3084c7c7b5e83
mini-program/pages/login/login.vue
@@ -8,19 +8,19 @@
            <view class="icon">
               <image src="/static/icon/login_ic_phone@2x.png" mode="widthFix"></image>
            </view>
            <input type="number" maxlength="11" placeholder="请输入手机号" />
            <text>获取验证码</text>
            <input :focus='focus' @blur="focus=false" type="text" v-model="form.userName" placeholder="请输入登录账号" />
         </view>
         <view class="login-list-item">
            <view class="icon">
               <image src="/static/icon/login_ic_password@2x.png" mode="widthFix"></image>
            </view>
            <input type="safe-password" placeholder="请输入密码" />
            <input :focus='focus1' @blur="focus1=false"    type="safe-password" v-model="form.password" placeholder="请输入密码" />
         </view>
      </view>
      <view class="login-btn">立即登录</view>
      <view class="login-btn" @click="submitDo">立即登录</view>
      <view class="login-info">
         <image src="/static/icon/ic_agree@2x.png" mode="widthFix"></image>
         <image src="/static/icon/ic_agree@2x.png" v-if="!radio" @click="changeRadio()" mode="widthFix"></image>
         <image src="/static/icon/ic_agree_sel@2x.png" v-if="radio" @click="changeRadio()"  mode="widthFix"></image>
         <view class="login-info-text">
            我已阅读并同意<text>《鼎元科技用户服务协议》</text>及<text>《鼎元科技用户隐私政策》</text>
         </view>
@@ -29,11 +29,83 @@
</template>
<script>
import { mapState } from 'vuex'
   export default {
      computed: {
         ...mapState(['shopInfo', 'shopToken','openid'])
      },
      data() {
         return {
            focus:false,
            focus1:false,
            loading:false,
            form:{
               userName:'',
               password:'',
               openid:'',
               memberId:''
            },
            radio:false
         };
      },
      onShow() {
         this.focus=false
         this.focus1=false
         this.form.openid=this.openid
         this.checkLogin()
      },
      methods:{
         checkLogin(){
            if( !this.shopInfo && !this.shopToken){
               let res = await that.$u.api.getUserInfo()
               if (res.code === 200) {
                  await that.$store.commit('setUserInfo', res.data)
                  await that.$store.commit('setOpenId', res.data.openId)
                  this.jumpShopIndex()
               }
            }
         },
         changeRadio(){
            this.radio = !this.radio
         },
         submitDo(){
            if(!this.form.userName){
               uni.showToast({
                  'title': '请输入登录账号',icon:'none'
               })
               this.focus=true
               this.loading=false
               return
            }
            if(!this.form.password){
               uni.showToast({
                  'title': '请输入登录密码',icon:'none'
               })
               this.focus1=true
               this.loading=false
               return
            }
            if(!this.radio){
               uni.showToast({
                  'title': '请先仔细阅读并同意用户协议和隐私政策',icon:'none'
               })
               this.loading=false
               return
            }
            this.$u.api.shopPasswordLogin(this.form)
               .then(res => {
                  if (res.code === 200) {
                     await that.$store.commit('setShopInfo', res.data.member)
                     await that.$store.commit('setShopToken', res.data.token)
                     this.jumpShopIndex()
                  }
               })
         },
         jumpShopIndex() {
            uni.navigateTo({
               url: '/pages/distributor/distributor'
            })
         }
      }
   }
</script>