Informationmodification.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.name"
  14. borderBottom
  15. ref="item1" >
  16. <u--input
  17. v-model="model1.userInfo.name"
  18. clearable
  19. border="none"
  20. ></u--input>
  21. </u-form-item>
  22. <u-form-item
  23. labelWidth="120"
  24. label="手机:"
  25. prop="userInfo.phone"
  26. borderBottom
  27. ref="item1"
  28. >
  29. <u--input
  30. v-model="model1.userInfo.phone"
  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.sex"
  52. borderBottom
  53. @click="showSex = true; hideKeyboard()"
  54. ref="item1"
  55. >
  56. <u--input
  57. v-model="model1.userInfo.sex"
  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--input
  75. v-model="model1.userInfo.address"
  76. clearable
  77. border="none"
  78. ></u--input>
  79. </u-form-item>
  80. <u-form-item
  81. labelWidth="120"
  82. label="部门:"
  83. prop="userInfo.department"
  84. borderBottom
  85. ref="item1" >
  86. <u--input
  87. v-model="model1.userInfo.department"
  88. clearable
  89. border="none"
  90. ></u--input>
  91. </u-form-item>
  92. <u-form-item
  93. labelWidth="120"
  94. label="职位:"
  95. prop="userInfo.position"
  96. borderBottom
  97. ref="item1" >
  98. <u--input
  99. v-model="model1.userInfo.position"
  100. clearable
  101. border="none"
  102. ></u--input>
  103. </u-form-item>
  104. </u--form>
  105. <u-action-sheet
  106. :show="showSex"
  107. :actions="actions"
  108. title="请选择性别"
  109. @close="showSex = false"
  110. @select="sexSelect"
  111. >
  112. </u-action-sheet>
  113. <view class="submitdata">
  114. <u-button type="primary" @click="submit">提交</u-button>
  115. </view>
  116. </view>
  117. </view>
  118. </template>
  119. <script>
  120. export default {
  121. data() {
  122. return {
  123. showSex: false,
  124. model1: {
  125. userInfo: {
  126. name: '李伟',
  127. sex: '男',
  128. phone:'18326607835',
  129. email:'328319643@qq.com',
  130. address:'安徽省合肥市',
  131. department:'合肥传秀科技技术部',
  132. position:'前端工程师'
  133. },
  134. },
  135. actions: [
  136. {
  137. name: '男',
  138. },
  139. {
  140. name: '女',
  141. },
  142. {
  143. name: '保密',
  144. },
  145. ],
  146. rules: {
  147. 'userInfo.name': {
  148. type: 'string',
  149. required: true,
  150. message: '请填写姓名',
  151. trigger: ['blur', 'change']
  152. },
  153. 'userInfo.email': [
  154. {
  155. required: true,
  156. message: '请输入邮箱号',
  157. trigger: ['change','blur'],
  158. },
  159. {
  160. // 自定义验证函数,见上说明
  161. validator: (rule, value, callback) => {
  162. // 上面有说,返回true表示校验通过,返回false表示不通过
  163. // uni.$u.test.mobile()就是返回true或者false的
  164. return uni.$u.test.email(value);
  165. },
  166. message: '邮箱不正确',
  167. // 触发器可以同时用blur和change
  168. trigger: ['change','blur'],
  169. }
  170. ],
  171. 'userInfo.phone': [
  172. {
  173. required: true,
  174. message: '请输入邮箱',
  175. trigger: ['change','blur'],
  176. },
  177. {
  178. // 自定义验证函数,见上说明
  179. validator: (rule, value, callback) => {
  180. // 上面有说,返回true表示校验通过,返回false表示不通过
  181. // uni.$u.test.mobile()就是返回true或者false的
  182. return uni.$u.test.mobile(value);
  183. },
  184. message: '手机号码不正确',
  185. // 触发器可以同时用blur和change
  186. trigger: ['change','blur'],
  187. }
  188. ],
  189. 'userInfo.sex': {
  190. type: 'string',
  191. max: 2,
  192. required: true,
  193. message: '请选择',
  194. trigger: ['blur', 'change']
  195. },
  196. },
  197. };
  198. },
  199. methods: {
  200. sexSelect(e) {
  201. this.model1.userInfo.sex = e.name
  202. this.$refs.form1.validateField('userInfo.sex')
  203. },
  204. submit() {
  205. this.$refs.form1.validate().then(res => {
  206. uni.$u.toast('校验通过')
  207. }).catch(errors => {
  208. uni.$u.toast('校验失败')
  209. })
  210. },
  211. },
  212. onReady() {
  213. //如果需要兼容微信小程序,并且校验规则中含有方法等,只能通过setRules方法设置规则。
  214. this.$refs.form1.setRules(this.rules)
  215. },
  216. };
  217. </script>
  218. <style lang="scss">
  219. .Personalinformationedit{
  220. padding: 30rpx;
  221. }
  222. .submitdata{
  223. margin-top: 40rpx;
  224. }
  225. </style>