EmailForm.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <template>
  2. <view style="width: 100%;">
  3. <u-action-sheet :show="show" @close="onClose">
  4. <view class="cu-bar bg-white">
  5. <view class="action text-blue" @tap="onClose">取消</view>
  6. <view class="action text-green" @tap="selectUsers">确定</view>
  7. </view>
  8. <u-form :show="show" :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" ref="inputForm">
  9. <u-form-item label="姓名" prop="userName"
  10. :rules="[]">
  11. <u-input v-model="inputForm.userName" :disabled="true" placeholder="请填写姓名" clearable></u-input>
  12. </u-form-item>
  13. <u-form-item label="邮箱" prop="userEmail"
  14. :rules="[]">
  15. <u-input v-model="inputForm.userEmail" placeholder="请填写邮箱" clearable></u-input>
  16. </u-form-item>
  17. <u-form-item label="电话" prop="userPhone"
  18. :rules="[]">
  19. <u-input v-model="inputForm.userPhone" :disabled="true" placeholder="请填写电话" clearable></u-input>
  20. </u-form-item>
  21. </u-form>
  22. </u-action-sheet>
  23. </view>
  24. </template>
  25. <script>
  26. import userService from "@/api/sys/userService"
  27. export default {
  28. data() {
  29. return {
  30. show: false,
  31. id: '',
  32. inputForm: {
  33. userName: '',
  34. userEmail: '',
  35. userPhone: '',
  36. }
  37. };
  38. },
  39. props: {
  40. value: String,
  41. placeholder: {
  42. type: String,
  43. default: '请选择项目'
  44. },
  45. readonly: {
  46. type: Boolean,
  47. default: false
  48. },
  49. disabled: {
  50. type: Boolean,
  51. default: false
  52. },
  53. },
  54. mounted() {
  55. },
  56. methods: {
  57. init(id,userEmail) {
  58. this.inputForm.userEmail = userEmail
  59. this.show = true;
  60. this.id = id;
  61. },
  62. onClose() {
  63. this.show = false;
  64. },
  65. selectUsers() {
  66. return new Promise((resolve, reject) => {
  67. // 表单规则验证
  68. let errors = [];
  69. // 验证邮箱
  70. if (this.isNotEmpty(this.inputForm.userEmail)) {
  71. var reg = /^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
  72. if (!reg.test(this.inputForm.userEmail)) {
  73. errors.push('请输入正确的邮箱地址');
  74. }
  75. }
  76. if (errors.length > 0) {
  77. // 存在错误,显示提示信息
  78. errors.forEach(error => {
  79. uni.showToast({
  80. title: error,
  81. icon: 'none',
  82. duration: 2000
  83. });
  84. });
  85. reject(errors); // 将错误数组传递给调用者
  86. } else {
  87. // 所有验证通过,执行保存操作
  88. // 处理确定按钮点击事件
  89. userService.updateEmail({ id: this.id, email: this.inputForm.userEmail })
  90. .then((data) => {
  91. if (data === '修改成功') {
  92. uni.showToast({
  93. title: '修改成功',
  94. icon: 'none',
  95. duration: 2000
  96. });
  97. this.show = false;
  98. // 在邮箱更新成功后触发父组件的输入事件
  99. this.$emit('input', this.inputForm.userEmail);
  100. resolve(); // 通知调用者操作成功
  101. }
  102. })
  103. .catch(error => {
  104. reject(error); // 将具体的错误信息传递给调用者
  105. });
  106. }
  107. });
  108. },
  109. isEmpty(value) {
  110. let result = false;
  111. if (value == null || value == undefined) {
  112. result = true;
  113. }
  114. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  115. result = true;
  116. }
  117. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  118. result = true;
  119. }
  120. return result;
  121. },
  122. isNotEmpty (value) {
  123. return !this.isEmpty(value)
  124. },
  125. }
  126. };
  127. </script>
  128. <style scoped>
  129. .u-action-sheet {
  130. /* 设置为绝对定位,使其相对于父元素定位 */
  131. position: absolute;
  132. /* 居中显示 */
  133. top: 50%;
  134. left: 50%;
  135. transform: translate(-50%, -50%);
  136. /* 设置最大宽度,以避免过宽 */
  137. max-width: 90%;
  138. /* 设置最大高度,以避免过高 */
  139. max-height: 90%;
  140. /* 设置溢出滚动 */
  141. overflow-y: auto;
  142. /* 设置背景颜色 */
  143. background-color: #fff;
  144. /* 设置边框 */
  145. border: 1px solid #ddd;
  146. /* 设置圆角 */
  147. border-radius: 8px;
  148. }
  149. .u-form {
  150. /* 设置内边距 */
  151. padding: 20px;
  152. }
  153. .u-form-item {
  154. /* 设置底部外边距 */
  155. margin-bottom: 20px;
  156. }
  157. .u-input {
  158. /* 设置输入框宽度 */
  159. width: 100%;
  160. }
  161. </style>