editUserPhoneModal.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <template>
  2. <div>
  3. <!-- 弹窗 -->
  4. <a-modal
  5. v-model="isShow"
  6. @cancle="isShow=false"
  7. :footer="null"
  8. :centered="true"
  9. title="修改手机号码">
  10. <a-form id="components-form-demo-validate-other" ref="form" :form="form" @submit="handleSubmit">
  11. <a-form-item label="手机号码" :label-col="{ span: 7 }" :wrapper-col="{ span: 12 }">
  12. <a-input
  13. id="editUserPhoneModal-mobile"
  14. :maxLength="11"
  15. v-decorator="[
  16. 'formData.mobile',
  17. { initialValue: formData.mobile, rules: [{ required: true, message: '请输入手机号码!' }, { pattern: /^\d{11}$/, message: '请输入正确的手机号' }] }
  18. ]"
  19. placeholder="请输入手机号码"
  20. allowClear />
  21. </a-form-item>
  22. <a-form-item :wrapper-col="{ span: 12, offset: 6}" style="text-align: center;">
  23. <a-button type="primary" html-type="submit" id="editUserPhoneModal-submit" style="margin-right: 15px">保存</a-button>
  24. <a-button @click="isShow=false" style="margin-left: 15px" id="editUserPhoneModal-close">取消</a-button>
  25. </a-form-item>
  26. </a-form>
  27. </a-modal>
  28. </div>
  29. </template>
  30. <script>
  31. import { updateMobile } from '@/api/userInfo.js'
  32. export default {
  33. name: 'EditUserPhoneModal',
  34. props: {
  35. openUserPhoneMoadl: {
  36. type: Boolean,
  37. default: false
  38. },
  39. userId: {
  40. type: String,
  41. default: ''
  42. }
  43. },
  44. data () {
  45. return {
  46. isShow: this.openUserPhoneMoadl,
  47. form: this.$form.createForm(this, { name: 'editUserPhoneModal' }),
  48. formData: {
  49. mobile: '' // 手机号码
  50. }
  51. }
  52. },
  53. methods: {
  54. // 点击保存;
  55. handleSubmit (e) {
  56. e.preventDefault()
  57. const _this = this
  58. this.form.validateFields((err, values) => {
  59. if (!err) {
  60. const formData = Object.assign({}, { id: this.userId }, this.formData, values.formData)
  61. updateMobile(formData).then(res => {
  62. console.log(res, 'rrrrrrrrr')
  63. if (res.status == 200) {
  64. _this.$message.success(res.message)
  65. location.reload()
  66. // _this.$emit('refresh')
  67. // _this.$router.push({ path: `/userInfo/userManageList/list` })
  68. setTimeout(function () {
  69. _this.isShow = false
  70. }, 300)
  71. }
  72. })
  73. }
  74. })
  75. }
  76. },
  77. watch: {
  78. openUserPhoneMoadl (newValue, oldValue) {
  79. this.isShow = newValue
  80. },
  81. isShow (val) {
  82. console.log(this.userId)
  83. if (!val) {
  84. this.$emit('close')
  85. } else {
  86. this.form.resetFields()
  87. }
  88. }
  89. }
  90. }
  91. </script>
  92. <style>
  93. </style>