Commit c224b75d by 李伟康

refactor(car): 优化车型选择组件的数据处理和UI渲染

- 重构CarBrands组件的数据类型定义,统一使用any类型替代具体接口
- 优化车型品牌列表的渲染逻辑,使用template循环提高性能
- 修复base64转换功能,增加对不同数据类型的判断和异常处理
- 调整组件样式布局,修改选择项宽度以改善显示效果
- 优化员工选择组件的数据绑定和渲染方式
- 重构完成步骤组件的状态管理和表单验证逻辑
- 替换自定义弹窗组件为uni-popup,提升弹窗交互体验
- 优化工具箱组件的数据映射和显示逻辑
1 parent 61547116
...@@ -260,10 +260,31 @@ async function getBase64(url: string): Promise<string> { ...@@ -260,10 +260,31 @@ async function getBase64(url: string): Promise<string> {
method: "GET", method: "GET",
responseType: "arraybuffer", responseType: "arraybuffer",
success: res => { success: res => {
const base64 = `data:image/png;base64,${uni.arrayBufferToBase64(res.data as ArrayBuffer)}`; try {
const data: any | null = res.data;
let base64: string;
if (data == null) {
console.warn('res.data is null or undefined');
resolve(url);
return;
}
if (typeof data === 'string') {
base64 = `data:image/png;base64,${data}`;
} else {
base64 = `data:image/png;base64,${uni.arrayBufferToBase64(data as ArrayBuffer)}`;
}
console.log('转换后的 base64:', base64.substring(0, 50) + '...');
resolve(base64); resolve(base64);
} catch (e) {
console.error('转换 base64 失败:', e, 'res.data:', res.data);
resolve(url);
}
}, },
fail: err => { fail: err => {
console.error('请求失败:', err);
resolve(url); resolve(url);
} }
}); });
......
...@@ -8,15 +8,14 @@ ...@@ -8,15 +8,14 @@
@close="handleClose" @close="handleClose"
> >
<view class="select-box"> <view class="select-box">
<template v-for="(item, index) in employeeList" :key="index" >
<view <view
class="select-item" :class="['select-item',{ checked: (salesUuid as string) == (item as UTSJSONObject).uuid }]"
:class="{ checked: salesUuid == item.uuid }"
@click="handleSelect(item)" @click="handleSelect(item)"
v-for="(item, index) in employeeList"
:key="index"
> >
{{ item.staffName }} {{ (item as UTSJSONObject).staffName }}
</view> </view>
</template>
</view> </view>
</MessageBox> </MessageBox>
</template> </template>
...@@ -29,11 +28,6 @@ ...@@ -29,11 +28,6 @@
import { getEmployeeListApi } from '@/api/common-api.uts' import { getEmployeeListApi } from '@/api/common-api.uts'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
interface EmployeeItem {
staffName: string
uuid: string
}
type Props = { type Props = {
title?: string title?: string
salesPropsUuid?: string salesPropsUuid?: string
...@@ -71,10 +65,10 @@ ...@@ -71,10 +65,10 @@
// const employeeList = computed(() => { // const employeeList = computed(() => {
// return state.user.employeeList // return state.user.employeeList
// }) // })
const employeeList = ref<Array<EmployeeItem>>([]) const employeeList = ref<Array<any>>([])
watch(updateView.value,()=>{ watch(updateView.value,()=>{
const list = storage.get("employeeList") as UTSArray<EmployeeItem> const list = storage.get("employeeList") as UTSArray<Any>
employeeList.value = list !== null ? list : [] employeeList.value = list != null ? list : []
}, { immediate: true, deep: true }) }, { immediate: true, deep: true })
function close(): void { function close(): void {
...@@ -83,7 +77,7 @@ ...@@ -83,7 +77,7 @@
} }
} }
watch(watchStatus.value, (newval: number) => { watch(watchStatus.value, () => {
close() close()
}, { immediate: true }) }, { immediate: true })
...@@ -101,7 +95,7 @@ ...@@ -101,7 +95,7 @@
// 获取销售人员列表 // 获取销售人员列表
getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => { getEmployeeListApi({ merchantId: shopMerchantId }).then((res: any) => {
const employeeList = res as Array<EmployeeItem> const employeeList = res as Array<any>
dispatch('setEmployeeList', employeeList) dispatch('setEmployeeList', employeeList)
const listToStore = employeeList != null ? employeeList : [] const listToStore = employeeList != null ? employeeList : []
storage.set('employeeList', listToStore, 0) storage.set('employeeList', listToStore, 0)
...@@ -110,7 +104,7 @@ ...@@ -110,7 +104,7 @@
}) })
} }
function handleSelect(item: EmployeeItem): void { function handleSelect(item: any): void {
close() close()
emit('select', item) emit('select', item)
} }
...@@ -122,14 +116,17 @@ ...@@ -122,14 +116,17 @@
<style scoped lang="scss"> <style scoped lang="scss">
.select-box { .select-box {
margin: 40rpx 0; margin: 40rpx 0;
display: grid; display: flex;
grid-template-columns: repeat(4, 1fr); flex-wrap: wrap;
gap: 32rpx;
overflow-y: scroll; overflow-y: scroll;
max-height: 50vh; max-height: 800rpx;
padding-bottom: 60rpx; padding-bottom: 60rpx;
flex-direction: row;
.select-item { .select-item {
width: 48%;
/* width: 23.5%; */
margin-right: 2%;
margin-bottom: 32rpx;
text-align: center; text-align: center;
height: 68rpx; height: 68rpx;
line-height: 44rpx; line-height: 44rpx;
...@@ -139,6 +136,10 @@ ...@@ -139,6 +136,10 @@
font-size: 32rpx; font-size: 32rpx;
border-radius: 8rpx; border-radius: 8rpx;
&:nth-child(4n) {
margin-right: 0;
}
&.checked { &.checked {
border: 2rpx solid #292d33; border: 2rpx solid #292d33;
} }
......
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
:cancelBtnText="`${step == 1 ? '取消' : '上一步'}`" :cancelBtnText="`${step == 1 ? '取消' : '上一步'}`"
:confirmBtnText="`${sceneType == 0 ? (step == 1 ? '下一步' : '完成接待') : '完成接待'}`" :confirmBtnText="`${sceneType == 0 ? (step == 1 ? '下一步' : '完成接待') : '完成接待'}`"
:title="`${step == 1 ? '客户信息完善' : '结果反馈'}`" :title="`${step == 1 ? '客户信息完善' : '结果反馈'}`"
:popupW="820" :popupW="660"
:maxHeight="820" :maxHeight="1000"
:isAutoClose="false" :isAutoClose="false"
> >
<view <view
name="content" name="content"
:key="updateViewKey" :key="updateViewKey"
class="content"
> >
<template v-if="step == 1"> <template v-if="step == 1">
<template v-if="!check(true)"> <template v-if="!check(true)">
...@@ -50,11 +51,11 @@ ...@@ -50,11 +51,11 @@
</template> </template>
<template v-else> <template v-else>
<view <view
:class="['select', `${formData[i.key] !== null && formData[i.key] !== '' ? '' : 'placeholder'}`]" :class="['select', `${(formData as UTSJSONObject)[i.key] != '' ? '' : 'placeholder'}`]"
@click="showPopup(i)" @click="showPopup(i)"
:key="selectKey" :key="selectKey"
> >
{{ formData[i.key] !== null && formData[i.key] !== '' ? formData[i.key] : i.placeholder }} {{ (formData as UTSJSONObject)[i.key] != '' ? (formData as UTSJSONObject)[i.key] : i.placeholder }}
<uni-icons <uni-icons
class="arrow" class="arrow"
type="down" type="down"
...@@ -75,7 +76,7 @@ ...@@ -75,7 +76,7 @@
<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 :class="['sprite-icon', `icon-face-${i.status == receptionStatus ? `${i.icon}-active` : i.icon}`]">
...@@ -107,6 +108,7 @@ ...@@ -107,6 +108,7 @@
</uni-popup-message> </uni-popup-message>
</uni-popup> --> </uni-popup> -->
</view> </view>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
...@@ -129,40 +131,32 @@ ...@@ -129,40 +131,32 @@
disabled?: boolean disabled?: boolean
} }
type FormData = {
customerName: string
carModel: string
phoneNumber: string
salesUuid: string
staffName: string
carModelId: string
}
type ResultListItem = { type ResultListItem = {
icon: string icon: string
text: string text: string
status: number status: string
} }
const formData = ref<FormData>({ const formData = ref<UTSJSONObject>({
customerName: "", customerName: "",
carModel: "", carModel: "",
phoneNumber: "", phoneNumber: "",
salesUuid: "", salesUuid: "",
staffName: "", staffName: "",
carModelId:"" carModelId:""
}) } as UTSJSONObject)
const resultList = ref<Array<ResultListItem>>([ const resultList = ref<Array<ResultListItem>>([
{ {
icon: 'success', icon: 'success',
text: '结果完美,成交了', text: '结果完美,成交了',
status: 1 status: '1'
}, },
{ {
icon: 'error', icon: 'error',
text: '仍需努力,战败了', text: '仍需努力,战败了',
status: 0 status: '0'
} }
]) ])
...@@ -254,7 +248,7 @@ ...@@ -254,7 +248,7 @@
]) ])
const errorTip = ref<boolean>(false) const errorTip = ref<boolean>(false)
const receptionStatus = ref<number>(-1) const receptionStatus = ref<string>('')
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(null) const formRef = ref(null)
...@@ -282,14 +276,15 @@ ...@@ -282,14 +276,15 @@
}) })
const tips = computed(() => { const tips = computed(() => {
let { sceneType, titleTips } = props let _sceneType = props.sceneType
let text = titleTips !== null && titleTips !== '' ? titleTips : '检测到"交车告知书"中未填写客户档案,请填写后再完成接待。' let _titleTips = props.titleTips
if (sceneType == 1) text = '请确认"车型加装选购页"中的客户信息,并点击「完成接待」结束客户接待。' let text = _titleTips !== null && _titleTips !== '' ? _titleTips : '检测到"交车告知书"中未填写客户档案,请填写后再完成接待。'
if (_sceneType == 1) text = '请确认"车型加装选购页"中的客户信息,并点击「完成接待」结束客户接待。'
return text return text
}) })
watch(watchStatus.value, () => { watch(watchStatus.value, () => {
receptionStatus.value = -1 receptionStatus.value = ''
errorTip.value = false errorTip.value = false
if (formRef.value != null) { if (formRef.value != null) {
(formRef.value as ComponentPublicInstance).$callMethod('close') (formRef.value as ComponentPublicInstance).$callMethod('close')
...@@ -297,20 +292,20 @@ ...@@ -297,20 +292,20 @@
}, { immediate: true }) }, { immediate: true })
function showError(key: string): boolean { function showError(key: string): boolean {
const value = formData.value[key] const value = formData.value
let flag = value === null || value === '' let flag = (value as UTSJSONObject)[key] == ''
if (key == 'phoneNumber') { if (key == 'phoneNumber') {
const phoneValue = formData.value[key] as string const phoneValue = (value as UTSJSONObject)[key] as string
if (phoneValue !== null && phoneValue !== '') { if (phoneValue !== null && phoneValue !== '') {
flag = phoneRex.test(phoneValue) == false flag = phoneRex.test(phoneValue) == false
} }
} }
console.log(errorTip.value , flag)
return errorTip.value && flag return errorTip.value && flag
} }
function showPopup(item: FormObjectItem): void { function showPopup(item: FormObjectItem): void {
let { customerType } = props if (props.customerType == 0 || (item.disabled === true)) return
if (customerType == 0 || (item.disabled === true)) return
const popKey = item.popKey !== null ? item.popKey : '' const popKey = item.popKey !== null ? item.popKey : ''
const refValue = getRefValue(popKey) const refValue = getRefValue(popKey)
if (refValue != null) { if (refValue != null) {
...@@ -318,11 +313,11 @@ ...@@ -318,11 +313,11 @@
} }
} }
function close(): void { function close(): void {
errorTip.value = false
receptionStatus.value = -1
if (formRef.value != null) { if (formRef.value != null) {
(formRef.value as ComponentPublicInstance).$callMethod('close') (formRef.value as ComponentPublicInstance).$callMethod('hide')
} }
errorTip.value = false
receptionStatus.value = ''
} }
// 取消 // 取消
function cancel(): void { function cancel(): void {
...@@ -337,13 +332,13 @@ ...@@ -337,13 +332,13 @@
formObject.value.forEach(e => { formObject.value.forEach(e => {
if (e.required == true) { if (e.required == true) {
const value = formData.value[e.key] const value = formData.value
if (value === null || value === '') { if (value == null || (value as UTSJSONObject)[e.key] == '') {
flag = false flag = false
return return
} }
if (!all && e.key == 'phoneNumber') { if (!all && e.key == 'phoneNumber') {
const phoneValue = formData.value[e.key] as string const phoneValue = (value as UTSJSONObject)[e.key] as string
if (phoneValue !== null && phoneValue !== '' && phoneRex.test(phoneValue) == false) { if (phoneValue !== null && phoneValue !== '' && phoneRex.test(phoneValue) == false) {
uni.showToast({ uni.showToast({
title: "请输入正确的车主电话", title: "请输入正确的车主电话",
...@@ -359,11 +354,11 @@ ...@@ -359,11 +354,11 @@
return flag return flag
} }
function success(receptionStatus: number): void { function success(): void {
if (successRef.value != null) { if (successRef.value != null) {
(successRef.value as ComponentPublicInstance).$callMethod('open') (successRef.value as ComponentPublicInstance).$callMethod('open')
} }
emit('submit', receptionStatus) emit('submit')
} }
// 保存 // 保存
function submit(): void { function submit(): void {
...@@ -373,41 +368,43 @@ ...@@ -373,41 +368,43 @@
const sceneType = props.sceneType const sceneType = props.sceneType
if (sceneType == 0) step.value = 2 if (sceneType == 0) step.value = 2
else { else {
receptionStatus.value = 1 receptionStatus.value = '1'
success(receptionStatus.value) success()
} }
} }
} else { } else {
if (receptionStatus.value == -1) { if (receptionStatus.value == '') {
uni.showToast({ uni.showToast({
title: '请完善本次接待结果', title: '请完善本次接待结果',
icon: 'none' icon: 'none'
}) })
return return
} }
success(receptionStatus.value) success()
} }
} }
function inputCustomer(): void { function inputCustomer(): void {
dispatch('setCustomerInfo', formData.value) dispatch('setCustomerInfo', formData.value as any)
} }
function handleSelect(item: IUTSObject, popkey: string): void { function handleSelect(item: IUTSObject, popkey: string): void {
const customerInfo = dispatch('getCustomerInfo') as IUTSObject const customerInfo = dispatch('getCustomerInfo') as IUTSObject
const value = formData.value as UTSJSONObject
if (popkey == "employeeBoxVisible") { if (popkey == "employeeBoxVisible") {
formData.value.salesUuid = item['uuid'] as string
formData.value.staffName = item['staffName'] as string (value as UTSJSONObject).salesUuid = item['uuid'] as string
dispatch("setCustomerInfo", { ...customerInfo, ...formData.value }) (value as UTSJSONObject).staffName = item['staffName'] as string
dispatch("setCustomerInfo", { ...customerInfo, ...value })
} else { } else {
if (carBrandListVisible.value != null) { if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('close') (carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
} }
formData.value.carModel = item['name'] as string (value as UTSJSONObject).carModel = item['name'] as string
formData.value.carModelId = item['id'] as string (value as UTSJSONObject).carModelId = item['id'] as number
} }
formData.value = value
selectKey.value = Date.now() selectKey.value = Date.now()
} }
...@@ -415,9 +412,9 @@ ...@@ -415,9 +412,9 @@
const customerInfo = dispatch('getCustomerInfo') const customerInfo = dispatch('getCustomerInfo')
if (customerInfo != null) { if (customerInfo != null) {
formData.value = customerInfo as FormData formData.value = customerInfo as UTSJSONObject
let { sceneType, customerType } = props let _sceneType = props.sceneType
let _customerType = props.customerType
let stepValue = 1 let stepValue = 1
const keys = ['customerName', 'carModel', 'phoneNumber'] const keys = ['customerName', 'carModel', 'phoneNumber']
...@@ -432,11 +429,11 @@ ...@@ -432,11 +429,11 @@
} }
errorTip.value = false errorTip.value = false
if (sceneType == 1) { if (_sceneType == 1) {
stepValue = 1 stepValue = 1
formObject.value = formObject_boutique formObject.value = formObject_boutique
const checkResult = check() const checkResult = check()
if (customerType == 0 && !checkResult) { if (_customerType == 0 && !checkResult) {
emit('back') emit('back')
return return
} }
...@@ -456,7 +453,7 @@ ...@@ -456,7 +453,7 @@
} }
} }
function chooseResult(val: number): void { function chooseResult(val: string): void {
receptionStatus.value = val receptionStatus.value = val
dispatch('setReceptionStatus', val) dispatch('setReceptionStatus', val)
} }
...@@ -479,16 +476,22 @@ ...@@ -479,16 +476,22 @@
step.value = stepValue step.value = stepValue
} }
defineExpose({ open, close }) defineExpose({ open, close })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
.content{
width: 100%;
flex-direction: column;
}
.pop-tips { .pop-tips {
width: 100%;
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 10rpx 24rpx;
/* padding: 24rpx 80rpx 24rpx; */
margin-top: 30rpx; margin-top: 30rpx;
text-align: center; text-align: center;
} }
...@@ -509,6 +512,7 @@ ...@@ -509,6 +512,7 @@
padding-top: 30rpx; padding-top: 30rpx;
&-item { &-item {
width: 100%;
display: flex; display: flex;
align-items: center; align-items: center;
color: #6c6c70; color: #6c6c70;
...@@ -538,7 +542,8 @@ ...@@ -538,7 +542,8 @@
} }
.value { .value {
width: 520rpx; /* width: 520rpx; */
width:68%;
height: 80rpx; height: 80rpx;
border: 2rpx solid #e8e8ea; border: 2rpx solid #e8e8ea;
background: #ffffff; background: #ffffff;
......
<template> <template>
<CustomPopup <un-popup :show="visible" @close="onClose" @open="open" :mode="position">
ref="popupRef"
:visible="visible"
:position="position"
:mask-closable="false"
:duration="300"
@update:visible="visible = $event as Boolean"
@close="onClose"
>
<view <view
:class="['tips-wrapper',{'radius': position === 'center'}]" :class="['tips-wrapper',{'radius': position === 'center'}]"
:style="{ width: (popupW ?? 0) + 'rpx', minHeight: (popupH ?? 0) + 'rpx', maxHeight: (maxHeight ?? 0) + 'rpx' }" :style="popupStyle"
> >
<view class="tips-content"> <view class="tips-content">
<view <view
class="icon-close-box flex" class="icon-close-box flex"
@click="close" @click="hide"
> >
<uni-icons <uni-icons
class="icon-close" class="icon-close"
...@@ -29,7 +21,7 @@ ...@@ -29,7 +21,7 @@
<template v-if="back"> <template v-if="back">
<view <view
class="sprite-icon icon-back" class="sprite-icon icon-back"
@click="close" @click="hide"
> >
</view> </view>
</template> </template>
...@@ -65,11 +57,10 @@ ...@@ -65,11 +57,10 @@
</slot> </slot>
</template> </template>
</view> </view>
</CustomPopup> </un-popup>
</template> </template>
<script setup lang="uts"> <script setup lang="uts">
import CustomPopup from './CustomPopup.uvue'
import { ComponentPublicInstance } from 'vue' import { ComponentPublicInstance } from 'vue'
const props = defineProps({ const props = defineProps({
...@@ -120,7 +111,13 @@ ...@@ -120,7 +111,13 @@
const visible = ref<boolean>(false) const visible = ref<boolean>(false)
const popupRef= ref(null) const popupRef= ref(null)
const popupStyle = computed(() => {
return {
width: props.popupW != null && props.popupW > 0 ? (props.popupW ?? 0) + 'rpx' : '100%',
minHeight: props.popupH != null && props.popupH > 0 ? (props.popupH ?? 0) + 'rpx' : '100%',
maxHeight: props.maxHeight != null && props.maxHeight > 0 ? (props.maxHeight ?? 0) + 'rpx' : '100%'
}
})
function onClose(): void { function onClose(): void {
emit('close') emit('close')
} }
...@@ -135,7 +132,9 @@ ...@@ -135,7 +132,9 @@
} }
emit('close') emit('close')
} }
function hide(): void {
visible.value = false
}
function open(): void { function open(): void {
visible.value = true visible.value = true
} }
...@@ -154,7 +153,7 @@ ...@@ -154,7 +153,7 @@
emit('confirm') emit('confirm')
} }
defineExpose({ open, close }) defineExpose({ open, close ,hide })
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
...@@ -162,13 +161,14 @@ ...@@ -162,13 +161,14 @@
background: #ffffff; background: #ffffff;
border-radius: 20rpx 20rpx 0 0; border-radius: 20rpx 20rpx 0 0;
height: 100%; height: 100%;
flex-direction: column;
.tips-content { .tips-content {
width: 100%;
padding: 48rpx; padding: 48rpx;
box-sizing: border-box; box-sizing: border-box;
height: calc(100% - 100rpx); height: calc(100% - 100rpx);
position: relative; position: relative;
flex-direction: column;
.icon-close-box { .icon-close-box {
position: absolute; position: absolute;
right: 0; right: 0;
...@@ -230,6 +230,7 @@ ...@@ -230,6 +230,7 @@
text-align: center; text-align: center;
line-height: 44rpx; line-height: 44rpx;
font-weight: 500; font-weight: 500;
justify-content: center;
} }
} }
.radius{ .radius{
......
<template> <template>
<view class="tool-box" :style="toolStyle as string"> <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,7 +10,7 @@ ...@@ -10,7 +10,7 @@
文件夹 文件夹
</view> </view>
<view class="list-body"> <view class="list-body">
<template v-for="(item, index) in displayData" :key="index"> <template v-for="(item, index) in (displayData as Array<ToolItem>)" :key="index">
<view :class="['item', { active: item.id == props.id }]" @click="jump(item)"> <view :class="['item', { active: item.id == props.id }]" @click="jump(item)">
<image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" /> <image class="icon" :src="item.shortTitleUrl" mode="scaleToFill" />
{{ item.shortTitle }} {{ item.shortTitle }}
...@@ -52,7 +52,10 @@ ...@@ -52,7 +52,10 @@
const props = defineProps({ const props = defineProps({
type: String, type: String,
data: Array as () => Array<ToolItem>, data:{
type: Array,
default: () => []
},
id: [String, Number], id: [String, Number],
showPayBtn: Boolean, showPayBtn: Boolean,
idKey: { idKey: {
...@@ -64,11 +67,17 @@ ...@@ -64,11 +67,17 @@
const show = ref<boolean>(true) const show = ref<boolean>(true)
const displayData = computed<Array<ToolItem>>(() => { const displayData = computed(() => {
if (props.data == null) { if (props.data == null) {
return [] return [] as Array<ToolItem>
} }
return props.data as Array<ToolItem> return (props.data as Array<UTSJSONObject>).map(element => {
return {
id: element.id,
shortTitleUrl: element.shortTitleUrl as string,
shortTitle: element.shortTitle as string
} as ToolItem
})
}) })
const watchStatus = computed(() => { const watchStatus = computed(() => {
......
<template>
<view class="reception">
<image :src="(props.views as UTSJSONObject).detailUrl" class="reception-image">
</image>
</view>
</template>
<script setup lang="uts">
const props = defineProps({
views: UTSJSONObject,
title: String,
show: Boolean
})
</script>
<style lang="scss">
.reception {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
.reception-image {
width: 100%;
height: 100%;
}
}
</style>
...@@ -53,39 +53,49 @@ function setViewInfo(data: any): void { ...@@ -53,39 +53,49 @@ function setViewInfo(data: any): void {
const dataObj = data as UTSJSONObject; const dataObj = data as UTSJSONObject;
moduleList.value = dataObj.moduleList as Array<any>; moduleList.value = dataObj.moduleList as Array<any>;
toolList.value = dataObj.toolList as Array<any>; toolList.value = dataObj.toolList as Array<any>;
mediaId.value = dataObj.id as string; const idValue = dataObj.id;
mediaId.value = typeof idValue === 'number' ? idValue.toString() : (idValue as string) ?? '';
loadComplete.value = true; loadComplete.value = true;
// 将 state.user 转换为 UTSJSONObject 后合并 // 直接将数据属性设置到 state.user 上
const userState = state.user as UTSJSONObject; // const userState = state.user as UserStateType;
for (const key in dataObj) { // for (const key in dataObj) {
if (key !== "moduleList" && key !== "toolList" && key !== "id") { // if (key !== "moduleList" && key !== "toolList" && key !== "id") {
userState[key] = dataObj[key]; // (userState as any)[key] = dataObj[key];
} // }
} // }
// state.user = userState as UserStateType
} }
function handleStart(): void { function handleStart(): void {
const currentModuleList = moduleList.value; // const currentModuleList = moduleList.value;
if (currentModuleList.length === 0) { // if (currentModuleList.length === 0) {
return uni.showToast({ // return uni.showToast({
title: "该场景尚未配置素材,请联系总部人员", // title: "该场景尚未配置素材,请联系总部人员",
icon: "none" // icon: "none"
}); // });
} // }
const firstItem = currentModuleList[0] as UTSJSONObject; // const firstItem = currentModuleList[0] as UTSJSONObject;
const firstId = firstItem.id as string; // const firstId = firstItem.id as number;
uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` }); // uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` });
uni.navigateTo({ url: `/pages/equity/detail/index` });
} }
async function getSoure(brandIdList: string[], subBrandIdList: string[]): Promise<void> { async function getSoure(brandIdList: number[], subBrandIdList: number[]): Promise<void> {
const userInfo = storage.get("userInfo") as UTSJSONObject; const userInfo = storage.get("userInfo") as UTSJSONObject;
const shopMerchantId: string = (userInfo.shopMerchantId as string) ?? ""; const shopMerchantId: string = (userInfo.shopMerchantId as string) ?? "";
const sceneType: number = (userInfo.sceneType as number) ?? 0; const sceneType: number = (userInfo.sceneType as number) ?? 0;
const storageKey = `source_${sceneType}_${shopMerchantId}`; const storageKey = `source_${sceneType}_${shopMerchantId}`;
const data = uni.getStorageSync(storageKey) as UTSJSONObject; const cachedData = uni.getStorageSync(storageKey);
let data: UTSJSONObject | null = null;
if (cachedData != null && cachedData !== '') {
try {
data = JSON.parse(cachedData as string) as UTSJSONObject;
} catch (e) {
console.error('解析缓存数据失败:', e);
}
}
console.log(data)
if (data != null) { if (data != null) {
setViewInfo(data); setViewInfo(data);
} }
...@@ -110,7 +120,7 @@ async function getCarBrandsList(carBrandList: Array<any>, index: number) { ...@@ -110,7 +120,7 @@ async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index] as UTSJSONObject; const item = carBrandList[index] as UTSJSONObject;
if (item == null) return; if (item == null) return;
const storageKey = `${(item.id as string) ?? ""}_${(item.brandId as string) ?? ""}_carlist`; const storageKey = `${(item.id as number)}_${(item.brandId as number)}_carlist`;
const carList = uni.getStorageSync(storageKey); const carList = uni.getStorageSync(storageKey);
if (index < carBrandList.length - 1) { if (index < carBrandList.length - 1) {
...@@ -136,14 +146,13 @@ function get_Vehicle_Sales_Data(): void { ...@@ -136,14 +146,13 @@ function get_Vehicle_Sales_Data(): void {
const shopMerchantId = userInfo.shopMerchantId; const shopMerchantId = userInfo.shopMerchantId;
getMerchantCarBrandList([shopMerchantId ?? ""]).then((res: any) => { getMerchantCarBrandList([shopMerchantId ?? ""]).then((res: any) => {
const resObj = res as UTSJSONObject; const resObj = res as UTSJSONObject;
const data = resObj.data as UTSJSONObject; const dataArray = resObj.data as Array<any>;
const dataArray = data as Array<any>;
const firstItem = dataArray[0] as UTSJSONObject; const firstItem = dataArray[0] as UTSJSONObject;
const carBrandList = [] as any[]; const carBrandList = [] as any[];
const list = firstItem.carBrandList as Array<any>; const list = firstItem.carBrandList as Array<any>;
const brandIdList: string[] = []; const brandIdList: number[] = [];
const subBrandIdList: string[] = []; const subBrandIdList: number[] = [];
list?.forEach((e: any) => { list?.forEach((e: any) => {
const eObj = e as UTSJSONObject; const eObj = e as UTSJSONObject;
const childs = eObj.childs as Array<any>; const childs = eObj.childs as Array<any>;
...@@ -151,16 +160,16 @@ function get_Vehicle_Sales_Data(): void { ...@@ -151,16 +160,16 @@ function get_Vehicle_Sales_Data(): void {
childs.forEach((i: any) => { childs.forEach((i: any) => {
const iObj = i as UTSJSONObject; const iObj = i as UTSJSONObject;
iObj.brandName = (eObj.name as string) ?? ""; iObj.brandName = (eObj.name as string) ?? "";
iObj.brandId = (eObj.id as string) ?? ""; iObj.brandId = (eObj.id as number);
carBrandList.push(iObj); carBrandList.push(iObj);
const idStr: string = (iObj.id as string) ?? ""; const idStr: number = (iObj.id as number);
subBrandIdList.push(idStr); subBrandIdList.push(idStr);
}); });
const idStr: string = (eObj.id as string) ?? ""; const idStr: number = (eObj.id as number);
brandIdList.push(idStr); brandIdList.push(idStr);
}); });
getSoure(brandIdList, subBrandIdList); // getSoure(brandIdList, subBrandIdList);
dispatch("setCarBrandsList", carBrandList); dispatch("setCarBrandsList", carBrandList);
storage.set("carBrandList", carBrandList, 0); storage.set("carBrandList", carBrandList, 0);
if (carBrandList.length > 0) { if (carBrandList.length > 0) {
...@@ -183,11 +192,11 @@ onLoad((options) => { ...@@ -183,11 +192,11 @@ onLoad((options) => {
console.log(mockdata, "==="); console.log(mockdata, "===");
const userInfo = storage.get("userInfo") as UTSJSONObject; const userInfo = storage.get("userInfo") as UTSJSONObject;
const mockDataObj = mockdata as UTSJSONObject; const mockDataObj = mockdata as UTSJSONObject;
const channelType = userInfo.channelType as string; const channelType = userInfo.channelType as number;
if (channelType == "1" && mockDataObj.boutiqueDefaultCarBrandId != null) { if (channelType == 1 && mockDataObj.boutiqueDefaultCarBrandId != null) {
state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as string) ?? ""; // 默认车辆品牌 state.user.boutiqueDefaultCarBrandId = (mockDataObj.boutiqueDefaultCarBrandId as number); // 默认车辆品牌
if (mockDataObj.defaultCarId != null) { if (mockDataObj.defaultCarId != null) {
state.user.defaultCarId = (mockDataObj.defaultCarId as string) ?? "";// 默认车系 state.user.defaultCarId = (mockDataObj.defaultCarId as number);// 默认车系
} }
} }
}); });
......
...@@ -38,13 +38,13 @@ function parseCustomerInfo(raw: any): UTSJSONObject { ...@@ -38,13 +38,13 @@ function parseCustomerInfo(raw: any): UTSJSONObject {
export class UserStateType { export class UserStateType {
static _C: string = "companion"; static _C: string = "companion";
boutiqueCarList: any[] = []; boutiqueCarList: any[] = [];
boutiqueDefaultCarBrandId: string = ""; boutiqueDefaultCarBrandId: number = 0;
boutiqueMediaConfig: Record<string, any> = {} as Record<string, any>; boutiqueMediaConfig: Record<string, any> = {} as Record<string, any>;
carBrands: any[] = []; carBrands: any[] = [];
currentCarInfo: Record<string, any> = {} as Record<string, any>; currentCarInfo: UTSJSONObject = {} as UTSJSONObject;
customerInfo: UTSJSONObject = parseCustomerInfo(storage.get("customerInfo") as any); customerInfo: UTSJSONObject = parseCustomerInfo(storage.get("customerInfo") as any);
customerKey: number = Date.now(); customerKey: number = Date.now();
defaultCarId: string = ""; defaultCarId: number = 0;
employeeList: any[] = []; employeeList: any[] = [];
haveCustomerAccess: boolean = true; haveCustomerAccess: boolean = true;
historyStatus: number = Date.now(); historyStatus: number = Date.now();
...@@ -127,7 +127,7 @@ export const actions = { ...@@ -127,7 +127,7 @@ export const actions = {
return null; return null;
}, },
setCurrentCarInfo: (payload: any): any | null => { setCurrentCarInfo: (payload: any): any | null => {
(state as UserStateType).currentCarInfo = (payload != null ? payload : {}) as Record<string, any>; (state as UserStateType).currentCarInfo = (payload != null ? payload : {}) as UTSJSONObject;
return null; return null;
}, },
getCustomerInfo: (payload: any): any | null => { getCustomerInfo: (payload: any): any | null => {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!