e72661a48d96bd56884695b17b16f210ccf98bae.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="600"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. @ok="handleOk"
  8. @cancel="handleCancel"
  9. cancelText="关闭"
  10. >
  11. <a-spin :spinning="confirmLoading">
  12. <a-form-model ref="form" :model="model" :rules="validatorRules">
  13. <a-form-model-item
  14. :labelCol="labelCol"
  15. :wrapperCol="wrapperCol"
  16. prop="dictName"
  17. required
  18. label="字典名称">
  19. <a-input placeholder="请输入字典名称" v-model="model.dictName"/>
  20. </a-form-model-item>
  21. <a-form-model-item
  22. :labelCol="labelCol"
  23. :wrapperCol="wrapperCol"
  24. prop="dictCode"
  25. required
  26. label="字典编码">
  27. <a-input placeholder="请输入字典编码" v-model="model.dictCode"/>
  28. </a-form-model-item>
  29. <a-form-model-item
  30. :labelCol="labelCol"
  31. :wrapperCol="wrapperCol"
  32. label="描述">
  33. <a-input v-model="model.description"/>
  34. </a-form-model-item>
  35. </a-form-model>
  36. </a-spin>
  37. </a-modal>
  38. </template>
  39. <script>
  40. import pick from 'lodash.pick'
  41. import { addDict, editDict, duplicateCheck } from '@/api/api'
  42. export default {
  43. name: 'DictModal',
  44. data() {
  45. return {
  46. value: 1,
  47. title: '操作',
  48. visible: false,
  49. model: {},
  50. labelCol: {
  51. xs: { span: 24 },
  52. sm: { span: 5 }
  53. },
  54. wrapperCol: {
  55. xs: { span: 24 },
  56. sm: { span: 16 }
  57. },
  58. confirmLoading: false,
  59. validatorRules: {
  60. dictName: [{ required: true, message: '请输入字典名称!' }],
  61. dictCode: [
  62. { required: true, message: '请输入字典编码!' },
  63. { validator: this.validateDictCode }]
  64. }
  65. }
  66. },
  67. created() {
  68. },
  69. methods: {
  70. validateDictCode(rule, value, callback) {
  71. // 重复校验
  72. var params = {
  73. tableName: 'sys_dict',
  74. fieldName: 'dict_code',
  75. fieldVal: value,
  76. dataId: this.model.id
  77. }
  78. duplicateCheck(params).then((res) => {
  79. if (res.success) {
  80. callback()
  81. } else {
  82. callback(res.message)
  83. }
  84. })
  85. },
  86. handleChange(value) {
  87. this.model.status = value
  88. },
  89. add() {
  90. this.edit({})
  91. },
  92. edit(record) {
  93. if (record.id) {
  94. this.visiblekey = true
  95. } else {
  96. this.visiblekey = false
  97. }
  98. this.model = Object.assign({}, record)
  99. this.visible = true
  100. },
  101. // 确定
  102. handleOk() {
  103. const that = this
  104. // 触发表单验证
  105. this.$refs.form.validate(valid => {
  106. if (valid) {
  107. that.confirmLoading = true
  108. this.model.dictName = (this.model.dictName || '').trim()
  109. this.model.dictCode = (this.model.dictCode || '').trim()
  110. this.model.description = (this.model.description || '').trim()
  111. let obj
  112. if (!this.model.id) {
  113. obj = addDict(this.model)
  114. } else {
  115. obj = editDict(this.model)
  116. }
  117. obj.then((res) => {
  118. if (res.success) {
  119. that.$message.success(res.message)
  120. that.$emit('ok')
  121. } else {
  122. that.$message.warning(res.message)
  123. }
  124. }).finally(() => {
  125. that.confirmLoading = false
  126. that.close()
  127. })
  128. }else{
  129. return false;
  130. }
  131. })
  132. },
  133. // 关闭
  134. handleCancel() {
  135. this.close()
  136. },
  137. close() {
  138. this.$emit('close')
  139. this.visible = false
  140. this.$refs.form.resetFields();
  141. }
  142. }
  143. }
  144. </script>