123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- <template>
- <view>
- <cu-custom bgColor="bg-gradual-pink" :isBack="true">
- <block slot="backText">返回</block>
- <block slot="content">编辑资料</block>
- </cu-custom>
- <form>
- <view class="cu-form-group">
- <view class="title">姓名</view>
- <input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
- </view>
- <view class="cu-form-group">
- <view class="title">英文名</view>
- <input placeholder="英文名" name="input" v-model="myFormData.egName"></input>
- </view>
- <view class="cu-form-group">
- <view class="title">头像</view>
- <view class="grid col-4 grid-square flex-sub">
- <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
- <image :src="imgList[index]" mode="aspectFill"></image>
- <view class="cu-tag bg-red radius" @tap.stop="DelImg" :data-index="index">
- <text class='cuIcon-close'></text>
- </view>
- </view>
- <view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
- <text class='cuIcon-cameraadd'></text>
- </view>
- </view>
- </view>
-
- <view class="cu-form-group margin-top">
- <view class="title">性别</view>
- <picker @change="sexType" :range="sexs" :value="typesex">
- <view class="picker">
- {{sexname}}
- </view>
-
- </picker>
-
- <!-- <switch class='switch-sex' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch> -->
- </view>
- <view class="cu-form-group">
- <view class="title">生日</view>
- <picker mode="date" :value="myFormData.birthday" @change="DateChange">
- <view class="picker">
- {{myFormData.birthday}}
- </view>
- </picker>
- </view>
-
- <!-- <view class="cu-form-group margin-top">
- <view class="title">用户名</view>
- <input placeholder="用户名" name="input" v-model="myFormData.username" disabled></input>
- </view> -->
- <view class="cu-form-group">
- <view class="title">工号</view>
- <input placeholder="工号" name="input" v-model="myFormData.workNo" disabled></input>
- </view>
-
- <view class="cu-form-group margin-top">
- <view class="title">手机号码</view>
- <input placeholder="输入手机号码" name="input" v-model="myFormData.phone"></input>
- <view class="cu-capsule radius">
- <view class='cu-tag bg-blue '>
- +86
- </view>
- <view class="cu-tag line-blue">
- 中国大陆
- </view>
- </view>
- </view>
- <view class="cu-form-group">
- <view class="title">邮箱</view>
- <input placeholder="输入邮箱" name="input" v-model="myFormData.email"></input>
- </view>
- <view class="padding flex flex-direction">
- <button class="cu-btn bg-blue lg" @click="onSubmit">提交</button>
- </view>
- </form>
- </view>
- </template>
- <script>
- export default {
- data() {
- return {
- sexs:["男","女"],
- typesex:null,
- sexname:'请选择',
- index: -1,
- switchC: true,
- imgList: [],
- uploadUrl:"/sys/common/upload",
- myFormData:{
- avatar:'',
- realname:'',
- username:'',
- sex:"",
- birthday:'',
- orgCode:'',
- workNo:'',
- phone:'',
- email:'',
- id:'',
- egName:''
- },
- };
- },
- onLoad: function (option) {
- console.log("this.$Route.query",this.$Route.query);
- let query=this.$Route.query
- this.myFormData=query;
- this.sexname=this.myFormData.sex;
- if(this.sexname=='男'){
- this.typesex=0;
- }else{
- this.typesex=1;
- }
- if(this.myFormData.avatar){
- this.imgList=[this.myFormData.avatar]
- }
- if(!this.myFormData.birthday){
- this.myFormData.birthday= '无'
- }
- this.Avatar=this.myFormData.avatar
- Object.keys(this.myFormData).map(key=>{
- if(this.myFormData[key]=='无'){
- this.myFormData[key] = ''
- }
- })
- console.log("this.myFormData",this.myFormData)
-
- },
- methods: {
- sexType(e){
- var index=e.target.value;
- console.log(index)
- this.sexname=this.sexs[index];
- },
- onSubmit() {
- let myForm = this.myFormData
- let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
- let checkEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
- console.log("myForm",myForm)
- if(!myForm.phone || myForm.phone.length==0){
- this.$tip.alert('请输入手机号');
- return false
- }
- if(!checkPhone.test(myForm.phone)){
- this.$tip.alert('请输入正确的手机号');
- return false
- }
- if(!checkEmail.test(myForm.email)){
- this.$tip.alert('请输入正确的邮箱地址');
- return false
- }
- if(this.sexname=="请选择"){
- this.$tip.alert('请选择性别');
- return false
- }if(this.sexname=="男"){
- this.myFormData.sex="1";
- }else{
- this.myFormData.sex="2";
- }
- this.myFormData.id = this.$store.getters.userid
-
- console.log('myform',this.myFormData)
- this.$tip.loading();
- this.$http.put('/sys/user/appEdit',this.myFormData).then(res=>{
- console.log(res)
- this.$tip.loaded();
- if (res.data.success){
- this.$tip.toast('提交成功')
- this.$Router.replace({name:'userdetail'})
- /* uni.navigateTo({
- url: '/pages/user/userdetail'
- }) */
- }
- }).catch(()=>{
- this.$tip.loaded();
- this.$tip.error('提交失败')
- });
- },
- DateChange(e) {
- this.myFormData.birthday = e.detail.value
- },
-
- ChooseImage() {
- var that=this;
- uni.chooseImage({
- count: 4, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album'], //从相册选择
- success: (res) => {
- that.$http.upload(that.$config.apiUrl+that.uploadUrl, {
- filePath: res.tempFilePaths[0],
- name: 'file'
- })
- .then(res => {
- that.myFormData.avatar=res.data.message;
- })
- .catch(err => {
- that.$tip.error(err.data.message)
- });
- this.imgList = res.tempFilePaths
- }
- });
- },
- ViewImage(e) {
- uni.previewImage({
- urls: this.imgList,
- current: e.currentTarget.dataset.url
- });
- },
- DelImg(e) {
- uni.showModal({
- title: '',
- content: '您确定要更换头像吗?',
- cancelText: '取消',
- confirmText: '确定',
- success: res => {
- if (res.confirm) {
- this.imgList.splice(e.currentTarget.dataset.index, 1)
- }
- }
- })
- }
- }
- }
- </script>
- <style>
- .cu-form-group .title {
- min-width: calc(4em + 15px);
- }
- </style>
|