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.

549 lines
15 KiB

<template>
<view class="container">
<image class="cbg" :src="base.imgHost('common_bg.png')"></image>
<view class="wrap">
<!-- 头像 -->
<view style="display:flex;justify-content:center;align-items:center;padding: 30rpx 0;">
<view @click="changeAvatar" style="width:140rpx;height:140rpx;border-radius:140rpx;overflow:hidden;">
<image style="width:100%;height:100%;" :src="userAvatar?userAvatar:base.imgHost('logo-add.png')"></image>
</view>
</view>
<u-form :model="form" :label-width="140" ref="uForm" :label-align="'left'" :error-type="['message']">
<u-form-item label="姓名" prop="username">
{{form.username}}
</u-form-item>
<u-form-item label="性别" prop="sex">
{{form.sex}}
</u-form-item>
<u-form-item label="联系方式" prop="mobile">
<view style="display: flex;justify-content: space-between;align-items: center;">
<u-input type="number" disabled placeholder="请输入联系方式" v-model="form.mobile" />
<!-- <view>{{form.mobile}}</view> -->
<u-button size="mini" type="primary" @click="addMobile">{{form.mobile?'修改':'绑定'}}</u-button>
</view>
</u-form-item>
<u-form-item label="身份证号" prop="idcard">
<u-input type="idcard" border placeholder="请输入身份证号" v-model="form.idcard" />
</u-form-item>
<u-form-item label="出生日期" prop="birthday">
<u-input @click="dateShow=true" placeholder="请选择出生日期" v-model="form.birthday"
type="select" />
</u-form-item>
<u-form-item label="邮箱" prop="email">
<u-input v-model="form.email" border placeholder="请输入邮箱" /></u-form-item>
<u-form-item label="公司名称" prop="company_name">
<u-input @click="showCompanySelector = true" type="select" v-model="form.company_name" border placeholder="请选择公司名称" />
</u-form-item>
<u-form-item label="职务" prop="company_position">
<u-input border v-model="form.company_position" placeholder="请输入职务" />
</u-form-item>
<u-form-item label="车牌" prop="plate">
<view style="display: flex;align-items: center;justify-content: space-between;">
<view v-if="plateList.length>0">
<view v-for="(item,index) in plateList" :key="index">
{{item}}
<u-icon color="red" style="margin-left:20rpx" @click="delPlate(index)"
name="close"></u-icon>
</view>
</view>
<u-button size="mini" type="primary" v-if="plateList.length<2" @click="addPlate">新增</u-button>
</view>
</u-form-item>
</u-form>
<view class="form-btn">
<view @click="saveUser" type="primary">提交</view>
</view>
</view>
<u-picker @confirm="dateConfirm" mode="time" v-model="dateShow" :params="dateParams"></u-picker>
<view class="modal">
<u-popup v-model="showPark" mode="bottom">
<view class="modal-tip">绑定车牌号</view>
<view class="modal-content" style="height:400rpx">
<view>
<plate ref="plates" @listenPlateChange="plateChange" :defaultPlate="plateNumber" />
</view>
</view>
<view class="form-btn">
<view @click="saveUser('add')" type="primary">确定</view>
</view>
</u-popup>
</view>
<!-- 修改手机号 -->
<view class="modal">
<u-popup v-model="showMobile" mode="bottom">
<view class="modal-tip">联系方式</view>
<view class="modal-content" style="height:400rpx">
<view class="login-form">
<view>
<u-input :custom-style="inputStyle" :clearable="false" v-model="myMobile"
placeholder="联系方式"></u-input>
</view>
<view class="sendmsg">
<u-input v-model="myCode" :custom-style="inputSendStyle" :clearable="false"
placeholder="验证码"></u-input>
<view @click="getSmsCode" class="send" :class="{'hasSend':hasSend}">
{{hasSend?'已发送':'获取验证码'}}<text v-if="hasSend">({{count}}s)</text>
</view>
</view>
</view>
</view>
<view class="form-btn">
<view @click="changeMobile" type="primary">确定</view>
</view>
</u-popup>
</view>
<!-- 公司选择器 -->
<company-selector v-model="showCompanySelector" @confirm="handleCompanyConfirm" @no-data="handleNoCompanyData"></company-selector>
<!-- 手动输入公司名称 -->
<view class="modal">
<u-popup v-model="showCompanyInput" mode="bottom">
<view class="modal-tip">输入公司名称</view>
<view class="modal-content" style="height:400rpx">
<view class="login-form">
<view>
<u-input :custom-style="inputStyle" :clearable="true" v-model="manualCompanyName"
placeholder="请输入公司全称"></u-input>
</view>
</view>
</view>
<view class="form-btn">
<view @click="confirmManualCompany" type="primary">确定</view>
</view>
</u-popup>
</view>
</view>
</template>
<script>
import tabbar from '@/components/tabbar/tabbar.vue';
import {
plate
} from '@/components/plate/index.vue'
import CompanySelector from '@/components/company-selector/company-selector.vue'
export default {
components: {
plate,
CompanySelector
},
data() {
return {
userAvatar: '',
showMobile: false,
myMobile: '',
myCode: '',
hasSend: false,
sendTimer: null,
count: 60,
inputStyle: {
'padding': '0rpx 30rpx',
'height': '80rpx',
'border': '1rpx solid #dad8d8;',
'border-radius': '20rpx'
},
inputSendStyle: {
'padding': '0rpx 30rpx',
'height': '80rpx',
'border': '1rpx solid #dad8d8;',
'border-radius': '20rpx 0 0 20rpx'
},
dateShow: false,
dateParams: {
year: true,
month: true,
day: true,
hour: false,
minute: false,
second: false
},
form: {
},
plateList: [],
showPark: false,
isLocked: false,
plate1: '',
plateNumber: ['苏', 'E', '', '', '', '', ''],
showCompanySelector: false,
showCompanyInput: false,
manualCompanyName: '',
rules: {
mobile: [{
required: true,
message: '请输入联系方式',
trigger: ['blur'],
}, {
validator: (rule, value, callback) => {
return this.$u.test.mobile(value);
},
message: '手机号码不正确',
trigger: ['blur'],
}],
idcard: [{
validator: (rule, value, callback) => {
console.log("value", value, this.base.isNull(value))
if (!this.base.isNull(value)) {
return this.$u.test.idCard(value);
} else {
return true
}
},
message: '身份证号不正确',
trigger: ['blur'],
}],
email: [{
validator: (rule, value, callback) => {
if (!this.base.isNull(value)) {
return this.$u.test.email(value);
} else {
return true
}
},
message: '邮箱不正确',
trigger: ['blur'],
}],
}
}
},
onReady() {
this.$refs.uForm.setRules(this.rules);
},
onShow() {
this.getUserInfo()
},
onLoad() {},
onUnload() {
if (this.sendTimer) {
clearInterval(this.sendTimer);
this.sendTimer = null
}
},
onHide() {
if (this.sendTimer) {
clearInterval(this.sendTimer);
this.sendTimer = null
}
},
methods: {
changeAvatar(){
uni.navigateTo({
url:'/packages/avatarUpload/index'
})
},
// 日期
dateConfirm(e) {
this.form.birthday = e.year + '-' + e.month + '-' + e.day
},
addMobile() {
this.myMobile = this.form.mobile
this.showMobile = true
},
getSmsCode() {
if (this.hasSend) {
return
}
if (this.base.isNull(this.myMobile)) {
this.base.toast('手机号码不能为空')
return
}
if (!this.base.isMobile(this.myMobile)) {
this.base.toast('手机号码错误')
return
}
if (this.myMobile == this.form.mobile && !this.base.isNull(this.form.mobile)) {
this.base.toast('请输入需要变更的手机号码')
return
}
let that = this
this.$u.api.sendSms({
mobile: this.myMobile
}).then(res => {
this.base.toast("发送成功")
this.hasSend = true
this.sendTimer = setInterval(function() {
if (that.count > 1) {
that.count--
} else {
clearInterval(that.sendTimer);
that.sendTimer = null
that.count = 60
that.hasSend = false;
}
}, 1000)
})
},
changeMobile() {
if (this.base.isNull(this.myMobile)) {
this.base.toast('请输入手机号')
return
}
if (this.base.isNull(this.myCode)) {
this.base.toast('请输入验证码')
return
}
let that = this
this.$u.api.bindMobile({
mobile: this.myMobile,
code: this.myCode,
is_bind: 1
}).then(res => {
this.base.toast('更改成功', 1500, function() {
that.myMobile = ''
that.myCode = ''
that.showMobile = false
setTimeout(function() {
that.getUserInfo()
}, 1500)
})
})
},
getUserInfo() {
this.$u.api.user().then(res => {
console.log("res", res)
// this.form = this.base.requestToForm(res.user, this.form)
this.form = this.base.deepCopy(res.user)
// 头像
this.userAvatar = res.user && res.user.headimgurl ? res.user.headimgurl : ''
if (res.user.plate) {
this.plateList = res.user.plate.split(',')
this.plateList.map((item, index) => {
if (this.base.isNull(item)) {
this.plateList.splice(index, 1)
}
})
}
this.isLocked = false
this.$u.vuex('vuex_user', res.user)
}).catch(res => {
this.isLocked = false
})
},
addPlate() {
if (this.plateList.length == 2) {
this.base.toast("每人最多只能添加两个车牌")
return
}
// this.plateList.push('')
this.showPark = true
},
delPlate(index) {
this.plateList.splice(index, 1)
this.saveUser('del')
},
plateChange(val) {
this.plate1 = val.join('')
},
// 处理公司选择确认事件
handleCompanyConfirm(company) {
console.log('选中的公司:', company);
this.form.company_name = company.enterpriseName||'';
this.form.company_date = company.startDate||'';
this.form.company_product = company.businessScope||'';
if(company.tagList && Array.isArray(company.tagList)){
this.form.company_type = company.tagList.join(',');
}
this.form.company_area = company.country||'';
this.form.company_address = company.address||'';
this.form.is_yuanhe = company.isYhInvested?'是':'否'
console.log("this.form",this.form)
},
// 处理搜索无数据事件
handleNoCompanyData(searchKeyword) {
uni.showModal({
title: '提示',
content: '当前没有查询到公司信息,是否输入公司全称?',
success: (res) => {
if (res.confirm) {
// 关闭搜索窗口
this.showCompanySelector = false;
// 设置默认值为搜索关键词
this.manualCompanyName = searchKeyword || '';
// 打开输入框
this.showCompanyInput = true;
}
}
});
},
// 确认手动输入的公司名称
confirmManualCompany() {
if (this.base.isNull(this.manualCompanyName)) {
this.base.toast('请输入公司名称');
return;
}
// 将输入的公司名称赋给 form.company_name
this.form.company_name = this.manualCompanyName.trim();
// 关闭输入框
this.showCompanyInput = false;
// 清空输入
this.manualCompanyName = '';
},
saveUser(type) {
if (type == 'add') {
console.log("this.plate1", this.plate1)
if (this.base.isNull(this.plate1) || this.plate1.length < 7) {
this.base.toast("车牌号不正确")
return
}
if (this.plateList.indexOf(this.plate1) !== -1) {
this.base.toast("车牌号不能重复")
return
}
this.plateList.push(this.plate1)
this.form.plate = this.plateList.join(",")
}
if (type == 'del') {
this.form.plate = this.plateList.join(",")
}
console.log("plateList", this.plateList)
let that = this
this.$refs.uForm.validate(valid => {
if (valid) {
if (this.isLocked) {
return
}
this.isLocked = true
this.$u.api.saveUser(this.form).then(res => {
this.showPark = false
this.plate1 = ''
let toastTitle = "更新用户信息成功"
if (type === 'add') {
toastTitle = "新增车牌成功"
} else if (type === 'del') {
toastTitle = "删除车牌成功"
} else {
toastTitle = "更新用户信息成功"
}
this.$refs.plates.panelReset()
this.base.toast(toastTitle, 2000, function() {
if (type === 'add' || type === 'del') {
that.getUserInfo()
} else {
setTimeout(function() {
uni.switchTab({
url: '/pages/me/index'
})
}, 2000)
}
})
}).catch(err => {
this.isLocked = false
})
} else {
console.log('验证失败');
// this.base.toast("注册失败")
}
});
},
}
}
</script>
<style scoped lang="scss">
.container {
padding: 30rpx;
height: 100vh;
overflow: scroll;
.cbg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
}
.wrap {
background: #fff;
position: relative;
padding: 35rpx;
border-radius: 30rpx;
padding-top: 0;
}
.form-btn {
width: 100%;
position: relative;
padding: 60rpx 0;
&>view {
width: 70%;
text-align: center;
margin: 0 auto;
color: #fff;
background: linear-gradient(to right, #5e5fbc, #0d0398);
border-radius: 30rpx;
padding: 20rpx;
}
}
.modal {
::v-deep .u-drawer-bottom {
border-radius: 40rpx;
}
&-tip {
text-align: center;
padding: 30rpx;
font-size: 32rpx;
}
&-content {
// height: 400rpx;
padding: 0 30rpx;
}
}
.login-form {
margin: 100rpx 50rpx;
&>view {
border-radius: 20rpx;
&:first-child {
margin-bottom: 50rpx;
}
}
.sendmsg {
display: flex;
justify-content: space-between;
align-items: center;
u-input {
width: calc(100% - 200rpx);
}
.send {
background: #c69c6d;
color: #fff;
height: 80rpx;
line-height: 80rpx;
border-radius: 0 20rpx 20rpx 0;
width: 200rpx;
text-align: center;
border: 1px solid #c69c6d;
box-sizing: content-box;
}
.hasSend {
background: #dad8d8;
color: #333;
border: 1px solid #dad8d8;
}
}
}
}
</style>