123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <template>
- <a-modal
- :title="modalTitle"
- :width="800"
- :visible="visible"
- :confirmLoading="confirmLoading"
- @cancel="handleCancel"
- >
- <a-form :form="form">
- <row-list :col="2">
- <row-item>
- <a-form-item
- label="显示名称"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['label']"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="字段名称"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['fieldName']"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="类型"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-select
- v-decorator="['type', {rules: [{required: true, message: '类型不能为空'}]}]"
- placeholder="请选择">
- <a-select-option
- v-for="(label,value) in typeMap"
- :key="value"
- :label="label"
- :value="parseInt(value)">{{ label }}
- </a-select-option>
- </a-select>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="是否必填"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-select
- v-decorator="['required', {rules: [{required: true, message: '类型不能为空'}]}]"
- placeholder="请选择">
- <a-select-option
- v-for="(label,value) in yesNoMap"
- :key="value"
- :label="label"
- :value="parseInt(value)">{{ label }}
- </a-select-option>
- </a-select>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="显示行数"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['rows', {rules: [{required: true, message: '不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="排序"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['sort', {rules: [{required: true, message: '不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="最小长度"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['minLength', {rules: [{required: true, message: '不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="最大长度"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['maxLength', {rules: [{required: true, message: '不能为空'}]}]"/>
- </a-form-item>
- </row-item>
- <row-item>
- <a-form-item
- label="默认值"
- :labelCol="BaseTool.Constant.labelCol"
- :wrapperCol="BaseTool.Constant.wrapperCol"
- >
- <a-input
- v-decorator="['defaultValue']"/>
- </a-form-item>
- </row-item>
- </row-list>
- </a-form>
- <title-divider title="下拉选择项明细" width="90px"></title-divider>
- <div class="table-operator" style="margin-bottom: 8px;">
- <a-button size="small" type="primary" @click="handleOption">
- <a-icon type="plus"/>
- 添加
- </a-button>
- <a-button class="margin-left8" size="small" type="danger" @click="handleDelOption">
- <a-icon type="delete"/>
- 删除
- </a-button>
- </div>
- <a-table
- bordered
- :data-source="data"
- :columns="columns"
- tableLayout="auto"
- rowKey="name"
- :row-selection="rowSelection">
- <span slot="action" slot-scope="record">
- <template>
- <a @click="handleOption(record)">修改</a>
- <a-divider type="vertical" />
- <a-popconfirm title="是否要删除该条数据?" @confirm="handleDelOption(record.name)">
- <a>删除</a>
- </a-popconfirm>
- </template>
- </span>
- </a-table>
- <template slot="footer">
- <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
- </template>
- <option-form ref="optionForm" @ok="handleOptionList" />
- </a-modal>
- </template>
- <script>
- import OptionForm from './OptionForm'
- import DetailList from '@/components/tools/DetailList'
- import pick from 'lodash.pick'
- import Vue from 'vue'
- export default {
- name: 'FieldTemplateOptionForm',
- components: {
- OptionForm,
- DetailList
- },
- data () {
- return {
- confirmLoading: false,
- modalTitle: null,
- form: this.$form.createForm(this),
- visible: false,
- data: [],
- // 下拉框map
- yesNoMap: {},
- record: {},
- typeMap: {},
- rowSelection: {
- onChange: (selectedRowKeys, selectedRows) => {
- this.selectedRowKeys = selectedRowKeys
- this.selectedRows = selectedRows
- }
- },
- selectedRowKeys: [],
- selectedRows: [],
- options: {
- rowSelection: {
- selectedRowKeys: this.selectedRowKeys
- }
- },
- // 表头
- columns: [
- {
- title: '序号',
- dataIndex: 'index',
- customRender: (text, record, index) => {
- return index + 1
- }
- },
- {
- title: '参数名称',
- dataIndex: 'name'
- },
- {
- title: '参数值',
- dataIndex: 'value'
- },
- {
- title: '操作',
- key: 'action',
- align: 'center',
- scopedSlots: { customRender: 'action' }
- }
- ]
- }
- },
- props: {
- },
- created () {
- // 下拉框map
- this.yesNoMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
- this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOM_FIELD_TEMPLATE_FILED_TYPE)
- },
- methods: {
- base (record) {
- this.visible = true
- // 如果是空标识添加
- this.modalTitle = '字段设置'
- this.record = record
- this.data = record.optionList || []
- const { form: { setFieldsValue } } = this
- // 日期处理
- this.$nextTick(() => {
- setFieldsValue(Object.assign(pick(record, [
- 'label',
- 'fieldName',
- 'type',
- 'required',
- 'sort',
- 'rows',
- 'minLength',
- 'maxLength',
- 'defaultValue'
- ])))
- })
- },
- save () {
- const { form: { validateFieldsAndScroll } } = this
- this.confirmLoading = true
- validateFieldsAndScroll((errors, values) => {
- if (errors) {
- this.confirmLoading = false
- return
- }
- values.optionList = this.data
- this.handleCancel(values)
- })
- },
- handleCancel (values) {
- this.visible = false
- this.confirmLoading = false
- this.data = []
- this.form.resetFields()
- console.log(values)
- if (this.BaseTool.Object.isNotBlank(values)) {
- console.log(values)
- this.$emit('ok', values)
- }
- },
- handleOption (record) {
- if (record == null) {
- const modal = this.$refs.optionForm
- modal.base()
- } else {
- const modal = this.$refs.optionForm
- modal.base(record)
- }
- },
- handleOptionList (values) {
- let dataSource = [...this.data]
- if (dataSource == null) {
- dataSource = []
- }
- if (values.name == null || values.name === '') {
- return
- }
- let find = false
- console.log('data.length: ' + dataSource.length)
- for (let j = 0; j < dataSource.length; j++) {
- if (values.name === dataSource[j].name) {
- find = true
- this.data = dataSource.map(item => {
- return item.name === values.name ? values : item
- })
- break
- }
- }
- if (!find) {
- dataSource.push(values)
- console.log('data.length: ' + dataSource.length)
- this.data = dataSource
- console.log('data.length: ' + this.data.length)
- }
- },
- handleDelOption (name) {
- const dataSource = [...this.data]
- this.data = dataSource.filter(item => item.name !== name)
- }
- }
- }
- </script>
|