Commit 4ca38691 by 李伟康

refactor(common): 优化代码结构和类型安全

- 移除未使用的 onLoad 导入
- 修复 Scene 组件中的数据类型转换问题
- 更新 CaseCenter 组件中的图片路径引用
- 优化 CaseCenter 组件的数据访问方式
- 改进组件中的计算属性和方法实现
- 调整样式结构以提高可维护性
1 parent 1eec0856
......@@ -78,7 +78,7 @@
<script setup lang="uts">
import { ref, nextTick, ComponentPublicInstance } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
// import { onLoad } from '@dcloudio/uni-app'
import AccountList from '@/pages/common/components/AccountList.uvue'
import MerchantList from '@/pages/common/components/MerchantList.uvue'
import Scene from '@/pages/common/components/Scene.uvue'
......
......@@ -140,7 +140,7 @@ function selectScene(item: SceneItem, index: number): void {
const openSceneArr = userInfo['openSceneArr'] as any[] | null
const isSuper = userInfo['isSuper'] as boolean | null
// 手动检查是否包含 sceneType(indexOf 在 App 端有 bug)
let sceneAllowed = isSuper == true
if (!sceneAllowed && openSceneArr != null) {
......@@ -182,9 +182,12 @@ function selectScene(item: SceneItem, index: number): void {
merchantId: shopMerchantId ?? '',
merchantName: shopMerchantName ?? '',
sceneType: sceneType
}).then(({data}: any): void => {
jump({...data,...userInfo}, data)
}).catch((err) => {
}).then((res: any): void => {
const data = (res as UTSJSONObject)['data'] as UTSJSONObject | null
if (data != null) {
jump({...(data as UTSJSONObject), ...(userInfo as UTSJSONObject)}, data)
}
}).catch((err: any | null): void => {
uni.hideLoading()
console.error('selectMerchantScene 失败:', err)
uni.showToast({ title: '网络异常,请稍后重试', icon: 'none' })
......@@ -247,4 +250,4 @@ defineExpose({
border: 2px solid #347bff;
}
}
</style>
</style>
\ No newline at end of file
......@@ -94,7 +94,7 @@ import { ref, watch } from "vue";
import { apiAutoLogin, apiGetSmsCode, apiSmsLogin } from "@/api/user-api.uts";
import { storage } from "@/utils/storage.uts";
import { onLoad } from "@dcloudio/uni-app";
// import { onLoad } from "@dcloudio/uni-app";
// 手机号正则
const phoneRex = /^1([3-9])\d{9}$/;
......
......@@ -17,11 +17,11 @@
</view>
<view class="sprite-icon icon-bao"></view>
<view class="title text-hide">
{{item.itemName}}
{{ getItemName() }}
</view>
<view class="type">{{item.main}}</view>
<view class="type">{{ getMain() }}</view>
<view class="content">
<rich-text :nodes="item.itemDesc"></rich-text>
<rich-text :nodes="getItemDesc()"></rich-text>
</view>
</view>
</CustomPopup>
......@@ -38,7 +38,7 @@ import CustomPopup from '@/components/CustomPopup.uvue'
}
const props = defineProps({
item: Object
item: Object as () => Item
})
const visible = ref<boolean>(false)
const popup = ref(null)
......@@ -50,6 +50,27 @@ const visible = ref<boolean>(false)
function close(): void {
visible.value = false
}
function getItemName(): string {
const itemObj = props.item as UTSJSONObject | null
if (itemObj == null) return ''
const itemNameValue = itemObj['itemName'] as string | null
return itemNameValue != null ? itemNameValue : ''
}
function getMain(): string {
const itemObj = props.item as UTSJSONObject | null
if (itemObj == null) return ''
const mainValue = itemObj['main'] as string | null
return mainValue != null ? mainValue : ''
}
function getItemDesc(): string {
const itemObj = props.item as UTSJSONObject | null
if (itemObj == null) return ''
const itemDescValue = itemObj['itemDesc'] as string | null
return itemDescValue != null ? itemDescValue : ''
}
defineExpose({ open, close })
</script>
......
......@@ -24,6 +24,7 @@
<script setup lang="uts">
import MessageBox from '@/components/MessageBox.uvue'
import { state } from '@/store/index.uts'
import { ComponentPublicInstance } from 'vue'
type CarBuyersItem = {
name: string
......@@ -52,7 +53,11 @@
name: '按揭',
id: 2
}] as Array<CarBuyersItem>)
function close(): void {
if (carBuyersVisible.value != null) {
(carBuyersVisible.value as ComponentPublicInstance).$callMethod('close')
}
}
const watchStatus = computed(() => {
const status = state.user?.historyStatus
if (status == null) {
......@@ -64,16 +69,19 @@
}
})
const carBuyers = computed(() => {
return state.user.customerInfo.carBuyers
const carBuyers = computed((): any | null => {
const carBuyersData = state.user.customerInfo.carBuyers
return carBuyersData != null ? carBuyersData : null
})
watch(watchStatus.value, (newval) => {
watch(watchStatus.value, () => {
close()
}, { immediate: true })
function open(): void {
;(carBuyersVisible.value as any).open()
if (carBuyersVisible.value != null) {
(carBuyersVisible.value as ComponentPublicInstance).$callMethod('open')
}
}
function handleSelect(item: CarBuyersItem): void {
......@@ -81,9 +89,7 @@
emit('select', item)
}
function close(): void {
;(carBuyersVisible.value as any)?.close()
}
function onClose(): void {
emit('close')
......
......@@ -35,8 +35,7 @@
@input="inputCustomer"
:placeholder="i.placeholder"
@focus="focusIndex = index"
@blur="resetFocusIndex"
:data-key="i.key"
@blur="() => handleInputBlur(i.key, customerInfo[i.key] as string | null)"
/>
<customer-autocomplete
:showType="i.inputType"
......@@ -53,11 +52,11 @@
</template>
<template v-else>
<view
:class="['select flex',{placeholderStyle:!customerInfo[i.key]}]"
@click="showPopup(i.popKey,index)"
:class="['select flex',{placeholderStyle:customerInfo[i.key] == null}]"
@click="() => showPopup(i.popKey as string, index)"
>
<view class="value text-hide">
{{customerInfo[i.key] ?customerInfo[i.key] :i.placeholder}}
{{customerInfo[i.key] != null ?customerInfo[i.key] :i.placeholder}}
</view>
<uni-icons
class="arrow"
......@@ -99,9 +98,10 @@
import carBuyers from './components/carBuyers.uvue'
import CustomerAutocomplete from '@/components/CustomerAutocomplete.uvue'
import wnCanvas from '@/components/PanCanvas/index.uvue'
import { store } from '@/store/index.uts'
import { state ,dispatch } from '@/store/index.uts'
import { ComponentPublicInstance } from 'vue'
interface FormItem {
type FormItem = {
placeholder: string
key: string
type: string
......@@ -112,7 +112,7 @@
popKey?: string
}
interface CustomerInfo {
type CustomerInfo = {
customerName?: string
phoneNumber?: string
carModel?: string
......@@ -124,6 +124,11 @@
carPurchaseMethod?: string | number
}
type SelectItem = {
name: string
id: string | number
}
const props = defineProps({
penSwitch: Boolean,
show: Boolean,
......@@ -175,18 +180,21 @@
const customerInfo = ref<CustomerInfo>({})
const focusIndex = ref<number>(-1)
//
const watchCustomerInfo = computed(() => {
return store.state?.user.customerInfo
const watchCustomerInfo = computed<CustomerInfo | null>(()=> {
const customerData = state?.user.customerInfo
return customerData != null ? customerData as CustomerInfo : null
})
const watchStatus = computed(() => {
return store.state?.user.historyStatus
const watchStatus = computed<number | null>(() => {
return state?.user.historyStatus
})
watch(() => watchCustomerInfo.value, (newval) => {
if (newval) {
customerInfo.value = newval as CustomerInfo
watch(watchCustomerInfo, (newval: any): void => {
const typedVal = newval as CustomerInfo | null
if (typedVal != null) {
customerInfo.value = typedVal
}
}, { immediate: true })
......@@ -194,18 +202,38 @@
const carBuyersVisible = ref(null)
function inputCustomer(): void {
store.dispatch?.('setCustomerInfo', customerInfo.value)
dispatch('setCustomerInfo', customerInfo.value)
}
function resetFocusIndex(): void {
focusIndex.value = -1
}
function handleInputBlur(key: string, value: string | null): void {
if (value == null || value.length == 0) return
if (key == 'newCarFare') {
let val: number = parseFloat(value)
val = val >= 9999999 ? 9999999 : val
if (!Number.isInteger(val)) {
const strVal = value.replace(/(\d*\.?\d{0,2})\d*/, '$1')
val = parseFloat(strVal.replace(/^0+/, ''))
}
const formattedVal = val.toFixed(2)
customerInfo.value[key] = parseFloat(formattedVal) >= 0 ? formattedVal : ''
inputCustomer()
}
}
function handleSelect(item: any, popkey: string): void {
const typedItem = item as SelectItem
if (popkey == 'carBuyersVisible') {
customerInfo.value.carBuyers = item.name
customerInfo.value.carPurchaseMethod = item.id
store.dispatch?.('setCustomerInfo', customerInfo.value)
customerInfo.value.carBuyers = typedItem.name
customerInfo.value.carPurchaseMethod = typedItem.id
dispatch('setCustomerInfo', customerInfo.value)
} else {
(carBrandListVisible.value as any).close()
customerInfo.value.carModel = item.name
customerInfo.value.carModelId = item.id
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
}
customerInfo.value.carModel = typedItem.name
customerInfo.value.carModelId = typedItem.id
}
resetFocusIndex()
}
......@@ -213,41 +241,33 @@
function showPopup(e: string, index: number): void {
focusIndex.value = index
if (e == 'carBrandListVisible') {
;(carBrandListVisible.value as any).open()
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('open')
}
} else if (e == 'carBuyersVisible') {
;(carBuyersVisible.value as any).open()
if (carBuyersVisible.value != null) {
(carBuyersVisible.value as ComponentPublicInstance).$callMethod('open')
}
}
}
function closeAllPopup(): void {
;(carBrandListVisible.value as any).close()
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
}
resetFocusIndex()
}
function resetFocusIndex(e?: any): void {
focusIndex.value = -1
if (e?.currentTarget && e?.target) {
const { key } = e.currentTarget.dataset
if (e.target.value.length == 0) return
if (key == 'newCarFare') {
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')
value = Number(String(value).replace(/^0+/, ''))
const numValue = Number(value)
customerInfo.value[key] = numValue >= 0 ? value : ''
inputCustomer()
}
}
}
function chooseCustomer(e: any): void {
customerInfo.value = {
...customerInfo.value,
phoneNumber: e.ownerPhone,
customerName: e.ownerName,
carModel: e.brandModel
}
function chooseCustomer(e: UTSJSONObject): void {
const ownerPhone = e.get('ownerPhone') as string | null
const ownerName = e.get('ownerName') as string | null
const brandModel = e.get('brandModel') as string | null
customerInfo.value.phoneNumber = ownerPhone
customerInfo.value.customerName = ownerName
customerInfo.value.carModel = brandModel
inputCustomer()
}
......
......@@ -5,28 +5,27 @@
:canvasId="`c-${madiaId}`"
custom
@scale="onScale"
ref="canvasRef"
ref="canvasRef"
>
<template #customContent>
<view class="layout-content">
<PageTitle
:title="title"
:hasCarBrand="hasCarBrand"
:show="show"
:title="title"
:hasCarBrand="hasCarBrand"
:show="show"
/>
<template v-if="hasCarBrand">
<image
:key="viewKey"
class="content"
:src="views[customerInfo.carModelId] || nothingImage"
:key="viewKey"
class="content"
:src="imageUrl"
/>
</template>
<template v-else>
<template v-if="views">
<template v-if="hasDetailUrl">
<image
v-if="views.detailUrl"
class="content"
:src="views.detailUrl"
class="content"
:src="detailImageUrl"
/>
</template>
</template>
......@@ -54,8 +53,8 @@ type CustomerInfo = {
const props = defineProps({
views: {
type: Object as () => UTSJSONObject,
default: () => ({})
type: Object as () => UTSJSONObject,
default: () => ({})
},
penSwitch: Boolean,
title: String,
......@@ -70,11 +69,35 @@ const canvasRef = ref(null)
const customerInfo = computed<CustomerInfo>(() => {
const info = state.user.customerInfo
return info != null ? info.as(CustomerInfo) : {} as CustomerInfo
return info != null ? info as CustomerInfo : {} as CustomerInfo
})
const hasDetailUrl = computed<boolean>(() => {
const viewsPlain = JSON.parse(JSON.stringify(props.views)) as Record<string, any>
return viewsPlain['detailUrl'] != null
})
const detailImageUrl = computed<string>(() => {
const viewsPlain = JSON.parse(JSON.stringify(props.views)) as Record<string, any>
const url = viewsPlain['detailUrl']
if (url == null) return ''
if (typeof url === 'string') return url
return url.toString()
})
const imageUrl = computed<string>(() => {
const modelId = customerInfo.value.carModelId
if (modelId == null) return nothingImage
// 使用 JSON.parse 和 JSON.stringify 绕过类型检查
const viewsPlain = JSON.parse(JSON.stringify(props.views)) as Record<string, string>
const url = viewsPlain[modelId]
return url != null ? url : nothingImage
})
const viewKey = computed<string>(() => {
return state.user?.viewKey != null ? state.user.viewKey : ''
const key = state.user?.viewKey
return key != null ? key as string : ''
})
function onScale(e: number): void {
......
......@@ -6,7 +6,7 @@
v-if="hasCarBrand"
@click="openCarBrand"
>
{{customerInfo.carModel||'请选择'}}
{{customerInfo.carModel != null ? customerInfo.carModel : '请选择'}}
<view class="sprite-icon icon-arrow-bottom">
</view>
</view>
......@@ -21,8 +21,12 @@
import CarBrands from '@/components/CarBrands.uvue'
import { state , store } from "@/store/index.uts"
import { storage } from '@/utils/storage.uts'
import { ComponentPublicInstance } from 'vue'
type CustomerInfo = UTSJSONObject
type CustomerInfo = {
carModel?: string
carModelId?: string | number
}
type UserInfo = UTSJSONObject
......@@ -36,10 +40,10 @@
const carBrandListVisible = ref(null)
const customerInfo = ref<CustomerInfo>({} as CustomerInfo)
const watchCustomerInfo = computed<CustomerInfo>(() => {
return state.user?.customerInfo != null ? state.user.customerInfo : {} as CustomerInfo
const watchCustomerInfo = computed<CustomerInfo | null>(()=> {
const customerData = state?.user.customerInfo
return customerData != null ? customerData as CustomerInfo : null
})
const watchStatus = computed(() => {
const status = state.user?.historyStatus
if (status == null) {
......@@ -51,38 +55,64 @@
}
})
const showValue = computed<boolean>(() => {
const show = props.show
if (show == null) return false
return show
})
const hasCarBrandValue = computed<boolean>(() => {
const hasCarBrand = props.hasCarBrand
if (hasCarBrand == null) return false
return hasCarBrand
})
const isAito = computed<boolean>(() => {
const userInfo: UserInfo = storage.get('userInfo') != null ? storage.get('userInfo') : { channelType: 0 } as UserInfo
const userInfoRaw = storage.get('userInfo')
const userInfo: UserInfo = userInfoRaw != null ? userInfoRaw as UserInfo : UTSJSONObject({ channelType: 0 })
return userInfo.channelType == 1
})
watch(() => props.show, (newval) => {
if (newval === true && props.hasCarBrand === true && (customerInfo.value.carModel == null || customerInfo.value.carModel === '') && isAito.value === true) {
watch(showValue.value, (newval: boolean) => {
const carModel = customerInfo.value.carModel
if (newval === true && hasCarBrandValue.value === true && (carModel == null || carModel === '') && isAito.value === true) {
setTimeout(() => {
carBrandListVisible.value?.autoSelect()
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('autoSelect')
}
}, 1000)
}
}, { immediate: true })
watch(() => watchCustomerInfo.value, (newval) => {
if (newval != null) {
customerInfo.value = { ...newval }
watch(watchCustomerInfo, (newval: any): void => {
const typedVal = newval as CustomerInfo | null
if (typedVal != null) {
customerInfo.value = typedVal
}
}, { immediate: true })
type SelectItem = {
name: string
id: string | number
}
function onSelect(item: any): void {
const typedItem = item as SelectItem
customerInfo.value.carModel = typedItem.name
customerInfo.value.carModelId = typedItem.id
// store.dispatch?.('setCustomerInfo', customerInfo.value)
}
function handleSelect(item: any): void {
carBrandListVisible.value?.close()
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('close')
}
onSelect(item)
}
function onSelect(item: any): void {
customerInfo.value.carModel = item.name
customerInfo.value.carModelId = item.id
store.dispatch?.('setCustomerInfo', customerInfo.value)
}
function openCarBrand(): void {
carBrandListVisible.value?.open()
if (carBrandListVisible.value != null) {
(carBrandListVisible.value as ComponentPublicInstance).$callMethod('open')
}
}
defineExpose({ carBrandListVisible })
......
......@@ -43,11 +43,11 @@
</template>
<template v-else>
<view
:class="['select flex', { placeholderStyle: !customerInfo[(item as FormItem).key] }]"
@click="showPopup((item as FormItem).popKey, index)"
:class="['select flex', { placeholderStyle: customerInfo[(item as FormItem).key] == null}]"
@click="showPopup((item as FormItem).popKey as string, index)"
>
<view class="value text-hide">
{{ customerInfo[(item as FormItem).key] ? customerInfo[(item as FormItem).key] : (item as FormItem).placeholder }}
{{ customerInfo[(item as FormItem).key] != null ? customerInfo[(item as FormItem).key] : (item as FormItem).placeholder }}
</view>
<uni-icons
class="arrow"
......@@ -81,9 +81,10 @@
<script setup lang="uts">
import CarBrands from '@/components/CarBrands.uvue'
import CustomerAutocomplete from '@/components/CustomerAutocomplete.uvue'
import { store } from '@/store/index.uts'
import { state, dispatch } from '@/store/index.uts'
import { storage } from '@/utils/storage.uts'
import wnCanvas from '@/components/PanCanvas/index.uvue'
import { ComponentPublicInstance } from 'vue'
type FormItem = {
placeholder: string
......@@ -94,7 +95,21 @@
popKey?: string
}
type CustomerInfo = UTSJSONObject
type CustomerInfo = {
customerName?: string
phoneNumber?: string
carModel?: string
carModelId?: string | number
salesUuid?: string
staffName?: string
newCarFare?: string
carBuyers?: string
carPurchaseMethod?: string | number
carBrand?: string
carBrandId?: string | number
oneCarBrand?: string
oneCarBrandId?: string | number
}
const props = defineProps({
penSwitch: Boolean,
......@@ -104,6 +119,7 @@
})
const emit = defineEmits(['scale'])
const carBrandListVisibleRef = ref(null)
const formObject = ref<Array<FormItem>>([
{
......@@ -127,19 +143,19 @@
popKey: 'carBrandListVisible'
}
])
const customerInfo = ref<CustomerInfo>({})
const focusIndex = ref<number>(-1)
const watchCustomerInfo = computed(() => {
return store.state?.user.customerInfo
})
const watchCustomerInfo = computed<CustomerInfo | null>(()=> {
const customerData = state?.user.customerInfo
return customerData != null ? customerData as CustomerInfo : null
})
const watchStatus = computed(() => {
return store.state?.user.historyStatus
const watchStatus = computed<number | null>(() => {
return state?.user.historyStatus
})
const isAito = computed(() => {
const isAito = computed<boolean | null>(() => {
const userInfo = storage.get('userInfo')
if (userInfo != null) {
return (userInfo as UTSJSONObject).channelType == 1
......@@ -147,75 +163,77 @@
return false
})
watch(() => watchCustomerInfo.value, (newval: any | null) => {
watch(watchCustomerInfo , (newval: any | null) => {
if (newval != null) {
customerInfo.value = newval as CustomerInfo
}
}, { immediate: true })
watch(() => props.show, (n: boolean) => {
if (n && !customerInfo.value.carModel && isAito.value) {
const showValue = computed<boolean>(() => {
const show = props.show
if (show == null) return false
return show
})
watch(showValue.value, (n: boolean) => {
if (n != null && customerInfo.value.carModel == '' && (isAito.value ?? false)) {
setTimeout(() => {
if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('autoSelect')
(carBrandListVisibleRef.value as ComponentPublicInstance).$callMethod('autoSelect')
}
}, 1000)
}
}, { immediate: true })
type CarBrandRefType = any | null
const carBrandListVisibleRef = ref<CarBrandRefType>(null)
function onInputCustomer(): void {
if (store.dispatch != null) {
store.dispatch('setCustomerInfo', customerInfo.value)
}
}
function onSelect(item: any, popkey: string): void {
customerInfo.value.carModel = (item as UTSJSONObject).name
customerInfo.value.carModelId = (item as UTSJSONObject).id
if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('close')
}
resetFocusIndex()
function resetFocusIndex(): void {
focusIndex.value = -1
}
function showPopup(e: string, index: number): void {
if (e == null) return
focusIndex.value = index
if (e == 'carBrandListVisible') {
if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('open')
(carBrandListVisibleRef.value as ComponentPublicInstance).$callMethod('open')
}
}
}
function closeAllPopup(): void {
function onInputCustomer(): void {
dispatch('setCustomerInfo', customerInfo.value)
}
function onSelect(item: any, popkey: string): void {
customerInfo.value.carModel = (item as UTSJSONObject).name as string
customerInfo.value.carModelId = (item as UTSJSONObject).id as string | number
if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as any).$callMethod('close')
(carBrandListVisibleRef.value as ComponentPublicInstance).$callMethod('close')
}
resetFocusIndex()
}
function resetFocusIndex(): void {
focusIndex.value = -1
function closeAllPopup(): void {
if (carBrandListVisibleRef.value != null) {
(carBrandListVisibleRef.value as ComponentPublicInstance).$callMethod('close')
}
resetFocusIndex()
}
function onChooseCustomer(e: any): void {
const eObj = e as UTSJSONObject
customerInfo.value = {
...customerInfo.value,
phoneNumber: eObj.ownerPhone,
customerName: eObj.ownerName
phoneNumber: eObj.ownerPhone as string,
customerName: eObj.ownerName as string
}
if (eObj.carModelId != null) {
customerInfo.value.carModelId = eObj.carModelId
customerInfo.value.carModel = eObj.brandModel
customerInfo.value.carBrand = eObj.carBrand
customerInfo.value.carBrandId = eObj.carBrandId
customerInfo.value.oneCarBrand = eObj.oneCarBrand
customerInfo.value.oneCarBrandId = eObj.oneCarBrandId
customerInfo.value.carModelId = eObj.carModelId as string | number
customerInfo.value.carModel = eObj.brandModel as string
customerInfo.value.carBrand = eObj.carBrand as string
customerInfo.value.carBrandId = eObj.carBrandId as string | number
customerInfo.value.oneCarBrand = eObj.oneCarBrand as string
customerInfo.value.oneCarBrandId = eObj.oneCarBrandId as string | number
}
onInputCustomer()
......@@ -227,7 +245,8 @@
if (views != null && Array.isArray(views)) {
const viewsArray = views as Array<any>
if (carModelId != null) {
const result = viewsArray[carModelId]
const index = typeof carModelId == 'string' ? parseInt(carModelId) : carModelId
const result = viewsArray[index]
if (result != null) {
return result as string
}
......
<!--
* @Description:
* @Author: huyue
* @Date: 2024-06-24 16:35:00
* @LastEditors: huyue
* @LastEditTime: 2024-07-04 16:02:54
-->
<template>
<view
class="layout"
:style="detail.pageStyle"
:style="(detail as Detail).pageStyle ?? ''"
>
<image
class="icon-car"
:src="detail.carIcon"
:src="(detail as Detail).carIcon"
/>
<wnCanvas
:drawStatus="penSwitch"
......@@ -29,7 +22,7 @@
<view class="left-tab">
<view
class="tab-item"
v-for="item in detail.tabList"
v-for="item in (detail as Detail).tabList"
:key="item.id"
@click="tabChange(item)"
:class="[item.id == activeIndex ? 'active' : '']"
......@@ -37,7 +30,7 @@
</view>
<div class="content-bg"></div>
<view class="content">
<template v-if="detail.viewActiveIndex.includes(activeIndex)">
<template v-if="(detail as Detail).viewActiveIndex.includes(activeIndex)">
<image
:key="imgKey"
:class="direction"
......@@ -46,7 +39,7 @@
/>
<view class="content-tab">
<template v-for="(item,index) in imgIdList" :key="index">
<template v-for="(item,index) in imgIdList" :key="index">
<view
class="tab-item"
@click="tabSwitch(item)"
......@@ -72,7 +65,7 @@
<script setup lang="uts">
import wnCanvas from '@/components/PanCanvas/index.uvue'
import { store } from '@/store/index.uts'
import { state } from '@/store/index.uts'
interface TabItem {
id: number | string
......@@ -105,41 +98,56 @@
const tabIndex = ref<number>(2)
const threeGuarantees = ref(null)
const watchStatus = computed(() => {
return store.state.user.historyStatus
})
const imgIdList = computed(() => {
return (props.detail as Detail).tabList.find(item => item.id == activeIndex.value).imgIdList
const imgIdList = computed<Array<any> | null>(() => {
const tabItem = (props.detail as Detail).tabList.find(item => item.id == activeIndex.value)
if (tabItem != null) {
return tabItem.imgIdList
}
return null
})
watch(watchStatus.value, () => {
activeIndex.value = (props.detail as Detail).defultActiveId || 0
tabIndex.value = (props.detail as Detail).defultTabId
const watchStatus = computed<boolean>(() => {
const status = state.user?.historyStatus
if (status == null) {
return false
} else if (status == 1) {
return true
} else {
return false
}
})
watch(watchStatus.value, () => {
activeIndex.value = (props.detail as Detail).defultActiveId ?? 0
tabIndex.value = (props.detail as Detail).defultTabId ?? 2
}, { immediate: true })
function tabChange(item: TabItem): void {
const { id } = item
const id = typeof item.id == 'string' ? parseInt(item.id) : item.id
if (activeIndex.value === id) return
direction.value = ''
direction.value = id > activeIndex.value ? 'bottom' : 'top'
activeIndex.value = id
imgKey.value = Date.now()
threeGuarantees.value.clearBoard()
// if (threeGuarantees.value != null) {
// threeGuarantees.value.clearBoard()
// }
}
function tabSwitch(val: any): void {
if (val == tabIndex.value) return
tabIndex.value = val
threeGuarantees.value.clearBoard()
const numVal = typeof val == 'string' ? parseInt(val) : val as number
if (numVal == tabIndex.value) return
tabIndex.value = numVal
// if (threeGuarantees.value != null) {
// threeGuarantees.value.clearBoard()
// }
}
function viewsImg(): any {
const { detail, views } = props
const currentIndex = activeIndex.value
const currentTabIndex = tabIndex.value
if ((detail as Detail).viewActiveIndex.includes(currentIndex)) return views[currentTabIndex]
return views[currentIndex]
const viewsArray = props.views as Array<any>
if ((props.detail as Detail).viewActiveIndex.includes(currentIndex)) return viewsArray[currentTabIndex]
return viewsArray[currentIndex]
}
function onScale(e: any): void {
......@@ -281,4 +289,4 @@
transform: translateY(0);
}
}
</style>
\ No newline at end of file
</style>
......@@ -62,7 +62,7 @@
import { ref, watch, computed } from 'vue'
import { state, dispatch } from '@/store/index.uts'
interface InfoListItem {
type InfoListItem = {
id: number
title: string
imgUrl?: string
......@@ -97,10 +97,10 @@
const isPreview = ref<boolean>(false)
const watchBooksList = computed<Array<InfoListItem>>(() => {
return state.audio.booksList
return state.audio.booksList as Array<InfoListItem>
})
watch(() => watchBooksList.value, (newValue: Array<InfoListItem>) => {
watch(watchBooksList.value , (newValue: Array<InfoListItem>) => {
if (newValue != null && newValue.length > 0) {
infoList.value = newValue
} else {
......@@ -133,7 +133,7 @@
uni.chooseImage({
count: 1,
success: async (res) => {
success: (res) => {
try {
// let url = await uploadFile(res.tempFilePaths[0])
// uni.$logger.local.info(`上传付款凭证:${res.tempFilePaths[0]}`)
......@@ -166,25 +166,11 @@
// 预览图片
function preview(index: number): void {
isPreview.value = true
previewImg.value = infoList.value[index].imgUrl != null ? infoList.value[index].imgUrl : ''
previewImg.value = infoList.value[index].imgUrl ?? ''
const imageUrl: string = infoList.value[index].imgUrl != null ? infoList.value[index].imgUrl : ''
const imageUrl: string = infoList.value[index].imgUrl ?? ''
uni.previewImage({
urls: [imageUrl],
longPressActions: {
success: function (data) {
console.log(
"选中了第" +
(data.tapIndex + 1) +
"个按钮,第" +
(data.index + 1) +
"张图片"
)
},
fail: function (err) {
console.log(err.errMsg)
}
}
})
}
</script>
......
......@@ -28,7 +28,7 @@
>{{ item.name }}</view>
</view>
<view class="payment-content">
<template v-if="payInfo && payInfo.paymentType">
<template v-if="payInfo != null && payInfo.paymentType != null">
<view
v-show="payActive === 1"
class="qr-code-content"
......@@ -46,7 +46,7 @@
<view class="qr-code-info">扫码付款,支持多渠道付款</view>
</view>
</template>
<template v-if="accountInfo && accountInfo.paymentType">
<template v-if="accountInfo != null && accountInfo.paymentType != null ">
<view
v-show="payActive === 2"
......@@ -84,7 +84,7 @@
import { ref, watch } from 'vue'
import CustomPopup from '@/components/CustomPopup.uvue'
import { state } from "@/store/index.uts"
const emit = defineEmits(['jumpPay'])
interface PaymentTypeItem {
name: string
type: number
......@@ -99,7 +99,7 @@
paymentAccount?: string
}
interface AccountListItem {
type AccountListItem = {
label: string
field: string
}
......@@ -110,50 +110,28 @@
const props = defineProps<Props>()
const ACCOUT_LIST: AccountListItem[] = [
{
label: "公司名称",
field: "companyName",
},
{
label: "基本账户",
field: "basicAccount",
},
{
label: "支行账号",
field: "subBranchAccount",
},
{
label: "一般账户",
field: "generalAccount",
},
{
label: "支付账户",
field: "paymentAccount",
},
]
const ACCOUT_LIST: AccountListItem[] = []
const item1: AccountListItem = {
label: "公司名称",
field: "companyName",
}
const item2: AccountListItem = {
label: "基本账户",
field: "basicAccount",
}
ACCOUT_LIST.push(item1, item2)
const payActive = ref<number>(1)
const accountList = ref<AccountListItem[]>(ACCOUT_LIST)
const title = ref<string>('')
const accountInfo = ref<Record<string, any>>({})
const payInfo = ref<Record<string, any>>({})
const accountInfo = ref<UTSJSONObject>({})
const payInfo = ref<UTSJSONObject>({})
const popup = ref(null)
const visible = ref<boolean>(false)
// 使用传入的 paymentType 或从 store 获取
const currentPaymentType = (): PaymentTypeItem[] => {
return props.paymentType || state.user.paymentType
}
watch(() => currentPaymentType(), (newval: PaymentTypeItem[]) => {
if (newval && newval.length) {
payInfo.value = newval.find(i => i.paymentType == 1) || {}
accountInfo.value = newval.find(i => i.paymentType == 2) || {}
handleSwitchTab(newval[0], false)
}
}, { immediate: true })
// 切换 tab
// 切换 tab
function handleSwitchTab(item: PaymentTypeItem, isClick: boolean = true): void {
payActive.value = item.type
title.value = item.title
......@@ -161,6 +139,19 @@
// uni.$logger.local.info(`付款方式:${item.title}`)
}
}
// 使用传入的 paymentType 或从 store 获取
const currentPaymentType = (): PaymentTypeItem[] => {
return props.paymentType != null ? props.paymentType as PaymentTypeItem[] : state.user.paymentType as PaymentTypeItem[]
}
watch(currentPaymentType(), (newval: PaymentTypeItem[]) => {
if (newval.length > 0) {
payInfo.value = (newval.find(i => i.paymentType == 1) ?? {}) as UTSJSONObject
accountInfo.value = (newval.find(i => i.paymentType == 2) ?? {}) as UTSJSONObject
handleSwitchTab(newval[0], false)
}
}, { immediate: true })
// 显示弹窗
function show(): void {
......@@ -179,7 +170,7 @@
close()
}
const emit = defineEmits(['jumpPay'])
// 暴露方法给父组件
defineExpose({
......
......@@ -44,7 +44,6 @@
import HomeFrame from '@/components/HomeFrame/index.uvue'
import { getMerchantCarBrandList, getEmployeeListApi , getCarBrandsListApi } from '@/api/common-api.uts'
import { getMockData, getSoureData } from '@/api/system-api.uts'
const homeRef = ref(null)
const detailRef = ref(null)
const loadComplete = ref<boolean>(false)
......@@ -53,16 +52,20 @@
const mediaId = ref<string | number>('')
function setViewInfo(data: any): void {
const { moduleList: dataModuleList, toolList: dataToolList, id: dataId } = data as UTSJSONObject
moduleList.value = dataModuleList
toolList.value = dataToolList
mediaId.value = dataId
const dataObj = data as UTSJSONObject
moduleList.value = dataObj.moduleList as Array<any>
toolList.value = dataObj.toolList as Array<any>
mediaId.value = dataObj.id as string
loadComplete.value = true
state.user = {
...state.user,
...data
// 将 state.user 转换为 UTSJSONObject 后合并
const userState = state.user as UTSJSONObject
for (const key in dataObj) {
if (key !== 'moduleList' && key !== 'toolList' && key !== 'id') {
userState[key] = dataObj[key]
}
}
// state.user = userState as UserStateType
}
function handleStart(): void {
......@@ -73,52 +76,17 @@
icon: 'none'
})
}
const firstId = currentModuleList[0].id
const firstItem = currentModuleList[0] as UTSJSONObject
const firstId = firstItem.id as string
uni.navigateTo({ url: `/pages/equity/detail/index?id=${firstId}&type=edit` })
}
function get_Vehicle_Sales_Data(): void {
const userInfo = storage.get('userInfo'),
storageCarBrandList = storage.get('carBrandList'),
storageEmployeeList = storage.get('employeeList'),
{shopMerchantId} = userInfo
getMerchantCarBrandList([shopMerchantId]).then(({data}) => {
let list = data[0].carBrandList,
carBrandList = [],
brandIdList = [],
subBrandIdList = []
list?.map(e => {
e.childs.map(i => {
i.brandName = e.name
i.brandId = e.id
carBrandList.push(i)
subBrandIdList.push(i.id)
})
brandIdList.push(e.id)
})
getSoure(brandIdList, subBrandIdList)
dispatch('setCarBrandsList', carBrandList)
storage.set('carBrandList', carBrandList)
if (carBrandList.length > 0) {
let index = 0
getCarBrandsList(carBrandList, index)
}
})
/**获取销售人员 */
getEmployeeListApi({
merchantId: shopMerchantId
}).then(res => {
dispatch('setEmployeeList', res != null ? res : [])
storage.set('employeeList', res != null ? res : [])
})
}
async function getSoure(brandIdList: string[], subBrandIdList: string[]): Promise<void> {
const userInfo = storage.get('userInfo')
const { shopMerchantId, sceneType } = userInfo as UTSJSONObject
async function getSoure(brandIdList: string[], subBrandIdList: string[]): Promise<void> {
const userInfo = storage.get('userInfo') as UTSJSONObject
const shopMerchantId: string = (userInfo.shopMerchantId as string) ?? ''
const sceneType: number = (userInfo.sceneType as number) ?? 0
const storageKey = `source_${sceneType}_${shopMerchantId}`
const data = uni.getStorageSync(storageKey)
const data = uni.getStorageSync(storageKey) as UTSJSONObject
if (data != null) {
setViewInfo(data)
......@@ -130,7 +98,7 @@
subBrandIdList: subBrandIdList
})
if (requestData != null) {
setViewInfo(requestData)
setViewInfo(requestData as UTSJSONObject)
} else {
loadComplete.value = true
}
......@@ -139,7 +107,79 @@
loadComplete.value = true
}
}
/**按序加载车型 */
async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index] as UTSJSONObject
if (item == null) return
const storageKey = `${(item.id as string) ?? ''}_${(item.brandId as string) ?? ''}_carlist`
const carList = uni.getStorageSync(storageKey)
if (index < carBrandList.length - 1) {
const nextIndex = index + 1
if (carList == null) {
const list = await getCarBrandsListApi({
brandId: (item.brandId as string) ?? '',
childBrandId: (item.id as string) ?? ''
})
if (list != null) {
uni.setStorageSync(storageKey, list)
}
getCarBrandsList(carBrandList, nextIndex)
} else {
getCarBrandsList(carBrandList, nextIndex)
}
}
}
function get_Vehicle_Sales_Data(): void {
const userInfo = storage.get('userInfo') as UTSJSONObject,
storageCarBrandList = storage.get('carBrandList'),
storageEmployeeList = storage.get('employeeList'),
shopMerchantId = userInfo.shopMerchantId
getMerchantCarBrandList([shopMerchantId ?? '']).then((res: any) => {
const resObj = res as UTSJSONObject
const data = resObj.data as UTSJSONObject
const dataArray = data as Array<any>
const firstItem = dataArray[0] as UTSJSONObject
let list = firstItem.carBrandList as Array<any>,
carBrandList = [] as any[]
const brandIdList: string[] = []
const subBrandIdList: string[] = []
list?.forEach((e: any) => {
const eObj = e as UTSJSONObject
const childs = eObj.childs as Array<any>
childs.forEach((i: any) => {
const iObj = i as UTSJSONObject
iObj.brandName = (eObj.name as string) ?? ''
iObj.brandId = (eObj.id as string) ?? ''
carBrandList.push(iObj)
const idStr: string = (iObj.id as string) ?? ''
subBrandIdList.push(idStr)
})
const idStr: string = (eObj.id as string) ?? ''
brandIdList.push(idStr)
})
getSoure(brandIdList, subBrandIdList)
dispatch('setCarBrandsList', carBrandList)
storage.set('carBrandList', carBrandList, 0)
if (carBrandList.length > 0) {
let index = 0
getCarBrandsList(carBrandList, index)
}
})
/**获取销售人员 */
getEmployeeListApi({
merchantId: shopMerchantId
}).then(res => {
dispatch('setEmployeeList', res)
storage.set('employeeList', res, 0)
})
}
onLoad((options) => {
getMockData(true).then(mockdata =>{
console.log(mockdata,'===')
......@@ -167,10 +207,10 @@
}
const userInfoObj = userInfo as UTSJSONObject
const shopMerchantId = userInfoObj['shopMerchantId'] as string | null
const shopMerchantName = userInfoObj['shopMerchantName'] as string | null
const shopMerchantId = (userInfoObj.shopMerchantId as string) ?? ''
const sceneType = (userInfoObj.sceneType as number) ?? 0
if (shopMerchantId == null || shopMerchantId == '' || shopMerchantName == null || shopMerchantName == '') {
if (shopMerchantId == null) {
storage.remove('userInfo')
storage.remove('sessionId')
uni.reLaunch({ url: '/pages/common/login/index' })
......@@ -182,30 +222,7 @@
}
})
/**按序加载车型 */
async function getCarBrandsList(carBrandList: Array<any>, index: number) {
const item = carBrandList[index]
if (item == null) return
const storageKey = `${item.id}_${item.brandId}_carlist`
const carList = uni.getStorageSync(storageKey)
if (index < carBrandList.length - 1) {
const nextIndex = index + 1
if (carList == null) {
const list = await getCarBrandsListApi({
brandId: item.brandId,
childBrandId: item.id
})
if (list != null) {
uni.setStorageSync(storageKey, list)
}
getCarBrandsList(carBrandList, nextIndex)
} else {
getCarBrandsList(carBrandList, nextIndex)
}
}
}
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!