corePersonnel.vue
17.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<template>
<view class="core-personnel" :class="{ 'history': mode == 'history' }">
<!-- 变更记录详情-核心人员 -->
<view v-if="mode === 'history'" class="header">
<text class="title">{{ title }}</text>
</view>
<!-- 新增&详情-核心人员 -->
<view v-else class="header" :class="{ 'bp': mode !== 'add' }">
<image class="opCollapse" src="/static/images/title.png" />
<text class="title">核心人员</text>
<view class="ops">
<image v-if="mode === 'add'" class="opAdd" @click="onAdd" src="/static/images/plus.png" />
<view v-if="mode === 'view'" class="op1" @click="toggleViewCollapse">
<image class="opAdd" :src="collapsedView ? '/static/images/down.png' : '/static/images/up.png'" />
<text class="op">{{ collapsedView ? '展开' : '收起' }} </text>
</view>
</view>
</view>
<view v-if="mode === 'add'" class="add-list">
<view v-for="(item, idx) in items" :key="idx" class="block">
<uni-list v-show="item.collapsed">
<uni-list-item title="姓名">
<template v-slot:footer>
<uni-easyinput v-model="item.name" :inputBorder="false" placeholder="请输入姓名" />
</template>
</uni-list-item>
<uni-list-item class="select-item" :class="item.sexName ? 'is-filled' : 'is-empty'" clickable
@click="openProductSheet(idx)" :rightText="item.sexName || '请选择性别'" showArrow>
<template v-slot:body>
<view class="item-title"><text>性别</text></view>
</template>
</uni-list-item>
</uni-list>
<uni-list v-show="!item.collapsed">
<uni-list-item title="姓名">
<template v-slot:footer>
<uni-easyinput v-model="item.name" :inputBorder="false" placeholder="请输入姓名" />
</template>
</uni-list-item>
<uni-list-item class="select-item" :class="item.sexName ? 'is-filled' : 'is-empty'" clickable
@click="openProductSheet(idx)" :rightText="item.sexName || '请选择性别'" showArrow>
<template v-slot:body>
<view class="item-title"><text>性别</text></view>
</template>
</uni-list-item>
<uni-list-item title="籍贯">
<template v-slot:footer>
<uni-easyinput v-model="item.nativePlace" :inputBorder="false" placeholder="请输入籍贯" />
</template>
</uni-list-item>
<uni-list-item title="年龄">
<template v-slot:footer>
<uni-easyinput v-model="item.age" :inputBorder="false" placeholder="请输入年龄" />
</template>
</uni-list-item>
<uni-list-item title="职务">
<template v-slot:footer>
<uni-easyinput v-model="item.position" :inputBorder="false" placeholder="请输入职务" />
</template>
</uni-list-item>
<uni-list-item title="手机">
<template v-slot:footer>
<uni-easyinput v-model="item.mobile" :inputBorder="false" placeholder="请输入手机" />
</template>
</uni-list-item>
<uni-list-item title="固定电话">
<template v-slot:footer>
<uni-easyinput v-model="item.phone" :inputBorder="false" placeholder="请输入固定电话" />
</template>
</uni-list-item>
<uni-list-item title="邮箱地址">
<template v-slot:footer>
<uni-easyinput v-model="item.email" :inputBorder="false" placeholder="请输入邮箱地址" />
</template>
</uni-list-item>
<uni-list-item title="现住址">
<template v-slot:footer>
<uni-easyinput v-model="item.address" :inputBorder="false" placeholder="请输入现住址" />
</template>
</uni-list-item>
</uni-list>
<view class="block-ops">
<div class="del" @click="onRemove(item.personId)">
<image src="/static/images/delete.png" class="icon" />
删除
</div>
<div class="toggle" @click="toggleItem(idx)">
<image :src="item.collapsed ? '/static/images/up.png' : '/static/images/down.png'"
class="icon" />
{{ item.collapsed ? '展开' : '收起' }}
</div>
</view>
</view>
</view>
<view v-else-if="mode === 'view'" class="view-list" v-show="!collapsedView">
<view v-for="(item, idx) in items" :key="'v-' + idx" class="card">
<view class="row"><text class="label">姓名</text><text class="value">{{ item.name }}</text></view>
<view class="row"><text class="label">性别</text><text class="value">{{ getSexName(item) }}</text></view>
<view class="row"><text class="label">籍贯</text><text class="value">{{ item.nativePlace }}</text></view>
<view class="row"><text class="label">年龄</text><text class="value">{{ item.age }}</text></view>
<view class="row"><text class="label">职务</text><text class="value">{{ item.position }}</text></view>
<view class="row"><text class="label">手机</text><text class="value">{{ item.mobile }}</text></view>
<view class="row"><text class="label">固定电话</text><text class="value">{{ item.phone }}</text></view>
<view class="row"><text class="label">邮箱地址</text><text class="value">{{ item.email }}</text></view>
<view class="row"><text class="label">现住址</text><text class="value">{{ item.address }}</text></view>
</view>
</view>
<view v-else-if="mode === 'history'" class="history-list" v-show="!collapsedView">
<view v-for="(item, idx) in items" :key="'v-' + idx" class="card">
<view class="row"><text class="label">姓名</text><text class="value" :class="{'change': item.nameChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.name }}</text></view>
<view class="row"><text class="label">性别</text><text class="value" :class="{'change': item.sexChange || ['ADD', 'DELETE'].includes(item.type)}">{{ getSexName(item) }}</text></view>
<view class="row"><text class="label">籍贯</text><text class="value" :class="{'change': item.nativePlaceChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.nativePlace }}</text></view>
<view class="row"><text class="label">年龄</text><text class="value" :class="{'change': item.ageChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.age }}</text></view>
<view class="row"><text class="label">职务</text><text class="value" :class="{'change': item.positionChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.position }}</text></view>
<view class="row"><text class="label">手机</text><text class="value" :class="{'change': item.mobileChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.mobile }}</text></view>
<view class="row"><text class="label">固定电话</text><text class="value" :class="{'change': item.phoneChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.phone }}</text></view>
<view class="row"><text class="label">邮箱地址</text><text class="value" :class="{'change': item.emailChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.email }}</text></view>
<view class="row"><text class="label">现住址</text><text class="value" :class="{'change': item.addressChange || ['ADD', 'DELETE'].includes(item.type)}">{{ item.address }}</text></view>
</view>
</view>
<SingleSelectSheet :visible.sync="sheet.visible" :title="sheet.title" :options="sheet.options"
v-model="sheet.value" @confirm="onProductConfirm" />
</view>
</template>
<script>
import SingleSelectSheet from '@/components/single-select/index.vue'
import { uuid } from '@/utils/uuid.js'
export default {
name: 'CorePersonnel',
props: {
title: { type: String, default: '' },
mode: { type: String, default: 'add' },
list: { type: Array, default: () => [] },
options: { type: Array, default: () => [] }
},
components: { SingleSelectSheet },
data() {
return {
items: [],
collapsedView: false,
sheet: { visible: false, title: '请选择性别', options: [], value: '', idx: -1 }
}
},
computed: {
selectOptions() {
const list = Array.isArray(this.options) ? this.options : []
return list.map(o => ({
label: o.label != null ? o.label : (o.text != null ? o.text : (o.name != null ? o.name : '')),
value: o.value != null ? o.value : (o.code != null ? o.code : (o.id != null ? o.id : o.productId))
}))
}
},
watch: {
items: {
handler() { this.emitChange() },
deep: true
},
list: {
handler(v) {
const arr = Array.isArray(v) ? v : []
const opts = this.selectOptions
this.items = arr.map(x => {
const it = { ...this.defaultItem(), ...x, collapsed: true }
const m = opts.find(o => String(o.value) === String(it.sex))
it.sexName = m ? (m.label || '') : it.sexName
return it
})
},
deep: true
},
options: {
handler() { this.refreshSexNames() }
}
},
created() {
const init = Array.isArray(this.list) && this.list.length > 0 ? this.list.map(v => ({ ...this.defaultItem(), ...v, collapsed: false })) : [{ ...this.defaultItem(), collapsed: false }]
this.items = init
},
methods: {
defaultItem() {
return { personId: uuid(), name: '', sex: '', sexName: '', nativePlace: '', age: '', position: '', mobile: '', phone: '', email: '', address: '', collapsed: false }
},
getSexName(item) {
const opts = this.selectOptions
const v = item && item.sex
const m = opts.find(o => String(o.value) === String(v))
return m ? (m.label || '') : ((item && item.sexName) || '')
},
refreshSexNames() {
const opts = this.selectOptions
this.items = (this.items || []).map(it => {
const m = opts.find(o => String(o.value) === String(it.sex))
return { ...it, sexName: m ? (m.label || '') : it.sexName }
})
},
openProductSheet(idx) {
const opts = this.selectOptions
const current = this.items[idx] && this.items[idx].sex
const match = opts.find(o => o.value === current)
this.sheet = { ...this.sheet, visible: true, title: '请选择性别', options: opts, idx, value: match ? match.value : '' }
},
onProductConfirm({ value, label }) {
const idx = this.sheet.idx
const it = this.items[idx]
if (!it) { this.sheet.visible = false; return }
it.sex = value
it.sexName = label || ''
this.$set(this.items, idx, it)
this.sheet.visible = false
this.emitChange()
},
onAdd() {
const obj = this.defaultItem()
obj.collapsed = true
this.items.push(obj)
this.emitChange()
},
onRemove(id) {
if (!id) return
uni.showModal({
title: '系统提示',
content: '是否确定删除选中的核心人员?',
confirmText: '确定',
cancelText: '取消',
success: (res) => {
if (res && res.confirm) {
const i = this.items.findIndex(it => String(it.personId) === String(id))
if (i >= 0) {
this.items.splice(i, 1)
this.emitChange()
}
}
}
})
},
toggleItem(idx) {
const it = this.items[idx]
if (!it) return
it.collapsed = !it.collapsed
this.$set(this.items, idx, it)
},
emitChange() {
const out = this.items.map(it => ({ ...it }))
this.$emit('input', out)
this.$emit('update:value', out)
this.$emit('change', out)
},
toggleViewCollapse() {
this.collapsedView = !this.collapsedView
}
}
}
</script>
<style lang="scss" scoped>
.core-personnel {
margin-top: 10px;
&.history {
margin-top: 0;
.header {
padding: 32rpx 0 0 32rpx;
}
}
}
.header {
background-color: #fff;
display: flex;
align-items: center;
padding: 24rpx 32rpx;
&.bp {
border-bottom: 1rpx dashed #f0f0f0;
}
}
.dot {
width: 16rpx;
height: 16rpx;
background: #3D48A3;
border-radius: 50%;
margin-right: 12rpx;
}
.title {
font-size: 32rpx;
color: rgba(0, 0, 0, 0.9);
font-weight: 600;
}
.ops {
margin-left: auto;
}
.op {
color: $theme-primary;
font-size: 28rpx;
margin-left: 8rpx;
}
.op1 {
display: flex;
align-items: center;
}
.opAdd {
color: rgba(0, 0, 0, 0.6);
width: 40rpx;
height: 40rpx;
}
.opCollapse {
color: rgba(0, 0, 0, 0.6);
width: 32rpx;
height: 28rpx;
margin-right: 16rpx;
}
.block {
background: #fff;
margin-bottom: 20rpx;
}
::v-deep .uni-list-item__content {
display: flex;
justify-content: center;
}
::v-deep .uni-list {
background: transparent;
&-item {
&__container {
padding: 32rpx;
}
&__content-title {
font-size: 28rpx;
color: rgba(0, 0, 0, 0.9);
}
&__extra-text {
font-size: 32rpx;
}
.uni-easyinput {
width: 100%;
&__placeholder-class {
font-size: 32rpx;
color: rgba(0, 0, 0, 0.4);
}
&__content {
border: none;
display: flex;
&-input {
padding-left: 0 !important;
height: 48rpx;
line-height: 48rpx;
font-size: 32rpx;
}
}
.uni-input-placeholder {
// z-index: 2;
}
}
}
}
.block-ops {
display: flex;
padding: 20rpx 32rpx 20rpx;
justify-content: space-around;
}
.del {
color: #D54941;
font-size: 28rpx;
display: flex;
align-items: center;
image {
width: 40rpx;
height: 40rpx;
}
}
.toggle {
color: $theme-primary;
font-size: 28rpx;
display: flex;
align-items: center;
image {
width: 40rpx;
height: 40rpx;
}
}
.view-list {
padding: 26rpx 32rpx;
background: #ffffff;
.card {
background: #f3f3f3;
border-radius: 16rpx;
padding: 32rpx 44rpx;
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
}
.row {
display: flex;
margin-bottom: 24rpx;
line-height: 32rpx;
}
.row:last-child {
margin-bottom: 0;
}
.label {
width: 180rpx;
margin-right: 14rpx;
color: rgba(0, 0, 0, 0.6);
font-size: 28rpx;
}
.value {
flex: 1;
color: rgba(0, 0, 0, 0.9);
font-size: 28rpx;
white-space: pre-wrap;
word-break: break-all;
}
}
.history-list {
padding: 20rpx 32rpx;
background: #ffffff;
.card {
background: #f3f3f3;
border-radius: 16rpx;
padding: 32rpx 44rpx;
margin-bottom: 20rpx;
&:last-child {
margin-bottom: 0;
}
}
.row {
display: flex;
margin-bottom: 24rpx;
line-height: 32rpx;
}
.row:last-child {
margin-bottom: 0;
}
.label {
width: 180rpx;
margin-right: 14rpx;
color: rgba(0, 0, 0, 0.6);
font-size: 28rpx;
}
.value {
flex: 1;
color: rgba(0, 0, 0, 0.9);
font-size: 28rpx;
white-space: pre-wrap;
word-break: break-all;
&.change {
color: $theme-primary;
}
}
}
</style>