手机号正则校验

lixuan
xk_guohonglei 5 years ago
parent 0bcbc4b3e1
commit f87b163385
  1. 423
      pages/staff/editStaff/addUser.vue

@ -1,210 +1,235 @@
<template> <template>
<view class="page-content my-bg"> <view class="page-content my-bg">
<cu-custom class="main-totextbar bg-main-oil" :isBack="true" bgColor="bg-main-oil"> <cu-custom class="main-totextbar bg-main-oil" :isBack="true" bgColor="bg-main-oil">
<block slot="backText">返回</block> <block slot="backText">返回</block>
<block slot="content">员工管理</block> <block slot="content">员工管理</block>
</cu-custom> </cu-custom>
<view class="margin radius"> <view class="margin radius">
<form> <form>
<view class="cu-form-group"> <view class="cu-form-group">
<view class="title">姓名</view> <view class="title">姓名</view>
<input :maxlength="8" @input="getChinese" :value="userInfo.cUserName" @blur="showChinese" placeholder="请输入姓名" name="input" /> <input
</view> :maxlength="8"
<view class="cu-form-group"> @input="getChinese"
<view class="title">手机号</view> :value="userInfo.cUserName"
<input type="number" v-model="userInfo.phone" placeholder="请输入手机号" name="input" /> @blur="showChinese"
</view> placeholder="请输入姓名"
name="input"
/>
</view>
<view class="cu-form-group">
<view class="title">手机号</view>
<input
type="number"
:maxlength="11"
v-model="userInfo.phone"
placeholder="请输入手机号"
name="input"
/>
</view>
<view class="cu-form-group text-right"> <view class="cu-form-group text-right">
<view class="title">权限设置</view> <view class="title">权限设置</view>
<view class>请选择以下权限</view> <view class>请选择以下权限</view>
</view> </view>
<view class=" padding bg-white "> <view class="padding bg-white">
<checkbox-group @change="checkboxChange" class="flex flex-wrap justify-between"> <checkbox-group @change="checkboxChange" class="flex flex-wrap justify-between">
<view class="basis-sm margin-bottom-sm" v-for="(item,index) in checkbox" :key="index"> <view class="basis-sm margin-bottom-sm" v-for="(item,index) in checkbox" :key="index">
<checkbox @tap="item.checked=!item.checked" class="round red" :class="item.checked?'checked':''" :checked="item.checked?true:false" <checkbox
:value="item.value"></checkbox> @tap="item.checked=!item.checked"
<text class="padding-left-xs">{{item.name}}</text> class="round red"
</view> :class="item.checked?'checked':''"
</checkbox-group> :checked="item.checked?true:false"
</view> :value="item.value"
</form> ></checkbox>
<view class="padding-top"> <text class="padding-left-xs">{{item.name}}</text>
<view class="text-lg">添加说明</view> </view>
<view class="padding-top-sm text-sm text-grey"> </checkbox-group>
<view class="margin-bottom-xs">1员工添加成功后系统会向该员工发送一条短信短信中包含了云站的识别码</view> </view>
<view class="margin-bottom-xs">2用户在收到短信后需要关注星油云站公众号进入小程序输入云站编码后根据页面要求输入对应的手机号姓名身份证信息与管理员添加的信息一致方可绑定成功</view> </form>
<view class>3绑定成功后无需再次登录操作</view> <view class="padding-top">
</view> <view class="text-lg">添加说明</view>
</view> <view class="padding-top-sm text-sm text-grey">
</view> <view class="margin-bottom-xs">1员工添加成功后系统会向该员工发送一条短信短信中包含了云站的识别码</view>
<view class="margin-left margin-right padding-lg bottom-bg"> <view
<button class="bg-main-oil round" @tap="saveInfo">保存</button> class="margin-bottom-xs"
</view> >2用户在收到短信后需要关注星油云站公众号进入小程序输入云站编码后根据页面要求输入对应的手机号姓名身份证信息与管理员添加的信息一致方可绑定成功</view>
</view> <view class>3绑定成功后无需再次登录操作</view>
</view>
</view>
</view>
<view class="margin-left margin-right padding-lg bottom-bg">
<button class="bg-main-oil round" @tap="saveInfo">保存</button>
</view>
</view>
</template> </template>
<script> <script>
import staffApi from '@/api/staff.js' import staffApi from '@/api/staff.js'
export default { export default {
data() { data() {
return { return {
tempUid: uni.getStorageSync('tempUid'), tempUid: uni.getStorageSync('tempUid'),
checkbox: [], checkbox: [],
userInfo: {}, userInfo: {},
mainURL: this.global.mainURL, mainURL: this.global.mainURL,
authList: [], authList: [],
lastAuthList: [] lastAuthList: []
} }
}, },
created() { created() {
this.getAllMenu() this.getAllMenu()
if (this.tempUid.type === 'edit') { if (this.tempUid.type === 'edit') {
setTimeout(() => { setTimeout(() => {
this.getUserInfo() this.getUserInfo()
}, 200); }, 200);
} }
}, },
methods: { methods: {
showChinese() {
const reg = /[\u4e00-\u9fa5]/g
var names = this.userInfo.cUserName.match(reg);
this.userInfo.cUserName = names.join("")
if (names) {
this.$set(this.userInfo, 'cUserName', names.join(""))
}
},
//
getChinese(e) {
var value = e.target.value
console.log('e-target-value', value)
if (value !== null && value !== '') {
const reg = /[\u4e00-\u9fa5]/g
var names = value.match(reg);
// console.log(names)
// this.$set(this.userInfo, 'cUserName', names.join(""))
if (names) {
this.$set(this.userInfo, 'cUserName', names.join(""))
}
console.log('v-model-name', this.userInfo.cUserName) showChinese() {
} const reg = /[\u4e00-\u9fa5]/g
var names = this.userInfo.cUserName.match(reg);
this.userInfo.cUserName = names.join("")
if (names) {
this.$set(this.userInfo, 'cUserName', names.join(""))
}
},
//
getChinese(e) {
var value = e.target.value
console.log('e-target-value', value)
if (value !== null && value !== '') {
const reg = /[\u4e00-\u9fa5]/g
var names = value.match(reg);
// console.log(names)
// this.$set(this.userInfo, 'cUserName', names.join(""))
if (names) {
this.$set(this.userInfo, 'cUserName', names.join(""))
}
console.log('v-model-name', this.userInfo.cUserName)
}
},
calcMenuList() { },
this.checkbox.forEach(item => { calcMenuList() {
console.log(item.checked) this.checkbox.forEach(item => {
if (item.checked) { console.log(item.checked)
this.lastAuthList.push(item.value) if (item.checked) {
} this.lastAuthList.push(item.value)
}) }
console.log('计算出来的', this.lastAuthList) })
}, console.log('计算出来的', this.lastAuthList)
checkboxChange(e) { },
var items = this.checkbox, checkboxChange(e) {
values = e.detail.value; var items = this.checkbox,
for (var i = 0, lenI = items.length; i < lenI; ++i) { values = e.detail.value;
const item = items[i] for (var i = 0, lenI = items.length; i < lenI; ++i) {
if (values.includes(item.value)) { const item = items[i]
this.$set(item, 'checked', true) if (values.includes(item.value)) {
} else { this.$set(item, 'checked', true)
this.$set(item, 'checked', false) } else {
} this.$set(item, 'checked', false)
} }
}, }
updateUser(data4) { },
staffApi.updateUser(data4).then(res => { updateUser(data4) {
if (res.code === 20000) { staffApi.updateUser(data4).then(res => {
uni.showToast({ if (res.code === 20000) {
title: res.msg, uni.showToast({
duration: 3000 title: res.msg,
}) duration: 3000
setTimeout(() => { })
uni.navigateBack() setTimeout(() => {
}, 2500); uni.navigateBack()
} }, 2500);
}) }
}, })
addUser(data4) { },
staffApi.addOilUser(data4).then(res => { addUser(data4) {
if (res.code === 20000) { staffApi.addOilUser(data4).then(res => {
uni.showToast({ if (res.code === 20000) {
title: res.msg, uni.showToast({
duration: 3000 title: res.msg,
}) duration: 3000
setTimeout(() => { })
uni.navigateBack() setTimeout(() => {
}, 2500); uni.navigateBack()
} }, 2500);
}) }
}, })
saveInfo() { },
if (!this.userInfo.cUserName) { saveInfo() {
uni.showToast({ if (!this.userInfo.cUserName) {
title: '请输入员工姓名', uni.showToast({
icon: 'none' title: '请输入员工姓名',
}) icon: 'none'
return false })
} return false
if (!this.userInfo.phone) { }
uni.showToast({ if (!this.userInfo.phone) {
title: '请输入员工手机号', uni.showToast({
icon: 'none' title: '请输入员工手机号',
}) icon: 'none'
return false })
} return false
this.calcMenuList() } else if (!/^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(17[0-9]{1})|(18[0-9]{1})|(19[0-9]{1})|(16[0-9]{1}))+\d{8})$/.test(this.userInfo.phone)) {
const data4 = { uni.showToast({
cUserId: this.userInfo.cUserId, title: '手机号码不正确',
cUserName: this.userInfo.cUserName, icon: 'none'
phone: this.userInfo.phone, })
menuIdLst: this.lastAuthList, return false
pushState: 1, }
pushProcedureState: 1 this.calcMenuList()
} const data4 = {
if (this.tempUid.type === 'add') { cUserId: this.userInfo.cUserId,
this.addUser(data4) cUserName: this.userInfo.cUserName,
} else if (this.tempUid.type === 'edit') { phone: this.userInfo.phone,
this.updateUser(data4) menuIdLst: this.lastAuthList,
} pushState: 1,
}, pushProcedureState: 1
getAllMenu() { }
staffApi.getOilSiteAllMenu(this.tempUid.id).then(res => {
if (res.code === 20000) { this.addUser(data4)
var auths = []
var temp = res.data },
temp.forEach(item => { getAllMenu() {
auths.push({ staffApi.getOilSiteAllMenu(this.tempUid.id).then(res => {
value: item.menuId, if (res.code === 20000) {
checked: false, var auths = []
name: item.menuName var temp = res.data
}) temp.forEach(item => {
}) auths.push({
this.checkbox = auths value: item.menuId,
} checked: false,
}) name: item.menuName
}, })
getUserInfo() { })
staffApi.findUserAuthById(this.tempUid.id).then(res => { this.checkbox = auths
if (res.code === 20000) { }
this.userInfo = res.data })
this.authList = res.data.authList },
if (this.authList && this.authList.length > 0) { getUserInfo() {
console.log('已有权限', this.authList) staffApi.findUserAuthById(this.tempUid.id).then(res => {
this.authList.forEach((auth, index) => { if (res.code === 20000) {
this.checkbox.forEach(item => { this.userInfo = res.data
if (auth.menuId === item.value) { this.authList = res.data.authList
this.$set(item, 'checked', true) if (this.authList && this.authList.length > 0) {
} console.log('已有权限', this.authList)
}) this.authList.forEach((auth, index) => {
}) this.checkbox.forEach(item => {
} if (auth.menuId === item.value) {
} this.$set(item, 'checked', true)
}) }
} })
} })
} }
}
})
}
}
}
</script> </script>
<style scoped> <style scoped>

Loading…
Cancel
Save