|
|
|
|
@@ -1,66 +1,85 @@
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, reactive, onMounted, inject ,watch} from 'vue'
|
|
|
|
|
import router from '@/router'
|
|
|
|
|
import { showConfirmDialog } from 'vant'
|
|
|
|
|
import { useUserInfoStore, useOverallStore } from '@/stores'
|
|
|
|
|
import { LogOut } from '@/api/login'
|
|
|
|
|
import { getCustomerList, type CustomerListParams,customerCheckin } from '@/api/workshop'
|
|
|
|
|
import MyEvent from '@/utils/myEvent'
|
|
|
|
|
import { ref, reactive, onMounted, inject } from 'vue'
|
|
|
|
|
import router from '@/router'
|
|
|
|
|
import { showConfirmDialog, showToast } from 'vant'
|
|
|
|
|
import { useUserInfoStore, useOverallStore } from '@/stores'
|
|
|
|
|
import { LogOut } from '@/api/login'
|
|
|
|
|
import { getCustomerList, type CustomerListParams, customerCheckin } from '@/api/workshop'
|
|
|
|
|
import MyEvent from '@/utils/myEvent'
|
|
|
|
|
import { encryptPassword } from '@/utils/tools'
|
|
|
|
|
import { updateUserInfo } from '@/api/login'
|
|
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
const props = defineProps<{
|
|
|
|
|
isCustomer?: boolean
|
|
|
|
|
}>()
|
|
|
|
|
}>()
|
|
|
|
|
|
|
|
|
|
const userInfoStore = useUserInfoStore()
|
|
|
|
|
const overallStore = useOverallStore()
|
|
|
|
|
const emit = defineEmits(['view-type', 'selected-customer','change-visible'])
|
|
|
|
|
const show = ref(false)
|
|
|
|
|
const isEdit = ref(false)
|
|
|
|
|
const form = reactive({
|
|
|
|
|
name: { msg: '', value: userInfoStore.state.userInfo.username },
|
|
|
|
|
email: { msg: '', value: userInfoStore.state.userInfo.email },
|
|
|
|
|
// password: { show: false, msg: '', value: userInfoStore.state.userInfo.password }
|
|
|
|
|
})
|
|
|
|
|
const open = () => {
|
|
|
|
|
const userInfoStore = useUserInfoStore()
|
|
|
|
|
const overallStore = useOverallStore()
|
|
|
|
|
const emit = defineEmits(['view-type', 'selected-customer'])
|
|
|
|
|
const show = ref(false)
|
|
|
|
|
const isEdit = ref(false)
|
|
|
|
|
const form = reactive({
|
|
|
|
|
name: { msg: '', value: '' },
|
|
|
|
|
email: { msg: '', value: '' },
|
|
|
|
|
password: { show: true, msg: '', value: '' }
|
|
|
|
|
})
|
|
|
|
|
const open = () => {
|
|
|
|
|
form.name.value = userInfoStore.state.userInfo.username
|
|
|
|
|
form.email.value = userInfoStore.state.userInfo.email
|
|
|
|
|
form.password.value = ''
|
|
|
|
|
isEdit.value = false
|
|
|
|
|
show.value = true
|
|
|
|
|
}
|
|
|
|
|
const close = () => {
|
|
|
|
|
}
|
|
|
|
|
const close = () => {
|
|
|
|
|
show.value = false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
watch(show,(newVal)=>{
|
|
|
|
|
emit('change-visible', newVal)
|
|
|
|
|
MyEvent.emit('change-profile-visible',newVal)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const onEditItem = (item) => {
|
|
|
|
|
}
|
|
|
|
|
const onEditItem = (item) => {
|
|
|
|
|
if (!form[item]) return
|
|
|
|
|
form[item].edit = true
|
|
|
|
|
}
|
|
|
|
|
const onSaveItem = (item) => {
|
|
|
|
|
}
|
|
|
|
|
const onSaveItem = (item) => {
|
|
|
|
|
if (!form[item]) return
|
|
|
|
|
form[item].edit = false
|
|
|
|
|
}
|
|
|
|
|
const switchCustomer = () => {
|
|
|
|
|
}
|
|
|
|
|
const switchCustomer = () => {
|
|
|
|
|
// console.log('switchCustomer')
|
|
|
|
|
handleShowPopup(true)
|
|
|
|
|
}
|
|
|
|
|
const edit = () => {
|
|
|
|
|
}
|
|
|
|
|
const edit = () => {
|
|
|
|
|
form.password.value = ''
|
|
|
|
|
isEdit.value = true
|
|
|
|
|
}
|
|
|
|
|
const confirm = () => {
|
|
|
|
|
overallStore.setLoading(true)
|
|
|
|
|
}
|
|
|
|
|
const confirm = () => {
|
|
|
|
|
if (!isEdit.value) return
|
|
|
|
|
const password = form.password.value
|
|
|
|
|
const params = {
|
|
|
|
|
username: form.name.value,
|
|
|
|
|
email: form.email.value,
|
|
|
|
|
password
|
|
|
|
|
}
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
if (password) {
|
|
|
|
|
if (password.length < 6) {
|
|
|
|
|
return showToast('Password must be at least 6 characters')
|
|
|
|
|
} else {
|
|
|
|
|
params.password = encryptPassword(password)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
params.password = userInfoStore.state.userInfo.password
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
overallStore.setLoading(true)
|
|
|
|
|
updateUserInfo(params).then((res) => {
|
|
|
|
|
overallStore.setLoading(false)
|
|
|
|
|
showToast('Update success')
|
|
|
|
|
userInfoStore.setUserInfo({
|
|
|
|
|
...userInfoStore.state.userInfo,
|
|
|
|
|
...params
|
|
|
|
|
})
|
|
|
|
|
form.password.value = ''
|
|
|
|
|
isEdit.value = false
|
|
|
|
|
}, 1000)
|
|
|
|
|
}
|
|
|
|
|
const logout = () => {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const logout = () => {
|
|
|
|
|
showConfirmDialog({
|
|
|
|
|
title: 'Log out',
|
|
|
|
|
message: 'Are you sure you want to log out?',
|
|
|
|
|
@@ -74,23 +93,23 @@ const logout = () => {
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const showSwitchCustomerPopup = ref(false)
|
|
|
|
|
const custmerParams = ref<CustomerListParams>({
|
|
|
|
|
const showSwitchCustomerPopup = ref(false)
|
|
|
|
|
const custmerParams = ref<CustomerListParams>({
|
|
|
|
|
current: 1,
|
|
|
|
|
size: 5,
|
|
|
|
|
desc: true
|
|
|
|
|
})
|
|
|
|
|
const customerList = ref<any[]>([])
|
|
|
|
|
const pager = reactive({
|
|
|
|
|
})
|
|
|
|
|
const customerList = ref<any[]>([])
|
|
|
|
|
const pager = reactive({
|
|
|
|
|
loading: false,
|
|
|
|
|
noMore: false,
|
|
|
|
|
total: null as number | null
|
|
|
|
|
})
|
|
|
|
|
const customerListEl = ref<HTMLElement | null>(null)
|
|
|
|
|
})
|
|
|
|
|
const customerListEl = ref<HTMLElement | null>(null)
|
|
|
|
|
|
|
|
|
|
const loadCustomers = async (reset = false) => {
|
|
|
|
|
const loadCustomers = async (reset = false) => {
|
|
|
|
|
if (pager.loading) return
|
|
|
|
|
if (reset) {
|
|
|
|
|
custmerParams.value.current = 1
|
|
|
|
|
@@ -134,35 +153,35 @@ const loadCustomers = async (reset = false) => {
|
|
|
|
|
} finally {
|
|
|
|
|
pager.loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onScroll = (e: Event) => {
|
|
|
|
|
const onScroll = (e: Event) => {
|
|
|
|
|
const el = e.target as HTMLElement
|
|
|
|
|
if (!el) return
|
|
|
|
|
if (pager.loading || pager.noMore) return
|
|
|
|
|
if (el.scrollTop + el.clientHeight >= el.scrollHeight - 50) {
|
|
|
|
|
loadCustomers(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 打开customer选择时关闭profile弹窗 如果不是点击confirem关闭则重新打开profile弹窗
|
|
|
|
|
const handleShowPopup = (flag: boolean) => {
|
|
|
|
|
}
|
|
|
|
|
// 打开customer选择时关闭profile弹窗 如果不是点击confirem关闭则重新打开profile弹窗
|
|
|
|
|
const handleShowPopup = (flag: boolean) => {
|
|
|
|
|
showSwitchCustomerPopup.value = flag
|
|
|
|
|
show.value = !flag
|
|
|
|
|
if (flag) {
|
|
|
|
|
loadCustomers(true)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const handleChangeChecked = (item) => {
|
|
|
|
|
}
|
|
|
|
|
const handleChangeChecked = (item) => {
|
|
|
|
|
customerList.value.forEach((customer) => {
|
|
|
|
|
customer.checked = customer.vipId === item.vipId
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const handleSelectCustomer = () => {
|
|
|
|
|
}
|
|
|
|
|
const handleSelectCustomer = () => {
|
|
|
|
|
const selectedCustomer = customerList.value.find((customer) => customer.checked)
|
|
|
|
|
if (selectedCustomer) {
|
|
|
|
|
emit('selected-customer', selectedCustomer)
|
|
|
|
|
}
|
|
|
|
|
if(!props.isCustomer){
|
|
|
|
|
if (!props.isCustomer) {
|
|
|
|
|
// show.value = true
|
|
|
|
|
customerCheckin({ nickname: selectedCustomer.name }).then((res) => {
|
|
|
|
|
useUserInfoStore().resetGenerateParams()
|
|
|
|
|
@@ -171,22 +190,22 @@ const handleSelectCustomer = () => {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
showSwitchCustomerPopup.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const handleFetchCustomerList = () => {
|
|
|
|
|
const handleFetchCustomerList = () => {
|
|
|
|
|
loadCustomers(true)
|
|
|
|
|
}
|
|
|
|
|
MyEvent.add('update-customer-list', handleFetchCustomerList)
|
|
|
|
|
}
|
|
|
|
|
MyEvent.add('update-customer-list', handleFetchCustomerList)
|
|
|
|
|
|
|
|
|
|
const openSwitchCustomerPopup = (flag = true) => {
|
|
|
|
|
const openSwitchCustomerPopup = (flag = true) => {
|
|
|
|
|
showSwitchCustomerPopup.value = flag
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
handleFetchCustomerList()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
@@ -237,7 +256,7 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
</label>
|
|
|
|
|
<p class="error" v-show="form.email.msg">{{ form.email.msg }}</p>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="form-item" v-if="form.password">
|
|
|
|
|
<div class="form-item" v-if="isEdit">
|
|
|
|
|
<div class="label">Password</div>
|
|
|
|
|
<label class="input">
|
|
|
|
|
<div class="icon" @click="form.password.show = !form.password.show">
|
|
|
|
|
@@ -265,7 +284,7 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
</template>
|
|
|
|
|
<template v-else>
|
|
|
|
|
<button class="switch" @click="switchCustomer">Switch Customer</button>
|
|
|
|
|
<!-- <button class="edit" @click="edit">Edit Profile</button> -->
|
|
|
|
|
<button class="edit" @click="edit">Edit Profile</button>
|
|
|
|
|
<button class="logout" @click="logout">Log out</button>
|
|
|
|
|
</template>
|
|
|
|
|
</form>
|
|
|
|
|
@@ -310,11 +329,11 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
.van-popup {
|
|
|
|
|
.van-popup {
|
|
|
|
|
max-height: 90%;
|
|
|
|
|
--van-popup-round-radius: 7.8rem;
|
|
|
|
|
}
|
|
|
|
|
.profile {
|
|
|
|
|
}
|
|
|
|
|
.profile {
|
|
|
|
|
margin: 6.5rem 0;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
@@ -423,9 +442,9 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
margin-top: 17.8rem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.van-popup.user-popup {
|
|
|
|
|
.van-popup.user-popup {
|
|
|
|
|
height: 116.1rem;
|
|
|
|
|
color: #181725;
|
|
|
|
|
border-top-left-radius: 7.8rem;
|
|
|
|
|
@@ -495,5 +514,5 @@ defineExpose({ open, close, openSwitchCustomerPopup })
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
text-align: center;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|