edit.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view class="">
  3. <!-- #ifdef H5 -->
  4. <navInfo :title="'编辑资料'"></navInfo>
  5. <view class="bgTopImg">
  6. <image slot="right" :src="`${urls}/navBg@2x.png`" class="bgTopImg"></image>
  7. </view>
  8. <!-- #endif -->
  9. <view class="uni-container">
  10. <view class="u-demo-block">
  11. <view class="u-demo-block__content">
  12. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  13. <u--form label-position="top" :model="user" ref="customForm" label-width='100'>
  14. <view class="flex flex-direction-row">
  15. <view class="flex justify-center align-center" style="width: 12%;">
  16. <image :src="`${urls}/info/id.svg`" class="editimg"></image>
  17. </view>
  18. <view style="width: 88%;">
  19. <u-form-item label-position="top" label="用户名" prop="userInfo.nickname" borderBottom>
  20. <u--input v-model="user.userInfo.nickname" border="none" placeholder="用户名">
  21. </u--input>
  22. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  23. </u-form-item>
  24. </view>
  25. </view>
  26. <!-- <view class="flex flex-direction-row">
  27. <view class="flex justify-center align-center" style="width: 12%;">
  28. <image :src="`${urls}/info/username.svg`" class="editimg"></image>
  29. </view>
  30. <view style="width: 88%;">
  31. <u-form-item label-position="top" label="姓名" prop="userInfo.username" borderBottom>
  32. <u--input v-model="user.userInfo.username" border="none" placeholder="姓名">
  33. </u--input>
  34. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  35. </u-form-item>
  36. </view>
  37. </view> -->
  38. <view class="flex flex-direction-row">
  39. <view class="flex justify-center align-center" style="width: 12%;">
  40. <image :src="`${urls}/info/gender.svg`" class="editimg"></image>
  41. </view>
  42. <view style="width: 88%;">
  43. <u-form-item label-position="top" label="性别" prop="userInfo.sexname" borderBottom
  44. @click="showSex = true; hideKeyboard()">
  45. <u--input v-model="user.userInfo.sexname" disabled disabledColor="#ffffff"
  46. placeholder="请选择性别" border="none"></u--input>
  47. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  48. </u-form-item>
  49. </view>
  50. </view>
  51. <!-- <view class="flex flex-direction-row">
  52. <view class="flex justify-center align-center" style="width: 12%;">
  53. <image :src="`${urls}s/info/birthday.svg`" class="editimg"></image>
  54. </view>
  55. <view style="width: 88%;">
  56. <u-form-item label-position="top" label="出生年月" prop="userInfo.birthday" borderBottom
  57. @click="showBirthday = true; hideKeyboard()">
  58. <u--input v-model="user.userInfo.birthday" disabled disabledColor="#ffffff"
  59. placeholder="请选择出生年月" border="none"></u--input>
  60. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  61. <u-icon slot="right" name="arrow-right"></u-icon>
  62. </u-form-item>
  63. </view>
  64. </view> -->
  65. <view class="flex flex-direction-row">
  66. <view class="flex justify-center align-center" style="width: 12%;">
  67. <image :src="`${urls}/info/phone.svg`" class="editimg"></image>
  68. </view>
  69. <view style="width: 88%;">
  70. <u-form-item label-position="top" label="手机号" prop="userInfo.mobile" borderBottom>
  71. <u--input v-model="user.userInfo.mobile" border="none" placeholder="手机号"></u--input>
  72. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  73. </u-form-item>
  74. </view>
  75. </view>
  76. <!-- <view class="flex flex-direction-row">
  77. <view class="flex justify-center align-center" style="width: 12%;">
  78. <image :src="`${urls}/info/address.svg`" class="editimg"></image>
  79. </view>
  80. <view style="width: 88%;">
  81. <u-form-item label-position="top" label="详细地址" prop="userInfo.remark" borderBottom>
  82. <u--input v-model="user.userInfo.remark" border="none" placeholder="详细地址">
  83. </u--input>
  84. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  85. </u-form-item>
  86. </view>
  87. </view>
  88. <view class="flex flex-direction-row">
  89. <view class="flex justify-center align-center" style="width: 12%;">
  90. <image :src="`${urls}/info/address.svg`" class="editimg"></image>
  91. </view>
  92. <view style="width: 88%;">
  93. <u-form-item label-position="top" label="角色" prop="userInfo.dept.name" borderBottom>
  94. <u--input v-model="user.userInfo.dept.name" border="none" placeholder="角色">
  95. </u--input>
  96. <image slot="right" :src="`${urls}/info/edit.svg`" class="edit"></image>
  97. </u-form-item>
  98. </view>
  99. </view> -->
  100. </u--form>
  101. <u-button type="primary" text="确认修改"
  102. customStyle="height: 72rpx;width: 340rpx;margin-top: 100rpx;display: flex;align-items: center;justify-content: center;border-radius: 60rpx;background: #4CB2B6;"
  103. @click="submit"></u-button>
  104. <u-action-sheet :show="showSex" :actions="actions" title="请选择性别" description="如果选择保密会报错"
  105. @close="showSex = false" @select="sexSelect">
  106. </u-action-sheet>
  107. <!-- <u-picker :show="showSex" :columns="actions" keyName="value" @close="showSex = false"
  108. @cancel="showSex = false" @confirm="sexSelect"></u-picker> -->
  109. <u-datetime-picker :show="showBirthday" :value="birthday" mode="date" closeOnClickOverlay
  110. @confirm="birthdayConfirm" @cancel="birthdayClose" @close="birthdayClose"></u-datetime-picker>
  111. </view>
  112. </view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import {
  118. getUserProfile,
  119. updateUserProfile
  120. } from "@/api/system/user"
  121. import config from '@/config'
  122. const baseUrlImg = config.baseUrlImg
  123. // #ifdef H5
  124. import navInfo from '@/pagesA/components/my-nav/nav'
  125. // #endif
  126. export default {
  127. components: {
  128. // #ifdef H5
  129. navInfo
  130. // #endif
  131. },
  132. data() {
  133. return {
  134. urls: baseUrlImg,
  135. fileList1: [],
  136. disabled1: false,
  137. tips: '',
  138. value: '',
  139. showCalendar: false,
  140. showBirthday: false,
  141. user: {
  142. userInfo: {
  143. nickname: '',
  144. username: '',
  145. sex: '',
  146. birthday: '',
  147. mobile: '',
  148. remark: '',
  149. dept:{name:''}
  150. },
  151. },
  152. showSex: false,
  153. birthday: Number(new Date()),
  154. actions: [{
  155. name: '男',
  156. id: 1
  157. }, {
  158. name: '女',
  159. id: 2
  160. }, {
  161. name: '保密',
  162. id: 3
  163. }, ],
  164. rules: {
  165. 'userInfo.username': {
  166. type: 'string',
  167. required: true,
  168. message: '用户名称不能为空',
  169. trigger: ['blur']
  170. },
  171. 'userInfo.nickname': {
  172. type: 'string',
  173. required: true,
  174. message: '用户昵称不能为空',
  175. trigger: ['blur']
  176. },
  177. 'userInfo.sex': {
  178. type: 'number',
  179. required: true,
  180. message: '请选择男或女',
  181. trigger: ['change']
  182. },
  183. 'userInfo.birthday': {
  184. type: 'string',
  185. required: true,
  186. message: '请选择生日',
  187. trigger: ['change']
  188. },
  189. 'userInfo.mobile': {
  190. // pattern: /^(?:(?:\+|00)86)?1(?:3[\d]|4[5-79]|5[0-35-9]|6[5-7]|7[0-8]|8[\d]|9[189])\d{8}$/,
  191. type: 'string',
  192. required: true,
  193. message: '请输入正确的手机号码',
  194. trigger: ['blur', 'change']
  195. },
  196. },
  197. }
  198. },
  199. onReady() {
  200. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  201. this.$refs.customForm.setRules(this.rules)
  202. },
  203. onLoad() {
  204. this.getUser()
  205. },
  206. methods: {
  207. sexTrans(val) {
  208. let eduStr = ''
  209. this.actions.map(i => {
  210. if (i.id == val) {
  211. eduStr = i.name
  212. }
  213. })
  214. return eduStr
  215. },
  216. getUser() {
  217. getUserProfile().then(response => {
  218. this.user.userInfo = response.data
  219. this.user.userInfo.sexname = this.sexTrans(this.user.userInfo.sex)
  220. localStorage.setItem('userMes',JSON.stringify(response.data))
  221. })
  222. },
  223. sexSelect(e) {
  224. this.user.userInfo.sexname = e.name
  225. this.user.userInfo.sex = e.id
  226. this.$refs.customForm.validateField('userInfo.sex')
  227. },
  228. birthdayClose() {
  229. this.showBirthday = false
  230. this.$refs.customForm.validateField('userInfo.birthday')
  231. },
  232. birthdayConfirm(e) {
  233. this.showBirthday = false
  234. this.user.userInfo.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  235. this.$refs.customForm.validateField('userInfo.birthday')
  236. },
  237. submit() {
  238. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  239. this.$refs.customForm.validate().then(res => {
  240. // uni.$u.toast('校验通过')
  241. updateUserProfile(this.user.userInfo).then(response => {
  242. // this.user = response.data
  243. uni.navigateBack()
  244. })
  245. }).catch(errors => {
  246. // uni.$u.toast('校验失败')/
  247. })
  248. },
  249. hideKeyboard() {
  250. uni.hideKeyboard()
  251. }
  252. }
  253. }
  254. </script>
  255. <style lang="scss" scoped>
  256. .editimg {
  257. width: 28px;
  258. height: 28px;
  259. }
  260. .edit {
  261. width: 13px;
  262. height: 13px;
  263. }
  264. .uni-container {
  265. padding: 10px;
  266. border-radius: 30px 30px 0px 0px;
  267. background: #fff;
  268. /*#ifdef H5*/
  269. margin-top: 10px;
  270. /* #endif */
  271. /* #ifdef MP-WEIXIN*/
  272. // margin-top: 200rpx;
  273. /* #endif */
  274. z-index: 9999999;
  275. position: relative;
  276. }
  277. </style>