平板端快衣店
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.
 
 
 
 
 

398 lines
9.9 KiB

<template>
<view class="content">
<view class="title-name">
快衣店
</view>
<view class="container">
<view class="">
<uni-section title="选择登录身份" type="line">
<uni-data-select v-model="wayValue" :localdata="range" @change="sectionChange"
:clear="false"></uni-data-select>
</uni-section>
</view>
<view class="login-content" v-if="loginWay == true">
<uni-easyinput v-model="username" placeholder="请输入账号" />
<com-zw />
<uni-easyinput v-model="password" :maxlength="25" placeholder="请输入密码" type="password" />
<com-zw />
<view class="flex" style="display: flex;">
<uni-easyinput v-model="code" :clearable="false" :maxlength="4" placeholder="请输入验证码" />
<img :src="captchaImg" alt="加载验证码失败"
style="width: 90px; height: 74rpx; cursor: pointer; display: block" @click="getCaptchaImg" />
</view>
</view>
<view class="login-content" v-else>
<uni-easyinput v-model="mobile" :maxlength="11" placeholder="请输入手机号" />
<com-zw />
<view class="code-box">
<uni-easyinput type="digit" v-model="code" placeholder="请输入验证码" trim="all" />
<button class="button" size="mini" type="default" @click="sendLoginSms" :disabled="choose"
:class="choose == false ? 'hasChosen':'notChosen'">
{{ choose ? clock + '重新获取' : '获取验证码' }}
</button>
</view>
</view>
<view class="tui-protocol" hover-class="opcity" :hover-stay-time="150">
点击"登录"即表示已同意
<text class="tui-protocol-red" @tap="protocol">《用户协议》</text>
</view>
<view @tap.stop="goLogin" class="login-btn">登录</view>
<view class="login-way">
<view class="" @tap="goRegister">新店铺注册</view>
<view class="" @tap="switchLoginWay">{{loginWay ? '验证码登录' : '账号密码登录'}}</view>
</view>
</view>
<!-- 多店铺的时候,选择店铺的弹窗 -->
<view>
<uni-popup ref="popup" background-color="#fff" @change="change">
<view class="popup-content">
<view class="popup-title">
<text>选择登录店铺</text>
</view>
<view class="popup-container" v-for="item in shopList" :key="item" @tap="checkShop(item)">
<text style="display: inline-block">{{item.shopName}}</text>
</view>
</view>
</uni-popup>
</view>
</view>
</template>
<script>
import {
mapMutations,
mapActions,
mapState
} from 'vuex';
import {
reg
} from '@/utils/global.js'
export default {
data() {
return {
mobile: '15630117759',
// username: '15101147760',
username: '15630117759',
code: '',
// password: '123456',
password: '19950123kang',
loginWay: true, //true账号密码登录 false验证码登录
captchaImg: '',
captchaId: '',
wayValue: 1,
range: [{
value: 0,
text: "店铺"
},
{
value: 1,
text: "物流公司"
},
{
value: 2,
text: "下游客户"
},
],
choose: false,
isChoose: false,
clock: 60, // 倒计时
shopList: []
}
},
computed: mapState(['type']),
onLoad() {
this.getCaptchaImg();
},
methods: {
...mapMutations(['login']),
...mapActions(['getUserInfo']),
getCaptchaImg() {
this.tui.request("/common/captcha/init", "GET", null).then((res) => {
if (res.code == 200) {
this.captchaId = res.result
this.captchaImg = this.tui.interfaceUrl() + '/common/captcha/draw/' + this
.captchaId
} else {
this.tui.toast(res.message)
}
}).catch((res) => {})
},
sectionChange(index) {
this.wayValue = index;
},
//登录
goLogin() {
let data = {},
loginUrl=''
if (this.loginWay) { //true
data = {
username: this.username,
password: this.password,
code: this.code,
captchaId: this.captchaId,
saveLogin: true,
type: this.wayValue
}
loginUrl='/auth/login' //type : 0管理员 1是普通员工
} else {
data = {
mobile: this.mobile,
code: this.code,
saveLogin: true,
type: this.wayValue
}
loginUrl='/auth/smsLogin'
}
if(this.wayValue == 1){ //15630117759 19950123kang
this.tui.request("/app/logitics/login", "POST", {
username: this.username,
password: this.password,
code: this.code,
saveLogin: true,
type: this.wayValue
}, true, true).then((res) => {
if (res.code == 200) {
uni.setStorageSync("hiver_token", res.result.lcomToken)
uni.setStorageSync("transCompany", res.result.logiticsCompany.id)
uni.setStorageSync("companyName", res.result.logiticsCompany.companyName)
uni.setStorageSync("signCompany", res.result.logiticsCompany.signCompany)
uni.setStorageSync("wayValue", this.wayValue)
this.tui.toast('登录成功', 2000, true)
setTimeout(() => {
uni.reLaunch({
url: '/pages/other/logistics'
})
}, 200)
}else{
this.tui.toast(res.message)
}
}).catch((res) => {})
}else{
this.tui.request(loginUrl, "POST", data, true, true).then((res) => {
if (res.code == 200) {
uni.setStorageSync("hiver_token", res.result.accessToken)
//多店铺的时候,在这里加上打开店铺选择弹窗
if(this.wayValue == 2){ //下游客户登录
setTimeout(() => {
uni.reLaunch({
url: '/pages/other/custom'
})
}, 200)
this.tui.toast('登录成功', 2000, true)
}else if (res.result.shopList.length > 1 && this.wayValue == 0) {
this.shopList = res.result.shopList;
this.toggle("center");
}else{
uni.setStorageSync('shopName',res.result.shopList[0].shopName)
uni.setStorageSync('type',res.result.shopList[0].type)
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
})
}, 200)
this.tui.toast('登录成功', 2000, true)
}
} else {
this.tui.toast(res.message)
}
}).catch((res) => {})
}
},
//多店铺的时候点击选择需要登录的店铺
checkShop(item) {
this.tui.request("/auth/chooseShop", "POST", {
shopId: item.shopId
}, false, true).then((res) => {
if (res.code == 200) {
uni.setStorageSync('shopName',item.shopName)
uni.setStorageSync('type',item.type)
setTimeout(() => {
uni.reLaunch({
url: '/pages/index/index'
// url: '/pages/index/logistics'
})
}, 200)
this.tui.toast('登录成功', 2000, true)
} else {
this.tui.toast(res.message)
return
}
}).catch((res) => {})
},
sendLoginSms() { // 获取验证码
this.isChoose = false
if (reg(this.mobile, this.clock) && this.isChoose == false) {
this.choose = true
this.setTime()
this.tui.request("/common/captcha/sendLoginSms/" + this.mobile, "GET", {
type: this.wayValue
}).then((res) => {
if (res.code == 200) {
uni.showToast({
title: "发送成功",
icon: 'success'
})
} else {
this.tui.toast(res.message)
}
}).catch((res) => {})
} else if (reg(this.mobile, this.clock) && this.isChoose == true) {
}
},
setTime() { // 倒计时函数
if (this.clock == 0) {
this.clock = 60
this.choose = false
return
} else {
this.clock--
if (this.clock < 10) {
this.clock = '0' + this.clock
}
}
setTimeout(() => {
this.setTime()
}, 1000)
},
//注册
goRegister() {
uni.navigateTo({
url: '/pages/login/register'
})
},
//切换登录方式
switchLoginWay() {
this.loginWay = !this.loginWay
},
protocol() {
uni.navigateTo({
url: '/pages/common/protocol/protocol'
})
},
//打开弹出层
toggle(type) {
this.type = type
this.$refs.popup.open(type)
},
}
}
</script>
<style lang="scss" scoped>
.content {
height: 1624rpx;
background: #fff;
}
.title-name {
width: 100%;
height: 400rpx;
line-height: 200rpx;
font-size: 80rpx;
text-align: center;
padding-top: 200rpx;
color: #000;
}
.container {
width: 90%;
height: 700rpx;
margin: 0 auto;
}
.login-content {
margin-top: 20rpx;
}
.tui-protocol {
color: #333;
font-size: 24rpx;
text-align: center;
width: 100%;
margin: 29rpx 0;
.tui-protocol-red {
color: $u-primary;
}
}
.login-btn {
width: 100%;
height: 80rpx;
align-items: center;
justify-content: center;
box-sizing: border-box;
color: #fff;
background-color: #0072E3;
border-radius: 80rpx !important;
line-height: 80rpx;
text-align: center;
}
.login-way {
display: flex;
height: 80rpx;
line-height: 80rpx;
}
.login-way view:first-child {
flex: 1;
padding-left: 40rpx;
}
.login-way view:last-child {
flex: 1;
padding-right: 40rpx;
text-align: right;
}
.hasChosen {
height: 74rpx;
line-height: 74rpx;
color: #fff;
border: none;
background: #5fd9ee;
}
.code-box {
display: flex;
}
.popup-content {
align-items: center;
justify-content: center;
padding: 15px;
width: 500rpx;
height: auto;
background-color: #fff;
}
.popup-title {
font-size: 36rpx;
font-weight: bold;
text-align: center;
position: relative;
}
.popup-container {
margin-top: 20rpx;
height: 100rpx;
border-radius: 10px;
background: #088FEB;
line-height: 100rpx;
text-align: center;
border-bottom: 1px solid #eee;
border-top: 1px solid #eee;
color: #fff;
}
.phone-btn {
width: 150rpx;
height: 75rpx;
color: #088FEB;
line-height: 75rpx;
font-size: 26rpx;
}
</style>