123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- import { computed, nextTick, reactive, ref, watch } from 'vue'
- import {
- requestBehaviorClues,
- requestGetStaticInfo,
- requestRetainedCapital,
- requestSubmitLeaveInfo
- } from '../api/api'
- import { getSourceInfo } from './utils'
- import { showToast } from './toast'
- // pc静态弹窗卡片信息获取
- export function useStaticCustomInfo() {
- const configInfo = reactive({
- name: '',
- remark: '',
- wxer: '',
- phone: '',
- })
- // 获取静态信息
- useStaticInfoRequest().then((r) => {
- if (r) {
- Object.assign(configInfo, r)
- }
- })
- return {
- configInfo
- }
- }
- // 线索弹窗卡片信息获取
- export function usePreLeaveInfo(options = {}) {
- const { props } = options
- const visible = ref(false)
- const configInfo = reactive({
- name: '',
- remark: '',
- wxer: '',
- phone: '', // 客服手机号
- userPhone: '', // 用户留资手机号
- isCurrentPhone: true,
- })
- const source = computed(() => props.source)
- const sourceDesc = computed(() => props.sourceDesc)
- const staticInfo = computed(() => props.staticInfo)
- function updateVisible(e) {
- visible.value = e
- if (props.onPopupVisibleChange && typeof props.onPopupVisibleChange === 'function') {
- props.onPopupVisibleChange(e)
- }
- if (e) {
- createClueWhenOpen()
- }
- }
- function close() {
- updateVisible(false)
- }
- watch(() => source.value, async (val) => {
- if (source) {
- const r = await useLeaveInfoRequest({ source: val })
- if (r.info) {
- configInfo.userPhone = r.info.phone
- configInfo.isCurrentPhone = r.info.isCurrentPhone
- }
- }
- })
- async function createClueWhenOpen() {
- if (staticInfo.value) {
- // 获取静态信息
- const r = await useStaticInfoRequest()
- if (r) {
- Object.assign(configInfo, r)
- }
- }
- else {
- // 获取动态分配信息
- const r = await useBehaviorCluesRequest(sourceDesc.value)
- if (r) {
- Object.assign(configInfo, r)
- }
- }
- }
- return {
- updateVisible,
- close,
- visible,
- configInfo
- }
- }
- // 与我联系-判断逻辑
- export function useContactMeLogic(options = {}) {
- const { configInfo, props } = options
- const userPhone = ref(configInfo?.userPhone || '')
- const source = computed(() => props.source)
- const isLoginPhone = computed(() => configInfo.isCurrentPhone || false)
- watch(() => configInfo?.userPhone, (val) => {
- userPhone.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">${userPhone.value}</span>,<br />请核对联系电话是否准确`
- })
- const confirmPhoneDialog = reactive({
- show: false,
- title: '联系电话确认',
- confirmButtonText: '准确,我要提交',
- cancelButtonText: '有误,我要修改',
- contentText: confirmContentText,
- })
- function closeAllDialog() {
- changePhoneDialog.show = false
- confirmPhoneDialog.show = false
- successCheckDialog.show = false
- }
- function showSuccessDialog() {
- changePhoneDialog.show = false
- confirmPhoneDialog.show = false
- successCheckDialog.show = true
- }
- const dialogEvents = {
- confirmPhoneConfirm() {
- doConfirmLeave()
- },
- confirmPhoneCancel() {
- confirmPhoneDialog.show = false
- changePhoneDialog.show = true
- },
- successConfirm() {
- successCheckDialog.show = false
- },
- async successClose() {
- closeAllDialog()
- },
- phoneChangeConfirm() {
- doConfirmLeave()
- },
- phoneChangeCancel() {
- confirmPhoneDialog.show = true
- changePhoneDialog.show = false
- },
- }
- function checkPhonePass(phone) {
- const reg = /^1[3-9]\d{9}$/
- return reg.test(phone)
- }
- const actualPhone = computed(() => {
- if (changePhoneDialog.show) {
- return changePhoneDialog.phoneNumber
- }
- else {
- return userPhone.value
- }
- })
- async function doConfirmLeave() {
- const phonePass = checkPhonePass(actualPhone.value)
- if (!phonePass) {
- return showToast('联系电话格式不正确')
- }
- const payload = {
- source: source.value,
- phone: actualPhone.value,
- source_desc: '',
- }
- const info = getSourceInfo(payload.source)
- if (info.desc) {
- payload.source_desc = info.desc
- }
- try {
- const res = await requestSubmitLeaveInfo(payload)
- if (res && res.data) {
- showSuccessDialog()
- }
- }
- catch (error) {
- console.log(error)
- }
- }
- function contactMe() {
- if (isLoginPhone.value) {
- doConfirmLeave()
- }
- else {
- confirmPhoneDialog.show = true
- }
- }
- return {
- userPhone,
- changePhoneDialog,
- successCheckDialog,
- confirmPhoneDialog,
- closeAllDialog,
- showSuccessDialog,
- checkPhonePass,
- dialogEvents,
- contactMe
- }
- }
- export async function useBehaviorCluesRequest(value) {
- const res = await requestBehaviorClues({ source_desc: value })
- const { error_code: code, data } = res
- if (code === 0 && data) {
- return data
- }
- }
- export async function useLeaveInfoRequest(options = {}) {
- const { source } = options
- const res = await requestRetainedCapital({ source })
- const { error_code: code } = res
- if (code === 0) {
- return res
- }
- }
- export async function useStaticInfoRequest() {
- const res = await requestGetStaticInfo()
- const { error_code: code, data } = res
- if (code === 0 && data) {
- return data
- }
- }
|