useredit.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.username" disabled></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. <switch class='switch-sex' @change="SwitchC" :class="switchC?'checked':''" :checked="switchC?true:false"></switch>
  33. </view>
  34. <view class="cu-form-group margin-top">
  35. <view class="title">手机号码</view>
  36. <input placeholder="输入手机号码" name="input" v-model="myFormData.phone"></input>
  37. <view class="cu-capsule radius">
  38. <view class='cu-tag bg-blue '>
  39. +86
  40. </view>
  41. <view class="cu-tag line-blue">
  42. 中国大陆
  43. </view>
  44. </view>
  45. </view>
  46. <view class="cu-form-group">
  47. <view class="title">邮箱</view>
  48. <input placeholder="输入邮箱" name="input" v-model="myFormData.email"></input>
  49. </view>
  50. <view class="padding flex flex-direction">
  51. <button class="cu-btn bg-blue lg" @click="onSubmit">提交</button>
  52. </view>
  53. </form>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. index: -1,
  61. switchC: true,
  62. imgList: [],
  63. uploadUrl:"/sys/common/upload",
  64. myFormData:{
  65. avatar:'',
  66. realname:'',
  67. username:'',
  68. sex:1,
  69. birthday:'',
  70. orgCode:'',
  71. workNo:'',
  72. phone:'',
  73. email:'',
  74. id:'',
  75. },
  76. };
  77. },
  78. onLoad: function (option) {
  79. console.log("this.$Route.query",this.$Route.query);
  80. let query=this.$Route.query
  81. if(query){
  82. this.myFormData=query;
  83. if(this.myFormData.sex=='女'){
  84. this.switchC = false
  85. }else if(this.myFormData.sex=='男'){
  86. this.switchC = true
  87. }
  88. if(this.myFormData.avatar){
  89. this.imgList=[this.myFormData.avatar]
  90. }
  91. if(!this.myFormData.birthday){
  92. this.myFormData.birthday= '无'
  93. }
  94. if(this.myFormData.identity=='普通成员'){
  95. this.myFormData.identity = 1
  96. }else if(this.myFormData.identity=='上级'){
  97. this.myFormData.identity = 2
  98. }
  99. if(this.myFormData.status=='正常'){
  100. this.myFormData.status = 1
  101. }else if(this.myFormData.status=='冻结'){
  102. this.myFormData.status = 2
  103. }
  104. this.Avatar=this.myFormData.avatar
  105. Object.keys(this.myFormData).map(key=>{
  106. if(this.myFormData[key]=='无'){
  107. this.myFormData[key] = ''
  108. }
  109. })
  110. console.log("this.myFormData",this.myFormData)
  111. }
  112. },
  113. methods: {
  114. onSubmit() {
  115. let myForm = this.myFormData
  116. let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
  117. let checkEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
  118. console.log("myForm",myForm)
  119. if(!myForm.phone || myForm.phone.length==0){
  120. this.$tip.alert('请输入手机号');
  121. return false
  122. }
  123. if(!checkPhone.test(myForm.phone)){
  124. this.$tip.alert('请输入正确的手机号');
  125. return false
  126. }
  127. if(!checkEmail.test(myForm.email)){
  128. this.$tip.alert('请输入正确的邮箱地址');
  129. return false
  130. }
  131. this.myFormData.id = this.$store.getters.userid
  132. if(this.switchC){
  133. this.myFormData.sex=1
  134. }else{
  135. this.myFormData.sex=2
  136. }
  137. console.log('myform',this.myFormData)
  138. this.$tip.loading();
  139. this.$http.put('/sys/user/appEdit',this.myFormData).then(res=>{
  140. console.log(res)
  141. this.$tip.loaded();
  142. if (res.data.success){
  143. this.$tip.toast('提交成功')
  144. this.$Router.replace({name:'userdetail'})
  145. /* uni.navigateTo({
  146. url: '/pages/user/userdetail'
  147. }) */
  148. }
  149. }).catch(()=>{
  150. this.$tip.loaded();
  151. this.$tip.error('提交失败')
  152. });
  153. },
  154. DateChange(e) {
  155. this.myFormData.birthday = e.detail.value
  156. },
  157. SwitchC(e) {
  158. this.switchC = e.detail.value
  159. },
  160. ChooseImage() {
  161. var that=this;
  162. uni.chooseImage({
  163. count: 4, //默认9
  164. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  165. sourceType: ['album'], //从相册选择
  166. success: (res) => {
  167. that.$http.upload(that.$config.apiUrl+that.uploadUrl, {
  168. filePath: res.tempFilePaths[0],
  169. name: 'file'
  170. })
  171. .then(res => {
  172. that.myFormData.avatar=res.data.message;
  173. })
  174. .catch(err => {
  175. that.$tip.error(err.data.message)
  176. });
  177. this.imgList = res.tempFilePaths
  178. }
  179. });
  180. },
  181. ViewImage(e) {
  182. uni.previewImage({
  183. urls: this.imgList,
  184. current: e.currentTarget.dataset.url
  185. });
  186. },
  187. DelImg(e) {
  188. uni.showModal({
  189. title: '召唤师',
  190. content: '确定要删除这段回忆吗?',
  191. cancelText: '再看看',
  192. confirmText: '再见',
  193. success: res => {
  194. if (res.confirm) {
  195. this.imgList.splice(e.currentTarget.dataset.index, 1)
  196. }
  197. }
  198. })
  199. }
  200. }
  201. }
  202. </script>
  203. <style>
  204. .cu-form-group .title {
  205. min-width: calc(4em + 15px);
  206. }
  207. </style>