edit.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="hui-flex hui-dialog">
  3. <div class="hui-flex-box hui-dialog-content">
  4. <el-form :model="userForm" :rules="userRulers" ref="userForm" label-position="top">
  5. <el-alert title="该账号已存在,请直接保存" show-icon type="success" :closable="false" v-if="alertShow"
  6. style="margin-bottom: 10px;"></el-alert>
  7. <el-form-item label="手机号" prop="phone">
  8. <el-input v-model="userForm.phone" autocomplete="off"></el-input>
  9. </el-form-item>
  10. <el-form-item label="姓名" prop="name" v-if="show">
  11. <el-input v-model="userForm.name" autocomplete="off"></el-input>
  12. </el-form-item>
  13. <el-form-item label="性别" v-if="show">
  14. <el-radio-group v-model="userForm.sex">
  15. <el-radio label="M">男</el-radio>
  16. <el-radio label="W">女</el-radio>
  17. </el-radio-group>
  18. </el-form-item>
  19. <el-form-item label="邮箱" v-if="show">
  20. <el-input v-model="userForm.email"></el-input>
  21. </el-form-item>
  22. </el-form>
  23. </div>
  24. <div class="hui-dialog-submit">
  25. <el-button size="medium" @click="$emit('callback')">取 消</el-button>
  26. <el-button size="medium" type="primary" @click="submit">保 存</el-button>
  27. </div>
  28. </div>
  29. </template>
  30. <script>
  31. import {
  32. insertUser,
  33. testPhone,
  34. bindProject
  35. } from '@/httpApi/organization'
  36. export default {
  37. props: ['part'],
  38. data() {
  39. return {
  40. userForm: {
  41. name: '',
  42. sex: 'M',
  43. phone: '',
  44. email: ''
  45. },
  46. userRulers: {
  47. name: [{
  48. required: true,
  49. message: '请输入姓名',
  50. trigger: 'blur'
  51. }],
  52. phone: [{
  53. required: true,
  54. message: '请输入手机号',
  55. trigger: 'blur'
  56. }, {
  57. validator: (rule, value, callback) => {
  58. if (!/^1[123456789]\d{9}$/.test(value)) {
  59. callback(new Error("请输入正确的手机号"));
  60. } else {
  61. testPhone(value).then(data => {
  62. this.show = !data.data;
  63. this.alertShow = !this.show;
  64. callback()
  65. })
  66. }
  67. },
  68. trigger: 'blur'
  69. }],
  70. },
  71. show: false,
  72. alertShow: false
  73. }
  74. },
  75. methods: {
  76. submit() {
  77. this.$nextTick(() => {
  78. this.$refs.userForm.validate(valid => {
  79. if (valid) {
  80. insertUser(this.$store.getters.organization.id, this.part.id, this.userForm)
  81. .then(res => {
  82. if (res.state) {
  83. bindProject({
  84. organizationId: this.$store.getters.organization
  85. .id,
  86. projectId: this.$store.getters.project.id,
  87. userId: res.data.id,
  88. identityId: 3
  89. }).then(res => {
  90. if (res.state) {
  91. this.$emit('callback', 'init');
  92. this.$message.success('操作成功');
  93. }
  94. })
  95. }
  96. })
  97. } else {
  98. return false;
  99. }
  100. });
  101. });
  102. }
  103. }
  104. }
  105. </script>