contact.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <view class="f-straight wrapper">
  3. <!-- <uni-notice-bar class="ss-m-b-30" scrollable text="填写联系人1后可获得500积分,可前往【门墩儿商城】兑换礼品【减压捏捏乐】,企业注册审核通过后积分将自动发放到您的账户中。" /> -->
  4. <view v-for="(val, index) in contacts" :key="index" class="f-straight contact-item">
  5. <view class="d-flex justify-space-between align-center ss-m-b-20">
  6. <view class="color-primary">{{ index === 0 ? '管理员' : '联系人' + index }}</view>
  7. <view v-if="index > 1">
  8. <uni-icons type="closeempty" size="20" color="#fe574a" @click="deleteContact(index)"></uni-icons>
  9. </view>
  10. </view>
  11. <uni-forms ref="formRef" :modelValue="val" :rules="formRules" validateTrigger="bind" label-width="105px" label-align="right" label-position="left">
  12. <uni-forms-item name="contactName" label="联系人姓名" required>
  13. <uni-easyinput v-model="val.contactName" placeholder="请输入"></uni-easyinput>
  14. </uni-forms-item>
  15. <uni-forms-item name="phone" label="联系电话" required>
  16. <uni-easyinput v-model="val.phone" placeholder="请输入" :disabled="index === 0"></uni-easyinput>
  17. </uni-forms-item>
  18. <uni-forms-item name="email" label="企业邮箱" required>
  19. <uni-easyinput v-model="val.email" placeholder="请输入企业邮箱(用于日后“登录邮箱”)"></uni-easyinput>
  20. </uni-forms-item>
  21. <uni-forms-item name="password" label="账户登录密码" required>
  22. <uni-easyinput v-model="val.password" placeholder="请输入"></uni-easyinput>
  23. </uni-forms-item>
  24. <uni-forms-item name="passwordConfirm" label="密码二次确认" required>
  25. <uni-easyinput v-model="val.passwordConfirm" placeholder="请输入"></uni-easyinput>
  26. </uni-forms-item>
  27. </uni-forms>
  28. </view>
  29. <view class="color-warning" style="text-align: center; margin-bottom: 50px;" @tap.stop="handleAddContact">
  30. <uni-icons type="plusempty" size="20" color="#fb8c00"></uni-icons>
  31. 继续添加联系人
  32. </view>
  33. <button class="send-button" @tap="handleSubmit">提 交</button>
  34. </view>
  35. </template>
  36. <script setup>
  37. import { ref, computed } from 'vue'
  38. import { userStore } from '@/store/user'
  39. import { onLoad } from '@dcloudio/uni-app'
  40. import { realName, mobile, emailRequired, password } from '@/utils/validate'
  41. import { enterpriseRegisterApply } from '@/api/enterprise'
  42. const useUserStore = userStore()
  43. const adminUserPhone = computed(() => useUserStore?.phone)
  44. const register = ref(JSON.parse(uni.getStorageSync('registerInfo')))
  45. console.log(adminUserPhone.value, '注册手机号', register.value)
  46. const formRef = ref()
  47. const formRules = {
  48. contactName: realName,
  49. phone: mobile,
  50. email: emailRequired,
  51. password,
  52. passwordConfirm: {
  53. rules: [
  54. { required: true, errorMessage: '请再次输入密码' },
  55. {
  56. validateFunction: function(rule, value, data, callback) {
  57. if (value !== data.password) callback('两次输入的密码不一致')
  58. return true
  59. }
  60. }
  61. ]
  62. }
  63. }
  64. const contacts = ref([
  65. {
  66. contactName: '',
  67. phone: adminUserPhone.value || '',
  68. email: '',
  69. password: '',
  70. passwordConfirm: ''
  71. },
  72. {
  73. contactName: '',
  74. phone: '',
  75. email: '',
  76. password: '',
  77. passwordConfirm: ''
  78. }
  79. ])
  80. onLoad((options) => {
  81. if (options?.isEdit) {
  82. const applyInfo = ref(uni.getStorageSync('entRegisterData') ? JSON.parse(uni.getStorageSync('entRegisterData')) : {})
  83. contacts.value = applyInfo.value.contacts.map(e => {
  84. e.passwordConfirm = e.password
  85. return e
  86. })
  87. }
  88. })
  89. const handleAddContact = () => {
  90. contacts.value.push({
  91. contactName: '',
  92. phone: '',
  93. email: '',
  94. password: '',
  95. passwordConfirm: ''
  96. })
  97. }
  98. const deleteContact = (index) => {
  99. contacts.value.splice(index, 1)
  100. }
  101. // 检查联系人信息是否重复
  102. const checkDuplicates = (dataList) => {
  103. const emailRecord = {}
  104. const phoneRecord = {}
  105. for (const item of dataList) {
  106. const email = item.email
  107. const phone = item.phone
  108. if (emailRecord[email]) {
  109. return false
  110. }
  111. if (phoneRecord[phone]) {
  112. return false
  113. }
  114. emailRecord[email] = true
  115. phoneRecord[phone] = true
  116. }
  117. return true
  118. }
  119. const handleSubmit = async () => {
  120. // 存储所有的验证Promise
  121. const validationPromises = []
  122. formRef.value.forEach((e) => {
  123. validationPromises.push(e.validate().catch(err => {
  124. return false
  125. }))
  126. })
  127. // 等待所有验证Promise完成
  128. const validationResults = await Promise.all(validationPromises)
  129. const errorCount = validationResults.filter(result => result === false).length
  130. if (errorCount > 0) return
  131. if (!contacts.value.length || contacts.value.length < 2) {
  132. uni.showToast({
  133. title: '请至少添加两个联系人',
  134. icon: 'none',
  135. duration: 2000
  136. })
  137. return
  138. }
  139. const checkValue = checkDuplicates(contacts.value)
  140. if (!checkValue) {
  141. uni.showToast({
  142. title: '手机号或邮箱不能重复',
  143. icon: 'none',
  144. duration: 2000
  145. })
  146. return
  147. }
  148. const params = {
  149. ...register.value,
  150. contacts: contacts.value,
  151. contactName: contacts.value[0].contactName,
  152. phone: contacts.value[0].phone,
  153. email: contacts.value[0].email
  154. }
  155. console.log(params, '企业注册参数')
  156. uni.showLoading({ title: '提交中' })
  157. try {
  158. await enterpriseRegisterApply(params)
  159. uni.hideLoading()
  160. uni.showToast({
  161. title: '提交成功',
  162. icon: 'success',
  163. duration: 2000
  164. })
  165. uni.reLaunch({
  166. url: '/pages/register/review'
  167. })
  168. } catch {
  169. uni.hideLoading()
  170. }
  171. }
  172. </script>
  173. <style lang="scss" scoped>
  174. .wrapper{
  175. padding: 15px;
  176. }
  177. .contact-item {
  178. border-bottom: 1px solid #eee;
  179. margin-bottom: 30px;
  180. }
  181. </style>