Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
saas_plus
/
dj-car-boutique-work-wechat
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
1
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6a744556
authored
Jan 28, 2026
by
Lin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
feat: 销售选择器选中回显
1 parent
9e64325b
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
19 deletions
packageEquity/pages/salaryAppeal/components/staffSelector/staffSelector.js
packageEquity/pages/salaryAppeal/salaryAppeal.js
packageEquity/pages/salaryAppeal/salaryAppeal.wxml
packageEquity/pages/salaryAppeal/components/staffSelector/staffSelector.js
View file @
6a74455
...
@@ -17,7 +17,11 @@ Component({
...
@@ -17,7 +17,11 @@ Component({
// 当前选中的值(整个对象)
// 当前选中的值(整个对象)
selectedValue
:
{
selectedValue
:
{
type
:
Object
,
type
:
Object
,
value
:
null
value
:
{
staffPhone
:
"13132112120"
,
text
:
"晨星1号"
,
value
:
"173690cbda6d4e8bbccdb3ab485858f8"
}
}
}
},
},
...
@@ -36,7 +40,11 @@ Component({
...
@@ -36,7 +40,11 @@ Component({
*/
*/
lifetimes
:
{
lifetimes
:
{
attached
:
function
()
{
attached
:
function
()
{
// 组件初始化
// 组件初始化时,如果弹框已显示且有数据,进行初始化
const
{
show
,
options
,
selectedValue
}
=
this
.
properties
if
(
show
&&
options
&&
options
.
length
>
0
)
{
this
.
initPopup
()
}
}
}
},
},
...
@@ -66,24 +74,56 @@ Component({
...
@@ -66,24 +74,56 @@ Component({
*/
*/
initPopup
:
function
()
{
initPopup
:
function
()
{
const
{
options
,
selectedValue
}
=
this
.
properties
const
{
options
,
selectedValue
}
=
this
.
properties
// 兼容处理:如果 selectedValue 是字符串,转换为对象;如果是对象,直接使用
let
selectedValueObj
=
selectedValue
// 兼容处理:支持多种数据格式
if
(
typeof
selectedValue
===
'string'
&&
selectedValue
)
{
// 1. 字符串格式:直接是 value
// 从 options 中查找对应的对象
// 2. 对象格式1:{ staffPhone, text, value } - 组件期望的格式
// 3. 对象格式2:{ staffName, staffId, staffPhone } - 从 filters 传递过来的格式
let
selectedValueObj
=
null
let
selectedValueId
=
null
if
(
selectedValue
)
{
if
(
typeof
selectedValue
===
'string'
)
{
// 字符串格式:直接是 value
selectedValueId
=
selectedValue
const
foundOption
=
options
.
find
(
opt
=>
opt
.
value
===
selectedValue
)
const
foundOption
=
options
.
find
(
opt
=>
opt
.
value
===
selectedValue
)
selectedValueObj
=
foundOption
||
null
if
(
foundOption
)
{
selectedValueObj
=
foundOption
}
}
else
if
(
typeof
selectedValue
===
'object'
)
{
// 对象格式
if
(
selectedValue
.
value
)
{
// 格式1:{ staffPhone, text, value }
selectedValueId
=
selectedValue
.
value
selectedValueObj
=
selectedValue
}
else
if
(
selectedValue
.
staffId
)
{
// 格式2:{ staffName, staffId, staffPhone }
selectedValueId
=
selectedValue
.
staffId
// 从 options 中查找对应的对象
const
foundOption
=
options
.
find
(
opt
=>
opt
.
value
===
selectedValue
.
staffId
)
if
(
foundOption
)
{
selectedValueObj
=
{
staffPhone
:
selectedValue
.
staffPhone
||
foundOption
.
staffPhone
,
text
:
selectedValue
.
staffName
||
foundOption
.
text
,
value
:
selectedValue
.
staffId
||
foundOption
.
value
}
}
}
}
}
}
// 处理选项列表,标记选中状态
let
processedOptions
=
options
.
map
(
option
=>
({
let
processedOptions
=
options
.
map
(
option
=>
({
...
option
,
...
option
,
checked
:
selectedValue
Obj
&&
option
.
value
===
selectedValueObj
.
value
checked
:
selectedValue
Id
&&
option
.
value
===
selectedValueId
}))
}))
// 设置选中的选项ID数组(用于单选模式)
let
selectedOptions
=
[]
let
selectedOptions
=
[]
if
(
selectedValue
Obj
&&
selectedValueObj
.
value
)
{
if
(
selectedValue
Id
)
{
const
selectedOption
=
processedOptions
.
find
(
opt
=>
opt
.
value
===
selectedValue
Obj
.
value
)
const
selectedOption
=
processedOptions
.
find
(
opt
=>
opt
.
value
===
selectedValue
Id
)
if
(
selectedOption
)
{
if
(
selectedOption
)
{
selectedOptions
=
[
selectedValue
Obj
.
value
]
selectedOptions
=
[
selectedValue
Id
]
}
}
}
}
...
@@ -223,8 +263,9 @@ Component({
...
@@ -223,8 +263,9 @@ Component({
* 属性观察器
* 属性观察器
*/
*/
observers
:
{
observers
:
{
// 监听弹框显示、选项列表和选中值的变化
'show, options, selectedValue'
:
function
(
show
,
options
,
selectedValue
)
{
'show, options, selectedValue'
:
function
(
show
,
options
,
selectedValue
)
{
// 当弹框显示
时,初始化数据
// 当弹框显示
且有选项数据时,初始化数据(包括选中回显)
if
(
show
&&
options
&&
options
.
length
>
0
)
{
if
(
show
&&
options
&&
options
.
length
>
0
)
{
this
.
initPopup
()
this
.
initPopup
()
}
}
...
...
packageEquity/pages/salaryAppeal/salaryAppeal.js
View file @
6a74455
...
@@ -82,7 +82,7 @@ Page({
...
@@ -82,7 +82,7 @@ Page({
async
showStaffPopup
()
{
async
showStaffPopup
()
{
if
(
!
this
.
data
.
staffAbled
)
return
if
(
!
this
.
data
.
staffAbled
)
return
// 如果员工列表为空,先加载数据
// 如果员工列表为空,先加载数据
//
if (!this.data.staffOptions || this.data.staffOptions.length === 0) {
if
(
!
this
.
data
.
staffOptions
||
this
.
data
.
staffOptions
.
length
===
0
)
{
wx
.
showLoading
({
title
:
'加载中...'
,
mask
:
true
})
wx
.
showLoading
({
title
:
'加载中...'
,
mask
:
true
})
try
{
try
{
await
this
.
getEmployeeAllList
()
await
this
.
getEmployeeAllList
()
...
@@ -94,11 +94,11 @@ Page({
...
@@ -94,11 +94,11 @@ Page({
wx
.
hideLoading
()
wx
.
hideLoading
()
wx
.
showToast
({
title
:
'加载失败'
,
icon
:
'none'
})
wx
.
showToast
({
title
:
'加载失败'
,
icon
:
'none'
})
}
}
//
} else {
}
else
{
//
this.setData({
this
.
setData
({
//
showStaffPopup: true
showStaffPopup
:
true
//
})
})
//
}
}
},
},
/**
/**
...
...
packageEquity/pages/salaryAppeal/salaryAppeal.wxml
View file @
6a74455
...
@@ -101,7 +101,7 @@
...
@@ -101,7 +101,7 @@
<staffSelector
<staffSelector
show="{{ showStaffPopup }}"
show="{{ showStaffPopup }}"
options="{{ staffOptions }}"
options="{{ staffOptions }}"
selected-value="{{ filters
.staffId
}}"
selected-value="{{ filters }}"
bind:close="onCloseStaffPopup"
bind:close="onCloseStaffPopup"
bind:confirm="onStaffSelectConfirm"
bind:confirm="onStaffSelectConfirm"
></staffSelector>
></staffSelector>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment