form-group-repeater.wxml 5.7 KB
<view class="group-repeater">
	<view class="group-repeater__section">
		<view class="group-repeater__header">
			<view class="group-repeater__title {{ disabled ? 'is-disabled' : '' }}">{{ group.label }}</view>
			<view
				wx:if="{{ canAdd }}"
				class="group-repeater__add-btn"
				bindtap="onAdd"
			>
				<view class="group-repeater__add-icon"></view>
				<text class="group-repeater__add-text">新增</text>
			</view>
		</view>

		<view wx:if="{{ rowTotal > 0 }}" class="group-repeater__nav">
			<view
				class="group-repeater__nav-btn {{ rowTotal <= 1 || activeIndex <= 0 ? 'is-disabled' : '' }}"
				data-direction="-1"
				bindtap="onNav"
			>
				<image class="group-repeater__nav-icon" src="{{ navIconLeft }}" mode="aspectFit" />
			</view>
			<view class="group-repeater__nav-text">{{ rowTotal ? activeIndex + 1 : 0 }}/{{ rowTotal }}</view>
			<view
				class="group-repeater__nav-btn {{ !rowTotal || activeIndex + 1 >= rowTotal ? 'is-disabled' : '' }}"
				data-direction="1"
				bindtap="onNav"
			>
				<image class="group-repeater__nav-icon" src="{{ navIconRight }}" mode="aspectFit" />
			</view>
		</view>

		<view wx:if="{{ rowTotal > 0 }}" class="group-repeater__card">
			<view class="group-repeater__card-hd">
				<text class="group-repeater__row-label">第{{ rowTotal ? activeIndex + 1 : 0 }}行</text>
				<view wx:if="{{ !disabled }}" class="group-repeater__delete" bindtap="onRemove">
					<image
						class="group-repeater__delete-icon"
						src="{{ IMG_URL }}images/delete.png"
						mode="aspectFit"
					/>
				</view>
			</view>
			<view class="group-repeater__fields">
				<block
					wx:for="{{ visibleRowFields }}"
					wx:key="_wxRowKey"
					wx:for-item="child"
				>
					<form-field-radio
						wx:if="{{ child.type === 'radio' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
					/>
					<form-field-select
						wx:elif="{{ child.type === 'select' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						request-context="{{ requestContext }}"
						row-values="{{ rowValues }}"
						group-brand-ids="{{ group.brandId }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
					/>
					<form-field-input
						wx:elif="{{ child.type === 'input' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
						bind:blur="onFieldBlur"
					/>
					<form-field-phone
						wx:elif="{{ child.type === 'phoneInput' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
						bind:blur="onFieldBlur"
					/>
					<form-field-datetime
						wx:elif="{{ child.type === 'datetime' || child.type === 'date' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
					/>
					<form-field-carBrand
						wx:elif="{{ child.type === 'carBrandSelect' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
					/>
					<form-field-multipleSelect
						wx:elif="{{ child.type === 'multipleSelect' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						request-context="{{ requestContext }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
					/>
					<form-field-number
						wx:elif="{{ child.type === 'numberInput' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
						bind:blur="onFieldBlur"
					/>
					<form-field-textarea
						wx:elif="{{ child.type === 'textarea' }}"
						id="{{ child._wxRowKey }}"
						field="{{ child }}"
						value="{{ child.value == null ? '' : child.value }}"
						disabled="{{ disabled || child.disabled }}"
						error="{{ errors[group.key + '__' + activeIndex + '__' + child.key] || '' }}"
						group-key="{{ group.key }}"
						row-index="{{ activeIndex }}"
						bind:change="onFieldChange"
					/>
				</block>
			</view>
		</view>
	</view>

	<view wx:if="{{ errors[group.key] }}" class="group-repeater__group-error">{{ errors[group.key] }}</view>
</view>