useredit.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <view>
  3. <cu-custom bgColor="bg-gradual-pink" :isBack="true">
  4. <block slot="backText">返回</block>
  5. <block slot="content">编辑资料</block>
  6. </cu-custom>
  7. <form>
  8. <view class="cu-form-group">
  9. <view class="title">姓名</view>
  10. <input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
  11. </view>
  12. <view class="cu-form-group">
  13. <view class="title">英文名</view>
  14. <input placeholder="英文名" name="input" v-model="myFormData.egName"></input>
  15. </view>
  16. <view class="cu-form-group">
  17. <view class="title">头像</view>
  18. <view class="grid col-4 grid-square flex-sub">
  19. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
  20. <image :src="imgList[index]" mode="aspectFill"></image>
  21. <view class="cu-tag bg-red radius" @tap.stop="DelImg" :data-index="index">
  22. <text class='cuIcon-close'></text>
  23. </view>
  24. </view>
  25. <view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
  26. <text class='cuIcon-cameraadd'></text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="cu-form-group margin-top">
  31. <view class="title">性别</view>
  32. <picker @change="sexType" :range="sexs" :value="typesex">
  33. <view class="picker">
  34. {{sexname}}
  35. </view>
  36. </picker>
  37. <!-- <switch class='switch-sex' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch> -->
  38. </view>
  39. <view class="cu-form-group">
  40. <view class="title">生日</view>
  41. <picker mode="date" fields="year" :value="myFormData.birthday" @change="DateChange">
  42. <view class="picker">
  43. {{myFormData.birthday}}
  44. </view>
  45. </picker>
  46. </view>
  47. <!-- <view class="cu-form-group margin-top">
  48. <view class="title">用户名</view>
  49. <input placeholder="用户名" name="input" v-model="myFormData.username" disabled></input>
  50. </view> -->
  51. <view class="cu-form-group">
  52. <view class="title">工号</view>
  53. <input placeholder="工号" name="input" v-model="myFormData.workNo" disabled></input>
  54. </view>
  55. <view class="cu-form-group margin-top">
  56. <view class="title">手机号码</view>
  57. <input placeholder="输入手机号码" name="input" v-model="myFormData.phone"></input>
  58. <view class="cu-capsule radius">
  59. <view class='cu-tag bg-blue '>
  60. +86
  61. </view>
  62. <view class="cu-tag line-blue">
  63. 中国大陆
  64. </view>
  65. </view>
  66. </view>
  67. <view class="cu-form-group">
  68. <view class="title">邮箱</view>
  69. <input placeholder="输入邮箱" name="input" v-model="myFormData.email"></input>
  70. </view>
  71. <view class="padding flex flex-direction">
  72. <button class="cu-btn bg-blue lg" @click="onSubmit">提交</button>
  73. </view>
  74. </form>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. data() {
  80. return {
  81. sexs:["男","女"],
  82. typesex:null,
  83. sexname:'请选择',
  84. index: -1,
  85. switchC: true,
  86. imgList: [],
  87. uploadUrl:"/sys/common/upload",
  88. myFormData:{
  89. avatar:'',
  90. realname:'',
  91. username:'',
  92. sex:"",
  93. birthday:'',
  94. orgCode:'',
  95. workNo:'',
  96. phone:'',
  97. email:'',
  98. id:'',
  99. egName:''
  100. },
  101. };
  102. },
  103. onLoad: function (option) {
  104. console.log("this.$Route.query",this.$Route.query);
  105. let query=this.$Route.query
  106. this.myFormData=query;
  107. this.sexname=this.myFormData.sex;
  108. if(this.sexname=='男'){
  109. this.typesex=0;
  110. }else{
  111. this.typesex=1;
  112. }
  113. if(this.myFormData.avatar){
  114. this.imgList=[this.myFormData.avatar]
  115. }
  116. if(!this.myFormData.birthday){
  117. this.myFormData.birthday= '无'
  118. }
  119. this.Avatar=this.myFormData.avatar
  120. Object.keys(this.myFormData).map(key=>{
  121. if(this.myFormData[key]=='无'){
  122. this.myFormData[key] = ''
  123. }
  124. })
  125. console.log("this.myFormData",this.myFormData)
  126. },
  127. methods: {
  128. sexType(e){
  129. var index=e.target.value;
  130. console.log(index)
  131. this.sexname=this.sexs[index];
  132. },
  133. onSubmit() {
  134. let myForm = this.myFormData
  135. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  136. let checkEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
  137. console.log("myForm",myForm)
  138. if(!myForm.phone || myForm.phone.length==0){
  139. this.$tip.alert('请输入手机号');
  140. return false
  141. }
  142. if(!checkPhone.test(myForm.phone)){
  143. this.$tip.alert('请输入正确的手机号');
  144. return false
  145. }
  146. if(!checkEmail.test(myForm.email)){
  147. this.$tip.alert('请输入正确的邮箱地址');
  148. return false
  149. }
  150. if(this.sexname=="请选择"){
  151. this.$tip.alert('请选择性别');
  152. return false
  153. }if(this.sexname=="男"){
  154. this.myFormData.sex="1";
  155. }else{
  156. this.myFormData.sex="2";
  157. }
  158. this.myFormData.id = this.$store.getters.userid
  159. console.log('myform',this.myFormData)
  160. this.$tip.loading();
  161. this.$http.put('/sys/user/appEdit',this.myFormData).then(res=>{
  162. console.log(res)
  163. this.$tip.loaded();
  164. if (res.data.success){
  165. this.$tip.toast('提交成功')
  166. this.$Router.replace({name:'userdetail'})
  167. /* uni.navigateTo({
  168. url: '/pages/user/userdetail'
  169. }) */
  170. }
  171. }).catch(()=>{
  172. this.$tip.loaded();
  173. this.$tip.error('提交失败')
  174. });
  175. },
  176. DateChange(e) {
  177. this.myFormData.birthday = e.detail.value
  178. },
  179. ChooseImage() {
  180. var that=this;
  181. uni.chooseImage({
  182. count: 4, //默认9
  183. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  184. sourceType: ['album'], //从相册选择
  185. success: (res) => {
  186. that.$http.upload(that.$config.apiUrl+that.uploadUrl, {
  187. filePath: res.tempFilePaths[0],
  188. name: 'file'
  189. })
  190. .then(res => {
  191. that.myFormData.avatar=res.data.message;
  192. })
  193. .catch(err => {
  194. that.$tip.error(err.data.message)
  195. });
  196. this.imgList = res.tempFilePaths
  197. }
  198. });
  199. },
  200. ViewImage(e) {
  201. uni.previewImage({
  202. urls: this.imgList,
  203. current: e.currentTarget.dataset.url
  204. });
  205. },
  206. DelImg(e) {
  207. uni.showModal({
  208. title: '',
  209. content: '您确定要更换头像吗?',
  210. cancelText: '取消',
  211. confirmText: '确定',
  212. success: res => {
  213. if (res.confirm) {
  214. this.imgList.splice(e.currentTarget.dataset.index, 1)
  215. }
  216. }
  217. })
  218. }
  219. }
  220. }
  221. </script>
  222. <style>
  223. .cu-form-group .title {
  224. min-width: calc(4em + 15px);
  225. }
  226. </style>