edit.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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.remark" 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. },
  150. },
  151. showSex: false,
  152. birthday: Number(new Date()),
  153. actions: [{
  154. name: '男',
  155. id: 1
  156. }, {
  157. name: '女',
  158. id: 2
  159. }, {
  160. name: '保密',
  161. id: 3
  162. }, ],
  163. rules: {
  164. 'userInfo.username': {
  165. type: 'string',
  166. required: true,
  167. message: '用户名称不能为空',
  168. trigger: ['blur']
  169. },
  170. 'userInfo.nickname': {
  171. type: 'string',
  172. required: true,
  173. message: '用户昵称不能为空',
  174. trigger: ['blur']
  175. },
  176. 'userInfo.sex': {
  177. type: 'number',
  178. required: true,
  179. message: '请选择男或女',
  180. trigger: ['change']
  181. },
  182. 'userInfo.birthday': {
  183. type: 'string',
  184. required: true,
  185. message: '请选择生日',
  186. trigger: ['change']
  187. },
  188. 'userInfo.mobile': {
  189. // 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}$/,
  190. type: 'string',
  191. required: true,
  192. message: '请输入正确的手机号码',
  193. trigger: ['blur', 'change']
  194. },
  195. },
  196. }
  197. },
  198. onReady() {
  199. // 如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则
  200. this.$refs.customForm.setRules(this.rules)
  201. },
  202. onLoad() {
  203. this.getUser()
  204. },
  205. methods: {
  206. sexTrans(val) {
  207. let eduStr = ''
  208. console.log(val)
  209. this.actions.map(i => {
  210. if (i.id == val) {
  211. console.log(i.name);
  212. eduStr = i.name
  213. }
  214. })
  215. return eduStr
  216. },
  217. getUser() {
  218. getUserProfile().then(response => {
  219. this.user.userInfo = response.data
  220. this.user.userInfo.sexname = this.sexTrans(this.user.userInfo.sex)
  221. localStorage.setItem('userMes',JSON.stringify(response.data))
  222. console.log('this.user.userInfo', this.user.userInfo);
  223. })
  224. },
  225. sexSelect(e) {
  226. this.user.userInfo.sexname = e.name
  227. this.user.userInfo.sex = e.id
  228. this.$refs.customForm.validateField('userInfo.sex')
  229. },
  230. birthdayClose() {
  231. this.showBirthday = false
  232. this.$refs.customForm.validateField('userInfo.birthday')
  233. },
  234. birthdayConfirm(e) {
  235. this.showBirthday = false
  236. this.user.userInfo.birthday = uni.$u.timeFormat(e.value, 'yyyy-mm-dd')
  237. this.$refs.customForm.validateField('userInfo.birthday')
  238. },
  239. submit() {
  240. // 如果有错误,会在catch中返回报错信息数组,校验通过则在then中返回true
  241. this.$refs.customForm.validate().then(res => {
  242. // uni.$u.toast('校验通过')
  243. updateUserProfile(this.user.userInfo).then(response => {
  244. // this.user = response.data
  245. uni.navigateBack()
  246. })
  247. }).catch(errors => {
  248. console.log(errors);
  249. // uni.$u.toast('校验失败')/
  250. })
  251. },
  252. hideKeyboard() {
  253. uni.hideKeyboard()
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="scss" scoped>
  259. .editimg {
  260. width: 28px;
  261. height: 28px;
  262. }
  263. .edit {
  264. width: 13px;
  265. height: 13px;
  266. }
  267. .uni-container {
  268. padding: 10px;
  269. border-radius: 30px 30px 0px 0px;
  270. background: #fff;
  271. /*#ifdef H5*/
  272. margin-top: 10px;
  273. /* #endif */
  274. /* #ifdef MP-WEIXIN*/
  275. // margin-top: 200rpx;
  276. /* #endif */
  277. z-index: 9999999;
  278. position: relative;
  279. }
  280. </style>