Prechádzať zdrojové kódy

feat: 新增留资手机号弹窗逻辑

cuiyalong 3 týždňov pred
rodič
commit
f1a5d1826f

+ 8 - 0
plugins/leave-source/src/api/api.js

@@ -54,3 +54,11 @@ export function requestGetStaticInfo() {
     method: 'post'
   })
 }
+
+export function requestSubmitLeaveInfo(data) {
+  return request({
+    url: '/salesLeads/portrait/clue',
+    method: 'post',
+    data
+  })
+}

+ 5 - 0
plugins/leave-source/src/data/index.js

@@ -0,0 +1,5 @@
+export const sourceMap = {
+  test: {
+    desc: '测试'
+  }
+}

+ 85 - 1
plugins/leave-source/src/utils/hooks.js

@@ -1,5 +1,11 @@
 import { computed, reactive, ref, watch } from 'vue'
-import { requestBehaviorClues, requestGetStaticInfo, requestRetainedCapital } from '@/api/api'
+import {
+  requestBehaviorClues,
+  requestGetStaticInfo,
+  requestRetainedCapital,
+  requestSubmitLeaveInfo
+} from '@/api/api'
+import { getSourceInfo, showToast } from '@/utils'
 
 // pc静态弹窗卡片信息获取
 export function useStaticCustomInfo() {
@@ -32,6 +38,7 @@ export function usePreLeaveInfo(options = {}) {
     remark: '',
     wxer: '',
     phone: '',
+    isCurrentPhone: true,
   })
 
   const source = computed(() => props.source)
@@ -48,6 +55,7 @@ export function usePreLeaveInfo(options = {}) {
     const r = await useLeaveInfoRequest({ source: val })
     if (r.info) {
       configInfo.phone = r.info.phone
+      configInfo.isCurrentPhone = r.info.isCurrentPhone
     }
   })
   watch(() => visible.value, async (val) => {
@@ -92,6 +100,82 @@ export async function useContactMeLogic(options = {}) {
   }
 }
 
+export function usePhoneCheck(options = {}) {
+  const { configInfo, props } = options
+  const phone = ref(configInfo.phone)
+  const source = computed(() => props.source)
+
+  const isLoginPhone = computed(() => configInfo.isCurrentPhone)
+
+  watch(() => configInfo.phone, (val) => {
+    phone.value = val
+  })
+
+  const changePhoneDialog = reactive({
+    show: false,
+    phoneNumber: '',
+  })
+  const successCheckDialog = reactive({
+    show: false,
+    title: '提交成功',
+    confirmButtonText: '我知道了',
+    cancelButtonText: '',
+    contentText: '我们的专属客服会在24小时内尽快与您联系,请注意电话接听。'
+  })
+
+  const confirmContentText = computed(() => {
+    return `专属客服将致电 <span class="highlight-text">${phone.value}</span>,<br />请核对联系电话是否准确`
+  })
+  const confirmPhoneDialog = reactive({
+    show: false,
+    confirmButtonText: '准确,我要提交',
+    cancelButtonText: '有误,我要修改',
+    contentText: confirmContentText,
+  })
+
+  function checkPhonePass(phone) {
+    const reg = /^1[3-9]\d{9}$/
+    return reg.test(phone)
+  }
+
+  async function doConfirmLeave() {
+    const payload = {
+      source: source.value,
+      phone: phone.value,
+      source_desc: '',
+    }
+    const info = getSourceInfo(payload.source)
+    if (info.desc) {
+      payload.source_desc = info.desc
+    }
+
+    requestSubmitLeaveInfo(payload)
+  }
+
+  function contactMe() {
+    const phonePass = checkPhonePass(phone.value)
+    if (!phonePass) {
+      return showToast('联系电话格式不正确')
+    }
+
+    if (isLoginPhone.value) {
+      doConfirmLeave()
+    }
+    else {
+      confirmPhoneDialog.show = true
+    }
+    doConfirmLeave()
+  }
+
+  return {
+    phone,
+    changePhoneDialog,
+    successCheckDialog,
+    confirmPhoneDialog,
+    contactMe
+  }
+}
+
 export async function useBehaviorCluesRequest(value) {
   const res = await requestBehaviorClues({ source_desc: value })
   const { error_code: code, data } = res

+ 7 - 0
plugins/leave-source/src/utils/utils.js

@@ -1,7 +1,14 @@
+import { sourceMap } from '@/data'
+
 export function isDOMElement(obj) {
   return obj && typeof obj === 'object' && obj.nodeType === 1
 }
 
+export function getSourceInfo(source) {
+  const t = sourceMap[source]
+  return t || {}
+}
+
 export function mobileCustomPage(platform) {
   const map = {
     app: '/jyapp/free/customer',