saveRecord.vue
11.4 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
<template>
<view class="data-container">
<view class="nav-bar">
<view class="back-btn" @click="backClick">
<uni-icons type="left" :size="20" color="#1a1a1a"></uni-icons>
</view>
<view class="title">接待记录</view>
</view>
<view class="content-scroll">
<view class="error-banner" v-if="errorTip">
<uni-icons type="info-filled" :size="16" color="#f45c3d"></uni-icons>
<text>请完善必填信息</text>
</view>
<view class="form-grid">
<template v-for="(i, index) in formObject">
<view :class="['form-item', { 'radio-type': i.type === 'radio', focused: focusIndex == index, error: showError(i.key) }]" :key="index" @click="handleItemClick(i, index)">
<view class="label-box">
<text class="label-text">{{ i.label }}</text>
<text class="required-mark" v-if="true">*</text>
</view>
<view class="input-box">
<template v-if="i.type == 'input'">
<input
:type="i.inputType"
:maxlength="i.maxlength"
v-model="customerInfo[i.key]"
class="uni-input"
:placeholder="i.placeholder"
placeholder-class="input-placeholder"
@focus="focusIndex = index"
@blur="resetFocusIndex"
/>
</template>
<template v-else-if="i.type == 'radio'">
<CustomerTypeRadio :value="customerInfo[i.key]" @change="radioChange" class="radio-group-box" />
</template>
<template v-else>
<view class="select-trigger">
<text :class="['select-text', { placeholder: !customerInfo[i.key] }]">
{{ customerInfo[i.key] || i.placeholder }}
</text>
<uni-icons class="arrow-icon" type="right" :size="14" color="#C0C4CC"></uni-icons>
</view>
</template>
</view>
</view>
</template>
</view>
</view>
<view class="footer-action">
<view class="btn cancel" @click="$emit('cancel')">取消</view>
<view class="btn submit" @click="handleSave">保存提交</view>
</view>
<ResultSelect ref="receptionStatusVisible" :value="customerInfo.status" @change="selectReception" maskBackgroundColor="rgba(0,0,0,0)" />
</view>
</template>
<script type="text/ecmascript-6">
// import CarBrands from '@/components/CarBrands.vue'
// import Employee from '@/components/Employee.vue'
import CustomerAutocomplete from '@/components/CustomerAutocomplete.vue'
import ResultSelect from '@/components/ResultSelect.vue'
import CustomerTypeRadio from '@/components/CustomerTypeRadio.vue'
const phoneRex = /^[1]([3-9])[0-9]{9}$/;
import utils from "@/utils/utils";
export default {
components: {
// CarBrands,
// Employee,
CustomerAutocomplete,
ResultSelect,
CustomerTypeRadio
},
props: {
customerInfoVal: {
type: Object,
default: () => ({})
}
},
data() {
return {
errorTip:false,
formObject: Object.freeze([{
label: "车主姓名",
placeholder: '车主姓名',
key: 'customerName',
type: 'input',
inputType: 'text',
maxlength: 50
},
{
label: "车主电话",
placeholder: '车主电话',
key: 'customerPhone',
type: 'input',
inputType: 'tel',
maxlength: 11
},
{
label: "客户类型",
key: "customerType",
type: "radio",
placeholder: '请输入客户类型',
required: true
},
{
label: "品牌车型",
placeholder: '品牌车型',
key: 'carType',
type: 'input',
maxlength: 20
},
{
label: "接待结果",
key: "status",
type: "select",
popKey: "receptionStatusVisible",
placeholder: '请选择',
}
]),
focusIndex: -1,
customerInfo:{}
}
},
mounted() {
this.customerInfo = utils.deepClone(this.customerInfoVal)
},
methods: {
selectReception(value) {
this.customerInfo.status = value
this.$refs.receptionStatusVisible.close()
this.resetFocusIndex()
},
showError(key) {
let flag = !this.customerInfo[key]
if (key == 'customerPhone' && this.customerInfo[key]) flag = !phoneRex.test(this.customerInfo[key])
return flag
},
handleSave() {
const result = this.check(true)
if (!result) return this.errorTip = true
this.$emit('submit',this.customerInfo)
},
check(all = false) {
let flag = true
try {
this.formObject.map(e => {
if (!this.customerInfo[e.key]) throw false
if (!all && e.key == 'customerPhone' && !phoneRex.test(this.customerInfo[e.key])) {
uni.showToast({
title: "请输入正确的车主电话",
icon: "none",
});
throw false
}
})
} catch (error) {
flag = error
}
return flag
},
// handleSelect(item, popkey) {
// this.$refs[popkey].close()
// if (popkey == 'employeeBoxVisible') {
// this.customerInfo.salesUuid = item.uuid
// this.customerInfo.salesName = item.staffName
// } else {
// this.$refs.carBrandListVisible.close()
// this.customerInfo.carModel = item.name
// this.customerInfo.carBrand = item.carChildsBrandName
// this.customerInfo.carBrandId = item.carChildsBrandId
// this.customerInfo.oneCarBrand = item.carBrand
// this.customerInfo.oneCarBrandId = item.carBrandId
// }
// this.resetFocusIndex()
// this.errorTip = false
// },
showPopup(e, index) {
this.focusIndex = index
this.$refs[e].open()
},
handleItemClick(item, index) {
if (item.type === 'select') {
this.showPopup(item.popKey, index)
} else {
this.focusIndex = index
}
},
resetFocusIndex() {
this.focusIndex = -1
this.errorTip = false
},
radioChange (e) {
this.customerInfo.customerType = e.detail.value
},
backClick() {
console.log('backClick')
this.$emit('cancel')
}
}
}
</script>
<style scoped lang="scss">
.data-container {
background: #ffffff;
border-radius: toRpx(24);
margin: toRpx(48) auto;
width: calc(100% - #{toRpx(64)});
height: calc(100% - #{toRpx(96)});
box-shadow: 0 toRpx(8) toRpx(24) rgba(0, 0, 0, 0.05);
display: flex;
flex-direction: column;
overflow: hidden;
position: relative;
// 硬件加速
transform: translateZ(0);
will-change: transform;
}
.nav-bar {
height: toRpx(100);
display: flex;
align-items: center;
justify-content: center;
position: absolute; // 改为 absolute
top: 0;
left: 0;
width: 100%;
border-bottom: 1px solid #f5f5f5;
background-color: #fff;
z-index: 999; // 提高层级
.back-btn {
position: absolute;
left: 0; // 扩大点击区域
top: 0;
height: 100%;
width: toRpx(100); // 增加宽度
display: flex;
align-items: center;
justify-content: center;
z-index: 11; // 确保在最上层
cursor: pointer;
display:none;
&:active {
opacity: 0.7;
}
// 让图标不拦截点击事件
/deep/ .uni-icons {
pointer-events: none;
}
}
.title {
font-size: toRpx(34);
font-weight: 600;
color: #1a1a1a;
}
}
.content-scroll {
flex: 1;
overflow-y: auto;
margin-top: toRpx(100); // 留出nav-bar的高度
padding: toRpx(32) toRpx(40);
-webkit-overflow-scrolling: touch;
}
.error-banner {
display: flex;
align-items: center;
justify-content: center;
gap: toRpx(12);
background-color: #fef0f0;
color: #f56c6c;
font-size: toRpx(26);
padding: toRpx(16);
border-radius: toRpx(12);
margin-bottom: toRpx(32);
animation: slideDown 0.3s ease-out;
}
.form-grid {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: toRpx(32) toRpx(40);
@media screen and (max-width: 768px) {
grid-template-columns: 1fr;
}
}
.form-item {
display: flex;
flex-direction: column;
gap: toRpx(16);
.label-box {
display: flex;
align-items: center;
.label-text {
font-size: toRpx(28);
color: #606266;
font-weight: 500;
}
.required-mark {
color: #f56c6c;
margin-left: toRpx(8);
font-size: toRpx(28);
}
}
.input-box {
height: toRpx(88);
background: #f5f7fa;
border-radius: toRpx(12);
border: 1px solid transparent;
transition: all 0.2s ease;
padding: 0 toRpx(24);
display: flex;
align-items: center;
.uni-input {
flex: 1;
font-size: toRpx(30);
color: #303133;
height: 100%;
}
.input-placeholder {
color: #c0c4cc;
}
.select-trigger {
flex: 1;
display: flex;
align-items: center;
justify-content: space-between;
height: 100%;
.select-text {
font-size: toRpx(30);
color: #303133;
&.placeholder {
color: #c0c4cc;
}
}
}
}
.radio-group-box {
display: flex;
align-items: center;
gap: toRpx(48); // 增加单选框之间的间距
height: 100%;
.radio {
display: flex;
align-items: center;
font-size: toRpx(30);
color: #303133;
radio {
transform: scale(0.8);
margin-right: toRpx(8);
}
}
}
// 单选框特殊处理:正常状态无边框无背景,只有报错时显示红色边框
&.radio-type .input-box {
background: transparent !important;
border: none !important;
box-shadow: none !important;
padding: 0;
}
&.focused .input-box {
background: #ffffff;
border-color: #2c66f7;
box-shadow: 0 0 0 2px rgba(44, 102, 247, 0.1);
}
// 错误状态通用处理
&.error .input-box {
background: #fef0f0 !important;
border-color: #f56c6c !important;
border-width: 1px !important;
border-style: solid !important;
box-shadow: none !important;
}
}
.footer-action {
padding: toRpx(32) toRpx(40);
border-top: 1px solid #f5f5f5;
display: flex;
gap: toRpx(32);
background: #ffffff;
flex-shrink: 0;
.btn {
flex: 1;
height: toRpx(88);
border-radius: toRpx(44);
display: flex;
align-items: center;
justify-content: center;
font-size: toRpx(30);
font-weight: 500;
transition: all 0.2s;
&:active {
transform: scale(0.98);
}
&.cancel {
background: #f5f7fa;
color: #606266;
}
&.submit {
background: linear-gradient(135deg, #2c66f7 0%, #5c8dff 100%);
color: #ffffff;
box-shadow: 0 toRpx(8) toRpx(16) rgba(44, 102, 247, 0.25);
}
}
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>