ExtendColumnDialogForm.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <el-dialog
  3. v-if="visible"
  4. :title="form.id?'编辑物务资源目录':'新建物务资源目录'"
  5. :visible.sync="visible"
  6. width="600px"
  7. append-to-body
  8. >
  9. <el-form v-loading="isLoading" :model="form" label-width="100px" label-position="top">
  10. <el-row :gutter="16">
  11. <el-col :span="8">
  12. <el-form-item label="字段编码">
  13. <el-input v-model="form.fieldKey" />
  14. </el-form-item>
  15. </el-col>
  16. <el-col :span="8">
  17. <el-form-item label="字段名称">
  18. <el-input v-model="form.fieldLabel" />
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8">
  22. <el-form-item label="排序">
  23. <el-input-number v-model="form.sortNumber" :min="0" />
  24. </el-form-item>
  25. </el-col>
  26. </el-row>
  27. <el-form-item label="默认值">
  28. <el-radio v-model="form.fieldType" label="string">文本</el-radio>
  29. <el-radio v-model="form.fieldType" label="number">数字</el-radio>
  30. <el-radio v-model="form.fieldType" label="bool">布尔</el-radio>
  31. <el-radio v-model="form.fieldType" label="bstring">多行文本</el-radio>
  32. <el-radio v-model="form.fieldType" label="radio">单选框</el-radio>
  33. <el-radio v-model="form.fieldType" label="checkbox">多选框</el-radio>
  34. <el-radio v-model="form.fieldType" label="select">下拉选择</el-radio>
  35. </el-form-item>
  36. <el-form-item label="默认值">
  37. <el-input v-model="form.defaultValue" type="textarea" />
  38. </el-form-item>
  39. </el-form>
  40. <div slot="footer" class="dialog-footer">
  41. <el-button @click="visible = false">取 消</el-button>
  42. <el-button type="primary" @click="handleSubmit">确 定</el-button>
  43. </div>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import { save, updateById } from '@/api/base/category_extend_column'
  48. import { Message } from 'element-ui'
  49. export default {
  50. data() {
  51. return {
  52. visible: false,
  53. isLoading: false,
  54. form: {},
  55. dataTypeId: null
  56. }
  57. },
  58. mounted() {
  59. },
  60. methods: {
  61. open(data, dataTypeId) {
  62. this.visible = true
  63. this.isLoading = false
  64. this.form = {}
  65. console.log(data, dataTypeId)
  66. this.form = Object.assign({}, data)
  67. if (this.form.fieldType) {
  68. this.form.fieldType = this.form.fieldType.name
  69. }
  70. this.dataTypeId = dataTypeId
  71. },
  72. handleSubmit() {
  73. const param = {
  74. ...this.form,
  75. 'dataTypeId': this.dataTypeId
  76. }
  77. if ((!param.defaultValue || param.defaultValue === '') && (param.fieldType === 'radio' || param.fieldType === 'checkbox' || param.fieldType === 'select')) {
  78. Message({
  79. message: '单选框、多选框、下拉选择的数据类型必需填写默认值,多个值请用英文逗号(“,”)分隔',
  80. type: 'error',
  81. duration: 5 * 1000
  82. })
  83. return
  84. }
  85. this.isLoading = true
  86. console.log(param)
  87. if (this.form.id) {
  88. updateById(this.form.id, param).then(() => {
  89. this.visible = false
  90. this.$emit('ok')
  91. }).finally(() => {
  92. this.isLoading = false
  93. })
  94. } else {
  95. save(param).then(res => {
  96. this.visible = false
  97. this.$emit('ok')
  98. }).finally(() => {
  99. this.isLoading = false
  100. })
  101. }
  102. }
  103. }
  104. }
  105. </script>