You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
<template>
|
|
|
|
<view class="form-item">
|
|
|
|
<!-- 左侧标签 + 必填提示 -->
|
|
|
|
<view class="label">
|
|
|
|
<!-- <text v-if="required" class="required">*</text> -->
|
|
|
|
<text>{{ label }}</text>
|
|
|
|
<image v-if="required" class="required" :src="cssUrl + 'required.svg'" />
|
|
|
|
</view>
|
|
|
|
|
|
|
|
<!-- 输入模式 -->
|
|
|
|
<input
|
|
|
|
v-if="type === 'input'"
|
|
|
|
class="input"
|
|
|
|
:placeholder="placeholder"
|
|
|
|
:value="value"
|
|
|
|
@input="handleInput"
|
|
|
|
:disabled="disabled"
|
|
|
|
/>
|
|
|
|
|
|
|
|
<!-- 点击选择模式(如性别、年份) -->
|
|
|
|
<view
|
|
|
|
v-else
|
|
|
|
class="picker"
|
|
|
|
@click="handleClick"
|
|
|
|
>
|
|
|
|
<text :class="{ 'placeholder': !value }">
|
|
|
|
{{ displayValue || placeholder }}
|
|
|
|
</text>
|
|
|
|
<image class="right_img" :src="cssUrl + 'input_ex.png'" />
|
|
|
|
|
|
|
|
<!-- <uni-icons type="arrowright" size="14" color="#999" /> -->
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'FormItem',
|
|
|
|
props: {
|
|
|
|
label: String, // 左侧标签文本(如"姓名")
|
|
|
|
type: { // 类型:input(输入)或 picker(点击选择)
|
|
|
|
type: String,
|
|
|
|
default: 'input',
|
|
|
|
validator: (val) => ['input', 'picker'].includes(val),
|
|
|
|
},
|
|
|
|
value: [String, Number], // 绑定的值
|
|
|
|
placeholder: String, // 占位文本
|
|
|
|
required: Boolean, // 是否必填
|
|
|
|
disabled: Boolean, // 是否禁用
|
|
|
|
displayValue: String, // 显示的值(用于picker模式,如性别显示"男/女")
|
|
|
|
},
|
|
|
|
data(){
|
|
|
|
return{
|
|
|
|
cssUrl: this.cssUrl,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleInput(e) {
|
|
|
|
this.$emit('input', e.detail.value);
|
|
|
|
},
|
|
|
|
handleClick() {
|
|
|
|
if (!this.disabled) {
|
|
|
|
this.$emit('click'); // 触发父组件的选择逻辑
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.form-item {
|
|
|
|
display: flex;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
padding: 36rpx 24rpx;
|
|
|
|
border-bottom: 1rpx solid #eee;
|
|
|
|
}
|
|
|
|
.right_img{
|
|
|
|
width: 26rpx;
|
|
|
|
height: 26rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
font-family: PingFang SC;
|
|
|
|
font-size: 32rpx;
|
|
|
|
font-weight: 500;
|
|
|
|
line-height: 44rpx;
|
|
|
|
letter-spacing: 2rpx;
|
|
|
|
color: #222222;
|
|
|
|
}
|
|
|
|
|
|
|
|
.required {
|
|
|
|
margin-left: 8rpx;
|
|
|
|
color: #f56c6c;
|
|
|
|
font-size: 12px;
|
|
|
|
width: 16rpx;
|
|
|
|
height: 16rpx;
|
|
|
|
}
|
|
|
|
|
|
|
|
.input,
|
|
|
|
.picker {
|
|
|
|
flex: 1;
|
|
|
|
text-align: right;
|
|
|
|
padding-left: 20rpx;
|
|
|
|
color: #333;
|
|
|
|
}
|
|
|
|
|
|
|
|
.placeholder {
|
|
|
|
font-family: PingFang SC;
|
|
|
|
font-size: 32rpx;
|
|
|
|
font-weight: normal;
|
|
|
|
line-height: 44rpx;
|
|
|
|
text-align: right;
|
|
|
|
letter-spacing: 0.24rpx;
|
|
|
|
color: #999999;
|
|
|
|
}
|
|
|
|
</style>
|