contact.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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="请输入" type="password"></uni-easyinput>
  23. </uni-forms-item>
  24. <uni-forms-item name="passwordConfirm" label="密码二次确认" required>
  25. <uni-easyinput v-model="val.passwordConfirm" placeholder="请输入" type="password"></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 { 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: {
  49. rules: [{required: true, errorMessage: '请输入姓名' }]
  50. },
  51. phone: mobile,
  52. email: emailRequired,
  53. password,
  54. passwordConfirm: {
  55. rules: [
  56. { required: true, errorMessage: '请再次输入密码' },
  57. {
  58. validateFunction: function(rule, value, data, callback) {
  59. if (value !== data.password) callback('两次输入的密码不一致')
  60. return true
  61. }
  62. }
  63. ]
  64. }
  65. }
  66. const contacts = ref([
  67. {
  68. contactName: '',
  69. phone: adminUserPhone.value || '',
  70. email: '',
  71. password: '',
  72. passwordConfirm: ''
  73. },
  74. {
  75. contactName: '',
  76. phone: '',
  77. email: '',
  78. password: '',
  79. passwordConfirm: ''
  80. }
  81. ])
  82. onLoad((options) => {
  83. if (options?.isEdit) {
  84. const applyInfo = ref(uni.getStorageSync('entRegisterData') ? JSON.parse(uni.getStorageSync('entRegisterData')) : {})
  85. contacts.value = applyInfo.value.contacts.map(e => {
  86. e.passwordConfirm = e.password
  87. return e
  88. })
  89. }
  90. })
  91. const handleAddContact = () => {
  92. contacts.value.push({
  93. contactName: '',
  94. phone: '',
  95. email: '',
  96. password: '',
  97. passwordConfirm: ''
  98. })
  99. }
  100. const deleteContact = (index) => {
  101. contacts.value.splice(index, 1)
  102. }
  103. // 检查联系人信息是否重复
  104. const checkDuplicates = (dataList) => {
  105. const emailRecord = {}
  106. const phoneRecord = {}
  107. for (const item of dataList) {
  108. const email = item.email
  109. const phone = item.phone
  110. if (emailRecord[email]) {
  111. return false
  112. }
  113. if (phoneRecord[phone]) {
  114. return false
  115. }
  116. emailRecord[email] = true
  117. phoneRecord[phone] = true
  118. }
  119. return true
  120. }
  121. const handleSubmit = async () => {
  122. // 存储所有的验证Promise
  123. const validationPromises = []
  124. formRef.value.forEach((e) => {
  125. validationPromises.push(e.validate().catch(err => {
  126. return false
  127. }))
  128. })
  129. // 等待所有验证Promise完成
  130. const validationResults = await Promise.all(validationPromises)
  131. const errorCount = validationResults.filter(result => result === false).length
  132. if (errorCount > 0) return
  133. if (!contacts.value.length || contacts.value.length < 2) {
  134. uni.showToast({
  135. title: '请至少添加两个联系人',
  136. icon: 'none',
  137. duration: 2000
  138. })
  139. return
  140. }
  141. const checkValue = checkDuplicates(contacts.value)
  142. if (!checkValue) {
  143. uni.showToast({
  144. title: '手机号或邮箱不能重复',
  145. icon: 'none',
  146. duration: 2000
  147. })
  148. return
  149. }
  150. const params = {
  151. ...register.value,
  152. contacts: contacts.value,
  153. contactName: contacts.value[0].contactName,
  154. phone: contacts.value[0].phone,
  155. email: contacts.value[0].email
  156. }
  157. console.log(params, '企业注册参数')
  158. uni.showLoading({ title: '提交中' })
  159. try {
  160. await enterpriseRegisterApply(params)
  161. uni.hideLoading()
  162. uni.showToast({
  163. title: '提交成功',
  164. icon: 'success',
  165. duration: 2000
  166. })
  167. uni.removeStorageSync('entRegisterData') // 重新提交时清除前面的缓存,否则重新提交申请后再刷会显示旧数据
  168. uni.reLaunch({
  169. url: '/pages/register/review?applySubmit=true'
  170. })
  171. } catch {
  172. uni.hideLoading()
  173. }
  174. }
  175. </script>
  176. <style lang="scss" scoped>
  177. .wrapper{
  178. padding: 15px;
  179. }
  180. .contact-item {
  181. border-bottom: 1px solid #eee;
  182. margin-bottom: 30px;
  183. }
  184. </style>