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.
228 lines
5.1 KiB
228 lines
5.1 KiB
5 years ago
|
<template>
|
||
|
<view>
|
||
|
<view class="infor-box" v-for="(item,index) in list" :key="index">
|
||
|
<view class="infor-title">{{ item.title }}<text class="fbt">*</text></view>
|
||
|
<input v-if="item.type === 0" placeholder="请输入" name="input" v-model.trim="item.content"></input>
|
||
|
<radio-group v-if="item.type === 1" name="sex" @change="radioChange">
|
||
|
<label class="w100">
|
||
|
<radio value="0" :checked="che===0?true:false" /></radio><text>女</text>
|
||
|
<radio value="1" :checked="che===1?true:false" /></radio><text>男</text>
|
||
|
</label>
|
||
|
</radio-group>
|
||
|
</view>
|
||
|
<button v-show="isId-0===0" class="btn cu-btn bg-green margin-tb-sm lg" @click="submit">提交</button>
|
||
|
<button v-show="isId-0===1" class="btn cu-btn bg-blue margin-tb-sm lg" @click="change">修改</button>
|
||
|
</view>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import { savecoach } from 'api/savecoach'
|
||
|
import { coachInfo } from 'api/coachInfo'
|
||
|
export default {
|
||
|
async onLoad(option) {
|
||
|
const that = this
|
||
|
if(option.id) {
|
||
|
console.log(option)
|
||
|
try{
|
||
|
const params = {
|
||
|
param: {
|
||
|
coachId: option.id
|
||
|
}
|
||
|
}
|
||
|
const data = await coachInfo(params)
|
||
|
console.log(data)
|
||
|
that.list[0].content = data.name
|
||
|
that.che = data.gender
|
||
|
that.list[2].content = data.phone
|
||
|
that.list[3].content = data.idCard
|
||
|
that.isId = 1
|
||
|
that.coachId = data.coachId
|
||
|
}catch(e){
|
||
|
//TODO handle the exception
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
data() {
|
||
|
return {
|
||
|
list: [{
|
||
|
title:'姓名',
|
||
|
type: 0 ,// 0是输入框,1是单选框,2是图片选择
|
||
|
content: ''
|
||
|
}, {
|
||
|
title:'性别',
|
||
|
type: 1,
|
||
|
content: ''
|
||
|
}, {
|
||
|
title:'联系方式',
|
||
|
type: 0,
|
||
|
content: ''
|
||
|
}, {
|
||
|
title:'身份证号',
|
||
|
type: 0,
|
||
|
content: ''
|
||
|
}],
|
||
|
che: 0,
|
||
|
isId: 0,
|
||
|
coachId: 0
|
||
|
// imgList: []
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
radioChange(e) {
|
||
|
const that = this
|
||
|
that.che = e.detail.value - 0
|
||
|
console.log(that.che)
|
||
|
},
|
||
|
async submit() {
|
||
|
const that = this
|
||
|
if (that.list[0].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '姓名不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else if (that.list[2].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '联系方式不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else if (!/^1([3-9])[0-9]{9}$/.test(that.list[2].content)) {
|
||
|
uni.showToast({
|
||
|
title: '请输入正确的手机号',
|
||
|
icon: 'none',
|
||
|
duration: 2000
|
||
|
})
|
||
|
}else if (that.list[3].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '身份证号不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else {
|
||
|
try{
|
||
|
const params = {
|
||
|
param: {
|
||
|
companyId: that.$store.state.project.companyId,
|
||
|
identity: 0,
|
||
|
name: that.list[0].content,
|
||
|
gender: that.che,
|
||
|
phone: that.list[2].content,
|
||
|
idCard: that.list[3].content
|
||
|
}
|
||
|
}
|
||
|
const data = await savecoach(params)
|
||
|
uni.showToast({
|
||
|
title: '添加成功',
|
||
|
icon: 'success',
|
||
|
duration: 1500
|
||
|
})
|
||
|
that.$store.state.project.num++
|
||
|
setTimeout(function(){
|
||
|
uni.navigateBack()
|
||
|
},1000)
|
||
|
}catch(e){
|
||
|
//TODO handle the exception
|
||
|
uni.showToast({
|
||
|
title: e,
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
// console.log('提交事件')
|
||
|
},
|
||
|
async change() {
|
||
|
const that = this
|
||
|
if (that.list[0].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '姓名不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else if (that.list[2].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '联系方式不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else if (!/^1([3-9])[0-9]{9}$/.test(that.list[2].content)) {
|
||
|
uni.showToast({
|
||
|
title: '请输入正确的手机号',
|
||
|
icon: 'none',
|
||
|
duration: 2000
|
||
|
})
|
||
|
}else if (that.list[3].content === '') {
|
||
|
uni.showToast({
|
||
|
title: '身份证号不能为空',
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
} else {
|
||
|
try{
|
||
|
const params = {
|
||
|
param: {
|
||
|
coachId: that.coachId,
|
||
|
companyId: that.$store.state.project.companyId,
|
||
|
identity: 0,
|
||
|
name: that.list[0].content,
|
||
|
gender: that.che,
|
||
|
phone: that.list[2].content,
|
||
|
idCard: that.list[3].content
|
||
|
}
|
||
|
}
|
||
|
const data = await savecoach(params)
|
||
|
uni.showToast({
|
||
|
title: '修改成功',
|
||
|
icon: 'success',
|
||
|
duration: 1500
|
||
|
})
|
||
|
that.$store.state.project.num++
|
||
|
setTimeout(function(){
|
||
|
uni.navigateBack()
|
||
|
},1000)
|
||
|
}catch(e){
|
||
|
//TODO handle the exception
|
||
|
uni.showToast({
|
||
|
title: e,
|
||
|
icon: 'none',
|
||
|
duration: 1500
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style lang="scss" scoped>
|
||
|
.infor-box {
|
||
|
width: 680rpx;
|
||
|
margin-left: 35rpx;
|
||
|
margin-top: 25px;
|
||
|
border-bottom: 1px solid #eee;
|
||
|
}
|
||
|
.infor-title {
|
||
|
font-size: 16px;
|
||
|
color: #505050;
|
||
|
margin-bottom: 10px;
|
||
|
}
|
||
|
.fbt {
|
||
|
color: $red;
|
||
|
}
|
||
|
.w100 {
|
||
|
width: 680rpx;
|
||
|
display: flex;
|
||
|
radio {
|
||
|
margin-right: 50rpx;
|
||
|
}
|
||
|
text {
|
||
|
flex: 1;
|
||
|
}
|
||
|
}
|
||
|
.btn {
|
||
|
width: 600rpx;
|
||
|
margin: 50px 0 0 75rpx;
|
||
|
}
|
||
|
</style>
|