contact.vue 6.0 KB

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