useredit.vue 5.8 KB

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