| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <template>
- <div>
- <el-col v-if='item.type ==="input" ' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div class='label full-width padding-left text-left bold' >
- {{ item.label }}
- </div>
- </template>
- <div class='full-width text-left flex full-width'>
- <input v-model='editData[item.prop]' :disabled='disable' :placeholder='`请输入` + item.label'
- @change='change($event,item)'
- class='full-width'/>
- <el-icon v-if='!disable' class="padding-right">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <!--textarea-->
- <el-col v-if='item.type ==="textarea" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-start full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <textarea v-model='editData[item.prop]' :disabled='disable'
- :placeholder='`请输入` + item.label'
- :style='`height:` + item.rows * 35 + `px`'
- class='full-width padding-right full-height padding-top'
- @change='change($event,item)'
- style='line-height:20px;resize:none '/>
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <!-- autoinput-->
- <el-col v-if='item.type ==="autoInput" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-start full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <el-select v-model="editData[item.prop]" class="m-2" :placeholder="`请选择${item.label}`"
- @change='change($event,item)'>
- <el-option
- v-for="item in item.dict"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <el-col v-if='item.type ==="select" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-start full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <el-select v-if='!disable' class="m-2" v-model="editData[item.prop]" :placeholder="`请选择${item.label}`" @change='change($event,item)'>
- <el-option
- v-for="item in item.dict"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select>
- <input v-else disabled v-model='editData[item.prop]' />
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <el-col v-if='item.type ==="area" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-start full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <el-cascader v-if='!disable' ref='area' :options="item.dict" v-model="editData[item.prop]" :disabled='disable' class="m-2"
- :placeholder="`请选择${item.label}`" @change='change($event,item)'>
- </el-cascader>
- <input v-else disabled v-model='editData[item.prop]' />
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <!-- daterange -->
- <el-col v-if='item.type ==="daterange" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-start full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <el-date-picker
- v-if='!disable'
- v-model="editData[item.prop]"
- :disabled='disable'
- type="daterange"
- @change='change($event,item)'
- range-separator="至"
- start-placeholder="开始日期"
- end-placeholder='结束日期'
- value-format='YYYY-MM-DD'
- format='YYYY-MM-DD'
- />
- <input v-else disabled v-model='editData[item.prop]' />
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- <!--number-->
- <el-col v-if='item.type ==="number" ' :style='`height:` + item.rows * 35 + `px`' class='full-width'>
- <div class='flex item full-width'>
- <el-form-item class='full-width '>
- <template v-slot:label>
- <div :style='`height:` + item.rows * 35 + `px`'
- class='label white-bg full-width text-left padding-left bold'>
- {{ item.label }}
- </div>
- </template>
- <div class='full-width flex flex-align-center full-height text-left full-width'
- style='white-space: pre-wrap;text-overflow: ellipsis;'>
- <input v-model='editData[item.prop]' :disabled='disable' type='number' class='full-width'
- :placeholder='`请输入` + item.label' step='2'
- @change='change($event,item)'/>
- <el-icon v-if='!disable' class="padding-right padding-top">
- <edit/>
- </el-icon>
- </div>
- </el-form-item>
- </div>
- </el-col>
- </div>
- </template>
- <script>
- export default {
- name: 'sub',
- props: {
- form: {
- type: Object,
- default: null
- },
- item: {
- type: Object,
- default: null
- },
- disable: {
- type: Boolean,
- default: false
- }
- },
- watch: {
- item: {
- handler (val) {
- if (val.type === 'autoInput') {
- this.getDic(val).then(res => {
- val.dict = res
- })
- console.log(val.dict)
- } else if (val.type === 'area') {
- const tmp = {
- dict: '/blade-system/region/lazy-list',
- props: {
- label: 'name',
- value: 'id'
- }
- }
- val.expand = JSON.stringify(tmp, null, 4)
- val.expand = JSON.parse(val.expand)
- this.getDic(val).then(res => {
- val.dict = res
- })
- } else if (val.type === 'select') {
- this.getDic(val).then(res => {
- val.dict = res
- })
- }
- },
- immediate: true
- },
- form: {
- handler (val) {
- this.editData = val
- },
- immediate: true
- },
- editData: {
- deep: true,
- immediate: false
- }
- },
- data () {
- return {
- data: {},
- dic: [],
- editData: null
- }
- },
- methods: {
- async getDic (item) {
- let result = []
- if (item.type === 'area') {
- const local = localStorage.getItem('lazy-list')
- if (local) {
- return JSON.parse(local)
- }
- const tmp = await this.$api.common.basicFormRequest(item.expand.dict)
- result = tmp.data.map(sub => this.mapTree(sub, item.expand))
- localStorage.setItem('lazy-list', JSON.stringify(result))
- } else {
- const tmp = await this.$api.common.basicFormRequest(item.expand.dict)
- result = tmp.data.map(sub => this.mapTree(sub, item.expand))
- }
- return result
- },
- mapTree (item, expand) {
- const haveChildren = Array.isArray(item.children) && item.children.length > 0
- return {
- key: item.label,
- value: item[expand.props.value],
- label: item[expand.props.label],
- children: haveChildren ? item.children.map(i => this.mapTree(i, expand)) : []
- }
- },
- change (res, item) {
- if (item.type === 'area') {
- this.editData[item.prop] = res[0]
- const tmp = this.$refs.area.getCheckedNodes()[0].pathLabels
- const keys = Object.keys(res)
- if (keys.length === 3) {
- this.editData.provinceCode = res[0]
- this.editData.province = tmp[0]
- this.editData.cityCode = res[1]
- this.editData.city = tmp[1]
- this.editData.districtCode = res[2]
- this.editData.district = tmp[2]
- } else if (keys.length === 2) {
- this.editData.provinceCode = res[0]
- this.editData.province = tmp[0]
- this.editData.cityCode = res[1]
- this.editData.city = res[1]
- } else {
- this.editData.provinceCode = res[0]
- this.editData.province = res[0]
- }
- }
- this.$emit('change', this.editData)
- }
- }
- }
- </script>
- <style lang='scss' scoped>
- .form {
- border-right: #CCCFCE solid 1px;
- border-left: #CCCFCE solid 1px;
- border-bottom: #CCCFCE solid 1px;
- .item {
- :deep(.el-form-item--default) {
- margin-bottom: 0;
- padding: 0;
- }
- }
- .label {
- padding-right: 10px;
- border-right: #CCCFCE solid 1px;
- }
- .sub-item {
- border-left: #CCCFCE solid 1px;
- }
- .sub-item:first-child {
- border-left: none;
- }
- }
- .form:first-child {
- padding: 0;
- border: #CCCFCE solid 1px;
- }
- </style>
|