123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850 |
- <template>
- <el-form ref="baseForm" :inline="isInline" :model="baseForm" :label-position="labelPosition" :label-width="labelWidth" class="xl-form" :class="isInline && 'inputw190'">
- <template v-for="(item, index) in curData">
- <template v-if="insertSlotArr.indexOf(index) > -1">
- <slot :name="`OI${index}`" />
- </template>
- <el-form-item
- v-if="item.type === 'select'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :label-width="item.singleLabelWidth || labelWidth"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-select
- v-model.trim="baseForm[item.key]"
- clearable
- :placeholder="`请选择${item.label2 || item.label}`"
- :disabled="item.disabled || false"
- :multiple="item.multiple || false"
- :filterable="item.filterable"
- @change="changeHandle"
- @remove-tag="focusHandle(item.key)"
- @focus="focusHandle(item.key)"
- >
- <el-option
- v-for="(op, o) in item.options"
- :key="o"
- :label="op.key"
- :disabled="op.disabled"
- :value="op.val"
- >{{ op.key }}</el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'colorPicker'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :label-width="item.singleLabelWidth || labelWidth"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-color-picker
- @change="changeHandle"
- @focus="focusHandle(item.key)"
- v-model.trim="baseForm[item.key]">
- </el-color-picker>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'selectRemote'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :label-width="item.singleLabelWidth || labelWidth"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-select
- v-model.trim="baseForm[item.key]"
- filterable
- remote
- clearable
- :disabled="item.disabled || false"
- :multiple="item.multiple || false"
- :remote-method="remoteMethod"
- :loading="formLoading"
- :placeholder="`搜索${item.label}`"
- @change="changeHandle"
- @remove-tag="focusHandle(item.key)"
- @focus="focusHandle(item.key)"
- >
- <el-option
- v-for="(op, o) in item.remoteOptions"
- :key="o"
- :label="op.keyRO"
- :disabled="op.disabled"
- :value="op.valRO"
- >{{ op.keyRO }}</el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'datePicker'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-date-picker
- v-model.trim="baseForm[item.key]"
- :style="item.type2 === 'date' && 'width: 100%;'"
- unlink-panels
- :type="`${item.type2 ? item.type2 : 'daterange'}`"
- :align="'right'"
- :value-format="`${item.valueFormat ? item.valueFormat : 'yyyy-MM-dd'}`"
- range-separator="至"
- :disabled="item.disabled || false"
- :placeholder="`请选择${item.label}`"
- :start-placeholder="item.label2"
- :end-placeholder="item.label3"
- :picker-options="`${item.type2 ? {} : item.datePickerOptions}`"
- @focus="focusHandle(item.key)"
- />
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'timePicker'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-time-picker
- v-model="baseForm[item.key]"
- :is-range="item.type2!=='time'"
- range-separator="至"
- :value-format="item.format || 'HH:mm'"
- :format="item.format || 'HH:mm'"
- :disabled="item.disabled || false"
- :start-placeholder="item.label2 || '开始时间'"
- :end-placeholder="item.label3 || '结束时间'"
- :placeholder="`请选择${item.label}`"
- />
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'inputFont'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请输入'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-input
- v-model.trim="baseForm[item.key]"
- clearable
- :disabled="item.disabled || false"
- :maxlength="item.maxlength || false"
- :placeholder="`请输入${item.label2 || item.label}`"
- @change="changeHandle"
- @focus="focusHandle(item.key)"
- >
- <template v-if="item.prependFont" slot="prepend">{{ item.prependFont }}</template>
- <template v-if="item.appendFont" slot="append">{{ item.appendFont }}</template>
- </el-input>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'cascader'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-cascader
- v-model.trim="baseForm[item.key]"
- clearable
- :options="item.options"
- :props="item.props || {}"
- :disabled="item.disabled || false"
- :placeholder="`请选择${item.label}`"
- @focus="focusHandle(item.key)"
- @change="changeHandle"
- />
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'upload'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- class="img-upload"
- :disabled="item.disabled || false"
- :action="`${requireUrl}/adm/upload/cloud`"
- :data="{logic_type: 'estate', token}"
- name="upload"
- :show-file-list="false"
- :on-success="uploadSuccess"
- :on-error="uploadError"
- :before-upload="uploadBefore"
- >
- <img v-if="baseForm[item.key]" :src="baseForm[item.key].indexOf('_adm0') > -1 ? baseForm[item.key] : baseForm[item.key] + '_adm0'" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'cuImg'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- class="img-upload"
- :action="`${requireUrl}/adm/upload/cloudpub`"
- :data="{logic_type: 'estate', token}"
- name="upload"
- ref="cui"
- :auto-upload="false"
- :show-file-list="false"
- :on-change='cuImgOpen'
- :on-success="uploadSuccess"
- >
- <template v-if="item.options && item.options.SY === 1">
- <img v-if="baseForm[item.key]" :src="baseForm[item.key].indexOf('_adm0') > -1 ? baseForm[item.key] : baseForm[item.key] + '_adm0'" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </template>
- <template v-else>
- <img v-if="baseForm[item.key]" :src="baseForm[item.key]" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </template>
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'uploads'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- class="img-upload"
- :disabled="item.disabled || false"
- :action="`${requireUrl}/adm/upload/cloudpub`"
- :data="{logic_type: 'estate', token}"
- name="upload"
- :show-file-list="false"
- :on-success="uploadSuccess"
- :on-error="uploadError"
- :before-upload="uploadBefore"
- >
- <img v-if="baseForm[item.key]" :src="baseForm[item.key]" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'uploadsGif'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- class="img-upload"
- :disabled="item.disabled || false"
- :action="`${requireUrl}/adm/upload/cloudpub`"
- :data="{logic_type: 'estate', token}"
- name="upload"
- :show-file-list="false"
- :on-success="uploadSuccess"
- :on-error="uploadError"
- :before-upload="uploadGifBefore"
- >
- <img v-if="baseForm[item.key]" :src="baseForm[item.key]" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'uploadIcon'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- class="img-upload"
- :disabled="item.disabled || false"
- :action="`${requireUrl}/adm/theme/icon/upload`"
- :data="{logic_type: 'estate', token}"
- name="upload"
- :show-file-list="false"
- :on-success="uploadSuccess"
- :on-error="uploadError"
- :before-upload="uploadBefore"
- >
- <img v-if="baseForm[item.key]" :src="baseForm[item.key]" class="img" @click="focusHandle(item.key)">
- <i v-else class="el-icon-plus icon" @click="focusHandle(item.key)" />
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'upload2'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请选择'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-upload
- :disabled="item.disabled || false"
- :action="`${requireUrl}/adm/upload/cloud`"
- :data="{filename: 'sysimg', token}"
- name="upload"
- :on-success="uploadSuccess2"
- :on-error="uploadError"
- :multiple="item.limit || false"
- :limit="item.limit || 1"
- :on-exceed="uploadHandleExceed"
- :on-remove="uploadHandleRemove"
- :file-list="baseForm[item.key] || []"
- :before-upload="uploadBefore2"
- @click.native="focusHandle(item.key)"
- >
- <el-button size="small" type="success" @click="focusHandle(item.key)">{{ baseForm[item.key].length > 0 ? '重新上传' : '立即上传' }}</el-button>
- </el-upload>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'inputSelect'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请输入'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-input
- v-model.trim="baseForm[item.key]"
- clearable
- :disabled="item.disabled || false"
- :placeholder="`请输入${item.label2 || item.label}`"
- @focus="focusHandle(item.key)"
- >
- <template slot="append">
- <el-select
- v-model.trim="baseForm[item.selectObj.key]"
- :disabled="item.disabled || false"
- :placeholder="`${item.selectObj.label}`"
- >
- <el-option
- v-for="(op, o) in item.selectObj.options"
- :key="o"
- :label="op.key"
- :value="op.val"
- >{{ op.key }}</el-option>
- </el-select>
- </template>
- </el-input>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'checkbox'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请勾选'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-checkbox-group v-model.trim="baseForm[item.key]" :disabled="item.disabled || false">
- <el-checkbox
- v-for="(op, o) in item.options"
- :key="o"
- :label="op.val"
- >{{ op.key }}</el-checkbox>
- </el-checkbox-group>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'radio'"
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :label-width="item.singleLabelWidth || labelWidth"
- :rules="item.rules === 1 ? [{ required: true, message: '请勾选'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-radio-group v-model.trim="baseForm[item.key]" :disabled="item.disabled || false">
- <el-radio
- v-for="(op, o) in item.options"
- :key="o"
- :label="op.val"
- :disabled="op.disabled"
- >{{ op.key }}</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item
- v-else-if="item.type === 'switch'"
- :key="index"
- :class="item.class"
- :label="isInline && noLabel ? '' : item.label"
- >
- <el-switch
- v-model="baseForm[item.key]"
- :active-value="item.labelTrue || '1'"
- :inactive-value="item.labelFalse || '2'"
- :active-color="item.activeColor || '#13ce66'"
- :inactive-color="item.inactiveColor || '#ccc'"
- :active-text="item.activeText"
- :inactive-text="item.inactiveText"
- :disabled="item.disabled || false"
- @change="changeHandle"
- @focus.native="focusHandle(item.key)"
- @click.native="focusHandle(item.key)"
- />
- </el-form-item>
- <el-form-item
- v-else
- :key="index"
- :class="item.class"
- :prop="item.key"
- :label="isInline && noLabel ? '' : item.label"
- :rules="item.rules === 1 ? [{ required: true, message: '请输入'+ item.label, trigger: 'blur' }] : item.rules"
- >
- <el-input
- v-model.trim="baseForm[item.key]"
- clearable
- :type="item.type || 'text'"
- :disabled="item.disabled || false"
- :placeholder="`请输入${item.label2 || item.label}`"
- :maxlength="item.maxlength || false"
- @change="changeHandle"
- @focus="focusHandle(item.key)"
- />
- </el-form-item>
- </template>
- <slot name="otherItem" />
- <el-form-item>
- <slot name="footer" />
- </el-form-item>
- <cropper-img
- :isShow="isCIShow"
- :curObj="uploadObj"
- @close="cuImgClose"
- />
- </el-form>
- </template>
- <script>
- import { strTrim } from '@/utils'
- import CropperImg from './CropperImg'
- export default {
- name: 'BaseForm',
- components: { CropperImg },
- props: {
- data: Array,
- labelWidth: {
- default: '80px',
- type: String
- },
- isInline: {
- default: true,
- type: Boolean
- },
- noLabel: {
- default: true,
- type: Boolean
- },
- labelPosition: {
- default: 'right',
- type: String
- },
- insertSlotArr: {
- default: () => [],
- type: Array
- }
- },
- data() {
- const curData = this.data
- let requireUrl = process.env.VUE_APP_BASE_API
- const userApi = window.sessionStorage.getItem('testUrl')
- const token = window.sessionStorage.getItem('fp_token')
- if (process.env.VUE_APP_BASE_API === 'http://api.t.antretail.cn' && userApi) {
- requireUrl = userApi
- }
- return {
- token,
- requireUrl,
- curData,
- formLoading: false,
- baseForm: {},
- curFormKey: '',
- curFormIndex: '',
- selectRemoteTotal: null,
- selectRemoteNum: null,
- uploadHeaders: {
- 'Content-Type': 'multipart/form-data'
- },
- remoteOptionsPrev: {},
- isCIShow: false,
- uploadObj: {},
- }
- },
- watch: {
- data: {
- handler: function(val) {
- if (val.length === 0) return
- this.curData = [...val]
- this.selectRemoteTotal = 0
- this.selectRemoteNum = 0
- const baseForm = {}
- val.forEach((item, index) => {
- let emptyVal = ''
- // if (item.type === 'cascader' || item.type === 'upload2') emptyVal = []
- if (item.type === 'switch') emptyVal = item.labelFalse || '2'
- if (item.type === 'selectRemote') this.selectRemoteTotal++
- baseForm[item.key] = item.defaultValue || emptyVal
- if (item.type === 'datePicker') {
- this.curData[index].datePickerOptions = {
- shortcuts: [{
- text: '昨天',
- onClick(picker) {
- // const end = new Date()
- const start = new Date()
- start.setTime(start.getTime() - 3600 * 1000 * 24)
- picker.$emit('pick', [start, start])
- }
- }, {
- text: '最近一周',
- onClick(picker) {
- const end = new Date()
- const start = new Date()
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
- picker.$emit('pick', [start, end])
- }
- }, {
- text: '最近一个月',
- onClick(picker) {
- const end = new Date()
- const start = new Date()
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
- picker.$emit('pick', [start, end])
- }
- }, {
- text: '最近三个月',
- onClick(picker) {
- const end = new Date()
- const start = new Date()
- start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
- picker.$emit('pick', [start, end])
- }
- }]
- }
- if (item.disabledDate === '-1') {
- this.curData[index].datePickerOptions.disabledDate = function(time) {
- return time.getTime() > Date.now() - 3600 * 1000 * 24
- }
- }
- }
- })
- this.baseForm = Object.assign({}, baseForm)
- const that = this
- that.$nextTick(() => {
- that.$refs['baseForm'].resetFields()
- val.forEach((op, i) => {
- // 待优化,目前每次open都有请求
- if (that.curData[i].type === 'selectRemote') {
- that.remoteMethod(null, i)
- }
- })
- })
- },
- immediate: true
- }
- },
- methods: {
- uploadHandleExceed(files, fileList) {
- this.$message.warning(`当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
- },
- uploadSuccess(res, file) {
- // console.log(res)
- const data = res.data || {}
- const uploadItem = this.curData[this.curFormIndex]
- // this.baseForm[uploadItem.key] = `${data.domain}${data.url}?url=${data.url}&id=${data.file_id}`
- this.baseForm[uploadItem.key] = `${data.url}`
- // this.baseForm[uploadItem.key] = uploadItem.uploadData.domain + res.key
- // this.imageUrl = URL.createObjectURL(file.raw)
- this.changeHandle(file)
- },
- uploadError(file) {
- this.changeHandle(file)
- },
- uploadGifBefore(file) {
- const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif'
- const isLtM = file.size / 1024 / 1024 < 30
- if (!isJPGPNG) {
- this.$message.error('上传图片只能是 JPG PNG GIF 格式!')
- }
- if (!isLtM) {
- this.$message.error('上传图片大小不能超过 30M!')
- }
- return isJPGPNG && isLtM
- },
- uploadBefore(file) {
- const isJPGPNG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif'
- const isLtM = file.size / 1024 / 1024 < 10
- if (!isJPGPNG) {
- this.$message.error('上传图片只能是 JPG PNG GIF 格式!')
- }
- if (!isLtM) {
- this.$message.error('上传图片大小不能超过 10M!')
- }
- return isJPGPNG && isLtM
- },
- uploadBefore2(file) {
- // console.log(file.type)
- },
- uploadSuccess2(res, file) {
- const data = res.data || {}
- const uploadItem = this.curData[this.curFormIndex]
- this.baseForm[uploadItem.key] = [{
- name: file.name,
- url: data.url
- }]
- this.changeHandle(file)
- },
- uploadHandleRemove(file, fileList) {
- window.setTimeout(() => {
- this.$set(this.baseForm, this.curFormKey, [])
- }, 100)
- },
- changeHandle(val) {
- this.$nextTick(() => {
- if (parseFloat(this.curFormIndex).toString() === 'NaN') return
- const curFormItem = this.curData[this.curFormIndex]
- if (curFormItem) {
- if (curFormItem.changeHandle) {
- if (curFormItem.type === 'selectRemote' && curFormItem.remoteOptions) {
- let curOption = curFormItem.multiple ? [] : {}
- curFormItem.remoteOptions.forEach(item => {
- if (curFormItem.multiple) {
- const subArr = String(val).split(',') || []
- subArr.forEach(sub => {
- if (String(item.valRO) === sub) {
- curOption.push(item)
- }
- })
- } else {
- if (item.valRO === val) {
- curOption = item
- }
- }
- })
- // let curOption = {}
- // curFormItem.remoteOptions.forEach(item => {
- // if (item.valRO === val) {
- // curOption = item
- // }
- // })
- curFormItem.changeHandle(val, curFormItem, curOption)
- } else if (curFormItem.type === 'select' && curFormItem.options) {
- let curOption = curFormItem.multiple ? [] : {}
- curFormItem.options.forEach(item => {
- if (curFormItem.multiple) {
- const subArr = val || []
- subArr.forEach(sub => {
- if (item.val === sub) {
- curOption.push(item)
- }
- })
- } else {
- if (item.val === val) {
- curOption = item
- }
- }
- })
- curFormItem.changeHandle(val, curFormItem, curOption)
- } else {
- curFormItem.changeHandle(val, curFormItem, this.curFormIndex)
- }
- }
- if (curFormItem.type === 'selectRemote') {
- this.remoteChange(val)
- }
- if (curFormItem.type === 'checkbox' || curFormItem.type === 'switch') {
- // console.log(this.curFormKey)
- this.$set(this.baseForm, this.curFormKey, val)
- }
- }
- })
- },
- focusHandle(key) {
- this.curFormKey = key
- for (let i = 0; i < this.curData.length; i++) {
- if (this.curData[i].key === this.curFormKey) {
- this.curFormIndex = i
- const curFormItem = this.curData[i]
- if (curFormItem.focusHandle) {
- curFormItem.focusHandle(key, curFormItem, this.curFormIndex)
- }
- return
- }
- }
- },
- cuImgOpen(file, fileList) {
- const isLt10M = file.size / 1024 / 1024 < 1000
- if (!isLt10M) {
- this.$msgw('上传文件大小不能超过 1000MB!')
- return false
- }
- this.$nextTick(() => {
- let cObj = this.curData[this.curFormIndex]
- this.uploadObj = {
- url: URL.createObjectURL(file.raw),
- file,
- options: cObj.options,
- }
- this.isCIShow = true
- })
- },
- cuImgClose (url) {
- this.isCIShow = false
- if (url) {
- this.baseForm[this.curFormKey] = url
- }
- },
- remoteChange(val) {
- if (val) {
- const remoteParams = this.curData[this.curFormIndex].remoteParams
- if (remoteParams && remoteParams.changeKey) {
- this.$set(this.baseForm, remoteParams.changeKey, val)
- }
- }
- },
- remoteMethod(val, curI) {
- // const loading = this.$loading({
- // lock: true,
- // spinner: 'none',
- // background: 'rgba(0, 0, 0, 0.7)'
- // })ss
- let curIndex = this.curFormIndex
- if (Number(curI) > -1) curIndex = curI
- this.formLoading = true
- if (!this.curData[curIndex]) return
- const remoteParams = this.curData[curIndex].remoteParams
- const apiArr = remoteParams.api.split('?')
- const apiUrl = apiArr[0]
- const params = this.noEmpty(val) ? { [remoteParams.skey]: strTrim(val) } : {}
- const apiUrlArr = apiUrl.split('.')
- if (apiArr[1]) {
- const queryArr = apiArr[1].split('&')
- queryArr.forEach(item => {
- const itemArr = item.split('=')
- if (this.noEmpty(itemArr[1])) params[itemArr[0]] = itemArr[1]
- })
- }
- if (!this.$api[apiUrlArr[0]] || !this.$api[apiUrlArr[0]][apiUrlArr[1]]) {
- console.warn('tip:接口不存在')
- return
- }
- if (val !== null && !params[remoteParams.skey]) {
- this.curData[curIndex].remoteOptions = this.remoteOptionsPrev[curIndex]
- this.$set(this.curData[curIndex], 'remoteOptions', this.remoteOptionsPrev[curIndex])
- this.formLoading = false
- const baseForm = { ...this.baseForm }
- this.$refs['baseForm'].resetFields()
- window.setTimeout(() => {
- this.baseForm = { ...baseForm }
- this.isRemoteOne = false
- }, 200)
- // loading.close()
- return
- }
- this.$api[apiUrlArr[0]][apiUrlArr[1]](params).then(data => {
- const arr = data.list || []
- const remoteOptions = []
- arr.forEach(item => {
- const curItem = { keyRO: item[remoteParams.opKey], valRO: item[remoteParams.opVal] }
- remoteOptions.push({ ...item, ...curItem })
- })
- const defaultRemoteOptions = this.curData[curIndex].remoteOptions || []
- if (val === null && defaultRemoteOptions && defaultRemoteOptions.length > 0) {
- const edIndexArr = []
- defaultRemoteOptions.forEach((old, o) => {
- remoteOptions.forEach(r => {
- if (String(old.valRO) === String(r.valRO)) {
- edIndexArr.push(o)
- }
- })
- if (edIndexArr.indexOf(o) === -1 && this.noEmpty(old.valRO)) {
- remoteOptions.unshift(old)
- }
- })
- }
- this.curData[curIndex].remoteOptions = remoteOptions
- const remoteOptionsPrev = this.remoteOptionsPrev[curIndex] || []
- const remoteOptionsPrev2 = [...remoteOptionsPrev]
- remoteOptionsPrev.forEach((one, o) => {
- remoteOptions.forEach(two => {
- if (one.valRO === two.valRO) {
- remoteOptionsPrev2.splice(o, 1)
- }
- })
- })
- this.remoteOptionsPrev[curIndex] = [...remoteOptionsPrev2, ...remoteOptions]
- this.formLoading = false
- this.selectRemoteNum++
- if (this.selectRemoteTotal === this.selectRemoteNum) {
- this.$emit('loaded')
- // loading.close()
- }
- this.curData = [...this.curData]
- })
- },
- btnHandle(key) { // 按钮回调
- this.curFormKey = key
- for (let i = 0; i < this.curData.length; i++) {
- if (this.curData[i].key === this.curFormKey) {
- this.$nextTick(() => {
- if (parseFloat(i).toString() === 'NaN') return
- const curFormItem = this.curData[i]
- if (curFormItem) {
- if (curFormItem.btnHandle) {
- curFormItem.btnHandle(key, this.curData[i].remoteOptions)
- }
- }
- })
- return
- }
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .img-upload {
- ::v-deep .el-upload {
- border: 1px dashed #d9d9d9;
- border-radius: 6px;
- cursor: pointer;
- position: relative;
- overflow: hidden;
- &:hover {
- border-color: #409EFF;
- }
- }
- .icon {
- font-size: 28px;
- color: #8c939d;
- width: 178px;
- height: 178px;
- line-height: 178px;
- text-align: center;
- }
- .img {
- width: 178px;
- height: 178px;
- display: block;
- }
- }
- ::v-deep .el-form-item__content{
- display: flex;
- align-items: center;
- height: 100%;
- }
- </style>
|