edit.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view style="padding: 20rpx;">
  3. <view style="padding: 30rpx;background-color: white;border-radius:50rpx">
  4. <u--form labelPosition="left" :model="userInfo" ref="uForm" labelWidth='120'>
  5. <u-form-item label="用户账号:" prop="account" borderBottom ref="uItem" :required="true">
  6. <u--input v-model="userInfo.account" clearable border="none" placeholder="请输入用户账号"></u--input>
  7. </u-form-item>
  8. <u-form-item label="用户名称:" prop="name" borderBottom ref="uItem" :required="true">
  9. <u--input v-model="userInfo.name" border="none" placeholder="请输入用户名称"></u--input>
  10. </u-form-item>
  11. <u-form-item label="联系电话:" prop="phone" borderBottom ref="uItem">
  12. <u-input v-model="userInfo.phone" border="none" placeholder="请输入联系电话"></u-input>
  13. </u-form-item>
  14. <u-form-item label="是否管理员:" prop="adminType" borderBottom ref="uItem">
  15. <u-switch v-model="userInfo.adminType"></u-switch>
  16. </u-form-item>
  17. <u-button type="primary" text="提交" customStyle="margin-top: 50px" @click="submit"></u-button>
  18. <u-button type="error" text="重置" customStyle="margin-top: 10px" @click="reset"></u-button>
  19. </u--form>
  20. </view>
  21. <u-toast ref="uToast"></u-toast>
  22. </view>
  23. </template>
  24. <script>
  25. import {add,edit} from '@/api/system/user.js'
  26. export default {
  27. data() {
  28. return {
  29. userInfo: {
  30. },
  31. rules: {
  32. 'account': {
  33. type: 'string',
  34. required: true,
  35. message: '请填写用户账号',
  36. trigger: ['blur', 'change']
  37. },
  38. 'password': {
  39. type: 'string',
  40. required: true,
  41. message: '请填写用户密码',
  42. trigger: ['blur', 'change']
  43. },
  44. 'name': {
  45. type: 'string',
  46. required: true,
  47. message: '请填写用户名称',
  48. trigger: ['blur', 'change']
  49. },
  50. }
  51. }
  52. },
  53. methods: {
  54. submit(){
  55. this.$refs.uForm.validate().then(val => {
  56. edit(this.userInfo).then(res=>{
  57. if (res.success) {
  58. this.$refs.uToast.show({
  59. type: 'success',
  60. message: "修改成功",
  61. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  62. })
  63. } else {
  64. this.$refs.uToast.show({
  65. type: 'error',
  66. message: res.message,
  67. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  68. })
  69. }
  70. })
  71. })
  72. },
  73. reset(){}
  74. },
  75. onReady(){
  76. this.$refs.uForm.setRules(this.rules)
  77. },
  78. onLoad(option) {
  79. const userInfo = JSON.parse(decodeURIComponent(option.userInfo))
  80. this.userInfo = userInfo
  81. },
  82. }
  83. </script>
  84. <style>
  85. </style>