Files
foton-laws-system-front/src/components/CustomFormComponents/DatePickerWithText2.vue
T
2021-05-25 18:06:45 +08:00

153 lines
3.3 KiB
Vue

<template>
<!-- <div>-->
<!-- </div>-->
<el-col :span="span" class="date-picker-with-text">
<div class="wrap">
<el-form-item
:label="config.attrName"
:prop="config.attrField"
:label-width="labelWidth"
class="add-form-item"
:class="{'form-item-disabled': disabled}"
:title="config.attrName"
>
<el-datePicker
v-if="radioValue === '1'"
:value="value"
type="date"
:editable="true"
:disabled="disabled"
:placeholder="placeholder"
@input="handleChange"
></el-datePicker>
<el-input
:value="value"
v-if="radioValue !== '1'"
disabled
/>
</el-form-item>
</div>
<div class="warp">
<el-form-item label-width="10px">
<el-radio-group :value="radioValue" :disabled="disabled">
<el-radio label="1" @click.native="handleRadioChange('1')">时间</el-radio>
<el-radio label="已发布" @click.native="handleRadioChange('已发布')">已发布</el-radio>
<el-radio label="TBD" @click.native="handleRadioChange('TBD')">TBD</el-radio>
</el-radio-group>
</el-form-item>
</div>
</el-col>
</template>
<script>
export default {
name: 'DatePickerWithText2',
props: {
config: {
type: Object,
required: true
},
value: {
required: true
},
disabled: {
type: Boolean,
default: false
},
// 栅格比例
span: {
type: Number,
default: 24
},
labelWidth: {
type: String,
default: '150px'
}
},
data() {
return {
// radioValue: ''
}
},
computed: {
placeholder () {
return `请选择${this.config.attrName}`
},
showMessage () {
return `${this.config.attrName}不能为空`
},
isRequired () {
return !!this.config.isMust
},
isString (str) {
return (typeof str === 'string') && str.constructor === String
},
radioValue() {
const value = this.value
if (value === '已发布' || value === 'TBD') {
return value
} else {
return '1'
}
}
},
watch: {
value: {
immediate: true,
handler: (newValue, oldValue) => {
// console.log(newValue)
// if (newValue === 'N/A') {
// this.radioValue = 'N/A'
// } else if (newValue === 'TBD') {
// this.radioValue = 'TBD'
// } else {
// this.radioValue = '1'
// }
}
}
},
methods: {
handleChange (value) {
if (value) {
this.$emit('input', this.$moment(value).format('YYYY-MM-DD'))
} else {
this.$emit('input', '')
}
},
handleRadioChange (val) {
switch (val) {
case '1':
this.$emit('input', '')
break
case '已发布':
this.$emit('validate')
this.$emit('input', '已发布')
break
case 'TBD':
this.$emit('validate')
this.$emit('input', 'TBD')
break
}
}
}
}
</script>
<style lang="less" scoped>
.date-picker-with-text {
display: flex;
.wrap {
&:first-child {
flex: 1;
overflow: hidden;
}
}
}
/deep/.el-form-item{
margin-bottom: 0;
}
/deep/.el-form-item__error{
right: 0 !important;
}
</style>