XhInput.vue 2.24 KB
<!-- *******************  输入框  *******************  -->
<template>
	<view :style="{'width': fieldsWidth}">
		<u-input :type="type" class="input-item" v-model="dataValue" @input="valueChange" :placeholder="placeholder" :placeholder-style="placeholderStyle"
		:custom-style="customStyle" :clearable="false" :border="border" border-color="#ECECEC" :maxlength="maxlength" :cursor-spacing="10" hold-keyboard/>
	</view>
</template>

<script>
	import stringMixin from './stringMixin'
	export default {
		name: 'XhInput', // 新建 input
		components: {},
		mixins: [stringMixin],
		props: {
			placeholder: {
				type: String,
				default: '请输入'
			},
			item: {
				type: Object,
				default() {
					return {}
				}
			},
			type: {
				type: String,
				default: 'text'
			}
			// width: { // 例如:454rpx
			// 	type: String,
			// 	default: '100%'
			// }
		},
		data() {
			return {
				inputType: 'text',
				// type: 'text'
			}
		},
		computed: {
			// type() {
			// 	if (this.item) {
			// 		let ty = this.item.fieldsType.toLocaleLowerCase()
			// 		switch (ty) {
			// 			case 'text':
			// 				return 'textarea'
			// 			case 'password':
			// 				return this.item.fieldsType
			// 			case 'decimal':
			// 			case 'number':
			// 			case 'double':
			// 			case 'integer':
			// 				this.maxlength = 9
			// 				return 'digit'
			// 			case 'textarea':
			// 			default:
			// 				return 'text'
			// 		}
			// 	} else {
			// 		return 'text'
			// 	}

			// },
			maxlength() {
				return this.type == 'digit' ? 9 : 140
			},
			fieldsWidth() {
				return this.item.fieldsWidth ?  (this.item.fieldsWidth + 'rpx') : '100%'
			},
			placeholderStyle() {
				return 'color:#999999;font-size:26rpx'
			},
			customStyle() {
				return {
					'background-color': this.backgroundColor,
					'border-radius': '12rpx',
					'color': '#333333',
					'padding-left': this.textarea ? '0rpx' : '20rpx',
					'font-size':'26rpx',
					'height': '76rpx'
				}
			},
			border() {
				return this.textarea
			},
			textarea() {
				return this.inputType == 'textarea'
			},
			backgroundColor() {
				return this.textarea ? 'transparent' : '#F4F5F7'
			}
		},
		watch: {},
		mounted() {},
		methods: {}
	}
</script>

<style scoped>
	.input-item{
		background: #F4F5F7;
	}
</style>