Commit f1259e46 by 李伟康

refactor(uniappX): 重构组件实现并优化API调用

- 将getEmployeeList函数重命名为getEmployeeListApi
- 更新BackPress组件中的组件实例调用方式为$callMethod
- 重构CarBrands组件的数据类型定义和状态管理逻辑
- 优化CustomPopup组件中的位置映射计算方法
- 调整CustomerAutocomplete组件的模板结构和样式
- 修复组件中多处类型安全问题并改进响应式数据处理
1 parent d901015c
Showing 25 changed files with 1251 additions and 1464 deletions
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import http from "@/api/request/http.uts"; import http from "@/api/request/http.uts";
/** 获取交付人员列表 */ /** 获取交付人员列表 */
export function getEmployeeList(data: UTSJSONObject): Promise<any> { export function getEmployeeListApi(data: UTSJSONObject): Promise<any> {
return http.post({ return http.post({
'method': 'dj.api.smartcarlife.employee.getByMerchantId.new', 'method': 'dj.api.smartcarlife.employee.getByMerchantId.new',
'projectName': 'boutique', 'projectName': 'boutique',
......
...@@ -8,12 +8,16 @@ ...@@ -8,12 +8,16 @@
</template> </template>
<template v-else> <template v-else>
完成接待 完成接待
<text>(推荐)</text> <text>
(推荐)
</text>
</template> </template>
</view> </view>
<view class="footer-btn cancel flex" @click="$emit('backHome')"> <view class="footer-btn cancel flex" @click="$emit('backHome')">
仍要退出 仍要退出
<text>(不推荐)</text> <text>
(不推荐)
</text>
</view> </view>
</view> </view>
</MessageBox> </MessageBox>
...@@ -21,6 +25,7 @@ ...@@ -21,6 +25,7 @@
<script setup lang="uts"> <script setup lang="uts">
import MessageBox from './MessageBox.uvue' import MessageBox from './MessageBox.uvue'
import { ComponentPublicInstance } from 'vue'
const props = defineProps({ const props = defineProps({
finishDoneText: String, finishDoneText: String,
...@@ -29,22 +34,19 @@ ...@@ -29,22 +34,19 @@
default: '当前操作视为强制退出接待,若需正常流程完成接待请点击「完成接待」' default: '当前操作视为强制退出接待,若需正常流程完成接待请点击「完成接待」'
} }
}) })
const finishRef = ref(null)
function open(): void { function open(): void {
finishRef.value.open() (finishRef.value as ComponentPublicInstance).$callMethod('open')
} }
function hide(): void { function hide(): void {
finishRef.value.close() (finishRef.value as ComponentPublicInstance).$callMethod('close')
} }
const finishRef = ref<any>(null)
const emit = defineEmits(['openStep', 'backHome']) const emit = defineEmits(['openStep', 'backHome'])
defineExpose({ defineExpose({ open, hide })
open,
hide
})
</script> </script>
<style lang="scss"> <style lang="scss">
.footer { .footer {
border-top: 2rpx solid #eff0f2; border-top: 2rpx solid #eff0f2;
font-weight: 600; font-weight: 600;
font-size: 32rpx; font-size: 32rpx;
...@@ -76,5 +78,5 @@ ...@@ -76,5 +78,5 @@
text { text {
font-size: 24rpx; font-size: 24rpx;
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -7,11 +7,11 @@ ...@@ -7,11 +7,11 @@
title="请选择车品牌" title="请选择车品牌"
@close="$emit('close')" @close="$emit('close')"
> >
<view class="select-box"> <view class="select-box" :key="updateView">
<view <view
class="select-item" class="select-item"
:class="{ checked: carBrand == item.name }" :class="{ checked: carBrand == item.name }"
@click="selectCar(item)" @click="selectCar(item, false ,'')"
v-for="(item, index) in carBrandList" v-for="(item, index) in carBrandList"
:key="index" :key="index"
> >
...@@ -45,44 +45,35 @@ ...@@ -45,44 +45,35 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import MessageBox from './MessageBox.uvue' import MessageBox from './MessageBox.uvue'
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import { getMerchantCarBrandList,getCarBrandsListApi } from '@/api/common-api.uts' import { getMerchantCarBrandList,getCarBrandsListApi } from '@/api/common-api.uts'
import { state, dispatch } from "@/store/index.uts" import { state, dispatch } from "@/store/index.uts"
import { ComponentPublicInstance } from 'vue'
interface CarBrandItem { type CarBrandItem = {
id: string id: string
name: string name: string
brandId?: string brandId?: string
brandName?: string brandName?: string
childs?: Array<CarBrandItem> childs?: Array<CarBrandItem>
} }
interface CustomerInfo {
carModel?: string
carBrand?: string
carBrandId?: string
oneCarBrand?: string
oneCarBrandId?: string
}
interface SelectItem { type SelectItem = {
carBrand: string carBrand: string
carBrandId: string carBrandId: string
carChildsBrandName: string carChildsBrandName: string
carChildsBrandId: string carChildsBrandId: string
} }
interface UserInfo { type UserInfo = UTSJSONObject
shopMerchantId: string
[key: string]: any
}
interface CarBrandListResponse { interface CarBrandListResponse {
carBrandList?: Array<CarBrandItem> carBrandList?: Array<CarBrandItem>
} }
const props = defineProps({ const props = defineProps({
carBrandKey: { carBrandKey: {
type: String, type: String,
default: 'carBrand' default: 'carBrand'
...@@ -95,107 +86,111 @@ const props = defineProps({ ...@@ -95,107 +86,111 @@ const props = defineProps({
type: Object, type: Object,
default: () => ({}) default: () => ({})
}, },
customBoolean: Boolean, customBoolean: {
type:Boolean,
default:false
},
linkage: { linkage: {
type: Boolean, type: Boolean,
default: true default: true
} }
}) })
const emit = defineEmits(['close', 'select'])
const carlist = ref<Array<CarBrandItem>>([])
const selectItem = ref<SelectItem>({} as SelectItem)
const clickFlga = ref<boolean>(false)
const carBrandListOff = ref<boolean>(false)
const carBrandListVisible = ref<any>(null)
const carBoxVisible = ref<any>(null)
const watchStatus = computed(() => {
return state.user.historyStatus
})
const carModel = computed<string | undefined>(() => {
return props.customBoolean ? props.echoData[props.carModelKey] : state.user.customerInfo.carModel
})
const carBrandList = computed<Array<CarBrandItem>>(() => {
return storage.get("carBrandList") || []
})
const carBrand = computed<string | undefined>(() => {
return props.customBoolean ? props.echoData[props.carBrandKey] : state.user.customerInfo.carBrand
})
const boutiqueDefaultCarBrandId = computed<string | undefined>(() => {
return state.user.boutiqueDefaultCarBrandId
})
const defaultCarId = computed<string>(() => {
return state.user.defaultCarId || ''
})
watch(() => watchStatus.value, (newval) => {
close()
}, { immediate: true })
function autoSelect(): void { const emit = defineEmits(['close', 'select'])
const boutiqueDefaultCarBrandIdVal = boutiqueDefaultCarBrandId.value
const defaultCarIdVal = defaultCarId.value
let carIndex = 0
if (boutiqueDefaultCarBrandIdVal) { const carlist = ref<Array<CarBrandItem>>([])
carIndex = carBrandList.value.findIndex(e => e.id == boutiqueDefaultCarBrandIdVal) const selectItem = ref<SelectItem>({
carBrand: '',
carBrandId: '',
carChildsBrandName: '',
carChildsBrandId: ''
})
const clickFlga = ref<boolean>(false)
const carBrandListOff = ref<boolean>(false)
const carBrandListVisible = ref(null)
const carBoxVisible = ref(null)
const updateView = ref<number>(Date.now())
const carBrandList = ref<Array<CarBrandItem>>([])
const watchStatus = computed<boolean>(() => {
const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
} }
})
if (carIndex < 0) carIndex = 0 const carModel = computed<string|null>(() => {
const car_key = props.carModelKey
if (carBrandList.value.length) { if (props.customBoolean === true) {
selectCar(carBrandList.value[carIndex], true, defaultCarIdVal) const echoObj = props.echoData as UTSJSONObject
const value = echoObj[car_key]
return value != null ? `${value}` : null
} else {
return `${state.user.customerInfo.carModel}`
} }
} })
function open(): void {
const userInfo: UserInfo = storage.get("userInfo")
const { shopMerchantId } = userInfo
getMerchantCarBrandList([shopMerchantId])
.then(({ data }) => {
let list = (data[0] as CarBrandListResponse).carBrandList
const carBrandListData: Array<CarBrandItem> = []
list?.forEach((e: CarBrandItem) => { const carBrand = computed<string|null>(() => {
e.childs?.forEach((i: CarBrandItem) => { const car_key = props.carModelKey
i.brandName = e.name if (props.customBoolean === true) {
i.brandId = e.id const echoObj = props.echoData as UTSJSONObject
carBrandListData.push(i) const value = echoObj[car_key]
}) return value != null ? `${value}` : null
} else {
return `${state.user.customerInfo.carBrand}`
}
}) })
dispatch("setCarBrandsList", carBrandListData) const boutiqueDefaultCarBrandId = computed<any>(() => {
storage.set("carBrandList", carBrandListData) return state.user.boutiqueDefaultCarBrandId
}) })
const { carBrand: carBrandVal } = props const defaultCarId = computed<any>(() => {
if (carBrandVal) { const val = state.user.defaultCarId
const carBrandListVal = carBrandList.value return val != null && val !== '' ? val : ''
const item = carBrandListVal.find(e => e.name == carBrandVal) })
function close(): void {
if (carBoxVisible.value != null) {
(carBoxVisible.value as ComponentPublicInstance).$callMethod('close')
}
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
}
carBrandListOff.value = false
}
if (item && carBrandListVal.length == 1) { function closeCarBoxVisible(): void {
selectCar(item) if (carBrandListOff.value) return
} else { else emit('close')
carBrandListVisible.value?.open()
carBrandListOff.value = true
} }
return function handleSelect(item: CarBrandItem): void {
const selectItemVal = selectItem.value
const customerInfo: UTSJSONObject = {
...state.user.customerInfo,
carBrand: selectItemVal.carChildsBrandName,
carBrandId: selectItemVal.carChildsBrandId,
oneCarBrand: selectItemVal.carBrand,
oneCarBrandId: selectItemVal.carBrandId,
carModel: item.name,
carModelId: item.id
} }
carBrandListVisible.value?.open() if (props.linkage) {
carBrandListOff.value = true dispatch('setCustomerInfo', customerInfo)
} dispatch('updateViewKey')
dispatch('setCurrentCarInfo', selectItemVal)
}
function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void { (carBoxVisible.value as ComponentPublicInstance).$callMethod('close')
if (!e.brandId || !e.id) { emit('select', { ...item, ...selectItemVal })
}
function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void {
if (e.brandId == null || e.id == null) {
return uni.showToast({ return uni.showToast({
title: "车型 ID 或品牌 ID 为空", title: "车型 ID 或品牌 ID 为空",
icon: "none" icon: "none"
...@@ -207,49 +202,49 @@ function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void ...@@ -207,49 +202,49 @@ function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void
if (clickFlga.value) return if (clickFlga.value) return
clickFlga.value = true clickFlga.value = true
selectItem.value = { const selectData: SelectItem = {
carBrand: e.brandName!, carBrand: e.brandName!,
carBrandId: e.brandId!, carBrandId: e.brandId!,
carChildsBrandName: e.name, carChildsBrandName: e.name,
carChildsBrandId: e.id carChildsBrandId: e.id
} }
selectItem.value = selectData
const cacheKey = `${e.id}_${e.brandId}_carlist` const cacheKey = `${e.id}_${e.brandId}_carlist`
const carList = uni.getStorageSync(cacheKey) let _carList = uni.getStorageSync(cacheKey) as Array<CarBrandItem> | null
if (carList) { if (_carList != null) {
clickFlga.value = false clickFlga.value = false
carlist.value = carList carlist.value = _carList
if (auto && carList.length) { if (auto) {
if (carId) index = carList.findIndex(i => i.id == carId) if (carId != null) index = _carList.findIndex(i => i.id == carId)
if (index < 0) index = 0 if (index < 0) index = 0
handleSelect(carList[index]) handleSelect(_carList[index])
} else { } else {
carBoxVisible.value?.open() (carBoxVisible.value as ComponentPublicInstance).$callMethod('open')
} }
} else { } else {
if (!auto) uni.showLoading({ if (!auto) uni.showLoading({
title: '',
mask: true mask: true
}) })
} }
getCarBrandsListApi({ getCarBrandsListApi({ brandId: e.brandId, childBrandId: e.id }).then(res => {
brandId: e.brandId,
childBrandId: e.id
}).then(res => {
uni.hideLoading() uni.hideLoading()
carlist.value = res const typedRes = res as UTSArray<CarBrandItem>
carlist.value = typedRes
if (res) uni.setStorageSync(cacheKey, res) if (typedRes.length > 0) uni.setStorageSync(cacheKey, typedRes)
if (!carList) { if (carlist.value != null) {
if (auto && res.length) { if (auto && typedRes.length > 0) {
if (carId) index = res.findIndex(i => i.id == carId) if (carId != null) index = typedRes.findIndex(i => i.id == carId)
if (index < 0) index = 0 if (index < 0) index = 0
handleSelect(res[index]) handleSelect(typedRes[index])
} else { } else {
carBoxVisible.value?.open() (carBoxVisible.value as ComponentPublicInstance).$callMethod('open')
} }
} }
clickFlga.value = false clickFlga.value = false
...@@ -257,54 +252,88 @@ function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void ...@@ -257,54 +252,88 @@ function selectCar(e: CarBrandItem, auto: boolean = false, carId?: string): void
clickFlga.value = false clickFlga.value = false
uni.hideLoading() uni.hideLoading()
}) })
} }
function handleSelect(item: CarBrandItem): void { watch(watchStatus.value, () => {
const selectItemVal = selectItem.value close()
}, { immediate: true })
watch(updateView.value ,()=>{
const carBrandListData = storage.get("carBrandList")
carBrandList.value = carBrandListData != null ? (carBrandListData as Array<CarBrandItem>) : []
}, { immediate: true, deep: true })
const customerInfo: CustomerInfo = { function autoSelect(): void {
...state.user.customerInfo, const boutiqueDefaultCarBrandIdVal = boutiqueDefaultCarBrandId.value
carBrand: selectItemVal.carChildsBrandName, const defaultCarIdVal = defaultCarId.value as String
carBrandId: selectItemVal.carChildsBrandId, let carIndex = 0
oneCarBrand: selectItemVal.carBrand,
oneCarBrandId: selectItemVal.carBrandId, if (boutiqueDefaultCarBrandIdVal != null) {
carModel:item.name, carIndex = carBrandList.value.findIndex(e => e.id == boutiqueDefaultCarBrandIdVal)
carModelId:item.id
} }
if (props.linkage) { if (carIndex < 0) carIndex = 0
dispatch('setCustomerInfo', customerInfo)
dispatch('updateViewKey') if (carBrandList.value.length > 0) {
dispatch('setCurrentCarInfo', selectItemVal) selectCar(carBrandList.value[carIndex], true, defaultCarIdVal)
} }
}
function open(): void {
const userInfo: UserInfo | null = storage.get("userInfo") as UTSJSONObject | null
if (userInfo == null) return
carBoxVisible.value?.close() const shopMerchantId = userInfo.shopMerchantId
emit('select', {
...item, getMerchantCarBrandList([shopMerchantId] as UTSArray<Any>)
...selectItemVal .then((res: Any) => {
const resObj = res as UTSJSONObject
const data = resObj.data as UTSArray<Any>
let list = (data[0] as CarBrandListResponse).carBrandList
const carBrandListData: Array<CarBrandItem> = []
list?.forEach((e: CarBrandItem) => {
e.childs?.forEach((i: CarBrandItem) => {
i.brandName = e.name
i.brandId = e.id
carBrandListData.push(i)
})
}) })
}
function close(): void { dispatch("setCarBrandsList", carBrandListData)
carBoxVisible.value?.close() storage.set("carBrandList", carBrandListData, 0)
carBrandListVisible.value?.close() updateView.value = Date.now()
carBrandListOff.value = false })
} const carBrandVal = carBrand.value
if (carBrandVal != null) {
const carBrandListVal: Array<CarBrandItem> = carBrandList.value
const item = carBrandListVal.find((e) => e.name == carBrandVal)
if (item != null && carBrandListVal.length == 1) {
selectCar(item as CarBrandItem, false, '')
} else {
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('open')
}
carBrandListOff.value = true
}
return
}
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('open')
}
carBrandListOff.value = true
}
function closeCarBoxVisible(): void {
if (carBrandListOff.value) return
else emit('close')
}
defineExpose({
open,
close, defineExpose({ open, close, autoSelect })
autoSelect
})
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.select-box { .select-box {
margin: 40rpx 0; margin: 40rpx 0;
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
...@@ -333,5 +362,5 @@ defineExpose({ ...@@ -333,5 +362,5 @@ defineExpose({
border: 2rpx solid #292d33; border: 2rpx solid #292d33;
} }
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -10,13 +10,14 @@ ...@@ -10,13 +10,14 @@
:class="[`popup-${positionClass}`, { 'content-visible': isAnimated }]" :class="[`popup-${positionClass}`, { 'content-visible': isAnimated }]"
@click.stop @click.stop
> >
<slot></slot> <slot>
</slot>
</view> </view>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
const props = defineProps({ const props = defineProps({
visible: { visible: {
type: Boolean, type: Boolean,
default: false default: false
...@@ -33,35 +34,56 @@ const props = defineProps({ ...@@ -33,35 +34,56 @@ const props = defineProps({
type: Number, type: Number,
default: 300 default: 300
} }
}) })
const emit = defineEmits(['update:visible', 'close', 'mask-click', 'opened', 'closed']) const emit = defineEmits(['update:visible', 'close', 'mask-click', 'opened', 'closed'])
const showMask = ref<boolean>(props.visible)
const isAnimated = ref<boolean>(false)
let closeTimer: any = null
let openTimer: any = null
const positionClass = computed(() => { function close(): void {
const positionMap: Record<string, string> = { emit('update:visible', false)
emit('close')
}
function open(): void {
emit('update:visible', true)
}
function handleMaskClick(): void {
emit('mask-click')
if (props.maskClosable) {
close()
}
}
const showMask = ref<boolean>(props.visible)
const isAnimated = ref<boolean>(false)
let closeTimer: any | null = null
let openTimer: any | null = null
const positionClass = computed<string>(() => {
const positionMap: UTSJSONObject = {
'top': 'top', 'top': 'top',
'center': 'center', 'center': 'center',
'bottom': 'bottom', 'bottom': 'bottom',
'left': 'left', 'left': 'left',
'right': 'right' 'right': 'right'
} as UTSJSONObject
const mappedValue = positionMap[props.position] as string | null
if (mappedValue == null) {
return 'center'
} }
return positionMap[props.position] || 'center' return mappedValue
}) })
watch(() => props.visible, (newVal) => { watch(props.visible, (newVal: boolean) => {
if (newVal) { if (newVal == true) {
// 打开流程 // 打开流程
if (closeTimer) { if (closeTimer != null) {
clearTimeout(closeTimer) clearTimeout(closeTimer as number)
closeTimer = null closeTimer = null
} }
if (openTimer) { if (openTimer != null) {
clearTimeout(openTimer) clearTimeout(openTimer as number)
openTimer= null openTimer= null
} }
...@@ -80,8 +102,8 @@ watch(() => props.visible, (newVal) => { ...@@ -80,8 +102,8 @@ watch(() => props.visible, (newVal) => {
} else { } else {
// 关闭流程 // 关闭流程
if (openTimer) { if (openTimer != null) {
clearTimeout(openTimer) clearTimeout(openTimer as number)
openTimer = null openTimer = null
} }
...@@ -92,32 +114,15 @@ watch(() => props.visible, (newVal) => { ...@@ -92,32 +114,15 @@ watch(() => props.visible, (newVal) => {
emit('closed') emit('closed')
}, props.duration) }, props.duration)
} }
}, { immediate: true }) }, { immediate: true })
function handleMaskClick(): void {
emit('mask-click')
if (props.maskClosable) {
close()
}
}
function close(): void {
emit('update:visible', false)
emit('close')
}
function open(): void {
emit('update:visible', true)
}
defineExpose({ defineExpose({ open, close })
open,
close
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.custom-popup-mask { .custom-popup-mask {
position: fixed; position: fixed;
top: 0; top: 0;
left: 0; left: 0;
...@@ -134,9 +139,9 @@ defineExpose({ ...@@ -134,9 +139,9 @@ defineExpose({
&.mask-visible { &.mask-visible {
opacity: 1; opacity: 1;
} }
} }
.custom-popup-content { .custom-popup-content {
position: absolute; position: absolute;
max-height: 90%; max-height: 90%;
opacity: 0; opacity: 0;
...@@ -213,5 +218,5 @@ defineExpose({ ...@@ -213,5 +218,5 @@ defineExpose({
transform: translateX(0) translateY(-50%); transform: translateX(0) translateY(-50%);
} }
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
<template> <template>
<view :class="['customer-box',{'is-show':showCustomerBox}]"> <view :class="['customer-box',{'is-show':showCustomerBox}]">
<view class="customer-title">客户档案的记录</view> <view class="customer-title">
客户档案的记录
</view>
<scroll-view <scroll-view
scroll-y scroll-y
class="scroll-box" class="scroll-box"
...@@ -12,7 +14,8 @@ ...@@ -12,7 +14,8 @@
:size="46" :size="46"
color="#3773F8" color="#3773F8"
class="icon" class="icon"
></uni-icons> >
</uni-icons>
</view> </view>
</template> </template>
<template v-else> <template v-else>
...@@ -30,7 +33,8 @@ ...@@ -30,7 +33,8 @@
</template> </template>
<template v-else> <template v-else>
<view class="nothing flex"> <view class="nothing flex">
<view class="icon"></view> <view class="icon">
</view>
未匹配到客户信息 未匹配到客户信息
</view> </view>
</template> </template>
...@@ -43,53 +47,41 @@ ...@@ -43,53 +47,41 @@
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import { state } from '@/store/index.uts' import { state } from '@/store/index.uts'
import { getCustomerInfoListApi } from '@/api/customer-api.uts' import { getCustomerInfoListApi } from '@/api/customer-api.uts'
interface CustomerInfo { type CustomerInfo = UTSJSONObject
ownerPhone?: string
ownerName?: string
[key: string]: any
}
interface UserInfo { type UserInfo = UTSJSONObject
shopMerchantId: string
sceneType: number
[key: string]: any
}
interface SearchParams { type SearchParams = {
merchantId: string merchantId: string
bussinessScene: number bussinessScene: number
ownerPhone?: string ownerPhone?: string
ownerName?: string ownerName?: string
} }
const props = defineProps({ const props = defineProps({
searchValue: String, searchValue: String,
showType: String, showType: String,
show: Boolean show: Boolean
}) })
const emit = defineEmits(['choose'])
const loading = ref<boolean>(true) const emit = defineEmits(['choose'])
const searchList = ref<Array<CustomerInfo>>([])
const showCustomerBox = computed<boolean>(() => { const loading = ref<boolean>(true)
return props.show && state.user?.haveCustomerAccess && props.searchValue const searchList = ref<Array<CustomerInfo>>([])
})
watch(() => showCustomerBox.value, (newval) => { const showCustomerBox = computed<boolean>(() => {
if (newval) { const searchValue = props.searchValue ?? ''
getCustomerInfoList(props.searchValue || '', props.showType || '') return props.show == true && (state.user?.haveCustomerAccess ?? false) && (searchValue !== '' && searchValue !== null)
} })
}, { immediate: true }) async function getCustomerInfoList(val: string, type: string): Promise<void> {
async function getCustomerInfoList(val: string, type: string): Promise<void> {
try { try {
loading.value = true loading.value = true
const userInfo: UserInfo = storage.get("userInfo") || { shopMerchantId: '', sceneType: 0 } const userInfo: UserInfo | null = storage.get("userInfo") as UTSJSONObject | null
const userInfoObj = userInfo ?? { shopMerchantId: '', sceneType: 0 }
const shopMerchantId = userInfoObj.shopMerchantId
const params: SearchParams = { const params: SearchParams = {
merchantId: userInfo.shopMerchantId, merchantId: shopMerchantId as String,
bussinessScene: userInfo.sceneType == 0 ? 1 : 2 bussinessScene: userInfoObj.sceneType == 0 ? 1 : 2
} }
if (type == 'tel') { if (type == 'tel') {
...@@ -98,22 +90,28 @@ async function getCustomerInfoList(val: string, type: string): Promise<void> { ...@@ -98,22 +90,28 @@ async function getCustomerInfoList(val: string, type: string): Promise<void> {
params.ownerName = val params.ownerName = val
} }
const result = await getCustomerInfoListApi(params) const result = await getCustomerInfoListApi(params as UTSJSONObject)
searchList.value = result || [] searchList.value = result as UTSArray<UTSJSONObject>
loading.value = false loading.value = false
} catch (error) { } catch (error) {
loading.value = false loading.value = false
console.error('获取客户信息失败:', error)
} }
} }
watch(showCustomerBox.value , (newVal: boolean) => {
if (newVal == true) {
getCustomerInfoList(props.searchValue ?? '', props.showType ?? '')
}
}, { immediate: true })
function chooseItem(item: CustomerInfo): void {
function chooseItem(item: CustomerInfo): void {
emit('choose', item) emit('choose', item)
} }
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.customer-box { .customer-box {
position: absolute; position: absolute;
left: 0; left: 0;
top: 88rpx; top: 88rpx;
...@@ -183,10 +181,10 @@ function chooseItem(item: CustomerInfo): void { ...@@ -183,10 +181,10 @@ function chooseItem(item: CustomerInfo): void {
} }
} }
} }
} }
.is-show { .is-show {
z-index: 1; z-index: 1;
opacity: 1; opacity: 1;
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -26,18 +26,20 @@ ...@@ -26,18 +26,20 @@
import MessageBox from './MessageBox.uvue' import MessageBox from './MessageBox.uvue'
import { state, dispatch } from '@/store/index.uts' import { state, dispatch } from '@/store/index.uts'
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import { getEmployeeList as getEmployeeListApi } from '@/api/common-api.uts' import { getEmployeeListApi } from '@/api/common-api.uts'
import { ComponentPublicInstance } from 'vue'
interface EmployeeItem { interface EmployeeItem {
staffName: string staffName: string
uuid: string uuid: string
[key: string]: any
} }
interface Props { interface Props {
title?: string title?: string
salesPropsUuid?: string salesPropsUuid?: string
} }
type UserInfo = UTSJSONObject
const props = withDefaults(defineProps<Props>(), { const props = withDefaults(defineProps<Props>(), {
title: '销售', title: '销售',
...@@ -46,21 +48,42 @@ ...@@ -46,21 +48,42 @@
const emit = defineEmits(['close', 'select']) const emit = defineEmits(['close', 'select'])
const employeeBoxVisible = ref<any>(null) const employeeBoxVisible = ref(null)
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
const updateView = ref<number>(Date.now())
const salesUuid = computed(() => { const salesUuid = computed(() => {
return state.user.customerInfo.salesUuid || props.salesPropsUuid const val1 = state.user.customerInfo.salesUuid
const val2 = props.salesPropsUuid
return val1 !== null && val1 !== '' ? val1 : val2
}) })
const employeeList = computed(() => { // const employeeList = computed(() => {
return state.user.employeeList // return state.user.employeeList
}) // })
const employeeList = ref<Array<EmployeeItem>>([])
watch(updateView.value,()=>{
const list = storage.get("employeeList") as UTSArray<EmployeeItem>
employeeList.value = list !== null ? list : []
}, { immediate: true, deep: true })
function close(): void {
if (employeeBoxVisible.value != null) {
(employeeBoxVisible.value as ComponentPublicInstance).$callMethod('close')
}
}
watch(() => watchStatus.value, (newval: number) => { watch(watchStatus.value, (newval: number) => {
close() close()
}, { immediate: true }) }, { immediate: true })
...@@ -69,19 +92,21 @@ ...@@ -69,19 +92,21 @@
} }
function open(): void { function open(): void {
employeeBoxVisible.value?.open() if (employeeBoxVisible.value != null) {
const userInfo = storage.get('userInfo') (employeeBoxVisible.value as ComponentPublicInstance).$callMethod('open')
const userInfoObj = userInfo as any }
const shopMerchantId = userInfoObj?.shopMerchantId const userInfo: UserInfo | null = storage.get("userInfo") as UTSJSONObject | null
if (userInfo == null) return
const shopMerchantId = userInfo.shopMerchantId
// 获取销售人员列表 // 获取销售人员列表
getEmployeeListApi({ getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => {
merchantId: shopMerchantId const employeeList = res as Array<EmployeeItem>
}).then((res: EmployeeItem[]) => { dispatch('setEmployeeList', employeeList)
dispatch('setEmployeeList', res) const listToStore = employeeList != null ? employeeList : []
storage.set('employeeList', res || []) storage.set('employeeList', listToStore, 0)
}).catch((error: any) => { updateView.value = Date.now()
console.error('获取员工列表失败:', error)
}) })
} }
...@@ -90,18 +115,12 @@ ...@@ -90,18 +115,12 @@
emit('select', item) emit('select', item)
} }
function close(): void {
employeeBoxVisible.value?.close()
}
defineExpose({ defineExpose({ open, close })
open,
close
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.select-box { .select-box {
margin: 40rpx 0; margin: 40rpx 0;
display: grid; display: grid;
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
...@@ -124,5 +143,5 @@ ...@@ -124,5 +143,5 @@
border: 2rpx solid #292d33; border: 2rpx solid #292d33;
} }
} }
} }
</style> </style>
...@@ -31,10 +31,11 @@ ...@@ -31,10 +31,11 @@
<template v-for="(i, index) in formObject" :key="index"> <template v-for="(i, index) in formObject" :key="index">
<view <view
class="form-item" class="form-item"
> >
<view :class="['label', { required: i.required }]">{{ i.label }}</view> <view :class="['label', { required: i.required == true}]">
<view :class="['value', { error: showError(i.key) && i.required }, { disabled: customerType == 0 || i.disabled }]"> {{ i.label }}
</view>
<view :class="['value', { error: showError(i.key) && i.required == true }, { disabled: customerType == 0 || i.disabled == true }]">
<template v-if="i.type == 'input'"> <template v-if="i.type == 'input'">
<input <input
:type="i.inputType" :type="i.inputType"
...@@ -49,16 +50,17 @@ ...@@ -49,16 +50,17 @@
</template> </template>
<template v-else> <template v-else>
<view <view
:class="['select', `${formData[i.key] ? '' : 'placeholder'}`]" :class="['select', `${formData[i.key] !== null && formData[i.key] !== '' ? '' : 'placeholder'}`]"
@click="showPopup(i)" @click="showPopup(i)"
:key="selectKey" :key="selectKey"
> >
{{ formData[i.key] || i.placeholder }} {{ formData[i.key] !== null && formData[i.key] !== '' ? formData[i.key] : i.placeholder }}
<uni-icons <uni-icons
class="arrow" class="arrow"
type="down" type="down"
:size="16" :size="16"
></uni-icons> >
</uni-icons>
</view> </view>
</template> </template>
</view> </view>
...@@ -67,14 +69,17 @@ ...@@ -67,14 +69,17 @@
</view> </view>
</template> </template>
<template v-else> <template v-else>
<view class="pop-tips">请完善本次接待结果</view> <view class="pop-tips">
请完善本次接待结果
</view>
<view class="choose-box"> <view class="choose-box">
<template v-for="(i, index) in resultList" :key="index"> <template v-for="(i, index) in resultList" :key="index">
<view <view
:class="['choose-item', `${i.status == receptionStatus ? (i.status == 1 ? 'success' : 'error') : ''}`]" :class="['choose-item', `${i.status == receptionStatus ? (i.status == 1 ? 'success' : 'error') : ''}`]"
@click="chooseResult(i.status)" @click="chooseResult(i.status)"
> >
<view :class="['sprite-icon', `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon}`]"></view> <view :class="['sprite-icon', `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon}`]">
</view>
{{ i.text }} {{ i.text }}
</view> </view>
</template> </template>
...@@ -84,11 +89,11 @@ ...@@ -84,11 +89,11 @@
</MessageBox> </MessageBox>
<car-brands <car-brands
ref="carBrandListVisible" ref="carBrandListVisible"
@select="handleSelect($event, 'carBrandListVisible')" @select="handleSelect($event as IUTSObject, 'carBrandListVisible')"
/> />
<employee <employee
ref="employeeBoxVisible" ref="employeeBoxVisible"
@select="handleSelect($event, 'employeeBoxVisible')" @select="handleSelect($event as IUTSObject, 'employeeBoxVisible')"
/> />
<!-- <uni-popup <!-- <uni-popup
ref="successRef" ref="successRef"
...@@ -98,7 +103,8 @@ ...@@ -98,7 +103,8 @@
type="success" type="success"
message="数据保存成功" message="数据保存成功"
:duration="1500" :duration="1500"
></uni-popup-message> >
</uni-popup-message>
</uni-popup> --> </uni-popup> -->
</view> </view>
</template> </template>
...@@ -109,8 +115,9 @@ ...@@ -109,8 +115,9 @@
import CarBrands from '@/components/CarBrands.uvue' import CarBrands from '@/components/CarBrands.uvue'
import { state, dispatch } from '@/store/index.uts' import { state, dispatch } from '@/store/index.uts'
import MessageBox from './MessageBox.uvue' import MessageBox from './MessageBox.uvue'
import { ComponentPublicInstance } from 'vue'
interface FormObjectItem { type FormObjectItem = {
label: string label: string
key: string key: string
type: string type: string
...@@ -122,24 +129,44 @@ ...@@ -122,24 +129,44 @@
disabled?: boolean disabled?: boolean
} }
interface FormData { type FormData = {
customerName: string customerName: string
carModel: string carModel: string
phoneNumber: string phoneNumber: string
salesUuid: string salesUuid: string
staffName: string staffName: string
[key: string]: string carModelId: string
} }
interface ResultListItem { type ResultListItem = {
icon: string icon: string
text: string text: string
status: number status: number
} }
const phoneRex = /^[1]([3-9])[0-9]{9}$/ const formData = ref<FormData>({
customerName: "",
carModel: "",
phoneNumber: "",
salesUuid: "",
staffName: "",
carModelId:""
})
const formObject_boutique: FormObjectItem[] = [{ const resultList = ref<Array<ResultListItem>>([
{
icon: 'success',
text: '结果完美,成交了',
status: 1
},
{
icon: 'error',
text: '仍需努力,战败了',
status: 0
}
])
const formObject_boutique: Array<FormObjectItem> = [{
label: "车主姓名", label: "车主姓名",
key: "customerName", key: "customerName",
type: "input", type: "input",
...@@ -189,7 +216,7 @@ ...@@ -189,7 +216,7 @@
const emit = defineEmits(['submit', 'back']) const emit = defineEmits(['submit', 'back'])
const step = ref<number>(1) const step = ref<number>(1)
const formObject = ref<FormObjectItem[]>([ const formObject = ref<Array<FormObjectItem>>([
{ {
label: "车主姓名", label: "车主姓名",
key: "customerName", key: "customerName",
...@@ -226,118 +253,128 @@ ...@@ -226,118 +253,128 @@
} }
]) ])
const formData = ref<FormData>({
customerName: "",
carModel: "",
phoneNumber: "",
salesUuid: "",
staffName: ""
})
const resultList = ref<ResultListItem[]>([
{
icon: 'success',
text: '结果完美,成交了',
status: 1
},
{
icon: 'error',
text: '仍需努力,战败了',
status: 0
}
])
const errorTip = ref<boolean>(false) const errorTip = ref<boolean>(false)
const receptionStatus = ref<number>(-1) const receptionStatus = ref<number>(-1)
const updateViewKey = ref<number>(Date.now()) const updateViewKey = ref<number>(Date.now())
const selectKey = ref<number>(Date.now()) const selectKey = ref<number>(Date.now())
const formRef = ref<any>(null) const formRef = ref(null)
const carBrandListVisible = ref<any>(null) const carBrandListVisible = ref(null)
const employeeBoxVisible = ref<any>(null) const employeeBoxVisible = ref(null)
const phoneRex = /^[1]([3-9])[0-9]{9}$/
// 获取动态 ref 的值 // 获取动态ref 的值
const getRefValue = (key: string): any => { const getRefValue = (key: string): any | null => {
if (key === 'carBrandListVisible') return carBrandListVisible.value if (key === 'carBrandListVisible') return carBrandListVisible.value
if (key === 'employeeBoxVisible') return employeeBoxVisible.value if (key === 'employeeBoxVisible') return employeeBoxVisible.value
return null return null
} }
const successRef = ref<any>(null) const successRef = ref(null)
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
const tips = computed(() => { const tips = computed(() => {
let { sceneType, titleTips } = props let { sceneType, titleTips } = props
let text = titleTips || '检测到"交车告知书"中未填写客户档案,请填写后再完成接待。' let text = titleTips !== null && titleTips !== '' ? titleTips : '检测到"交车告知书"中未填写客户档案,请填写后再完成接待。'
if (sceneType == 1) text = '请确认"车型加装选购页"中的客户信息,并点击「完成接待」结束客户接待。' if (sceneType == 1) text = '请确认"车型加装选购页"中的客户信息,并点击「完成接待」结束客户接待。'
return text return text
}) })
watch(() => watchStatus.value, (newval: number) => { watch(watchStatus.value, () => {
receptionStatus.value = -1 receptionStatus.value = -1
errorTip.value = false errorTip.value = false
formRef.value?.close() if (formRef.value != null) {
(formRef.value as ComponentPublicInstance).$callMethod('close')
}
}, { immediate: true }) }, { immediate: true })
function showError(key: string): boolean { function showError(key: string): boolean {
let flag = !formData.value[key] const value = formData.value[key]
if (key == 'phoneNumber' && formData.value[key]) flag = !phoneRex.test(formData.value[key]) let flag = value === null || value === ''
if (key == 'phoneNumber') {
const phoneValue = formData.value[key] as string
if (phoneValue !== null && phoneValue !== '') {
flag = phoneRex.test(phoneValue) == false
}
}
return errorTip.value && flag return errorTip.value && flag
} }
function showPopup(item: FormObjectItem): void { function showPopup(item: FormObjectItem): void {
let { customerType } = props let { customerType } = props
if (customerType == 0 || item.disabled) return if (customerType == 0 || (item.disabled === true)) return
const popKey = item.popKey || '' const popKey = item.popKey !== null ? item.popKey : ''
const refValue = getRefValue(popKey) const refValue = getRefValue(popKey)
refValue?.open() if (refValue != null) {
(refValue as ComponentPublicInstance).$callMethod('open')
}
}
function close(): void {
errorTip.value = false
receptionStatus.value = -1
if (formRef.value != null) {
(formRef.value as ComponentPublicInstance).$callMethod('close')
}
} }
// 取消 // 取消
function cancel(): void { function cancel(): void {
if (step.value == 1) close() if (step.value == 1) close()
else step.value = 1 else step.value = 1
} }
function close(): void {
errorTip.value = false
receptionStatus.value = -1
formRef.value?.close()
}
function check(all: boolean = false): boolean { function check(all: boolean = false): boolean {
let flag = true let flag = true
try {
formObject.value.forEach(e => { formObject.value.forEach(e => {
if (e.required) { if (e.required == true) {
if (!formData.value[e.key]) throw false const value = formData.value[e.key]
if (!all && e.key == 'phoneNumber' && !phoneRex.test(formData.value[e.key])) { if (value === null || value === '') {
flag = false
return
}
if (!all && e.key == 'phoneNumber') {
const phoneValue = formData.value[e.key] as string
if (phoneValue !== null && phoneValue !== '' && phoneRex.test(phoneValue) == false) {
uni.showToast({ uni.showToast({
title: "请输入正确的车主电话", title: "请输入正确的车主电话",
icon: "none" icon: "none"
}) })
throw false flag = false
return
} }
} }
})
} catch (error) {
flag = error as boolean
} }
})
return flag return flag
} }
function success(receptionStatus: number): void {
if (successRef.value != null) {
(successRef.value as ComponentPublicInstance).$callMethod('open')
}
emit('submit', receptionStatus)
}
// 保存 // 保存
function submit(): void { function submit(): void {
let { receptionStatus: status } = { receptionStatus: receptionStatus.value }
if (step.value == 1) { if (step.value == 1) {
errorTip.value = true errorTip.value = true
if (check()) { if (check()) {
const { sceneType } = props const sceneType = props.sceneType
if (sceneType == 0) step.value = 2 if (sceneType == 0) step.value = 2
else { else {
status = 1 receptionStatus.value = 1
success(status) success(receptionStatus.value)
} }
} }
} else { } else {
...@@ -352,28 +389,23 @@ ...@@ -352,28 +389,23 @@
} }
} }
function success(receptionStatus: number): void {
successRef.value?.open()
emit('submit', receptionStatus)
}
function inputCustomer(): void { function inputCustomer(): void {
dispatch('setCustomerInfo', formData.value) dispatch('setCustomerInfo', formData.value)
} }
function handleSelect(item: any, popkey: string): void { function handleSelect(item: IUTSObject, popkey: string): void {
const customerInfo = dispatch('getCustomerInfo') const customerInfo = dispatch('getCustomerInfo') as IUTSObject
if (popkey == "employeeBoxVisible") { if (popkey == "employeeBoxVisible") {
formData.value.salesUuid = item.uuid formData.value.salesUuid = item['uuid'] as string
formData.value.staffName = item.staffName formData.value.staffName = item['staffName'] as string
dispatch("setCustomerInfo", { dispatch("setCustomerInfo", { ...customerInfo, ...formData.value })
...customerInfo,
...formData.value
})
} else { } else {
carBrandListVisible.value?.close() if (carBrandListVisible.value != null) {
formData.value.carModel = item.name (carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
formData.value.carModelId = item.id }
formData.value.carModel = item['name'] as string
formData.value.carModelId = item['id'] as string
} }
selectKey.value = Date.now() selectKey.value = Date.now()
...@@ -381,58 +413,96 @@ ...@@ -381,58 +413,96 @@
function open(): void { function open(): void {
const customerInfo = dispatch('getCustomerInfo') const customerInfo = dispatch('getCustomerInfo')
formData.value = customerInfo
if (customerInfo != null) {
formData.value = customerInfo as FormData
let { sceneType, customerType } = props let { sceneType, customerType } = props
let stepValue = Object.values(customerInfo).every((value) => !!value) ? 2 : 1
let stepValue = 1
const keys = ['customerName', 'carModel', 'phoneNumber']
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const value = customerInfo[key] as string | null
if (value == null || value === '') {
stepValue = 1
break
}
stepValue = 2
}
errorTip.value = false errorTip.value = false
if (sceneType == 1) { if (sceneType == 1) {
stepValue = 1 stepValue = 1
formObject.value = formObject_boutique formObject.value = formObject_boutique
if (customerType == 0 && !check()) { const checkResult = check()
if (customerType == 0 && !checkResult) {
emit('back') emit('back')
return return
} }
} }
if (stepValue == 2 && !check()) { if (stepValue == 2) {
const checkResult = check()
if (!checkResult) {
errorTip.value = true errorTip.value = true
stepValue = 1 stepValue = 1
} }
}
step.value = stepValue step.value = stepValue
formRef.value?.open() if (formRef.value != null) {
(formRef.value as ComponentPublicInstance).$callMethod('open')
}
updateViewKey.value = Date.now() updateViewKey.value = Date.now()
} }
}
function chooseResult(val: number): void { function chooseResult(val: number): void {
receptionStatus.value = val receptionStatus.value = val
dispatch('setReceptionStatus', val) dispatch('setReceptionStatus', val)
} }
defineExpose({ function updateStep(): void {
open, const customerInfo = dispatch('getCustomerInfo') as IUTSObject
close
}) let stepValue = 1
const keys = ['customerName', 'carModel', 'phoneNumber']
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
const value = customerInfo[key]
if (value == null || value === '') {
stepValue = 1
break
}
stepValue = 2
}
step.value = stepValue
}
defineExpose({ open, close })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.pop-tips { .pop-tips {
background: rgba(44, 102, 247, 0.1); background: rgba(44, 102, 247, 0.1);
color: #2c66f7; color: #2c66f7;
font-size: 28rpx; font-size: 28rpx;
padding: 24rpx 80rpx 24rpx; padding: 24rpx 80rpx 24rpx;
margin-top: 30rpx; margin-top: 30rpx;
text-align: center; text-align: center;
} }
.error-tip { .error-tip {
font-size: 28rpx; font-size: 28rpx;
padding: 32rpx 60rpx 24rpx; padding: 32rpx 60rpx 24rpx;
margin-top: 30rpx; margin-top: 30rpx;
text-align: center; text-align: center;
background-color: rgb(254, 237, 234); background-color: rgb(254, 237, 234);
color: #f45c3d; color: #f45c3d;
} }
.form { .form {
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
gap: 24rpx 0; gap: 24rpx 0;
...@@ -521,9 +591,9 @@ ...@@ -521,9 +591,9 @@
} }
} }
} }
} }
.choose-box { .choose-box {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
...@@ -552,5 +622,5 @@ ...@@ -552,5 +622,5 @@
background: #f247241a; background: #f247241a;
border-color: #f247241a; border-color: #f247241a;
} }
} }
</style> </style>
...@@ -5,12 +5,12 @@ ...@@ -5,12 +5,12 @@
:position="position" :position="position"
:mask-closable="false" :mask-closable="false"
:duration="300" :duration="300"
@update:visible="visible = $event" @update:visible="visible = $event as Boolean"
@close="onClose" @close="onClose"
> >
<view <view
:class="['tips-wrapper',{'radius': position === 'center'}]" :class="['tips-wrapper',{'radius': position === 'center'}]"
:style="{ width: popupW + 'rpx', minHeight: popupH + 'rpx', maxHeight: maxHeight + 'rpx' }" :style="{ width: (popupW ?? 0) + 'rpx', minHeight: (popupH ?? 0) + 'rpx', maxHeight: (maxHeight ?? 0) + 'rpx' }"
> >
<view class="tips-content"> <view class="tips-content">
<view <view
...@@ -22,14 +22,16 @@ ...@@ -22,14 +22,16 @@
type="closeempty" type="closeempty"
:size="18" :size="18"
color="#1A1A1A" color="#1A1A1A"
></uni-icons> >
</uni-icons>
</view> </view>
<view class="tips-title"> <view class="tips-title">
<template v-if="back"> <template v-if="back">
<view <view
class="sprite-icon icon-back" class="sprite-icon icon-back"
@click="close" @click="close"
></view> >
</view>
</template> </template>
{{ title }} {{ title }}
</view> </view>
...@@ -37,7 +39,8 @@ ...@@ -37,7 +39,8 @@
class="tips-text" class="tips-text"
v-if="content" v-if="content"
>{{ content }}</text> >{{ content }}</text>
<slot></slot> <slot>
</slot>
</view> </view>
<view <view
class="tips-footer" class="tips-footer"
...@@ -58,16 +61,18 @@ ...@@ -58,16 +61,18 @@
}}</view> }}</view>
</view> </view>
<template v-else> <template v-else>
<slot name="footer"></slot> <slot name="footer">
</slot>
</template> </template>
</view> </view>
</CustomPopup> </CustomPopup>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import CustomPopup from './CustomPopup.uvue' import CustomPopup from './CustomPopup.uvue'
import { ComponentPublicInstance } from 'vue'
const props = defineProps({ const props = defineProps({
isAutoClose: { isAutoClose: {
type: Boolean, type: Boolean,
default: true default: true
...@@ -107,52 +112,53 @@ const props = defineProps({ ...@@ -107,52 +112,53 @@ const props = defineProps({
type: Boolean, type: Boolean,
default: true default: true
} }
}) })
const emit = defineEmits(['close', 'cancel', 'confirm']) const emit = defineEmits(['close',
'cancel',
'confirm'])
const visible = ref<boolean>(false) const visible = ref<boolean>(false)
const popupRef= ref<any>(null) const popupRef= ref(null)
function onClose(): void { function onClose(): void {
emit('close') emit('close')
} }
function close(): void { function close(): void {
if (props.isAutoClose) { if (props.isAutoClose) {
visible.value = false visible.value = false
} else { } else {
popupRef.value?.close() if (popupRef.value != null) {
(popupRef.value as ComponentPublicInstance).$callMethod('close')
}
} }
emit('close') emit('close')
} }
function open(): void { function open(): void {
visible.value = true visible.value = true
} }
function cancel(): void { function cancel(): void {
if (props.isAutoClose) { if (props.isAutoClose) {
visible.value = false visible.value = false
} }
emit('cancel') emit('cancel')
} }
function confirm(): void { function confirm(): void {
if (props.isAutoClose) { if (props.isAutoClose) {
visible.value = false visible.value = false
} }
emit('confirm') emit('confirm')
} }
defineExpose({ defineExpose({ open, close })
open,
close
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.tips-wrapper { .tips-wrapper {
background: #ffffff; background: #ffffff;
border-radius: 20rpx 20rpx 0 0; border-radius: 20rpx 20rpx 0 0;
height: 100%; height: 100%;
...@@ -207,7 +213,7 @@ defineExpose({ ...@@ -207,7 +213,7 @@ defineExpose({
justify-content: center; justify-content: center;
height: 100rpx; height: 100rpx;
border-top: 1px solid #e8e8e8; border-top: 1px solid #e8e8e8;
flex-direction: row; flex-direction: row;
.close { .close {
color: #6c6c70; color: #6c6c70;
} }
...@@ -225,9 +231,9 @@ flex-direction: row; ...@@ -225,9 +231,9 @@ flex-direction: row;
line-height: 44rpx; line-height: 44rpx;
font-weight: 500; font-weight: 500;
} }
} }
.radius{ .radius{
border-radius: 20rpx; border-radius: 20rpx;
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
<view class="wn-canvas"> <view class="wn-canvas">
<zoom-pan <zoom-pan
:class="['canvas-box', { fill: custom }]" :class="['canvas-box', { fill: custom }]"
:disabled="drawStatus || !scaleSwitch" :disabled="(drawStatus == true || scaleSwitch == false)"
:scale-max="3" :scale-max="3"
:scale-min="1" :scale-min="1"
@scale="onScale" @scale="onScale"
> >
<template #content> <template #content>
<canvas <!-- <canvas
:class="['board-canvas', { 'draw-canvas': drawStatus }]" :class="['board-canvas', { 'draw-canvas': drawStatus }]"
:canvas-id="canvasId" :canvas-id="canvasId"
:disable-scroll="drawStatus" :disable-scroll="drawStatus"
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
@touchmove="onTouchMove" @touchmove="onTouchMove"
@touchend="onTouchEnd" @touchend="onTouchEnd"
> >
</canvas> </canvas> -->
<template v-if="custom"> <template v-if="custom">
<slot name="customContent"> <slot name="customContent">
</slot> </slot>
...@@ -43,24 +43,28 @@ ...@@ -43,24 +43,28 @@
import zoomPan from './zoom-pan.uvue' import zoomPan from './zoom-pan.uvue'
import { state } from "@/store/index.uts" import { state } from "@/store/index.uts"
interface HistoryItem { type HistoryItemStyle = {
style: {
color: string color: string
width: number width: number
} }
coordinates: Array<{
type HistoryItemCoordinate = {
type: string type: string
mode: string mode: string
x: number x: number
y: number y: number
}> }
type HistoryItem = {
style: HistoryItemStyle
coordinates: Array<HistoryItemCoordinate>
}
type ColorPickObj = {
color: string
} }
const props = defineProps({ const props = defineProps({
showSave: {
type: Boolean,
default: false
},
drawImage: { drawImage: {
type: String, type: String,
default: '' default: ''
...@@ -81,13 +85,12 @@ ...@@ -81,13 +85,12 @@
} }
}) })
const emit = defineEmits(['scale', const emit = defineEmits(['scale',])
'dowmloadSuc',
'dowmloadErr',
'saveImage'])
const colorShow = ref<boolean>(false) const colorShow = ref<boolean>(false)
const drawContext = ref<any>(null) // Canvas 相关 - 已注释
// let canvasContext: CanvasContext | null = null
// let renderingContext: CanvasRenderingContext2D | null = null
const historyList = ref<Array<HistoryItem>>([]) const historyList = ref<Array<HistoryItem>>([])
const startX = ref<number>(0) const startX = ref<number>(0)
const startY = ref<number>(0) const startY = ref<number>(0)
...@@ -97,8 +100,8 @@ ...@@ -97,8 +100,8 @@
const currentColor = ref<string>('red') const currentColor = ref<string>('red')
const bgColor = ref<string>('#fff') const bgColor = ref<string>('#fff')
const lineWidth = ref<number>(2) const lineWidth = ref<number>(2)
const lastRect = ref<UJSObject>({}) const lastRect = ref<UTSObject>({})
const lastCircle = ref<UJSObject>({}) const lastCircle = ref<UTSObject>({})
const isLandScape = ref<boolean>(false) const isLandScape = ref<boolean>(false)
const aspectRatio = ref<number | null>(null) const aspectRatio = ref<number | null>(null)
const height = ref<number | string | null>(null) const height = ref<number | string | null>(null)
...@@ -112,522 +115,42 @@ ...@@ -112,522 +115,42 @@
const isUnderBkg = ref<boolean>(false) const isUnderBkg = ref<boolean>(false)
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
}) if (status == null) {
return false
watch(() => watchStatus.value, (newval) => { } else if (status == 1) {
if (newval) { return true
clearBoard()
}
}, { immediate: true })
watch(() => props.drawImage, (n) => {
if (n) {
initBoard()
}
})
onMounted(() => {
drawContext.value = uni.createCanvasContext(props.canvasId)
initBoard()
})
function penBegin(x: number, y: number): void {
x = x / scaleValue.value
y = y / scaleValue.value
begin.value = true
drawContext.value.beginPath()
drawContext.value.setStrokeStyle(currentColor.value)
startX.value = x
startY.value = y
drawContext.value.moveTo(startX.value / scaleValue.value, startY.value / scaleValue.value)
drawPen(x, y)
}
function drawPen(x: number, y: number): void {
drawContext.value.moveTo(startX.value, startY.value)
drawContext.value.lineTo(x, y)
drawContext.value.stroke()
startX.value = x
startY.value = y
}
function lineBegin(x: number, y: number): void {
begin.value = true
startX.value = x
startY.value = y
}
function lineDraw(x: number, y: number): void {
drawContext.value.beginPath()
drawContext.value.moveTo(startX.value, startY.value)
drawContext.value.lineTo(x, y)
drawContext.value.stroke()
drawContext.value.draw(true)
}
function lineEnd(x: number, y: number): void {
if (startX.value == x && startY.value == y && !lastX.value && !lastY.value) {
drawContext.value.beginPath()
drawContext.value.moveTo(startX.value - 1, startY.value - 1)
drawContext.value.lineTo(x + 1, y + 1)
drawContext.value.stroke()
drawContext.value.draw(true)
}
lastX.value = 0
lastY.value = 0
drawContext.value.closePath()
begin.value = false
}
function rectFillBegin(x: number, y: number): void {
begin.value = true
drawContext.value.beginPath()
startX.value = x
startY.value = y
}
function rectBegin(x: number, y: number): void {
begin.value = true
drawContext.value.beginPath()
startX.value = x
startY.value = y
}
function circleFillBegin(x: number, y: number): void {
begin.value = true
drawContext.value.beginPath()
startX.value = x
startY.value = y
}
function circleBegin(x: number, y: number): void {
begin.value = true
drawContext.value.beginPath()
startX.value = x
startY.value = y
}
function drawRectFill(x: number, y: number, isReverse: boolean = true): void {
const width = x !== startX.value ? x - startX.value : startX.value - x
const height = y !== startY.value ? y - startY.value : startY.value - y
drawContext.value.rect(startX.value, startY.value, width, height)
drawContext.value.setFillStyle(currentColor.value)
drawContext.value.fill()
draw(isReverse)
}
function drawRect(x: number, y: number, isReverse: boolean = true): void {
const pointLT = {} as UTSJSONObject
const pointRB = {} as UTSJSONObject
const pointRT = {} as UTSJSONObject
const pointLB = {} as UTSJSONObject
pointLT.X = startX.value <= x ? startX.value : x
pointLT.Y = startY.value <= y ? startY.value : y
pointRB.X = startX.value >= x ? startX.value : x
pointRB.Y = startY.value >= y ? startY.value : y
pointRT.X = pointRB.X
pointRT.Y = pointLT.Y
pointLB.X = pointLT.X
pointLB.Y = pointRB.Y
const width = x !== startX.value ? x - startX.value : startX.value - x
const height = y !== startY.value ? y - startY.value : startY.value - y
drawContext.value.rect(startX.value, startY.value, width, height)
drawContext.value.setStrokeStyle(currentColor.value)
drawContext.value.stroke()
draw(isReverse)
lastRect.value = {
x: startX.value,
y: startY.value,
width: Math.abs(width),
height: Math.abs(height),
pointLT: pointLT
}
clearLastRect()
}
function clearLastRect(): void {
drawContext.value.clearRect(
lastRect.value.pointLT.X + lineWidth.value / 2,
lastRect.value.pointLT.Y + lineWidth.value / 2,
lastRect.value.width - lineWidth.value,
lastRect.value.height - lineWidth.value
)
}
function drawCircleFill(x: number, y: number, isReverse: boolean = true): void {
const pointLT = {} as UTSJSONObject
const pointRB = {} as UTSJSONObject
pointLT.X = startX.value <= x ? startX.value : x
pointLT.Y = startY.value <= y ? startY.value : y
pointRB.X = startX.value >= x ? startX.value : x
pointRB.Y = startY.value >= y ? startY.value : y
const centerX = (pointRB.X + pointLT.X) / 2
const centerY = (pointRB.Y + pointLT.Y) / 2
const dx = pointRB.X - pointLT.X
const dy = pointRB.Y - pointLT.Y
const r = Math.sqrt(dx * dx + dy * dy) / 2
drawContext.value.arc(centerX, centerY, r, 0, 2 * Math.PI)
drawContext.value.setFillStyle(currentColor.value)
drawContext.value.fill()
draw(isReverse)
}
function drawCircle(x: number, y: number, isReverse: boolean = true): void {
const pointLT = {} as UTSJSONObject
const pointRB = {} as UTSJSONObject
pointLT.X = startX.value <= x ? startX.value : x
pointLT.Y = startY.value <= y ? startY.value : y
pointRB.X = startX.value >= x ? startX.value : x
pointRB.Y = startY.value >= y ? startY.value : y
const centerX = (pointRB.X + pointLT.X) / 2
const centerY = (pointRB.Y + pointLT.Y) / 2
const dx = pointRB.X - pointLT.X
const dy = pointRB.Y - pointLT.Y
const r = Math.sqrt(dx * dx + dy * dy) / 2
drawContext.value.arc(centerX, centerY, r, 0, 2 * Math.PI)
drawContext.value.stroke()
drawContext.value.beginPath()
drawContext.value.arc(centerX, centerY, r - lineWidth.value / 2, 0, 2 * Math.PI)
drawContext.value.setFillStyle(bgColor.value)
drawContext.value.fill()
draw(isReverse)
}
function onTouchStart(e: any): void {
if (!props.drawStatus) return
drawContext.value.setLineWidth(lineWidth.value)
const { x, y } = e.touches[0]
switch (mode.value) {
case 'pen':
penBegin(x, y)
break
case 'eraser':
penBegin(x, y)
break
case 'rect':
rectBegin(x, y)
break
case 'circle':
circleBegin(x, y)
break
case 'rect-fill':
rectFillBegin(x, y)
break
case 'circle-fill':
circleFillBegin(x, y)
break
}
historyList.value.push({
style: {
color: currentColor.value,
width: lineWidth.value
},
coordinates: [{
type: e.type,
mode: mode.value,
x: e.touches[0].x,
y: e.touches[0].y
}]
})
}
function onTouchMove(e: any): void {
if (!props.drawStatus) return
drawContext.value.setLineWidth(lineWidth.value)
const { x, y } = e.touches[0]
const scaledX = x / scaleValue.value
const scaledY = y / scaleValue.value
lastX.value = scaledX
lastY.value = scaledY
switch (mode.value) {
case 'pen':
drawPen(scaledX, scaledY)
draw(true)
break
case 'eraser':
drawPen(scaledX, scaledY)
draw(true)
break
case 'rect':
drawRect(scaledX, scaledY)
break
case 'circle':
drawCircle(scaledX, scaledY)
break
case 'rect-fill':
drawRectFill(scaledX, scaledY)
break
case 'circle-fill':
drawCircleFill(scaledX, scaledY)
break
}
historyList.value[historyList.value.length - 1].coordinates.push({
type: e.type,
mode: mode.value,
x: scaledX,
y: scaledY
})
}
function onTouchEnd(e: any): void {
if (!props.drawStatus) return
drawContext.value.setLineWidth(lineWidth.value)
const { x, y } = e.changedTouches[0]
switch (mode.value) {
case 'pen':
lineEnd(x, y)
break
case 'eraser':
drawContext.value.setFillStyle(currentColor.value)
lineEnd(x, y)
break
case 'rect':
drawRect(x, y, true)
break
case 'circle':
drawCircle(x, y)
break
case 'rect-fill':
drawRectFill(x, y)
break
case 'circle-fill':
drawCircleFill(x, y)
break
}
}
function backHandle(): void {
drawContext.value.draw()
historyList.value.pop()
drawHistory()
}
function drawHistory(): void {
historyList.value.forEach((item) => {
drawContext.value.beginPath()
drawContext.value.setLineCap('round')
drawContext.value.setStrokeStyle(item.style.color)
drawContext.value.setLineWidth(item.style.width)
item.coordinates.forEach(it => {
if (it.type == 'touchstart') {
switchModeToLine(it.mode, 1, it.x, it.y)
} else {
switchModeToLine(it.mode, 2, it.x, it.y)
}
})
drawContext.value.stroke()
})
drawContext.value.draw(true)
}
function switchModeToLine(modeName: string, type: number, x: number, y: number): void {
drawContext.value.setFillStyle(currentColor.value)
if (modeName == 'pen') {
if (type == 1) {
drawContext.value.moveTo(x, y)
} else {
drawContext.value.lineTo(x, y)
}
} else if (modeName == 'eraser') {
drawContext.value.setFillStyle(bgColor.value)
if (type == 1) {
startX.value = x
startY.value = y
} else {
lineDraw(x, y)
}
} else if (modeName == 'rect') {
if (type == 1) {
startX.value = x
startY.value = y
} else {
drawRect(x, y, true)
}
} else if (modeName == 'circle') {
if (type == 1) {
startX.value = x
startY.value = y
} else {
drawCircle(x, y, true)
}
} else if (modeName == 'rect-fill') {
if (type == 1) {
startX.value = x
startY.value = y
} else { } else {
drawRectFill(x, y, true) return false
}
} else if (modeName == 'circle-fill') {
if (type == 1) {
startX.value = x
startY.value = y
} else {
drawCircleFill(x, y, true)
}
}
}
function colorPickTapHandler(obj: { color: string }): void {
colorShow.value = false
currentColor.value = obj.color
drawContext.value.strokeStyle = obj.color
}
function downloadHandle(): void {
if (props.saveImageType == '1' || props.saveImageType == '3') {
saveImage()
}
if (props.saveImageType == '2' || props.saveImageType == '3') {
uni.canvasToTempFilePath({
canvasId: props.canvasId,
success: function(res: any) {
uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath,
success: function(res: any) {
emit('dowmloadSuc', JSON.stringify(res))
},
fail: function(res: any) {
emit('dowmloadErr', JSON.stringify(res))
}
})
} }
}) })
}
}
function saveImage(): void { function onScale(e: number): void {
if (isUnderBkg.value) { scaleValue.value = e
saveImageUrl() emit('scale', e)
} else {
uni.canvasToTempFilePath({
canvasId: props.canvasId,
success: function(res: any) {
emit('saveImage', res.tempFilePath)
}
})
}
}
function saveImageUrl(): void {
const query = uni.createSelectorQuery()
query.select('.canvas-box').boundingClientRect(data => {
drawContext.value.setFillStyle(bgColor.value)
drawContext.value.fillRect(0, 0, data.width, data.height)
drawContext.value.fill()
drawContext.value.drawImage(props.drawImage, 0, 0, data.width, data.height)
drawContext.value.draw()
drawHistory()
uni.canvasToTempFilePath({
canvasId: props.canvasId,
success: function(res: any) {
emit('saveImage', res.tempFilePath)
}
})
}).exec()
}
function fillBackground(): void {
const query = uni.createSelectorQuery()
query.select('.canvas-box').boundingClientRect(data => {
drawContext.value.setFillStyle(bgColor.value)
drawContext.value.fillRect(0, 0, data.width, data.height)
drawContext.value.fill()
if (props.drawImage && !isUnderBkg.value) {
drawContext.value.drawImage(props.drawImage, 0, 0, data.width, data.height)
}
drawContext.value.draw()
}).exec()
}
function draw(isReverse: boolean = false, cb?: Function): void {
drawContext.value.draw(isReverse, () => {
if (cb && typeof cb == 'function') {
cb()
}
})
}
function setBoardMode(key: string): void {
mode.value = key
}
function clearBoard(): void {
historyList.value = []
drawContext.value?.draw()
}
async function initBoard(): Promise<void> {
try {
const systemInfo = uni.getSystemInfoSync()
if (systemInfo.screenWidth > systemInfo.screenHeight) {
isLandScape.value = true
} else {
isLandScape.value = false
} }
onMounted(() => {
if (props.drawImage) { // initBoard()
const imageInfo = await uni.getImageInfo({ // uni.createCanvasContextAsync({
src: props.drawImage // id: props.canvasId as string,
// component: getCurrentInstance()?.proxy,
// success: (context : CanvasContext) => {
// canvasContext = context
// renderingContext = context.getContext('2d')!
// }
// })
}) })
watch(watchStatus, (newval: boolean) => {
if (imageInfo) { if (newval != null) {
const imageInfoObj = imageInfo[1] || {} as any // clearBoard()
aspectRatio.value = imageInfoObj.width / imageInfoObj.height
height.value = `${imageInfoObj.height * (systemInfo.windowWidth / imageInfoObj.width)}px`
}
} }
}, { immediate: true })
if (isUnderBkg.value) { watch(props.drawImage, (n: string) => {
bgColor.value = 'rgba(0,0,0,0)' if (n != null) {
} else { // initBoard()
bgColor.value = 'rgba(255,255,255,0)'
} }
drawContext.value.setLineCap('round')
drawContext.value.strokeStyle = currentColor.value
drawContext.value.setLineWidth(lineWidth.value)
nextTick(() => {
drawContext.value.setLineWidth(lineWidth.value)
}) })
} catch (error) {
console.error(error)
}
}
function onScale(e: number): void {
scaleValue.value = e
emit('scale', e)
}
defineExpose({ colorPickTapHandler, downloadHandle, saveImage, fillBackground, draw, setBoardMode, clearBoard, initBoard })
</script> </script>
<style lang="scss"> <style lang="scss">
......
...@@ -2,10 +2,11 @@ ...@@ -2,10 +2,11 @@
<view <view
class="zoom-pan-container" class="zoom-pan-container"
:style="{ 'overflow': 'hidden', 'position': 'relative', 'touch-action': 'none' }" :style="{ 'overflow': 'hidden', 'position': 'relative', 'touch-action': 'none' }"
@touchstart="handleTouchStart"
@touchmove="handleTouchMove"
@touchend="handleTouchEnd"
> >
<!-- @touchstart="handleTouchStart"
@touchmove="handleTouchMove"
@touchend="handleTouchEnd" -->
<view <view
class="content" class="content"
:style="contentStyle" :style="contentStyle"
...@@ -17,10 +18,29 @@ ...@@ -17,10 +18,29 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import { throttle } from '@/utils/common.uts' import { throttle } from '@/utils/common.uts'
import { state } from "@/store/index.uts" import { state } from "@/store/index.uts"
type Point = {
x: number
y: number
}
type TouchPoint = {
pageX: number
pageY: number
clientX: number
clientY: number
x: number
y: number
}
type TouchEvent = {
touches: Array<TouchPoint>
changedTouches: Array<TouchPoint>
}
const props = defineProps({ const props = defineProps({
disabled: Boolean, disabled: Boolean,
scaleMax: { scaleMax: {
type: Number, type: Number,
...@@ -30,18 +50,18 @@ const props = defineProps({ ...@@ -30,18 +50,18 @@ const props = defineProps({
type: Number, type: Number,
default: 1 default: 1
} }
}) })
const scale = ref<number>(1) const scale = ref<number>(1)
const isScaling = ref<boolean>(false) const isScaling = ref<boolean>(false)
const initialDistance = ref<number>(0) const initialDistance = ref<number>(0)
const initialScale = ref<number>(1) const initialScale = ref<number>(1)
const translateX = ref<number>(0) const translateX = ref<number>(0)
const translateY = ref<number>(0) const translateY = ref<number>(0)
const lastTouchCenter = ref<{ x: number; y: number }>({ x: 0, y: 0 }) const lastTouchCenter = ref<Point>({ x: 0, y: 0 })
const currentTouchCenter = ref<{ x: number; y: number }>({ x: 0, y: 0 }) const currentTouchCenter = ref<Point>({ x: 0, y: 0 })
const contentStyle = computed(() => { const contentStyle = computed(() => {
return { return {
'transform': `translate(${translateX.value}px, ${translateY.value}px) scale(${scale.value})`, 'transform': `translate(${translateX.value}px, ${translateY.value}px) scale(${scale.value})`,
'transform-origin': 'center center', 'transform-origin': 'center center',
...@@ -53,103 +73,110 @@ const contentStyle = computed(() => { ...@@ -53,103 +73,110 @@ const contentStyle = computed(() => {
'width': '100%', 'width': '100%',
'height': '100%' 'height': '100%'
} }
}) })
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
}) if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
})
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value , () => {
if (scale.value != 1) { if (scale.value != 1) {
scale.value = 1 scale.value = 1
translateX.value = 0 translateX.value = 0
translateY.value = 0 translateY.value = 0
} }
}, { immediate: true }) }, { immediate: true })
function handleTouchStart(e: any): void { // function handleTouchStart(e: TouchEvent): void {
if (props.disabled) return // if (props.disabled == true) return
if (e.touches.length === 2) { // if (e.touches.length === 2) {
isScaling.value = true // isScaling.value = true
initialDistance.value = getTouchDistance(e.touches) // initialDistance.value = getTouchDistance(e.touches)
initialScale.value = scale.value // initialScale.value = scale.value
const center = getTouchCenter(e.touches) // const center = getTouchCenter(e.touches)
lastTouchCenter.value = center // lastTouchCenter.value = center
currentTouchCenter.value = center // currentTouchCenter.value = center
} // }
} // }
const handleTouchMove = throttle(function(e: any): void { // const handleTouchMove = throttle(function(e: TouchEvent): void {
if (props.disabled) return // if (props.disabled == true) return
if (isScaling.value && e.touches.length === 2) { // if (isScaling.value && e.touches.length === 2) {
const currentDistance = getTouchDistance(e.touches) // const currentDistance = getTouchDistance(e.touches)
const newScale = Math.max( // const newScale = Math.max(
props.scaleMin, // props.scaleMin,
Math.min( // Math.min(
props.scaleMax, // props.scaleMax,
initialScale.value * (currentDistance / initialDistance.value) // initialScale.value * (currentDistance / initialDistance.value)
) // )
) // )
scale.value = newScale // scale.value = newScale
const center = getTouchCenter(e.touches) // const center = getTouchCenter(e.touches)
currentTouchCenter.value = center // currentTouchCenter.value = center
if (scale.value > 1) { // if (scale.value > 1) {
const deltaX = center.x - lastTouchCenter.value.x // const deltaX = center.x - lastTouchCenter.value.x
const deltaY = center.y - lastTouchCenter.value.y // const deltaY = center.y - lastTouchCenter.value.y
translateX.value += deltaX // translateX.value += deltaX
translateY.value += deltaY // translateY.value += deltaY
} // }
lastTouchCenter.value = center // lastTouchCenter.value = center
emit('scale', scale.value) // emit('scale', scale.value)
} // }
}, 16) // }, 16)
function handleTouchEnd(): void { // function handleTouchEnd(): void {
if (isScaling.value) { // if (isScaling.value) {
isScaling.value = false // isScaling.value = false
adjustPosition() // adjustPosition()
} // }
} // }
function adjustPosition(): void { function adjustPosition(): void {
if (scale.value <= 1) { if (scale.value <= 1) {
translateX.value = 0 translateX.value = 0
translateY.value = 0 translateY.value = 0
scale.value = 1 scale.value = 1
} }
} }
function getTouchDistance(touches: Array<any>): number { function getTouchDistance(touches: Array<TouchPoint>): number {
const dx = touches[0].pageX - touches[1].pageX const dx = touches[0].pageX - touches[1].pageX
const dy = touches[0].pageY - touches[1].pageY const dy = touches[0].pageY - touches[1].pageY
return Math.sqrt(dx * dx + dy * dy) return Math.sqrt(dx * dx + dy * dy)
} }
function getTouchCenter(touches: Array<any>): { x: number; y: number } { function getTouchCenter(touches: Array<TouchPoint>): Point {
const centerX = (touches[0].pageX + touches[1].pageX) / 2 const centerX = (touches[0].pageX + touches[1].pageX) / 2
const centerY = (touches[0].pageY + touches[1].pageY) / 2 const centerY = (touches[0].pageY + touches[1].pageY) / 2
return { x: centerX, y: centerY } return { x: centerX, y: centerY }
} }
const emit = defineEmits(['scale']) const emit = defineEmits(['scale'])
</script> </script>
<style lang="scss"> <style lang="scss">
.zoom-pan-container { .zoom-pan-container {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
touch-action: none; touch-action: none;
} }
.content { .content {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
...@@ -157,5 +184,5 @@ const emit = defineEmits(['scale']) ...@@ -157,5 +184,5 @@ const emit = defineEmits(['scale'])
top: 0; top: 0;
transform-origin: center center; transform-origin: center center;
will-change: transform; will-change: transform;
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
<template> <template>
<view class="tool-box" :style="toolStyle"> <view class="tool-box" :style="toolStyle as string">
<view :class="['btn', { hideIcon: !show }]" @click="show = false"> <view :class="['btn', { hideIcon: !show }]" @click="show = false">
<view class="icon sprite-icon icon-tool-file"> <view class="icon sprite-icon icon-tool-file">
</view> </view>
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
文件夹 文件夹
</view> </view>
<view class="list-body"> <view class="list-body">
<template v-for="(i, index) in data" :key="index"> <template v-for="(item, index) in displayData" :key="index">
<view :class="['item', { active: i[idKey] == id }]" @click="jump(i)"> <view :class="['item', { active: item.id == props.id }]" @click="jump(item)">
<image class="icon" :src="i.shortTitleUrl" mode="scaleToFill" /> <image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" />
{{ i.shortTitle }} {{ item.shortTitle }}
</view> </view>
</template> </template>
</view> </view>
<template v-if="showPayBtn"> <template v-if="props.showPayBtn">
<view class="item" @click="toPay"> <view class="item" @click="toPay">
<view class="icon"> <view class="icon">
<view class="sprite-icon icon-tool-pay"> <view class="sprite-icon icon-tool-pay">
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
付款方式 付款方式
</view> </view>
</template> </template>
<template v-if="type != 'preview'"> <template v-if="props.type != 'preview'">
<view class="item" @click="finish"> <view class="item" @click="finish">
<view class="icon"> <view class="icon">
<view class="sprite-icon icon-tool-finish"> <view class="sprite-icon icon-tool-finish">
...@@ -42,11 +42,18 @@ ...@@ -42,11 +42,18 @@
<script setup lang="uts"> <script setup lang="uts">
import { state } from "@/store/index.uts"; import { state } from "@/store/index.uts";
const emit = defineEmits(['choose', 'finish', 'toPay'])
type ToolItem = {
id?: string | number
shortTitleUrl?: string
shortTitle?: string
}
const props = defineProps({ const props = defineProps({
type: String, type: String,
data: Array, data: Array as () => Array<ToolItem>,
id: [String, id: [String, Number],
Number],
showPayBtn: Boolean, showPayBtn: Boolean,
idKey: { idKey: {
type: String, type: String,
...@@ -57,11 +64,25 @@ ...@@ -57,11 +64,25 @@
const show = ref<boolean>(true) const show = ref<boolean>(true)
const displayData = computed<Array<ToolItem>>(() => {
if (props.data == null) {
return []
}
return props.data as Array<ToolItem>
})
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value, () => {
show.value = true show.value = true
}, { immediate: true }) }, { immediate: true })
...@@ -69,7 +90,21 @@ ...@@ -69,7 +90,21 @@
show.value = true show.value = true
} }
function jump(item: any): void { function getItemTitle(item: ToolItem): string {
if (item.shortTitle == null) {
return ''
}
return item.shortTitle
}
function getItemImageUrl(item: ToolItem): string {
if (item.shortTitleUrl == null) {
return ''
}
return item.shortTitleUrl
}
function jump(item: ToolItem): void {
show.value = true show.value = true
emit('choose', item) emit('choose', item)
} }
...@@ -82,12 +117,8 @@ ...@@ -82,12 +117,8 @@
emit('toPay') emit('toPay')
} }
const emit = defineEmits(['choose',
'finish', defineExpose({ hide })
'toPay'])
defineExpose({
hide
})
</script> </script>
......
...@@ -227,31 +227,27 @@ ...@@ -227,31 +227,27 @@
<script setup lang="uts"> <script setup lang="uts">
import { ref, computed, watch } from 'vue' import { ref, computed, watch } from 'vue'
interface ReceptionpriproCusCaseStageDetail { type ReceptionpriproCusCaseStageDetail = {
stageName: string stageName: string
imageUrl: string imageUrl: string
imageTag: string imageTag: string
[key: string]: any
} }
interface ReceptionpriproCusCaseStage { type ReceptionpriproCusCaseStage = {
receptionpriproCusCaseStageDetailList: Array<ReceptionpriproCusCaseStageDetail> receptionpriproCusCaseStageDetailList: Array<ReceptionpriproCusCaseStageDetail>
[key: string]: any
} }
interface ReceptionpriproCusCase { type ReceptionpriproCusCase = {
customerName: string customerName: string
licPlateNumber: string licPlateNumber: string
comAmount: string | number comAmount: string | number
receptionpriproCusCaseStageList: Array<ReceptionpriproCusCaseStage> receptionpriproCusCaseStageList: Array<ReceptionpriproCusCaseStage>
[key: string]: any
} }
interface DetailData { type DetailData = {
title: string title: string
productPoster: string productPoster: string
receptionpriproCusCaseList: Array<ReceptionpriproCusCase> receptionpriproCusCaseList: Array<ReceptionpriproCusCase>
[key: string]: any
} }
interface Thumbnail { interface Thumbnail {
......
<template> <template>
<view class="layout"> <view class="layout">
<view class="layout-content"> <view class="layout-content">
<view class="title flex">{{ title }}</view> <view class="title flex">
{{ title }}
</view>
<view class="form-box" :key="watchStatus"> <view class="form-box" :key="watchStatus">
<view class="form"> <view class="form">
<template v-for="(i, index) in formObject" :key="index"> <template v-for="(i, index) in formObject" :key="index">
...@@ -9,17 +11,27 @@ ...@@ -9,17 +11,27 @@
<view class="form-item-box" v-if="i.key == 'goodsCtegory'"> <view class="form-item-box" v-if="i.key == 'goodsCtegory'">
<view :class="['select flex', { placeholderStyle: !customerInfo[i.key] }]" @click="showPopup(i.popKey, index)"> <view :class="['select flex', { placeholderStyle: !customerInfo[i.key] }]" @click="showPopup(i.popKey, index)">
<view class="value text-hide" v-if="chooseContent.length > 0"> <view class="value text-hide" v-if="chooseContent.length > 0">
<text class="category-name" v-for="(item, index) in chooseContent.slice(0, 2)" :key="index">{{ item.categoryName }}</text> <text class="category-name" v-for="(item, index) in chooseContent.slice(0, 2)" :key="index">
<text class="category-name" v-if="chooseContent.length > 2">+ {{ chooseContent.length - 2 }}</text> {{ item.categoryName }}
</text>
<text class="category-name" v-if="chooseContent.length >
2">+ {{ chooseContent.length - 2 }}
</text>
</view>
<view class="value text-hide" v-else>
请选择
</view> </view>
<view class="value text-hide" v-else>请选择</view> <uni-icons class="arrow" type="right" :size="16">
<uni-icons class="arrow" type="right" :size="16"></uni-icons> </uni-icons>
</view> </view>
</view> </view>
<view class="form-item-box" v-else> <view class="form-item-box" v-else>
<view :class="['select flex', { placeholderStyle: !customerInfo[i.key] }]" @click="showPopup(i.popKey, index)"> <view :class="['select flex', { placeholderStyle: !customerInfo[i.key] }]" @click="showPopup(i.popKey, index)">
<view class="value text-hide">{{ customerInfo[i.key] || i.placeholder }}</view> <view class="value text-hide">
<uni-icons class="arrow" type="right" :size="16"></uni-icons> {{ customerInfo[i.key] ? customerInfo[i.key] : i.placeholder }}
</view>
<uni-icons class="arrow" type="right" :size="16">
</uni-icons>
</view> </view>
</view> </view>
</view> </view>
...@@ -27,13 +39,15 @@ ...@@ -27,13 +39,15 @@
<view class="form-check flex" @click="showphoto = !showphoto"> <view class="form-check flex" @click="showphoto = !showphoto">
<view :class="['check-box flex', { checked: showphoto }]"> <view :class="['check-box flex', { checked: showphoto }]">
<uni-icons type="checkmarkempty" :size="14" color="#fff"></uni-icons> <uni-icons type="checkmarkempty" :size="14" color="#fff">
</uni-icons>
</view> </view>
显示凭证 显示凭证
</view> </view>
<view class="form-check flex" @click="merchantOrder = !merchantOrder" v-if="!subLoginUserChannelType"> <view class="form-check flex" @click="merchantOrder = !merchantOrder" v-if="!subLoginUserChannelType">
<view :class="['check-box flex', { checked: merchantOrder }]"> <view :class="['check-box flex', { checked: merchantOrder }]">
<uni-icons type="checkmarkempty" :size="14" color="#fff"></uni-icons> <uni-icons type="checkmarkempty" :size="14" color="#fff">
</uni-icons>
</view> </view>
门店订单 门店订单
</view> </view>
...@@ -46,43 +60,69 @@ ...@@ -46,43 +60,69 @@
<template v-if="showphoto"> <template v-if="showphoto">
<image v-if="item.paymentDocUrl" class="image-box" :src="item.paymentDocUrl" /> <image v-if="item.paymentDocUrl" class="image-box" :src="item.paymentDocUrl" />
<image v-else class="image-box photo" src="https://img02.glsx.com.cn/weapp/resource/app-tape/media/common/pay.webp" /> <image v-else class="image-box photo" src="https://img02.glsx.com.cn/weapp/resource/app-tape/media/common/pay.webp" />
<view class="gradient-overlay"></view> <view class="gradient-overlay">
</view>
</template> </template>
<template v-else> <template v-else>
<div :class="['payType sprite-icon', `icon-payType-${item.payType}`]"></div> <div :class="['payType sprite-icon', `icon-payType-${item.payType}`]">
</div>
</template> </template>
<view> <view>
<view class="name">{{ nameHide(item.customerName) }}</view> <view class="name">
<view class="goods-name">{{ item.goodsName }}</view> {{ nameHide(item.customerName) }}
</view>
<view class="goods-name">
{{ item.goodsName }}
</view>
<view class="card-info"> <view class="card-info">
<view class="label">车架号</view> <view class="label">
<view class="value">{{ item.carVin || '-' }}</view> 车架号
</view>
<view class="value">
{{ item.carVin || '-' }}
</view>
</view> </view>
<view class="card-info"> <view class="card-info">
<view class="label">工单号</view> <view class="label">
<view class="value">{{ item.payId }}</view> 工单号
</view>
<view class="value">
{{ item.payId }}
</view>
</view> </view>
<view class="card-info"> <view class="card-info">
<view class="label">交易流水号</view> <view class="label">
<view class="value">{{ item.transactionNo }}</view> 交易流水号
</view>
<view class="value">
{{ item.transactionNo }}
</view>
</view> </view>
<view class="card-info"> <view class="card-info">
<view class="label">实收金额</view> <view class="label">
实收金额
</view>
<view class="price"> <view class="price">
<view class="flag">¥</view> <view class="flag">
¥
</view>
{{ item.equityPrice }} {{ item.equityPrice }}
</view> </view>
</view> </view>
</view> </view>
</view> </view>
</view> </view>
<view class="end-text" v-if="list.length > 0 && isEnd">我是一个有底线的人</view> <view class="end-text" v-if="list.length >
0 && isEnd">我是一个有底线的人
</view>
</scroll-view> </scroll-view>
</template> </template>
<template v-else> <template v-else>
<view class="no-data"> <view class="no-data">
<glsx-image class="no-data-img" src="media/no-data.png" mode="scaleToFill" /> <glsx-image class="no-data-img" src="media/no-data.png" mode="scaleToFill" />
<view class="no-data-text">暂无数据</view> <view class="no-data-text">
暂无数据
</view>
</view> </view>
</template> </template>
</view> </view>
...@@ -92,37 +132,37 @@ ...@@ -92,37 +132,37 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import CarBrands from '@/components/CarBrands.uvue' import CarBrands from '@/components/CarBrands.uvue'
// import OrderPopup from '@/components/OrderPopup/index.uvue' // import OrderPopup from '@/components/OrderPopup/index.uvue'
import { state, dispatch } from "@/store/index.uts" import { state, dispatch } from "@/store/index.uts"
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { getOrderListPage } from '@/api/boutique-api.uts' import { getOrderListPage } from '@/api/boutique-api.uts'
interface FormItem { type FormItem = {
placeholder: string placeholder: string
key: string key: string
type: string type: string
popKey: string popKey: string
} }
interface CustomerInfo { type CustomerInfo = {
carModel?: string carModel?: string
carModelId?: string carModelId?: string
[key: string]: any }
}
interface UserInfo { type SubLoginUser = {
channelType: number
}
type UserInfo = {
shopMerchantId: string shopMerchantId: string
sceneType: number sceneType: number
subLoginUser: { subLoginUser: SubLoginUser
channelType: number channelType: number
} }
channelType: number
[key: string]: any
}
interface QuotationListItem { type QuotationListItem = {
id: string id: string
customerName: string customerName: string
goodsName: string goodsName: string
...@@ -133,90 +173,93 @@ interface QuotationListItem { ...@@ -133,90 +173,93 @@ interface QuotationListItem {
paymentDocUrl?: string paymentDocUrl?: string
payType: number payType: number
createdTime: string createdTime: string
[key: string]: any }
}
const props = defineProps({ const props = defineProps({
title: String, title: String,
madiaId: Number, madiaId: Number,
show: Boolean, show: Boolean,
}) })
const carBrandListVisible = ref<any>(null) const carBrandListVisible = ref(null)
const goodsCtegoryVisible = ref<any>(null) const goodsCtegoryVisible = ref(null)
const scrollTop = ref<number>(0) const scrollTop = ref<number>(0)
const formObject = ref<Array<FormItem>>([ const formObject = ref<Array<FormItem>>([{
{
placeholder: '品牌车型', placeholder: '品牌车型',
key: 'carModel', key: 'carModel',
type: 'select', type: 'select',
popKey: 'carBrandListVisible' popKey: 'carBrandListVisible'
}, }, {
{
placeholder: '商品类目', placeholder: '商品类目',
key: 'goodsCtegory', key: 'goodsCtegory',
type: 'select', type: 'select',
popKey: 'goodsCtegoryVisible' popKey: 'goodsCtegoryVisible'
}] as Array<FormItem>)
const customerInfo = ref<CustomerInfo>({} as CustomerInfo)
const focusIndex = ref<number>(-1)
const showphoto = ref<boolean>(false)
const merchantOrder = ref<boolean>(false)
const historyOrderGoodsTypes = ref<Array<any>>([] as Array<any>)
const chooseContent = ref<Array<any>>([] as Array<any>)
const list = ref<Array<QuotationListItem>>([] as Array<QuotationListItem>)
const formatList = ref<Array<any>>([] as Array<any>)
const pageNum = ref<number>(1)
const pageSize = ref<number>(10)
const total = ref<number>(0)
const isEnd = ref<boolean>(false)
const flag = ref<boolean>(true)
const watchStatus = computed(() => {
const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
} }
]) })
const customerInfo = ref<CustomerInfo>({})
const focusIndex = ref<number>(-1) const watchCustomerInfo = computed<CustomerInfo>(() => {
const showphoto = ref<boolean>(false) return state.user.customerInfo != null ? state.user.customerInfo : {} as CustomerInfo
const merchantOrder = ref<boolean>(false) })
const historyOrderGoodsTypes = ref<Array<any>>([])
const chooseContent = ref<Array<any>>([]) const shopMerchantId = computed<string>(() => {
const list = ref<Array<QuotationListItem>>([]) const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : {} as UserInfo
const formatList = ref<Array<any>>([]) return userInfo.shopMerchantId != null && userInfo.shopMerchantId !== '' ? userInfo.shopMerchantId : ''
const pageNum = ref<number>(1) })
const pageSize = ref<number>(10)
const total = ref<number>(0) const subLoginUserChannelType = computed<boolean>(() => {
const isEnd = ref<boolean>(false) const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : {} as UserInfo
const flag = ref<boolean>(true)
const watchStatus = computed(() => {
return state.user.historyStatus
})
const watchCustomerInfo = computed<CustomerInfo>(() => {
return state.user.customerInfo || {}
})
const shopMerchantId = computed<string>(() => {
const userInfo: UserInfo = storage.get('userInfo') || {}
return userInfo.shopMerchantId || ''
})
const subLoginUserChannelType = computed<boolean>(() => {
const userInfo: UserInfo = storage.get('userInfo') || {}
return userInfo.subLoginUser?.channelType == 9 return userInfo.subLoginUser?.channelType == 9
}) })
const channelType = computed<number>(() => { const channelType = computed<number>(() => {
const userInfo: UserInfo = storage.get('userInfo') || {} const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : {} as UserInfo
return userInfo.channelType || 0 return userInfo.channelType != null ? userInfo.channelType : 0
}) })
watch(() => props.show, (n) => { watch(() => props.show, (n) => {
if (n) { if (n === true) {
init() init()
} else { } else {
scrollTop.value = 0 scrollTop.value = 0
} }
}) })
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value, (newval) => {
pageNum.value = 1 pageNum.value = 1
scrollTop.value = 1000 scrollTop.value = 1000
list.value = [] list.value = []
customerInfo.value = {} customerInfo.value = {} as CustomerInfo
if (channelType.value == 1) merchantOrder.value = true if (channelType.value == 1) merchantOrder.value = true
setTimeout(() => { setTimeout(() => {
scrollTop.value = 0 scrollTop.value = 0
}, 100) }, 100)
}, { immediate: true }) }, { immediate: true })
watch(() => merchantOrder.value, (newval) => { watch(() => merchantOrder.value, (newval) => {
pageNum.value = 1 pageNum.value = 1
scrollTop.value = 1000 scrollTop.value = 1000
list.value = [] list.value = []
...@@ -224,51 +267,53 @@ watch(() => merchantOrder.value, (newval) => { ...@@ -224,51 +267,53 @@ watch(() => merchantOrder.value, (newval) => {
scrollTop.value = 0 scrollTop.value = 0
getQuotationList() getQuotationList()
}, 100) }, 100)
}, { immediate: true }) }, { immediate: true })
watch(() => watchCustomerInfo.value, (newval) => { watch(() => watchCustomerInfo.value, (newval) => {
if (newval) { if (newval != null) {
customerInfo.value = { ...newval } customerInfo.value = { ...newval }
} }
}, { immediate: true }) }, { immediate: true })
function init(): void { function init(): void {
customerInfo.value = watchCustomerInfo.value customerInfo.value = watchCustomerInfo.value
if (subLoginUserChannelType.value) { if (subLoginUserChannelType.value === true) {
merchantOrder.value = true merchantOrder.value = true
} }
search() search()
} }
function search(): void { function search(): void {
if (pageNum.value == 1) { if (pageNum.value == 1) {
getQuotationList() getQuotationList()
} }
} }
async function getQuotationList(): Promise<void> { async function getQuotationList(): Promise<void> {
try { try {
uni.showLoading({ uni.showLoading({
title: '',
mask: true mask: true
}) })
const carBrandList: Array<any> = storage.get('carBrandList') || [] const carBrandList: Array<any> = storage.get('carBrandList') != null ? storage.get('carBrandList') : []
const carChildsBrandIds: Array<string> = carBrandList.map((i: any) => i.id) const carChildsBrandIds: Array<string> = carBrandList.map((i: any) => i.id)
const userInfo: UserInfo = storage.get('userInfo') || {} const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : {} as UserInfo
let params: any = { let params: any = {
merchantId: shopMerchantId.value, merchantId: shopMerchantId.value,
pageNum: pageNum.value, pageNum: pageNum.value,
pageSize: pageSize.value, pageSize: pageSize.value,
carModel: customerInfo.value.carModel || '', carModel: customerInfo.value.carModel != null ? customerInfo.value.carModel : '',
orderStatus: 3, orderStatus: 3,
merchantOrder: merchantOrder.value, merchantOrder: merchantOrder.value,
sceneType: userInfo.sceneType, sceneType: userInfo.sceneType,
historyOrderGoodsTypes: historyOrderGoodsTypes.value historyOrderGoodsTypes: historyOrderGoodsTypes.value
} }
if (!params.merchantOrder) { if (params.merchantOrder === false) {
delete params.merchantId // delete params.merchantId
params.merchantId = null
params.maxCreateTime = dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss') params.maxCreateTime = dayjs(Date.now()).format('YYYY-MM-DD HH:mm:ss')
params.minCreateTime = dayjs(Date.now() - 90 * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss') params.minCreateTime = dayjs(Date.now() - 90 * 24 * 60 * 60 * 1000).format('YYYY-MM-DD HH:mm:ss')
params.carChildsBrandIds = carChildsBrandIds params.carChildsBrandIds = carChildsBrandIds
...@@ -304,20 +349,21 @@ async function getQuotationList(): Promise<void> { ...@@ -304,20 +349,21 @@ async function getQuotationList(): Promise<void> {
flag.value = true flag.value = true
total.value = result.total total.value = result.total
if (!customerInfo.value.carModel && pageNum.value == 1 && list.value.length) { if (customerInfo.value.carModel == null && pageNum.value == 1 && list.value.length > 0) {
uni.setStorageSync(`${shopMerchantId.value}-historyList`, list.value) uni.setStorageSync(`${shopMerchantId.value}-historyList`, list.value)
} }
} catch (error) { } catch (error) {
uni.hideLoading() uni.hideLoading()
flag.value = true flag.value = true
isEnd.value = true isEnd.value = true
if (!customerInfo.value.carModel && pageNum.value == 1) { if (customerInfo.value.carModel == null && pageNum.value == 1) {
list.value = uni.getStorageSync(`${shopMerchantId.value}-historyList`) || [] const cachedList = uni.getStorageSync(`${shopMerchantId.value}-historyList`)
list.value = cachedList != null ? cachedList : []
}
} }
} }
}
function pageonReachBottom(): void { function pageonReachBottom(): void {
isEnd.value = false isEnd.value = false
if (Math.ceil(total.value / pageSize.value) > pageNum.value) { if (Math.ceil(total.value / pageSize.value) > pageNum.value) {
pageNum.value += 1 pageNum.value += 1
...@@ -325,14 +371,14 @@ function pageonReachBottom(): void { ...@@ -325,14 +371,14 @@ function pageonReachBottom(): void {
} else { } else {
isEnd.value = true isEnd.value = true
} }
} }
function nameHide(name: string): string { function nameHide(name: string): string {
if (!name) return '' if (name == null || name === '') return ''
return name.substring(0, 1) + '*' return name.substring(0, 1) + '*'
} }
function handleSelect(item: any, popkey: string): void { function handleSelect(item: any, popkey: string): void {
if (popkey === 'carBrandListVisible') { if (popkey === 'carBrandListVisible') {
carBrandListVisible.value?.close() carBrandListVisible.value?.close()
} }
...@@ -343,31 +389,31 @@ function handleSelect(item: any, popkey: string): void { ...@@ -343,31 +389,31 @@ function handleSelect(item: any, popkey: string): void {
list.value = [] list.value = []
pageNum.value = 1 pageNum.value = 1
getQuotationList() getQuotationList()
} }
function showPopup(e: string, index: number): void { function showPopup(e: string, index: number): void {
focusIndex.value = index focusIndex.value = index
if (e === 'carBrandListVisible') { if (e === 'carBrandListVisible') {
carBrandListVisible.value?.open() carBrandListVisible.value?.open()
} else if (e === 'goodsCtegoryVisible') { } else if (e === 'goodsCtegoryVisible') {
goodsCtegoryVisible.value?.open() goodsCtegoryVisible.value?.open()
} }
} }
function closeAllPopup(): void { function closeAllPopup(): void {
carBrandListVisible.value?.close() carBrandListVisible.value?.close()
resetFocusIndex() resetFocusIndex()
} }
function resetFocusIndex(): void { function resetFocusIndex(): void {
focusIndex.value = -1 focusIndex.value = -1
} }
function onConfirm(chooseList: any): void { function onConfirm(chooseList: any): void {
chooseContent.value = chooseList.chooseContent || [] chooseContent.value = chooseList.chooseContent != null ? chooseList.chooseContent : []
historyOrderGoodsTypes.value = [] historyOrderGoodsTypes.value = []
if (chooseList && chooseList.chooseContent && chooseList.chooseContent.length > 0) { if (chooseList != null && chooseList.chooseContent != null && chooseList.chooseContent.length > 0) {
const level3Map = new Map<string, Array<any>>() const level3Map = new Map<string, Array<any>>()
chooseList.chooseContent.forEach((item: any) => { chooseList.chooseContent.forEach((item: any) => {
...@@ -398,15 +444,13 @@ function onConfirm(chooseList: any): void { ...@@ -398,15 +444,13 @@ function onConfirm(chooseList: any): void {
pageNum.value = 1 pageNum.value = 1
// uni.$track?.add({ eventCode: 'app_goodsGategory_change', eventType: 0 }) // uni.$track?.add({ eventCode: 'app_goodsGategory_change', eventType: 0 })
getQuotationList() getQuotationList()
} }
defineExpose({ defineExpose({ closeAllPopup })
closeAllPopup
})
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.layout { .layout {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: relative; position: relative;
...@@ -661,16 +705,16 @@ defineExpose({ ...@@ -661,16 +705,16 @@ defineExpose({
} }
} }
} }
} }
.end-text { .end-text {
width: 100%; width: 100%;
color: #999; color: #999;
text-align: center; text-align: center;
padding: 50rpx 0; padding: 50rpx 0;
} }
.no-data { .no-data {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 50%;
...@@ -687,5 +731,5 @@ defineExpose({ ...@@ -687,5 +731,5 @@ defineExpose({
text-align: center; text-align: center;
margin-top: 24rpx; margin-top: 24rpx;
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -35,14 +35,13 @@ import CustomPopup from '@/components/CustomPopup.uvue' ...@@ -35,14 +35,13 @@ import CustomPopup from '@/components/CustomPopup.uvue'
itemName: string itemName: string
main: string main: string
itemDesc: string itemDesc: string
[key: string]: any
} }
const props = defineProps({ const props = defineProps({
item: Object item: Object
}) })
const visible = ref<boolean>(false) const visible = ref<boolean>(false)
const popup = ref<any>(null) const popup = ref(null)
function open(): void { function open(): void {
visible.value = true visible.value = true
......
...@@ -26,7 +26,8 @@ ...@@ -26,7 +26,8 @@
v-if="showInsurance(i)" v-if="showInsurance(i)"
> >
<view class="row-1 flex"> <view class="row-1 flex">
<view :class="['block',defaultBlock(i)]"></view> <view :class="['block',defaultBlock(i)]">
</view>
<view <view
class="name flex" class="name flex"
@click="choose(i,index)" @click="choose(i,index)"
...@@ -37,10 +38,13 @@ ...@@ -37,10 +38,13 @@
type="checkmarkempty" type="checkmarkempty"
:size="14" :size="14"
color="#fff" color="#fff"
></uni-icons> >
</uni-icons>
</view> </view>
</template> </template>
<view class="text-two-line">{{i.itemName}}</view> <view class="text-two-line">
{{i.itemName}}
</view>
</view> </view>
</view> </view>
<view <view
...@@ -48,7 +52,8 @@ ...@@ -48,7 +52,8 @@
@click="showDetail(i)" @click="showDetail(i)"
> >
<view class="text-two-line"> <view class="text-two-line">
<rich-text :nodes="i.itemDesc"></rich-text> <rich-text :nodes="i.itemDesc">
</rich-text>
</view> </view>
</view> </view>
<view class="cost row-3"> <view class="cost row-3">
...@@ -64,21 +69,25 @@ ...@@ -64,21 +69,25 @@
@blur="handleInput" @blur="handleInput"
:data-index="index" :data-index="index"
/> />
<view class="unit">元</view> <view class="unit">
元
</view>
</view> </view>
</view> </view>
<view <view
class="show row-4" class="show row-4"
@click="setItemDisabled(i,index)" @click="setItemDisabled(i,index)"
> >
<view :class="['sprite-icon',`${i.show ? 'icon-visible' : 'icon-invisible'}`]"></view> <view :class="['sprite-icon',`${i.show ? 'icon-visible' : 'icon-invisible'}`]">
</view>
</view> </view>
</view> </view>
</template> </template>
</template> </template>
<template v-else> <template v-else>
<view class="nothing flex"> <view class="nothing flex">
<view class="sprite-icon icon-no-insurance-data"></view> <view class="sprite-icon icon-no-insurance-data">
</view>
暂无数据{{!isPreview?',请进入预览模式,开启相关车险及权益内容':''}} 暂无数据{{!isPreview?',请进入预览模式,开启相关车险及权益内容':''}}
</view> </view>
</template> </template>
...@@ -87,24 +96,30 @@ ...@@ -87,24 +96,30 @@
</view> </view>
<view class="views-footer flex"> <view class="views-footer flex">
<view class="sprite-icon icon-total"></view> <view class="sprite-icon icon-total">
</view>
合计 合计
<view class="total">{{total}}</view> <view class="total">
<view class="util">元</view> {{total}}
</view>
<view class="util">
元
</view>
</view> </view>
<insurance-popup <insurance-popup
ref="popupRef" ref="popupRef"
:item="currentItem" :item="currentItem"
></insurance-popup> >
</insurance-popup>
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import NP from 'number-precision' import NP from 'number-precision'
import InsurancePopup from './InsurancePopup.uvue' import InsurancePopup from './InsurancePopup.uvue'
import { store } from '@/store/index.uts' import { store } from '@/store/index.uts'
import {getMerchantInsuranceListApi} from '@/api/user-api.uts' import {getMerchantInsuranceListApi} from '@/api/user-api.uts'
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
interface InsuranceItem { interface InsuranceItem {
id: string | number id: string | number
itemName: string itemName: string
...@@ -113,7 +128,6 @@ import { storage } from '@/utils/storage.uts' ...@@ -113,7 +128,6 @@ import { storage } from '@/utils/storage.uts'
checked: boolean checked: boolean
show: boolean show: boolean
main: string main: string
[key: string]: any
} }
const props = defineProps({ const props = defineProps({
...@@ -121,29 +135,40 @@ import { storage } from '@/utils/storage.uts' ...@@ -121,29 +135,40 @@ import { storage } from '@/utils/storage.uts'
show: Boolean show: Boolean
}) })
const viewsTitle = ref<Array<string>>(['险种及权益', '主要保障范围', '费用', '是否显示']) const viewsTitle = ref<Array<string>>(['险种及权益',
const currentItem = ref<any>({}) '主要保障范围',
const insuranceList = ref<Array<InsuranceItem>>([]) '费用',
'是否显示'])
const currentItem = ref<any>({} as any)
const insuranceList = ref<Array<InsuranceItem>>([] as Array<InsuranceItem>)
const scrollTop = ref<number>(0) const scrollTop = ref<number>(0)
const storageKey = ref<string>('') const storageKey = ref<string>('')
const flag = ref<boolean>(false) const flag = ref<boolean>(false)
const popupRef = ref<any>(null) const popupRef = ref(null)
const watchStatus = computed(() => { const watchStatus = computed(() => {
return store.state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
const total = computed(() => { const total = computed(() => {
return insuranceList.value.reduce((pre, cur) => { return insuranceList.value.reduce((pre, cur) => {
return NP.plus(pre, NP.times(cur.cost, (props.isPreview ? cur.show : cur.checked) ? 1 : 0)) const shouldCount: boolean = props.isPreview ? (cur.show === true) : (cur.checked === true)
return NP.plus(pre, NP.times(cur.cost, shouldCount ? 1 : 0))
}, 0) }, 0)
}) })
const check = computed(() => { const check = computed(() => {
return props.isPreview ? insuranceList.value.length : insuranceList.value.filter(item => item.show).length return props.isPreview === true ? insuranceList.value.length : insuranceList.value.filter(item => item.show === true).length
}) })
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value, (newval) => {
;(popupRef.value as any)?.close() ;(popupRef.value as any)?.close()
flag.value = false flag.value = false
scrollTop.value = -1 scrollTop.value = -1
...@@ -153,15 +178,15 @@ import { storage } from '@/utils/storage.uts' ...@@ -153,15 +178,15 @@ import { storage } from '@/utils/storage.uts'
const key = getStorageKey() const key = getStorageKey()
const insuranceListData = uni.getStorageSync(key) const insuranceListData = uni.getStorageSync(key)
if (insuranceListData) { if (insuranceListData != null) {
insuranceListData.map((e: any) => e.cost = '') insuranceListData.map((e: any) => e.cost = '')
insuranceList.value = JSON.parse(JSON.stringify(insuranceListData)) insuranceList.value = JSON.parse(JSON.stringify(insuranceListData)) as Array<InsuranceItem>
flag.value = true flag.value = true
} }
}, { immediate: true }) }, { immediate: true })
watch(() => props.show, (n) => { watch(() => props.show, (n) => {
if (n) { if (n === true) {
getMerchantInsuranceList() getMerchantInsuranceList()
} }
}) })
...@@ -175,7 +200,7 @@ import { storage } from '@/utils/storage.uts' ...@@ -175,7 +200,7 @@ import { storage } from '@/utils/storage.uts'
function showRow(index: number): boolean { function showRow(index: number): boolean {
let flg = true let flg = true
if (index == viewsTitle.value.length - 1 && !props.isPreview) flg = false if (index == viewsTitle.value.length - 1 && props.isPreview === false) flg = false
return flg return flg
} }
...@@ -191,19 +216,24 @@ import { storage } from '@/utils/storage.uts' ...@@ -191,19 +216,24 @@ import { storage } from '@/utils/storage.uts'
value = Number(value) > 999999 ? 999999 : value value = Number(value) > 999999 ? 999999 : value
if (!Number.isInteger(value)) value = String(value).replace(/(\d*\.?\d{0,2})\d*/, '$1') if (!Number.isInteger(value)) value = String(value).replace(/(\d*\.?\d{0,2})\d*/, '$1')
value = Number(String(value).replace(/^0+/, '')) value = Number(String(value).replace(/^0+/, ''))
insuranceList.value[index].cost = Number(value).toFixed(2) ? Number(value).toFixed(2) >= 0 ? value : '' : '' insuranceList.value[index].cost = Number(value).toFixed(2) != null && Number(value).toFixed(2) >= 0 ? value : ''
} }
function defaultBlock(item: InsuranceItem): string { function defaultBlock(item: InsuranceItem): string {
return item.main == '交强险' ? (props.isPreview ? 'has-default' : item.show ? 'has-default' : '') : '' const isJq: boolean = item.main == '交强险'
if (props.isPreview === true) {
return isJq === true ? 'has-default' : ''
} else {
return item.show === true ? 'has-default' : ''
}
} }
function showInsurance(item: InsuranceItem): boolean { function showInsurance(item: InsuranceItem): boolean {
return props.isPreview ? true : item.show ? true : false return props.isPreview === true ? true : (item.show === true ? true : false)
} }
function setItemDisabled(item: InsuranceItem, index: number): void { function setItemDisabled(item: InsuranceItem, index: number): void {
insuranceList.value[index].show = !item.show insuranceList.value[index].show = item.show === true ? false : true
uni.setStorageSync(storageKey.value, insuranceList.value) uni.setStorageSync(storageKey.value, insuranceList.value)
} }
...@@ -220,19 +250,19 @@ import { storage } from '@/utils/storage.uts' ...@@ -220,19 +250,19 @@ import { storage } from '@/utils/storage.uts'
e.checked = true e.checked = true
e.main = e.itemName == '交强险' ? '交强险' : '商业险' e.main = e.itemName == '交强险' ? '交强险' : '商业险'
e.show = false e.show = false
e.itemDesc = e.itemDesc ? processHtmlString(e.itemDesc) : '' e.itemDesc = e.itemDesc != null ? processHtmlString(e.itemDesc) : ''
}) })
if (!storageInsuranceList) { if (storageInsuranceList == null) {
uni.showLoading({ mask: true }) uni.showLoading({ mask: true })
setInsuranceList(storageKey.value, list || []) setInsuranceList(storageKey.value, list || [])
} else { } else {
const combinedList = [...insuranceList.value, ...list] const combinedList = [...insuranceList.value, ...list]
const deduplicatedList = combinedList.reduce((acc: any[], item: any) => { const deduplicatedList = combinedList.reduce((acc: Array<any>, item: any) => {
const existingItem = acc.find(existing => String(existing.id) === String(item.id)) const existingItem = acc.find(existing => String(existing.id) === String(item.id))
if (existingItem) { if (existingItem != null) {
existingItem.itemName = item.itemName || '' existingItem.itemName = existingItem.itemName != null ? existingItem.itemName : ''
existingItem.itemDesc = item.itemDesc || '' existingItem.itemDesc = existingItem.itemDesc != null ? existingItem.itemDesc : ''
if (currentItem.value.id == existingItem.id) currentItem.value = existingItem if (currentItem.value.id == existingItem.id) currentItem.value = existingItem
} else { } else {
acc.push(item) acc.push(item)
...@@ -240,7 +270,7 @@ import { storage } from '@/utils/storage.uts' ...@@ -240,7 +270,7 @@ import { storage } from '@/utils/storage.uts'
return acc return acc
}, []) }, [])
const arr: any[] = [] const arr: Array<any> = []
deduplicatedList.map((e: any) => { deduplicatedList.map((e: any) => {
const index = list.findIndex((item: any) => String(item.id) === String(e.id)) const index = list.findIndex((item: any) => String(item.id) === String(e.id))
if (index != -1) arr.push(e) if (index != -1) arr.push(e)
...@@ -252,16 +282,16 @@ import { storage } from '@/utils/storage.uts' ...@@ -252,16 +282,16 @@ import { storage } from '@/utils/storage.uts'
} }
} }
function setInsuranceList(key: string, value: any[]): void { function setInsuranceList(key: string, value: Array<any>): void {
uni.hideLoading() uni.hideLoading()
insuranceList.value = JSON.parse(JSON.stringify(value)) insuranceList.value = JSON.parse(JSON.stringify(value)) as Array<InsuranceItem>
value.map((e: any) => e.checked = true) value.map((e: any) => e.checked = true)
uni.setStorageSync(key, value) uni.setStorageSync(key, value)
flag.value = true flag.value = true
} }
function processHtmlString(htmlString: string): string { function processHtmlString(htmlString: string): string {
let processedString = htmlString.replace(/<\/?br\s*\/??>|\n/g, '<div></div>') let processedString = htmlString.replace(/<\/?br\s*\/??>|\n/g, 'div></div>')
processedString = processedString.replace(/style="[^"]*"/g, '') processedString = processedString.replace(/style="[^"]*"/g, '')
processedString = processedString.replace(/<strong>|<\/strong>|<em>|<\/em>|<>/g, '') processedString = processedString.replace(/<strong>|<\/strong>|<em>|<\/em>|<>/g, '')
processedString = processedString.replace(/<(?!div|span|p)[^>]*>/g, '</div>') processedString = processedString.replace(/<(?!div|span|p)[^>]*>/g, '</div>')
...@@ -269,8 +299,8 @@ import { storage } from '@/utils/storage.uts' ...@@ -269,8 +299,8 @@ import { storage } from '@/utils/storage.uts'
} }
function choose(item: InsuranceItem, index: number): void { function choose(item: InsuranceItem, index: number): void {
if (props.isPreview) return if (props.isPreview === true) return
insuranceList.value[index].checked = !item.checked insuranceList.value[index].checked = item.checked === true ? false : true
} }
</script> </script>
...@@ -280,7 +310,7 @@ import { storage } from '@/utils/storage.uts' ...@@ -280,7 +310,7 @@ import { storage } from '@/utils/storage.uts'
align-items: center; align-items: center;
flex-direction: row; flex-direction: row;
} }
.views-box { .views-box {
width: 2090rpx; width: 2090rpx;
height: 1080rpx; height: 1080rpx;
...@@ -551,9 +581,9 @@ import { storage } from '@/utils/storage.uts' ...@@ -551,9 +581,9 @@ import { storage } from '@/utils/storage.uts'
color: #2c66f7; color: #2c66f7;
} }
} }
} }
//预览模式样式 //预览模式样式
.preview { .preview {
.row-1, .row-1,
.row-2, .row-2,
.row-3, .row-3,
...@@ -592,5 +622,5 @@ import { storage } from '@/utils/storage.uts' ...@@ -592,5 +622,5 @@ import { storage } from '@/utils/storage.uts'
content: ''; content: '';
} }
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -25,6 +25,11 @@ ...@@ -25,6 +25,11 @@
import MessageBox from '@/components/MessageBox.uvue' import MessageBox from '@/components/MessageBox.uvue'
import { state } from '@/store/index.uts' import { state } from '@/store/index.uts'
type CarBuyersItem = {
name: string
id: number
}
const props = defineProps({ const props = defineProps({
title: { title: {
type: String, type: String,
...@@ -38,28 +43,32 @@ ...@@ -38,28 +43,32 @@
const emit = defineEmits(['close', 'select']) const emit = defineEmits(['close', 'select'])
const carBuyersVisible = ref<any>(null) const carBuyersVisible = ref(null)
const carBuyersList = ref<Array<{name: string, id: number}>>([ const carBuyersList = ref<Array<CarBuyersItem>>([{
{
name: '全款', name: '全款',
id: 1 id: 1
}, }, {
{
name: '按揭', name: '按揭',
id: 2 id: 2
} }] as Array<CarBuyersItem>)
])
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
const carBuyers = computed(() => { const carBuyers = computed(() => {
return state.user.customerInfo.carBuyers return state.user.customerInfo.carBuyers
}) })
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value, (newval) => {
close() close()
}, { immediate: true }) }, { immediate: true })
...@@ -67,7 +76,7 @@ ...@@ -67,7 +76,7 @@
;(carBuyersVisible.value as any).open() ;(carBuyersVisible.value as any).open()
} }
function handleSelect(item: {name: string, id: number}): void { function handleSelect(item: CarBuyersItem): void {
close() close()
emit('select', item) emit('select', item)
} }
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
<template #customContent> <template #customContent>
<view class="layout-content"> <view class="layout-content">
<view class="title"> <view class="title">
<view class="text">{{title}}</view> <view class="text">
{{title}}
</view>
</view> </view>
<view class="content"> <view class="content">
<view <view
...@@ -44,7 +46,9 @@ ...@@ -44,7 +46,9 @@
v-if="i.hasCustomerAutocomplete" v-if="i.hasCustomerAutocomplete"
/> />
<template v-if="i.unit"> <template v-if="i.unit">
<view class="unit">{{i.unit}}</view> <view class="unit">
{{i.unit}}
</view>
</template> </template>
</template> </template>
<template v-else> <template v-else>
...@@ -52,12 +56,15 @@ ...@@ -52,12 +56,15 @@
:class="['select flex',{placeholderStyle:!customerInfo[i.key]}]" :class="['select flex',{placeholderStyle:!customerInfo[i.key]}]"
@click="showPopup(i.popKey,index)" @click="showPopup(i.popKey,index)"
> >
<view class="value text-hide">{{customerInfo[i.key] ||i.placeholder}}</view> <view class="value text-hide">
{{customerInfo[i.key] ?customerInfo[i.key] :i.placeholder}}
</view>
<uni-icons <uni-icons
class="arrow" class="arrow"
type="right" type="right"
:size="16" :size="16"
></uni-icons> >
</uni-icons>
</view> </view>
</template> </template>
</view> </view>
...@@ -115,7 +122,6 @@ ...@@ -115,7 +122,6 @@
newCarFare?: string newCarFare?: string
carBuyers?: string carBuyers?: string
carPurchaseMethod?: string | number carPurchaseMethod?: string | number
[key: string]: any
} }
const props = defineProps({ const props = defineProps({
...@@ -171,11 +177,11 @@ ...@@ -171,11 +177,11 @@
const focusIndex = ref<number>(-1) const focusIndex = ref<number>(-1)
const watchCustomerInfo = computed(() => { const watchCustomerInfo = computed(() => {
return store.state.user.customerInfo return store.state?.user.customerInfo
}) })
const watchStatus = computed(() => { const watchStatus = computed(() => {
return store.state.user.historyStatus return store.state?.user.historyStatus
}) })
watch(() => watchCustomerInfo.value, (newval) => { watch(() => watchCustomerInfo.value, (newval) => {
...@@ -184,29 +190,24 @@ ...@@ -184,29 +190,24 @@
} }
}, { immediate: true }) }, { immediate: true })
const carBrandListVisible = ref<any>(null) const carBrandListVisible = ref(null)
const carBuyersVisible = ref<any>(null) const carBuyersVisible = ref(null)
function inputCustomer(): void { function inputCustomer(): void {
store.dispatch('setCustomerInfo', customerInfo.value) store.dispatch?.('setCustomerInfo', customerInfo.value)
} }
function handleSelect(item: any, popkey: string): void { function handleSelect(item: any, popkey: string): void {
;(carBuyersVisible.value as any).close() if (popkey == 'carBuyersVisible') {
if (popkey == 'employeeBoxVisible') {
customerInfo.value.salesUuid = item.uuid
customerInfo.value.staffName = item.staffName
} else if (popkey == 'carBuyersVisible') {
customerInfo.value.carBuyers = item.name customerInfo.value.carBuyers = item.name
customerInfo.value.carPurchaseMethod = item.id customerInfo.value.carPurchaseMethod = item.id
store.dispatch?.('setCustomerInfo', customerInfo.value)
} else { } else {
;(carBrandListVisible.value as any).close() (carBrandListVisible.value as any).close()
customerInfo.value.carModel = item.name customerInfo.value.carModel = item.name
customerInfo.value.carModelId = item.id customerInfo.value.carModelId = item.id
} }
resetFocusIndex() resetFocusIndex()
store.dispatch('setCustomerInfo', customerInfo.value)
} }
function showPopup(e: string, index: number): void { function showPopup(e: string, index: number): void {
...@@ -232,8 +233,10 @@ ...@@ -232,8 +233,10 @@
let value = Number(e.target.value) >= 9999999 ? 9999999 : e.target.value let value = Number(e.target.value) >= 9999999 ? 9999999 : e.target.value
if (!Number.isInteger(value)) value = String(value).replace(/(\d*\.?\d{0,2})\d*/, '$1') if (!Number.isInteger(value)) value = String(value).replace(/(\d*\.?\d{0,2})\d*/, '$1')
value = Number(String(value).replace(/^0+/, '')) value = Number(String(value).replace(/^0+/, ''))
customerInfo.value[key] = Number(value).toFixed(2) ? Number(value).toFixed(2) >= 0 ? value : '' : '' const numValue = Number(value)
customerInfo.value[key] = numValue >= 0 ? value : ''
inputCustomer() inputCustomer()
} }
} }
} }
...@@ -256,7 +259,7 @@ ...@@ -256,7 +259,7 @@
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.layout { .layout {
position: relative; position: relative;
width: 100%; width: 100%;
height: 100%; height: 100%;
...@@ -361,6 +364,5 @@ ...@@ -361,6 +364,5 @@
} }
} }
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -42,21 +42,19 @@ import wnCanvas from '@/components/PanCanvas/index.uvue' ...@@ -42,21 +42,19 @@ import wnCanvas from '@/components/PanCanvas/index.uvue'
import { state } from "@/store/index.uts" import { state } from "@/store/index.uts"
import nothingImage from '@/assets/images/media/nothing.webp' import nothingImage from '@/assets/images/media/nothing.webp'
interface Views { type Views = {
detailUrl?: string detailUrl?: string
bgUrl?: string bgUrl?: string
[key: string]: any
} }
interface CustomerInfo { type CustomerInfo = {
carModelId?: string carModelId?: string
[key: string]: any
} }
const props = defineProps({ const props = defineProps({
views: { views: {
type: Object as () => Views | Array<any>, type: Object as () => UTSJSONObject,
default: () => ({}) default: () => ({})
}, },
penSwitch: Boolean, penSwitch: Boolean,
...@@ -68,14 +66,15 @@ const props = defineProps({ ...@@ -68,14 +66,15 @@ const props = defineProps({
const emit = defineEmits(['scale']) const emit = defineEmits(['scale'])
const canvasRef = ref<any>(null) const canvasRef = ref(null)
const customerInfo = computed<CustomerInfo>(() => { const customerInfo = computed<CustomerInfo>(() => {
return state.user.customerInfo || {} const info = state.user.customerInfo
return info != null ? info.as(CustomerInfo) : {} as CustomerInfo
}) })
const viewKey = computed<string>(() => { const viewKey = computed<string>(() => {
return state.user?.viewKey || '' return state.user?.viewKey != null ? state.user.viewKey : ''
}) })
function onScale(e: number): void { function onScale(e: number): void {
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
@click="openCarBrand" @click="openCarBrand"
> >
{{customerInfo.carModel||'请选择'}} {{customerInfo.carModel||'请选择'}}
<view class="sprite-icon icon-arrow-bottom"></view> <view class="sprite-icon icon-arrow-bottom">
</view>
</view> </view>
<CarBrands <CarBrands
ref="carBrandListVisible" ref="carBrandListVisible"
...@@ -17,76 +18,78 @@ ...@@ -17,76 +18,78 @@
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import CarBrands from '@/components/CarBrands.uvue' import CarBrands from '@/components/CarBrands.uvue'
import { state , store } from "@/store/index.uts" import { state , store } from "@/store/index.uts"
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
interface CustomerInfo { type CustomerInfo = UTSJSONObject
carModel?: string
carModelId?: string
[key: string]: any
}
interface UserInfo { type UserInfo = UTSJSONObject
channelType: number
[key: string]: any
}
const props = defineProps({ const props = defineProps({
title: String, title: String,
hasCarBrand: Boolean, hasCarBrand: Boolean,
show: Boolean show: Boolean
}) })
const carBrandListVisible = ref<any>(null) const carBrandListVisible = ref(null)
const customerInfo = ref<CustomerInfo>({}) const customerInfo = ref<CustomerInfo>({} as CustomerInfo)
const watchCustomerInfo = computed<CustomerInfo>(() => { const watchCustomerInfo = computed<CustomerInfo>(() => {
return state.user?.customerInfo || {} return state.user?.customerInfo != null ? state.user.customerInfo : {} as CustomerInfo
}) })
const watchStatus = computed<boolean>(() => { const watchStatus = computed(() => {
return state.user?.historyStatus || false const status = state.user?.historyStatus
}) if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
})
const isAito = computed<boolean>(() => { const isAito = computed<boolean>(() => {
const userInfo: UserInfo = storage.get('userInfo') || { channelType: 0 } const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : { channelType: 0 } as UserInfo
return userInfo.channelType == 1 return userInfo.channelType == 1
}) })
watch(() => props.show, (newval) => { watch(() => props.show, (newval) => {
if (newval && props.hasCarBrand && !customerInfo.value.carModel && isAito.value) { if (newval === true && props.hasCarBrand === true && (customerInfo.value.carModel == null || customerInfo.value.carModel === '') && isAito.value === true) {
setTimeout(() => { setTimeout(() => {
carBrandListVisible.value?.autoSelect() carBrandListVisible.value?.autoSelect()
}, 1000) }, 1000)
} }
}, { immediate: true }) }, { immediate: true })
watch(() => watchCustomerInfo.value, (newval) => { watch(() => watchCustomerInfo.value, (newval) => {
if (newval) { if (newval != null) {
customerInfo.value = { ...newval } customerInfo.value = { ...newval }
} }
}, { immediate: true }) }, { immediate: true })
function handleSelect(item: any): void { function handleSelect(item: any): void {
carBrandListVisible.value?.close() carBrandListVisible.value?.close()
onSelect(item)
}
function onSelect(item: any): void {
customerInfo.value.carModel = item.name customerInfo.value.carModel = item.name
customerInfo.value.carModelId = item.id customerInfo.value.carModelId = item.id
store.dispatch('setCustomerInfo', customerInfo.value) store.dispatch?.('setCustomerInfo', customerInfo.value)
} }
function openCarBrand(): void { function openCarBrand(): void {
carBrandListVisible.value?.open() carBrandListVisible.value?.open()
} }
defineExpose({ defineExpose({ carBrandListVisible })
carBrandListVisible
})
</script> </script>
<style scoped lang='scss'> <style scoped lang='scss'>
.page-title-box { .page-title-box {
justify-content: center; justify-content: center;
position: absolute; position: absolute;
height: 96rpx; height: 96rpx;
...@@ -101,7 +104,7 @@ defineExpose({ ...@@ -101,7 +104,7 @@ defineExpose({
align-items: center; align-items: center;
.car-options { .car-options {
align-items: center; align-items: center;
flex-direction: row;; flex-direction: row;
&::before { &::before {
content: ''; content: '';
width: 2rpx; width: 2rpx;
...@@ -111,5 +114,5 @@ defineExpose({ ...@@ -111,5 +114,5 @@ defineExpose({
margin: 0 24rpx; margin: 0 24rpx;
} }
} }
} }
</style> </style>
\ No newline at end of file \ No newline at end of file
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
@click="showPopup(i.popKey, index)" @click="showPopup(i.popKey, index)"
> >
<view class="value text-hide"> <view class="value text-hide">
{{ customerInfo[i.key] || i.placeholder }} {{ customerInfo[i.key] ? customerInfo[i.key] : i.placeholder }}
</view> </view>
<uni-icons <uni-icons
class="arrow" class="arrow"
...@@ -95,19 +95,7 @@ ...@@ -95,19 +95,7 @@
popKey?: string popKey?: string
} }
interface CustomerInfo { type CustomerInfo = UTSJSONObject
customerName?: string
phoneNumber?: string
carModel?: string
carModelId?: string | number
salesUuid?: string
staffName?: string
carBrand?: string
carBrandId?: string | number
oneCarBrand?: string
oneCarBrandId?: string | number
[key: string]: any
}
const props = defineProps({ const props = defineProps({
penSwitch: Boolean, penSwitch: Boolean,
...@@ -146,22 +134,21 @@ ...@@ -146,22 +134,21 @@
const focusIndex = ref<number>(-1) const focusIndex = ref<number>(-1)
const watchCustomerInfo = computed(() => { const watchCustomerInfo = computed(() => {
return store.state.user.customerInfo return store.state?.user.customerInfo
}) })
const watchStatus = computed(() => { const watchStatus = computed(() => {
return store.state.user.historyStatus return store.state?.user.historyStatus
}) })
const isAito = computed(() => { const isAito = computed(() => {
const userInfo = storage.get('userInfo') const userInfo = storage.get('userInfo')
return userInfo.channelType == 1 return userInfo?.channelType == 1
}) })
watch(() => watchCustomerInfo.value, (newval) => { watch(() => watchCustomerInfo.value, (newval) => {
if (newval) { if (newval) {
customerInfo.value = newval as CustomerInfo customerInfo.value = newval as CustomerInfo
console.log( customerInfo.value,'==========')
} }
}, { immediate: true }) }, { immediate: true })
...@@ -169,42 +156,33 @@ ...@@ -169,42 +156,33 @@
if (n && !customerInfo.value.carModel && isAito.value) { if (n && !customerInfo.value.carModel && isAito.value) {
setTimeout(() => { setTimeout(() => {
carBrandListVisibleRef.value.$callMethod('autoSelect') carBrandListVisibleRef.value?.$callMethod('autoSelect')
}, 1000) }, 1000)
} }
}, { immediate: true }) }, { immediate: true })
const carBrandListVisibleRef = ref<any>(null) const carBrandListVisibleRef = ref(null)
function onInputCustomer(): void { function onInputCustomer(): void {
store.dispatch('setCustomerInfo', customerInfo.value) store.dispatch?.('setCustomerInfo', customerInfo.value)
} }
function onSelect(item: any, popkey: string): void { function onSelect(item: any, popkey: string): void {
carBrandListVisibleRef.value.$callMethod('close') customerInfo.value.carModel = item.name
// const customerInfo = dispatch('getCustomerInfo') customerInfo.value.carModelId = item.id
// if (popkey == 'employeeBoxVisible') { carBrandListVisibleRef.value?.$callMethod('close')
// customerInfo.value.salesUuid = item.uuid
// customerInfo.value.staffName = item.staffName
// } else {
// customerInfo.value.carModel = item.name
// customerInfo.value.carModelId = item.id
// }
resetFocusIndex() resetFocusIndex()
// store.dispatch('setCustomerInfo', customerInfo.value)
} }
function showPopup(e: string, index: number): void { function showPopup(e: string, index: number): void {
focusIndex.value = index focusIndex.value = index
if (e == 'carBrandListVisible') { if (e == 'carBrandListVisible') {
carBrandListVisibleRef.value.$callMethod('open') carBrandListVisibleRef.value?.$callMethod('open')
} }
} }
function closeAllPopup(): void { function closeAllPopup(): void {
carBrandListVisibleRef.value.$callMethod('close') carBrandListVisibleRef.value?.$callMethod('close')
resetFocusIndex() resetFocusIndex()
} }
...@@ -219,7 +197,7 @@ ...@@ -219,7 +197,7 @@
customerName: e.ownerName customerName: e.ownerName
} }
uni.$logger.local.info(`从客户档案选择:${JSON.stringify(e)}`) // uni.$logger.local.info(`从客户档案选择:${JSON.stringify(e)}`)
if (e.carModelId) { if (e.carModelId) {
customerInfo.value.carModelId = e.carModelId customerInfo.value.carModelId = e.carModelId
...@@ -236,9 +214,8 @@ ...@@ -236,9 +214,8 @@
function contentUrl(): string { function contentUrl(): string {
const views = props.views as any const views = props.views as any
const carModelId = customerInfo.value.carModelId const carModelId = customerInfo.value.carModelId
if (Array.isArray(views)) { if (Array.isArray(views)) {
return (views as any)[carModelId] || '/static/images/media/nothing.webp' return (views as any)[carModelId ?? ''] || '/static/images/media/nothing.webp'
} else if ((views as UTSJSONObject).detailUrl) { } else if ((views as UTSJSONObject).detailUrl) {
return (views as UTSJSONObject).detailUrl as string return (views as UTSJSONObject).detailUrl as string
} else { } else {
......
...@@ -87,7 +87,6 @@ ...@@ -87,7 +87,6 @@
defultTabId?: number defultTabId?: number
pageStyle?: string pageStyle?: string
carIcon?: string carIcon?: string
[key: string]: any
} }
const props = defineProps({ const props = defineProps({
...@@ -104,7 +103,7 @@ ...@@ -104,7 +103,7 @@
const direction = ref<string>('bottom') const direction = ref<string>('bottom')
const imgKey = ref<number>(Date.now()) const imgKey = ref<number>(Date.now())
const tabIndex = ref<number>(2) const tabIndex = ref<number>(2)
const threeGuarantees = ref<any>(null) const threeGuarantees = ref(null)
const watchStatus = computed(() => { const watchStatus = computed(() => {
return store.state.user.historyStatus return store.state.user.historyStatus
...@@ -114,7 +113,7 @@ ...@@ -114,7 +113,7 @@
return (props.detail as Detail).tabList.find(item => item.id == activeIndex.value).imgIdList return (props.detail as Detail).tabList.find(item => item.id == activeIndex.value).imgIdList
}) })
watch(() => watchStatus.value, () => { watch(watchStatus.value, () => {
activeIndex.value = (props.detail as Detail).defultActiveId || 0 activeIndex.value = (props.detail as Detail).defultActiveId || 0
tabIndex.value = (props.detail as Detail).defultTabId tabIndex.value = (props.detail as Detail).defultTabId
}) })
......
...@@ -68,7 +68,7 @@ ...@@ -68,7 +68,7 @@
imgUrl?: string imgUrl?: string
} }
const INFO_LIST: InfoListItem[] = [ const INFO_LIST: Array<InfoListItem> = [
{ {
id: 1, id: 1,
title: "客户付款凭证", title: "客户付款凭证",
...@@ -92,19 +92,19 @@ ...@@ -92,19 +92,19 @@
}) })
const emit = defineEmits(['update:showPayPage', 'finish']) const emit = defineEmits(['update:showPayPage', 'finish'])
const infoList = ref<InfoListItem[]>(JSON.parse(JSON.stringify(INFO_LIST))) const infoList = ref<Array<InfoListItem>>(JSON.parse(JSON.stringify(INFO_LIST)) as Array<InfoListItem>)
const previewImg = ref<string>('') const previewImg = ref<string>('')
const isPreview = ref<boolean>(false) const isPreview = ref<boolean>(false)
const watchBooksList = computed(() => { const watchBooksList = computed<Array<InfoListItem>>(() => {
return state.audio.booksList return state.audio.booksList
}) })
watch(() => watchBooksList.value, (newValue: InfoListItem[]) => { watch(() => watchBooksList.value, (newValue: Array<InfoListItem>) => {
if (newValue && newValue.length) { if (newValue != null && newValue.length > 0) {
infoList.value = newValue infoList.value = newValue
} else { } else {
infoList.value = JSON.parse(JSON.stringify(INFO_LIST)) infoList.value = JSON.parse(JSON.stringify(INFO_LIST)) as Array<InfoListItem>
} }
}, { immediate: true }) }, { immediate: true })
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
// "imgUrl", // "imgUrl",
// url // url
// ); // );
infoList.value[index].imgUrl = url // infoList.value[index].imgUrl = url
// setBooks(utils.deepClone(infoList.value)) // setBooks(utils.deepClone(infoList.value))
} catch (error) { } catch (error) {
console.error(`上传付款凭证失败:${error}`) console.error(`上传付款凭证失败:${error}`)
...@@ -160,16 +160,17 @@ ...@@ -160,16 +160,17 @@
// 删除图片 // 删除图片
function close(index: number): void { function close(index: number): void {
infoList.value[index].imgUrl = '' infoList.value[index].imgUrl = ''
dispatch('setBooks', JSON.parse(JSON.stringify(infoList.value))) dispatch('setBooks', JSON.parse(JSON.stringify(infoList.value)) as Array<InfoListItem>)
} }
// 预览图片 // 预览图片
function preview(index: number): void { function preview(index: number): void {
isPreview.value = true isPreview.value = true
previewImg.value = infoList.value[index].imgUrl || '' previewImg.value = infoList.value[index].imgUrl != null ? infoList.value[index].imgUrl : ''
const imageUrl: string = infoList.value[index].imgUrl != null ? infoList.value[index].imgUrl : ''
uni.previewImage({ uni.previewImage({
urls: [infoList.value[index].imgUrl || ''], urls: [imageUrl],
longPressActions: { longPressActions: {
success: function (data) { success: function (data) {
console.log( console.log(
......
...@@ -138,7 +138,7 @@ ...@@ -138,7 +138,7 @@
const title = ref<string>('') const title = ref<string>('')
const accountInfo = ref<Record<string, any>>({}) const accountInfo = ref<Record<string, any>>({})
const payInfo = ref<Record<string, any>>({}) const payInfo = ref<Record<string, any>>({})
const popup = ref<any>(null) const popup = ref(null)
const visible = ref<boolean>(false) const visible = ref<boolean>(false)
// 使用传入的 paymentType 或从 store 获取 // 使用传入的 paymentType 或从 store 获取
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
:penSwitch="penSwitch" :penSwitch="penSwitch"
:show="id == item.id" :show="id == item.id"
:ref="'media' + item.id" :ref="'media' + item.id"
:title="item.detailTitle || ''" :title="title"
:madiaId="item.id" :madiaId="item.id"
@scale="scale" @scale="scale"
:ulList="item.ulList" :ulList="item.ulList"
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
:penSwitch="penSwitch" :penSwitch="penSwitch"
:show="id == item.id" :show="id == item.id"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
/> />
</template> </template>
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<history <history
:show="id == item.id" :show="id == item.id"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
:madiaId="item.id" :madiaId="item.id"
/> />
</template> </template>
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
:penSwitch="penSwitch" :penSwitch="penSwitch"
:show="id == item.id" :show="id == item.id"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
:madiaId="item.id" :madiaId="item.id"
:detail="item" :detail="item"
/> />
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
<insurance <insurance
:show="id == item.id" :show="id == item.id"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
:madiaId="item.id" :madiaId="item.id"
:penSwitch="penSwitch" :penSwitch="penSwitch"
:isPreview="isPreview" :isPreview="isPreview"
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
<case-center <case-center
:detail="item" :detail="item"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
:show="id == item.id" :show="id == item.id"
/> />
</template> </template>
...@@ -97,7 +97,7 @@ ...@@ -97,7 +97,7 @@
:penSwitch="penSwitch" :penSwitch="penSwitch"
:show="id == item.id" :show="id == item.id"
:ref="(el) => setMediaRef(item.id, el)" :ref="(el) => setMediaRef(item.id, el)"
:title="item.detailTitle || ''" :title="title"
:madiaId="item.id" :madiaId="item.id"
:hasCarBrand="item.hasCarBrand" :hasCarBrand="item.hasCarBrand"
/> />
...@@ -165,26 +165,30 @@ ...@@ -165,26 +165,30 @@
import { getSoureData } from '@/api/system-api.uts' import { getSoureData } from '@/api/system-api.uts'
import { findPayInfo as findPayInfoApi } from '@/api/common-api.uts' import { findPayInfo as findPayInfoApi } from '@/api/common-api.uts'
type BackPressEvent = {
from: string
}
const backZindex = ref<number>(9) const backZindex = ref<number>(9)
const drawStatus = ref<boolean>(false) const drawStatus = ref<boolean>(false)
const startX = ref<any>(null) const startX = ref(null)
const startY = ref<any>(null) const startY = ref(null)
const screenWidth = ref<any>(null) const screenWidth = ref(null)
const scaleValueObject = ref<UJSObject>({}) const scaleValueObject = ref<Record<string, number>>({})
const showPayPage = ref<boolean>(false) const showPayPage = ref<boolean>(false)
const productModelStatus = ref<boolean>(false) const productModelStatus = ref<boolean>(false)
const modeName = ref<string>('') const modeName = ref<string>('')
const pageToolList = ref<Array>([]) const pageToolList = ref<Array<any>>([])
const moduleList = ref<Array>([]) const moduleList = ref<Array<any>>([])
const useCarConfig = ref<boolean>(false) const useCarConfig = ref<boolean>(false)
const dateilKey = ref<number>(Date.now()) const dateilKey = ref<number>(Date.now())
const currentMediaId = ref<string>('') const currentMediaId = ref<string>('')
const id = ref<string>('') const id = ref<string>('')
const type = ref<string>('') const type = ref<string>('')
const media = ref<Array>([]) const media = ref<Array<any>>([])
const toolList = ref<Array>([]) const toolList = ref<Array<any>>([])
const paymentTypeList = ref<Array<any>>([]) const paymentTypeList = ref<Array<any>>([])
// 用于存储动态 ref 的对象 // 用于存储动态ref 的对象
const mediaRefs = ref<Record<string, any>>({}) const mediaRefs = ref<Record<string, any>>({})
// 设置动态 ref 的函数 // 设置动态 ref 的函数
...@@ -194,7 +198,8 @@ ...@@ -194,7 +198,8 @@
} }
} }
onBackPress((event: {from: string}) => {
onBackPress((event: BackPressEvent) => {
console.log('返回键触发', event.from) console.log('返回键触发', event.from)
if (event.from === 'backbutton') { if (event.from === 'backbutton') {
...@@ -214,18 +219,18 @@ ...@@ -214,18 +219,18 @@
}) })
const channelType = computed(() => { const channelType = computed(() => {
const { channelType } = storage.get('userInfo') const userInfo = storage.get('userInfo')
return channelType return userInfo?.channelType
}) })
const shopMerchantId = computed(() => { const shopMerchantId = computed(() => {
const { shopMerchantId } = storage.get('userInfo') const userInfo = storage.get('userInfo')
return shopMerchantId return userInfo?.shopMerchantId
}) })
const sceneType = computed(() => { const sceneType = computed(() => {
const { sceneType } = storage.get('userInfo') const userInfo = storage.get('userInfo')
return sceneType return userInfo?.sceneType
}) })
const currentCarInfo = computed(() => { const currentCarInfo = computed(() => {
...@@ -233,16 +238,23 @@ ...@@ -233,16 +238,23 @@
}) })
const watchStatus = computed(() => { const watchStatus = computed(() => {
return state.user.historyStatus const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
}) })
const penSwitch = computed(() => { const penSwitch = computed(() => {
return !isPreview.value && drawStatus.value return isPreview.value === false && drawStatus.value === true
}) })
const title = computed(() => { const title = computed(() => {
let name = media.value.find(e => e.id == id.value)?.detailTitle || '' let name = media.value.find(e => e.id == id.value)?.detailTitle != null ? media.value.find(e => e.id == id.value)?.detailTitle : ''
return name return name
}) })
...@@ -256,42 +268,42 @@ ...@@ -256,42 +268,42 @@
return type.value == 'preview' return type.value == 'preview'
}) })
const viewKey = computed(() => { const viewKey = computed(() => {
return state.user.viewKey return state.user.viewKey
}) })
watch(() => viewKey.value, (newval) => { watch(() => viewKey.value, (newval) => {
if(id.value) setPageData() if(id.value != null && id.value !== '') setPageData()
}, { immediate: true }) }, { immediate: true })
watch(() => watchStatus.value, (newval) => { watch(watchStatus.value, (newval) => {
useCarConfig.value = false useCarConfig.value = false
dateilKey.value = Date.now() dateilKey.value = Date.now()
pageToolList.value = toolList.value pageToolList.value = toolList.value
currentMediaId.value = id.value currentMediaId.value = id.value
if (newval) drawStatus.value = false if (newval === true) drawStatus.value = false
}, { immediate: true }) }, { immediate: true })
watch(() => id.value, (newval) => { watch(() => id.value, (newval) => {
if (!pageToolList.value.length) pageToolList.value = toolList.value if (pageToolList.value.length == 0) pageToolList.value = toolList.value
}, { immediate: true }) }, { immediate: true })
onMounted(() => { onMounted(() => {
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getSystemInfoSync()
screenWidth.value = systemInfo.screenWidth screenWidth.value = systemInfo.screenWidth
}) })
onLoad((options: OnLoadOptions) => { onLoad((options) => {
dispatch('setCustomerInfo', {}) dispatch('setCustomerInfo', {})
const storageKey = `source_${sceneType.value}_${shopMerchantId.value}` const storageKey = `source_${sceneType.value}_${shopMerchantId.value}`
const data = uni.getStorageSync(storageKey) const data = uni.getStorageSync(storageKey)
id.value = options.id id.value = options.id ?? ''
type.value = options.type type.value = options.type ?? ''
if (data != null) {
toolList.value = data.toolList toolList.value = data.toolList
media.value = data.moduleList media.value = data.moduleList
}
setPageData() setPageData()
findPayInfo() findPayInfo()
}) })
...@@ -305,7 +317,7 @@ ...@@ -305,7 +317,7 @@
} }
function handleFull(val: boolean) { function handleFull(val: boolean) {
backZindex.value = val ? 0 : 9 backZindex.value = val === true ? 0 : 9
} }
function choose(e: any): void { function choose(e: any): void {
...@@ -322,15 +334,15 @@ ...@@ -322,15 +334,15 @@
const refsToClose: Array<any> = [] const refsToClose: Array<any> = []
// 收集所有 media 开头的 ref // 收集所有 media 开头的 ref
const currentList = useCarConfig.value ? moduleList.value : media.value const currentList = useCarConfig.value === true ? moduleList.value : media.value
currentList.forEach(item => { currentList.forEach(item => {
const refName = `media${item.id}` const refName = `media${item.id}`
const refValue = mediaRefs.value[refName] const refValue = mediaRefs.value[refName]
if (refValue) { if (refValue != null) {
// 处理可能是数组的情况(v-for 生成的 ref 通常是数组) // 处理可能是数组的情况(v-for 生成的 ref 通常是数组)
const componentInstance = Array.isArray(refValue) ? refValue[0] : refValue const componentInstance = Array.isArray(refValue) ? refValue[0] : refValue
if (componentInstance && componentInstance.closeAllPopup) { if (componentInstance != null && componentInstance.closeAllPopup != null) {
componentInstance.closeAllPopup() componentInstance.closeAllPopup()
} }
} }
...@@ -341,9 +353,9 @@ ...@@ -341,9 +353,9 @@
payRef, payRef,
stepRef] stepRef]
fixedRefs.forEach(ref => { fixedRefs.forEach(ref => {
if (ref && ref.value) { if (ref != null && ref.value != null) {
const componentInstance = ref.value const componentInstance = ref.value
if (componentInstance.closeAllPopup) { if (componentInstance.closeAllPopup != null) {
componentInstance.closeAllPopup() componentInstance.closeAllPopup()
} }
} }
...@@ -354,9 +366,15 @@ ...@@ -354,9 +366,15 @@
dispatch('clearHistory') dispatch('clearHistory')
dispatch('clearReceptionTrack') dispatch('clearReceptionTrack')
} }
function back (): void{ function back(): void {
if(showPayPage.value) return showPayPage.value = false if(showPayPage.value === true) {
if(!isPreview.value) return backpressRef.value.open() showPayPage.value = false
return
}
if(isPreview.value === false) {
backpressRef.value?.open()
return
}
backHome() backHome()
} }
...@@ -376,7 +394,7 @@ ...@@ -376,7 +394,7 @@
} }
function touchStart(e: any) { function touchStart(e: any) {
if (!drawStatus.value && e.changedTouches?.length) { if (drawStatus.value === false && e.changedTouches != null && e.changedTouches.length > 0) {
startX.value = e.changedTouches[0].pageX startX.value = e.changedTouches[0].pageX
startY.value = e.changedTouches[0].pageY startY.value = e.changedTouches[0].pageY
} }
...@@ -384,16 +402,16 @@ ...@@ -384,16 +402,16 @@
function touchEnd(e: any) { function touchEnd(e: any) {
if (modeName.value) return if (modeName.value != null && modeName.value !== '') return
try { try {
if (!e || !e.changedTouches || drawStatus.value || pageToolList.value.length == 0 || e.changedTouches.length === 0) return if (e == null || e.changedTouches == null || drawStatus.value === true || pageToolList.value.length == 0 || (e.changedTouches.length == 0)) return
let halfScreenWidth = screenWidth.value / 2, let halfScreenWidth = screenWidth.value / 2,
touch = e.changedTouches[0], touch = e.changedTouches[0],
isDistanceSignificant = Math.abs(touch.pageX - startX.value) > screenWidth.value / 6, isDistanceSignificant = Math.abs(touch.pageX - startX.value) > screenWidth.value / 6,
index = pageToolList.value.findIndex((item: any) => item.id == id.value) index = pageToolList.value.findIndex((item: any) => item.id == id.value)
if (Math.abs(startY.value - touch.pageY) > 150) return if (Math.abs(startY.value - touch.pageY) > 150) return
if (!scaleValueObject.value[id.value]) scaleValueObject.value[id.value] = 1 if (scaleValueObject.value[id.value] == null) scaleValueObject.value[id.value] = 1
if (isDistanceSignificant && index != -1 && scaleValueObject.value[id.value] == 1 && !productModelStatus.value) { if (isDistanceSignificant === true && index != -1 && scaleValueObject.value[id.value] == 1 && productModelStatus.value === false) {
const { nextId, modeName: modeNameVal, title: titleVal } = getNextId(index, pageToolList.value, startX.value, halfScreenWidth) const { nextId, modeName: modeNameVal, title: titleVal } = getNextId(index, pageToolList.value, startX.value, halfScreenWidth)
modeName.value = modeNameVal modeName.value = modeNameVal
// receptionTrackLeave() // receptionTrackLeave()
...@@ -408,8 +426,8 @@ ...@@ -408,8 +426,8 @@
} }
} }
function getNextId(index: number, pageToolList: Array, startX: number, halfScreenWidth: number) { function getNextId(index: number, pageToolList: Array<any>, startX: number, halfScreenWidth: number) {
let nextItem = {}, let nextItem: any = {},
modeName = '' modeName = ''
if (startX > halfScreenWidth) { if (startX > halfScreenWidth) {
nextItem = index === pageToolList.length - 1 ? pageToolList[0] : pageToolList[index + 1] nextItem = index === pageToolList.length - 1 ? pageToolList[0] : pageToolList[index + 1]
...@@ -426,8 +444,7 @@ ...@@ -426,8 +444,7 @@
} }
function scale(e: number) { function scale(e: number) {
let { id } = props scaleValueObject.value[id.value] = e
scaleValueObject.value[id] = e
} }
async function setPageData() { async function setPageData() {
...@@ -441,31 +458,32 @@ ...@@ -441,31 +458,32 @@
try { try {
console.log('try',currentCarInfo.value) console.log('try',currentCarInfo.value)
let requestData = await getSoureData(shopMerchantId.value, sceneType.value, params) let requestData = await getSoureData(shopMerchantId.value, sceneType.value, params)
if (requestData) setViewInfo(requestData) if (requestData != null) setViewInfo(requestData)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
if (data) setViewInfo(data) if (data != null) setViewInfo(data)
} }
} }
function setViewInfo(data: any): void { function setViewInfo(data: any): void {
const currentMediaIdVal = currentMediaId.value if (data == null) return
const pageId = id.vlaue
const pageId = id.value
const useCarConfigVal = useCarConfig.value const useCarConfigVal = useCarConfig.value
const pageModuleListVal = moduleList.value const pageModuleListVal = moduleList.value
const pageMediaVal = media.value const pageMediaVal = media.value
const array = useCarConfigVal ? pageModuleListVal : pageMediaVal const array = useCarConfigVal === true ? pageModuleListVal : pageMediaVal
const findItem = array.find(item => item.id == pageId) const findItem = array.find(item => item.id == pageId)
const detailTitle = findItem?.detailTitle || '' const detailTitle = findItem != null ? (findItem.detailTitle != null ? findItem.detailTitle : '') : ''
// receptionTrackLeave() // receptionTrackLeave()
moduleList.value = data.moduleList moduleList.value = data.moduleList
pageToolList.value = data.toolList pageToolList.value = data.toolList
useCarConfig.value = true useCarConfig.value = true
if (id != currentMediaIdVal) { if (id.value != currentMediaId.value) {
const jumpItem = data.moduleList.find(e => e.detailTitle == detailTitle) const jumpItem = data.moduleList.find(e => e.detailTitle == detailTitle)
id.value = jumpItem ? jumpItem.id : data.moduleList[0].id id.value = jumpItem != null ? jumpItem.id : data.moduleList[0].id
} }
currentMediaId.value = data.id currentMediaId.value = data.id
} }
...@@ -507,10 +525,10 @@ ...@@ -507,10 +525,10 @@
'back', 'back',
'done']) 'done'])
const toolRef = ref<any>(null) const toolRef = ref(null)
const payRef = ref<any>(null) const payRef = ref(null)
const stepRef = ref<any>(null) const stepRef = ref(null)
const backpressRef = ref<any>(null) const backpressRef = ref(null)
</script> </script>
<style lang="scss"> <style lang="scss">
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
import { storage } from '@/utils/storage.uts' import { storage } from '@/utils/storage.uts'
import { state , dispatch } from "@/store/index.uts"; import { state , dispatch } from "@/store/index.uts";
import HomeFrame from '@/components/HomeFrame/index.uvue' import HomeFrame from '@/components/HomeFrame/index.uvue'
import { getMerchantCarBrandList, getEmployeeList , getCarBrandsListApi } from '@/api/common-api.uts' import { getMerchantCarBrandList, getEmployeeListApi , getCarBrandsListApi } from '@/api/common-api.uts'
import { getMockData, getSoureData } from '@/api/system-api.uts' import { getMockData, getSoureData } from '@/api/system-api.uts'
const homeRef = ref(null) const homeRef = ref(null)
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
function handleStart(): void { function handleStart(): void {
const currentModuleList = moduleList.value const currentModuleList = moduleList.value
if (!currentModuleList.length) { if (currentModuleList.length == 0) {
return uni.showToast({ return uni.showToast({
title: '该场景尚未配置素材,请联系总部人员', title: '该场景尚未配置素材,请联系总部人员',
icon: 'none' icon: 'none'
...@@ -99,17 +99,17 @@ ...@@ -99,17 +99,17 @@
getSoure(brandIdList, subBrandIdList) getSoure(brandIdList, subBrandIdList)
dispatch('setCarBrandsList', carBrandList) dispatch('setCarBrandsList', carBrandList)
storage.set('carBrandList', carBrandList) storage.set('carBrandList', carBrandList)
if (carBrandList.length) { if (carBrandList.length > 0) {
let index = 0 let index = 0
getCarBrandsList(carBrandList, index) getCarBrandsList(carBrandList, index)
} }
}) })
/**获取销售人员 */ /**获取销售人员 */
getEmployeeList({ getEmployeeListApi({
merchantId: shopMerchantId merchantId: shopMerchantId
}).then(res => { }).then(res => {
dispatch('setEmployeeList', res || []) dispatch('setEmployeeList', res != null ? res : [])
storage.set('employeeList', res || []) storage.set('employeeList', res != null ? res : [])
}) })
} }
...@@ -120,7 +120,7 @@ ...@@ -120,7 +120,7 @@
const storageKey = `source_${sceneType}_${shopMerchantId}` const storageKey = `source_${sceneType}_${shopMerchantId}`
const data = uni.getStorageSync(storageKey) const data = uni.getStorageSync(storageKey)
if (data) { if (data != null) {
setViewInfo(data) setViewInfo(data)
} }
...@@ -129,7 +129,7 @@ ...@@ -129,7 +129,7 @@
brandIdList: brandIdList, brandIdList: brandIdList,
subBrandIdList: subBrandIdList subBrandIdList: subBrandIdList
}) })
if (requestData) { if (requestData != null) {
setViewInfo(requestData) setViewInfo(requestData)
} else { } else {
loadComplete.value = true loadComplete.value = true
...@@ -140,15 +140,15 @@ ...@@ -140,15 +140,15 @@
} }
} }
onLoad((options: OnLoadOptions) => { onLoad((options) => {
getMockData(true).then(mockdata =>{ getMockData(true).then(mockdata =>{
console.log(mockdata,'===') console.log(mockdata,'===')
const userInfo = storage.get('userInfo') const userInfo = storage.get('userInfo')
const mockDataObj = mockdata as UTSJSONObject const mockDataObj = mockdata as UTSJSONObject
const {channelType} = userInfo as UTSJSONObject const {channelType} = userInfo as UTSJSONObject
if (channelType == 1 && mockDataObj.boutiqueDefaultCarBrandId) { if (channelType == 1 && mockDataObj.boutiqueDefaultCarBrandId != null) {
state.user.boutiqueDefaultCarBrandId = mockDataObj.boutiqueDefaultCarBrandId //默认车辆品牌 state.user.boutiqueDefaultCarBrandId = mockDataObj.boutiqueDefaultCarBrandId //默认车辆品牌
if (mockDataObj.defaultCarId) { if (mockDataObj.defaultCarId != null) {
state.user.defaultCarId = mockDataObj.defaultCarId //默认车系 state.user.defaultCarId = mockDataObj.defaultCarId //默认车系
} }
} }
...@@ -185,19 +185,19 @@ ...@@ -185,19 +185,19 @@
/**按序加载车型 */ /**按序加载车型 */
async function getCarBrandsList(carBrandList: Array<any>, index: number) { async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index] const item = carBrandList[index]
if (!item) return if (item == null) return
const storageKey = `${item.id}_${item.brandId}_carlist` const storageKey = `${item.id}_${item.brandId}_carlist`
const carList = uni.getStorageSync(storageKey) const carList = uni.getStorageSync(storageKey)
if (index < carBrandList.length - 1) { if (index < carBrandList.length - 1) {
const nextIndex = index + 1 const nextIndex = index + 1
if (!carList) { if (carList == null) {
const list = await getCarBrandsListApi({ const list = await getCarBrandsListApi({
brandId: item.brandId, brandId: item.brandId,
childBrandId: item.id childBrandId: item.id
}) })
if (list) { if (list != null) {
uni.setStorageSync(storageKey, list) uni.setStorageSync(storageKey, list)
} }
getCarBrandsList(carBrandList, nextIndex) getCarBrandsList(carBrandList, nextIndex)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!