Commit f84b6f84 by 胡悦

feat(GlCell): Add GlCell component for dynamic form handling

- Introduced a new GlCell component to manage various input types (input, select, radio, textarea) within forms.
- Enhanced CreateOrder component to utilize GlCell for form data management.
- Added new icons for improved UI representation.
- Updated sprite styles and images to accommodate new icons and ensure consistent design.
1 parent bc8e9a1c

2.53 MB | W: | H:

2.53 MB | W: | H:

assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
assets/images/sprite.png
  • 2-up
  • Swipe
  • Onion skin
<template>
<view class="cell-box">
<view
v-for="(item, index) in fromList"
:key="index"
class="cell"
@click="handleCell(item)"
:class="[
item.noBorder ? '' : 'border',
item.onlyLabel ? 'small-height' : '',
item.class
]"
>
<view :class="['cell-label', item.onlyLabel ? 'only-label' : '']">
{{ item.label }}
<view v-if="item.required" class="required">*</view>
</view>
<view class="cell-value">
<template v-if="item.type == 'input'">
<!-- <view v-if="item.valueIcon" :class="['sprite-icon input-icon', `icon-${item.valueIcon}`]"></view> -->
<input
class="input-value"
v-model="formData[item.value]"
:placeholder="item.placeholder || '请输入'"
:maxlength="item.maxlength || 500"
/>
</template>
<template v-else-if="item.type == 'select'">
<view v-if="formData[item.value][item.key]" class="value">
{{ formData[item.value][item.key] }}
</view>
<view v-else class="placeholder value">
请选择
<view class="sprite-icon icon-icon-select"></view>
</view>
</template>
<template v-else-if="item.type == 'radio'">
<radio-group class="radio-group value" @change="radioChange($event, item)">
<label class="uni-list-cell uni-list-cell-pd" v-for="(i, ind) in item.radioList" :key="i.name + item.value">
<radio style="transform:scale(0.7)" :value="i.value" :checked="i.value == item.current" />
<view class="radio-name">{{i.name}}</view>
</label>
</radio-group>
</template>
<template v-else-if="item.type == 'textarea'">
<textarea class="textarea" v-model="formData[item.value]" :placeholder="item.placeholder || '请输入'" placeholder-class="textarea-placeholder" confirm-type="done" auto-height :maxlength="item.maxlength"></textarea>
</template>
</view>
</view>
</view>
</template>
<script>
const debounce = function(fn, delay = 300) {
let timer = null;
return function(...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
fn.apply(this, args);
}, delay);
};
}
export default {
name: "GlCell",
props: {
/**
* noBorder:默认false:有下边框,true:无下边框
* onlyLabel:判断是否只有label,默认false,主要是为了做样式区分
* class:cell-row:不一行显示,主要用于文本域
* required:是否为必填项,添加星号
* value: 绑定的字段名称
* key:如果绑定的字段名称为对象,则需要传入需要显示在页面上的属性名
* type: 表单的类型 有:input、select、radio、textarea
* placeholder: 占位符,input、textarea默认为[请输入],select默认为[请选择],
* radioList: type为radio时传入
* current: type为radio时传入,设置radio的默认值
*/
fromList: {
type: Array,
default: () => []
},
formData: {
type: Object,
default: () => {}
}
},
data() {
return {
}
},
methods: {
handleCell(item) {
if (item.type == 'select') {
this.$emit('handleCell', item)
}
},
radioChange(e, item) {
this.$emit('radioChange', e, item)
}
}
}
</script>
<style scoped lang="scss">
.cell-box {
background-color: #fff;
border-radius: toRpx(16);
overflow: hidden;
}
.cell {
display: flex;
align-items: center;
padding: 0 toRpx(32);
height: toRpx(96);
&.small-height {
height: toRpx(72);
}
&.cell-row {
flex-direction: column;
align-items: normal;
height: auto;
}
&.border {
border-bottom: toRpx(2) solid #f7f7f6;
}
}
.cell-label {
color: #333;
font-size: toRpx(28);
.required {
display: inline-block;
margin-left: toRpx(8);
color: #F24724;
}
&.only-label {
font-size: toRpx(24);
color: #777;
}
}
.cell-row .cell-label {
height: toRpx(96);
line-height: toRpx(96);
}
.cell-row .cell-value {
width: 100%;
margin-left: 0;
}
.cell-value {
position: relative;
flex: 1;
height: 100%;
margin-left: toRpx(20);
overflow: hidden;
font-size: toRpx(28);
uni-input {
font-size: toRpx(28);
}
.uni-input-placeholder {
color: #999;
}
.value {
display: flex;
justify-content: flex-end;
align-items: center;
height: 100%;
}
.input-value {
height: 100%;
text-align: right;
}
.input-bottom {
min-height: toRpx(100);
line-height: toRpx(56);
font-size: toRpx(38);
padding: toRpx(32);
}
.placeholder {
color: #999;
font-size: toRpx(28);
}
.uni-list-cell {
margin-left: toRpx(57.2);
}
.radio-name {
display: inline-block;
}
.input-icon {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
}
.textarea {
width: 100%;
border-radius: toRpx(16);
border: toRpx(2) solid #eff0f2;
background: #f4f5f7;
padding: toRpx(24);
margin-bottom: toRpx(32);
}
.textarea-placeholder {
line-height: normal;
font-size: toRpx(28);
}
}
</style>
<template>
<view>
<view class="order">
<view class="common-title">新增工单</view>
<view class="box">
<scroll-view class="scroll-view" scroll-y="true">
<view class="box-content">
<GlCell :fromList="fromList" :formData="formData" @radioChange="radioChange" @handleCell="handleCell"></GlCell>
</view>
<view @click="submit">直接下单</view>
</scroll-view>
</view>
</view>
</template>
<script>
import GlCell from '../../../../components/Form/GlCell.vue';
export default {
name: 'CreateOrder',
components: {
GlCell
},
data() {
return {
formData: {
carName: '',
phone: '',
user: '',
salesType: '1',
sexType: '1'
},
fromList: [
{
label: '销售顾问',
value: 'user',
type: 'select',
key: 'name',
required: true
},
{
label: '请选择产品',
onlyLabel: true,
required: true,
noBorder: true
},
{
label: '手机号',
value: 'phone',
maxlength: '11',
type: 'input'
},
{
label: '客户来源',
value: 'salesType',
type: 'radio',
current: '1',
radioList: [
{
value: '1',
name: '售前'
},
{
value: '2',
name: '售后'
}
]
},
{
label: '性别',
value: 'sexType',
type: 'radio',
current: '1',
radioList: [
{
value: '1',
name: '男'
},
{
value: '2',
name: '女'
}
]
},
{
label: '车牌号',
value: 'carNumber',
type: 'input',
valueIcon: 'icon-scanning'
},
{
label: '车主姓名1',
value: 'carName1',
maxlength: '10',
type: 'input',
required: true
},
{
label: '车主姓名2',
value: 'carName2',
maxlength: '10',
type: 'input',
required: true
},
{
label: '车主姓名3',
value: 'carName3',
maxlength: '10',
type: 'input',
required: true
},
{
label: '车主姓名4',
value: 'carName4',
maxlength: '10',
type: 'input',
required: true
},
{
label: '车主姓名5',
value: 'carName5',
maxlength: '10',
type: 'input',
required: true
},
{
label: '车主姓名6',
value: 'carName6',
maxlength: '100',
type: 'textarea',
required: true,
placeholder: '请输入 (100字以内)',
class: 'cell-row'
},
]
}
},
methods: {
handleCell(val) {
console.log(val)
switch(val.value) {
case 'user':
setTimeout(() => {
this.formData.user ={
id: 1,
name: '波波的单店门店'
}
}, 1000)
break
default:
break
}
},
radioChange(e, val) {
console.log(e, val)
this.formData[val.value] = e.detail.value
},
submit() {
console.log(this.formData)
}
}
}
</script>
<style scoped lang="scss">
.order {
height: 100%;
}
.box {
height: calc(100% - #{toRpx(120)});
.scroll-view {
height: 100%;
}
}
.box-content {
padding: 0 toRpx(48);
}
</style>
\ No newline at end of file
......@@ -48,7 +48,10 @@ export default {
entranceClick(item) {
console.log(item)
this.toolComponentName = item.name
}
},
backPage() {
uni.navigateBack();
},
}
}
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!