ParamForm.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="800"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @cancel="handleCancel"
  8. >
  9. <a-form :form="form">
  10. <row-list :col="2">
  11. <row-item>
  12. <a-form-item
  13. label="显示名称"
  14. :labelCol="BaseTool.Constant.labelCol"
  15. :wrapperCol="BaseTool.Constant.wrapperCol"
  16. >
  17. <a-input
  18. v-decorator="['label']"/>
  19. </a-form-item>
  20. </row-item>
  21. <row-item>
  22. <a-form-item
  23. label="字段名称"
  24. :labelCol="BaseTool.Constant.labelCol"
  25. :wrapperCol="BaseTool.Constant.wrapperCol"
  26. >
  27. <a-input
  28. v-decorator="['fieldName']"/>
  29. </a-form-item>
  30. </row-item>
  31. <row-item>
  32. <a-form-item
  33. label="类型"
  34. :labelCol="BaseTool.Constant.labelCol"
  35. :wrapperCol="BaseTool.Constant.wrapperCol"
  36. >
  37. <a-select
  38. v-decorator="['type', {rules: [{required: true, message: '类型不能为空'}]}]"
  39. placeholder="请选择">
  40. <a-select-option
  41. v-for="(label,value) in typeMap"
  42. :key="value"
  43. :label="label"
  44. :value="parseInt(value)">{{ label }}
  45. </a-select-option>
  46. </a-select>
  47. </a-form-item>
  48. </row-item>
  49. <row-item>
  50. <a-form-item
  51. label="是否必填"
  52. :labelCol="BaseTool.Constant.labelCol"
  53. :wrapperCol="BaseTool.Constant.wrapperCol"
  54. >
  55. <a-select
  56. v-decorator="['required', {rules: [{required: true, message: '类型不能为空'}]}]"
  57. placeholder="请选择">
  58. <a-select-option
  59. v-for="(label,value) in yesNoMap"
  60. :key="value"
  61. :label="label"
  62. :value="parseInt(value)">{{ label }}
  63. </a-select-option>
  64. </a-select>
  65. </a-form-item>
  66. </row-item>
  67. <row-item>
  68. <a-form-item
  69. label="显示行数"
  70. :labelCol="BaseTool.Constant.labelCol"
  71. :wrapperCol="BaseTool.Constant.wrapperCol"
  72. >
  73. <a-input
  74. v-decorator="['rows', {rules: [{required: true, message: '不能为空'}]}]"/>
  75. </a-form-item>
  76. </row-item>
  77. <row-item>
  78. <a-form-item
  79. label="排序"
  80. :labelCol="BaseTool.Constant.labelCol"
  81. :wrapperCol="BaseTool.Constant.wrapperCol"
  82. >
  83. <a-input
  84. v-decorator="['sort', {rules: [{required: true, message: '不能为空'}]}]"/>
  85. </a-form-item>
  86. </row-item>
  87. <row-item>
  88. <a-form-item
  89. label="最小长度"
  90. :labelCol="BaseTool.Constant.labelCol"
  91. :wrapperCol="BaseTool.Constant.wrapperCol"
  92. >
  93. <a-input
  94. v-decorator="['minLength', {rules: [{required: true, message: '不能为空'}]}]"/>
  95. </a-form-item>
  96. </row-item>
  97. <row-item>
  98. <a-form-item
  99. label="最大长度"
  100. :labelCol="BaseTool.Constant.labelCol"
  101. :wrapperCol="BaseTool.Constant.wrapperCol"
  102. >
  103. <a-input
  104. v-decorator="['maxLength', {rules: [{required: true, message: '不能为空'}]}]"/>
  105. </a-form-item>
  106. </row-item>
  107. <row-item>
  108. <a-form-item
  109. label="默认值"
  110. :labelCol="BaseTool.Constant.labelCol"
  111. :wrapperCol="BaseTool.Constant.wrapperCol"
  112. >
  113. <a-input
  114. v-decorator="['defaultValue']"/>
  115. </a-form-item>
  116. </row-item>
  117. </row-list>
  118. </a-form>
  119. <title-divider title="下拉选择项明细" width="90px"></title-divider>
  120. <div class="table-operator" style="margin-bottom: 8px;">
  121. <a-button size="small" type="primary" @click="handleOption">
  122. <a-icon type="plus"/>
  123. 添加
  124. </a-button>
  125. <a-button class="margin-left8" size="small" type="danger" @click="handleDelOption">
  126. <a-icon type="delete"/>
  127. 删除
  128. </a-button>
  129. </div>
  130. <a-table
  131. bordered
  132. :data-source="data"
  133. :columns="columns"
  134. tableLayout="auto"
  135. rowKey="name"
  136. :row-selection="rowSelection">
  137. <span slot="action" slot-scope="record">
  138. <template>
  139. <a @click="handleOption(record)">修改</a>
  140. <a-divider type="vertical" />
  141. <a-popconfirm title="是否要删除该条数据?" @confirm="handleDelOption(record.name)">
  142. <a>删除</a>
  143. </a-popconfirm>
  144. </template>
  145. </span>
  146. </a-table>
  147. <template slot="footer">
  148. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  149. </template>
  150. <option-form ref="optionForm" @ok="handleOptionList" />
  151. </a-modal>
  152. </template>
  153. <script>
  154. import OptionForm from './OptionForm'
  155. import DetailList from '@/components/tools/DetailList'
  156. import pick from 'lodash.pick'
  157. import Vue from 'vue'
  158. export default {
  159. name: 'FieldTemplateOptionForm',
  160. components: {
  161. OptionForm,
  162. DetailList
  163. },
  164. data () {
  165. return {
  166. confirmLoading: false,
  167. modalTitle: null,
  168. form: this.$form.createForm(this),
  169. visible: false,
  170. data: [],
  171. // 下拉框map
  172. yesNoMap: {},
  173. record: {},
  174. typeMap: {},
  175. rowSelection: {
  176. onChange: (selectedRowKeys, selectedRows) => {
  177. this.selectedRowKeys = selectedRowKeys
  178. this.selectedRows = selectedRows
  179. }
  180. },
  181. selectedRowKeys: [],
  182. selectedRows: [],
  183. options: {
  184. rowSelection: {
  185. selectedRowKeys: this.selectedRowKeys
  186. }
  187. },
  188. // 表头
  189. columns: [
  190. {
  191. title: '序号',
  192. dataIndex: 'index',
  193. customRender: (text, record, index) => {
  194. return index + 1
  195. }
  196. },
  197. {
  198. title: '参数名称',
  199. dataIndex: 'name'
  200. },
  201. {
  202. title: '参数值',
  203. dataIndex: 'value'
  204. },
  205. {
  206. title: '操作',
  207. key: 'action',
  208. align: 'center',
  209. scopedSlots: { customRender: 'action' }
  210. }
  211. ]
  212. }
  213. },
  214. props: {
  215. },
  216. created () {
  217. // 下拉框map
  218. this.yesNoMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  219. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CUSTOM_FIELD_TEMPLATE_FILED_TYPE)
  220. },
  221. methods: {
  222. base (record) {
  223. this.visible = true
  224. // 如果是空标识添加
  225. this.modalTitle = '字段设置'
  226. this.record = record
  227. this.data = record.optionList || []
  228. const { form: { setFieldsValue } } = this
  229. // 日期处理
  230. this.$nextTick(() => {
  231. setFieldsValue(Object.assign(pick(record, [
  232. 'label',
  233. 'fieldName',
  234. 'type',
  235. 'required',
  236. 'sort',
  237. 'rows',
  238. 'minLength',
  239. 'maxLength',
  240. 'defaultValue'
  241. ])))
  242. })
  243. },
  244. save () {
  245. const { form: { validateFieldsAndScroll } } = this
  246. this.confirmLoading = true
  247. validateFieldsAndScroll((errors, values) => {
  248. if (errors) {
  249. this.confirmLoading = false
  250. return
  251. }
  252. values.optionList = this.data
  253. this.handleCancel(values)
  254. })
  255. },
  256. handleCancel (values) {
  257. this.visible = false
  258. this.confirmLoading = false
  259. this.data = []
  260. this.form.resetFields()
  261. console.log(values)
  262. if (this.BaseTool.Object.isNotBlank(values)) {
  263. console.log(values)
  264. this.$emit('ok', values)
  265. }
  266. },
  267. handleOption (record) {
  268. if (record == null) {
  269. const modal = this.$refs.optionForm
  270. modal.base()
  271. } else {
  272. const modal = this.$refs.optionForm
  273. modal.base(record)
  274. }
  275. },
  276. handleOptionList (values) {
  277. let dataSource = [...this.data]
  278. if (dataSource == null) {
  279. dataSource = []
  280. }
  281. if (values.name == null || values.name === '') {
  282. return
  283. }
  284. let find = false
  285. console.log('data.length: ' + dataSource.length)
  286. for (let j = 0; j < dataSource.length; j++) {
  287. if (values.name === dataSource[j].name) {
  288. find = true
  289. this.data = dataSource.map(item => {
  290. return item.name === values.name ? values : item
  291. })
  292. break
  293. }
  294. }
  295. if (!find) {
  296. dataSource.push(values)
  297. console.log('data.length: ' + dataSource.length)
  298. this.data = dataSource
  299. console.log('data.length: ' + this.data.length)
  300. }
  301. },
  302. handleDelOption (name) {
  303. const dataSource = [...this.data]
  304. this.data = dataSource.filter(item => item.name !== name)
  305. }
  306. }
  307. }
  308. </script>