|
|
@@ -1,34 +1,101 @@
|
|
|
<script setup lang="ts">
|
|
|
-const customer = ref('')
|
|
|
-const isShowMapping = ref(true)
|
|
|
+import { useUserStore } from '@/stores/modules/user'
|
|
|
+import { use } from 'vxe-pc-ui'
|
|
|
+
|
|
|
+const userStore = useUserStore()
|
|
|
+const customer = ref(userStore.customerInfo.name || '')
|
|
|
+const isShowMapping = ref(userStore.customerInfo.isShowMapping || false)
|
|
|
const visible = ref(false)
|
|
|
const myPopover = ref()
|
|
|
const customerSearchQuery = ref('')
|
|
|
|
|
|
-const customerList = ref([
|
|
|
- 'alice@dummy customer.com',
|
|
|
- 'bob@dummy customer.com',
|
|
|
- 'charlie@dummy customer.com',
|
|
|
- 'dave@dummy customer.com'
|
|
|
-])
|
|
|
-const showCustomerList = ref(customerList.value)
|
|
|
+const customerList = ref(userStore.userInfo?.kam_customers_name)
|
|
|
+const showCustomerList = ref(userStore.userInfo?.kam_customers_name)
|
|
|
+watch(
|
|
|
+ () => userStore.userInfo.kam_customers_name,
|
|
|
+ (newVal) => {
|
|
|
+ if (newVal) {
|
|
|
+ customerList.value = newVal
|
|
|
+ showCustomerList.value = newVal
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { immediate: true, deep: true }
|
|
|
+)
|
|
|
|
|
|
const filterCustomer = (query: string) => {
|
|
|
showCustomerList.value = customerList.value.filter((item) => {
|
|
|
- return item.includes(query)
|
|
|
+ return item.kam_customers_name?.includes(query)
|
|
|
})
|
|
|
}
|
|
|
-const changeShowMapping = () => {
|
|
|
+
|
|
|
+const loadingVisible = ref(false)
|
|
|
+const changeShowMapping = async () => {
|
|
|
+ userStore.setCustomerInfo({ name: '', isShowMapping: isShowMapping.value })
|
|
|
customer.value = ''
|
|
|
+ if (!isShowMapping.value && userStore.originalUName !== userStore.userInfo.uname) {
|
|
|
+ try {
|
|
|
+ loadingVisible.value = true
|
|
|
+ const res = await $api.handleCustomerSelection({ uname: userStore.originalUName })
|
|
|
+ if (res.code === 200) {
|
|
|
+ userStore.setUserInfo(
|
|
|
+ {
|
|
|
+ ...res.data.user_info,
|
|
|
+ kam_customers_name: userStore.userInfo.kam_customers_name
|
|
|
+ },
|
|
|
+ true
|
|
|
+ )
|
|
|
+ window.location.reload()
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('Error occurred while selecting customer:', err)
|
|
|
+ } finally {
|
|
|
+ loadingVisible.value = false
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-const changeCustomer = (cust: string) => {
|
|
|
+const changeCustomer = async (cust: string) => {
|
|
|
+ if (cust === customer.value) return
|
|
|
customer.value = cust
|
|
|
myPopover.value?.hide()
|
|
|
+ try {
|
|
|
+ loadingVisible.value = true
|
|
|
+ const res = await $api.handleCustomerSelection({ uname: cust })
|
|
|
+ if (res.code === 200) {
|
|
|
+ userStore.setUserInfo(
|
|
|
+ {
|
|
|
+ ...res.data.user_info,
|
|
|
+ kam_customers_name: userStore.userInfo.kam_customers_name
|
|
|
+ },
|
|
|
+ true
|
|
|
+ )
|
|
|
+ userStore.setCustomerInfo({ name: cust, isShowMapping: true })
|
|
|
+ window.location.reload()
|
|
|
+ }
|
|
|
+ } catch (err) {
|
|
|
+ console.error('Error occurred while selecting customer:', err)
|
|
|
+ } finally {
|
|
|
+ loadingVisible.value = false
|
|
|
+ }
|
|
|
}
|
|
|
+watch(
|
|
|
+ () => userStore.customerInfo,
|
|
|
+ (newVal) => {
|
|
|
+ if (newVal && customer.value !== newVal.name) {
|
|
|
+ customer.value = newVal.name
|
|
|
+ isShowMapping.value = newVal.isShowMapping
|
|
|
+ changeCustomer(newVal.name)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ { deep: true }
|
|
|
+)
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div
|
|
|
+ v-loading.fullscreen.lock="loadingVisible"
|
|
|
+ element-loading-text="Loading..."
|
|
|
+ element-loading-custom-class="element-loading"
|
|
|
+ element-loading-background="rgb(43, 47, 54, 0.7)"
|
|
|
class="kam-mapping-container"
|
|
|
:class="{ focus: visible }"
|
|
|
:style="{ 'justify-content': !isShowMapping ? 'center' : 'space-between' }"
|
|
|
@@ -69,10 +136,10 @@ const changeCustomer = (cust: string) => {
|
|
|
<div
|
|
|
class="customer-item"
|
|
|
v-for="cust in showCustomerList"
|
|
|
- :key="cust"
|
|
|
- @click="changeCustomer(cust)"
|
|
|
+ :key="cust.kam_customers_name"
|
|
|
+ @click="changeCustomer(cust.kam_customers_name)"
|
|
|
>
|
|
|
- {{ cust }}
|
|
|
+ {{ cust.kam_customers_name }}
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|