Informationmodification.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <template>
  2. <view class="OutermostLayer">
  3. <view class="Personalinformationedit">
  4. <!-- 注意,如果需要兼容微信小程序,最好通过setRules方法设置rules规则 -->
  5. <u--form
  6. labelPosition="left"
  7. :model="model1"
  8. :rules="rules"
  9. ref="form1">
  10. <u-form-item
  11. labelWidth="120"
  12. label="用户名:"
  13. prop="userInfo.realName"
  14. borderBottom
  15. ref="item1" >
  16. <u--input
  17. v-model="model1.userInfo.realName"
  18. clearable
  19. border="none"
  20. ></u--input>
  21. </u-form-item>
  22. <u-form-item
  23. labelWidth="120"
  24. label="手机:"
  25. prop="userInfo.mobile"
  26. borderBottom
  27. ref="item1"
  28. >
  29. <u--input
  30. v-model="model1.userInfo.mobile"
  31. clearable
  32. border="none"
  33. ></u--input>
  34. </u-form-item>
  35. <u-form-item
  36. labelWidth="120"
  37. label="邮箱:"
  38. prop="userInfo.email"
  39. borderBottom
  40. ref="item1"
  41. >
  42. <u--input
  43. v-model="model1.userInfo.email"
  44. clearable
  45. border="none"
  46. ></u--input>
  47. </u-form-item>
  48. <u-form-item
  49. label="性别:"
  50. labelWidth="120"
  51. prop="userInfo.gender"
  52. borderBottom
  53. @click="showSex = true"
  54. ref="item1"
  55. >
  56. <u--input
  57. v-model="model1.userInfo.gender"
  58. disabled
  59. disabledColor="#ffffff"
  60. placeholder="请选择性别"
  61. border="none"
  62. ></u--input>
  63. <u-icon
  64. slot="right"
  65. name="arrow-right"
  66. ></u-icon>
  67. </u-form-item>
  68. <!--<u-form-item-->
  69. <!--labelWidth="120"-->
  70. <!--label="地址:"-->
  71. <!--prop="userInfo.address"-->
  72. <!--borderBottom-->
  73. <!--ref="item1" >-->
  74. <!--<u&#45;&#45;input-->
  75. <!--v-model="model1.userInfo.address"-->
  76. <!--clearable-->
  77. <!--border="none"-->
  78. <!--&gt;</u&#45;&#45;input>-->
  79. <!--</u-form-item>-->
  80. <u-form-item
  81. labelWidth="120"
  82. label="部门:"
  83. prop="userInfo.deptName"
  84. borderBottom
  85. ref="item1" >
  86. <u--input
  87. v-model="model1.userInfo.deptName"
  88. clearable
  89. border="none"
  90. ></u--input>
  91. </u-form-item>
  92. </u--form>
  93. <view class="submitdata">
  94. <u-button type="primary" @click="submit">提交</u-button>
  95. </view>
  96. </view>
  97. <u-notify ref="uNotify" message="" ></u-notify>
  98. <u-picker :show="showSex" :itemHeight="80" @cancel="showSex = false" @confirm="sexSelect" :columns="actions" keyName="name"></u-picker>
  99. </view>
  100. </template>
  101. <script>
  102. export default {
  103. data() {
  104. return {
  105. getuserInfo:{},
  106. showSex: false,
  107. model1: {
  108. userInfo: {
  109. realName: '',
  110. gender: '',
  111. mobile:'',
  112. email:'',
  113. deptName:'合肥传秀科技技术部',
  114. },
  115. },
  116. actions: [
  117. [
  118. {
  119. id:0,
  120. name: '男',
  121. },
  122. {
  123. id:1,
  124. name: '女',
  125. },
  126. {id:2,
  127. name: '保密',
  128. },
  129. ]
  130. ],
  131. rules: {
  132. 'userInfo.name': {
  133. type: 'string',
  134. required: true,
  135. message: '请填写姓名',
  136. trigger: ['blur', 'change']
  137. },
  138. 'userInfo.email': [
  139. {
  140. required: true,
  141. message: '请输入邮箱号',
  142. trigger: ['change','blur'],
  143. },
  144. {
  145. // 自定义验证函数,见上说明
  146. validator: (rule, value, callback) => {
  147. // 上面有说,返回true表示校验通过,返回false表示不通过
  148. // uni.$u.test.mobile()就是返回true或者false的
  149. return uni.$u.test.email(value);
  150. },
  151. message: '邮箱不正确',
  152. // 触发器可以同时用blur和change
  153. trigger: ['change','blur'],
  154. }
  155. ],
  156. 'userInfo.mobile': [
  157. {
  158. required: true,
  159. message: '请输入邮箱',
  160. trigger: ['change','blur'],
  161. },
  162. {
  163. // 自定义验证函数,见上说明
  164. validator: (rule, value, callback) => {
  165. // 上面有说,返回true表示校验通过,返回false表示不通过
  166. // uni.$u.test.mobile()就是返回true或者false的
  167. return uni.$u.test.mobile(value);
  168. },
  169. message: '手机号码不正确',
  170. // 触发器可以同时用blur和change
  171. trigger: ['change','blur'],
  172. }
  173. ],
  174. 'userInfo.gender': {
  175. type: 'string',
  176. max: 2,
  177. required: true,
  178. message: '请选择',
  179. trigger: ['blur', 'change']
  180. },
  181. },
  182. };
  183. },
  184. onLoad(options){
  185. let userInfo= uni.getStorageSync('getuserInfo');
  186. if(userInfo.gender==0){
  187. userInfo.gender='男'
  188. }else if(userInfo.gender==1){
  189. userInfo.gender='女'
  190. }else if(userInfo.gender==2){
  191. userInfo.gender='保密'
  192. }
  193. // console.log('111111111111111111',userInfo)
  194. this.model1.userInfo=userInfo;
  195. //this.getuserInfo
  196. },
  197. methods: {
  198. sexSelect(e) {
  199. //console.log('111111111111111111',e)
  200. this.model1.userInfo.gender = e.value[0].name;
  201. this.$refs.form1.validateField('userInfo.gender')
  202. this.showSex=false;
  203. },
  204. submit() {
  205. this.$refs.form1.validate().then(res => {
  206. if(this.model1.userInfo.gender=='男'){
  207. this.model1.userInfo.gender=0
  208. }else if(this.model1.userInfo.gender=='女'){
  209. this.model1.userInfo.gender=1
  210. }else if(this.model1.userInfo.gender=='保密'){
  211. this.model1.userInfo.gender=2
  212. }
  213. this.$api.put('/user',this.model1.userInfo)
  214. .then(res=>{
  215. console.log('111111111111111111',res)
  216. if(res.data.code==0){
  217. uni.navigateBack({
  218. delta: 1
  219. });
  220. }else{
  221. this.$refs.uNotify.error(res.data.msg)
  222. }
  223. })
  224. }).catch(errors => {
  225. uni.$u.toast('校验失败')
  226. })
  227. },
  228. },
  229. onReady() {
  230. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  231. this.$refs.form1.setRules(this.rules)
  232. },
  233. };
  234. </script>
  235. <style lang="scss">
  236. .Personalinformationedit{
  237. padding: 30rpx;
  238. }
  239. .submitdata{
  240. margin-top: 40rpx;
  241. }
  242. </style>