codeModal.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <div>
  3. <a-modal class="modalBox" :title="titleText" v-model="isshow" @cancel="cancel">
  4. <a-form :form="form" id="code-modal-form" @submit="handleSubmit">
  5. <!-- 类别编码 -->
  6. <a-form-item label="类别编码" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  7. <a-input
  8. placeholder="请输入类别编码"
  9. :disabled="true"
  10. id="codeModal-code"
  11. v-decorator="['formData.code', {
  12. initialValue: formData.code,
  13. rules: [{ required: true, message: '请输入类别编码!' }] }]"
  14. />
  15. </a-form-item>
  16. <!-- 名称 -->
  17. <a-form-item label="名称" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  18. <a-input
  19. id="codeModal-name"
  20. placeholder="请输入名称(最多30个字符)"
  21. :maxLength="30"
  22. v-decorator="['formData.name', {
  23. initialValue: formData.name,
  24. rules: [{ required: true, message: '请输入名称!' }] }]"
  25. />
  26. </a-form-item>
  27. <!-- 排序值 -->
  28. <a-form-item label="排序值" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  29. <a-input-number
  30. id="codeModal-sort"
  31. style="width: 100%;"
  32. placeholder="请输入排序值(0~999999)"
  33. v-decorator="['formData.sort', {
  34. initialValue: formData.sort,
  35. rules: [{ required: true, message: '请输入排序值!' }] }]"
  36. :max="99999999"
  37. :min="0"
  38. />
  39. </a-form-item>
  40. <!-- 状态 -->
  41. <a-form-item label="启用" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  42. <a-radio-group
  43. id="codeModal-isEnable"
  44. name="radioGroup"
  45. v-decorator="[
  46. 'formData.isEnable',
  47. {
  48. initialValue: formData.isEnable,
  49. rules: [{ required: true, message: '请选择状态!' }] },
  50. ]"
  51. >
  52. <a-radio :value="1" id="codeModal-isEnable1">是</a-radio>
  53. <a-radio :value="0" id="codeModal-isEnable0">否</a-radio>
  54. </a-radio-group>
  55. </a-form-item>
  56. <a-form-item label="备注" :label-col="{ span: 5 }" :wrapper-col="{ span: 14 }">
  57. <a-textarea
  58. id="codeModal-remarks"
  59. v-decorator="[
  60. 'formData.remarks',
  61. { initialValue: formData.remarks,
  62. rules: [] },
  63. ]"
  64. :maxLength="500"
  65. style="min-height: 60px;"
  66. placeholder="最多500字符"
  67. autosize />
  68. </a-form-item>
  69. <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
  70. <a-button id="codeModal-save-btn" type="primary" @click="handleSubmit()">
  71. 保存
  72. </a-button>
  73. <a-button id="codeModal-cancel-btn" :style="{ marginLeft: '8px' }" @click="handleCancel()">
  74. 取消
  75. </a-button>
  76. </a-form-item>
  77. </a-form>
  78. </a-modal>
  79. </div>
  80. </template>
  81. <script>
  82. // 组件
  83. import { STable, VSelect } from '@/components'
  84. // 接口
  85. import { saveLookUp } from '@/api/lookup.js'
  86. export default {
  87. name: 'CodeModal',
  88. components: { STable, VSelect },
  89. props: {
  90. visible: {
  91. type: Boolean,
  92. default: false
  93. },
  94. data: {
  95. type: Object,
  96. default: function () {
  97. return {}
  98. }
  99. }
  100. },
  101. data () {
  102. return {
  103. titleText: '添加字典', // 弹窗标题
  104. isshow: this.visible, // 是否显示弹窗
  105. formLayout: 'horizontal',
  106. // 可以使用任何数据,不仅仅局限于上层组件的属性
  107. form: this.$form.createForm(this, { name: 'miniForm' }),
  108. // 提交参数
  109. formData: {
  110. name: '', // 名称
  111. code: '', // 类别编码
  112. sort: '', // 排序值
  113. isEnable: '', // 活动状态
  114. remarks: ''// 备注
  115. }
  116. }
  117. },
  118. methods: {
  119. // 取消
  120. cancel (e) {
  121. this.clear()
  122. this.$emit('close')
  123. },
  124. // 保存提交
  125. handleSubmit () {
  126. const _this = this
  127. this.form.validateFields((err, values) => {
  128. if (!err) {
  129. console.log(values.formData, ' formData.type222222222')
  130. saveLookUp(Object.assign(this.formData, values.formData)).then(res => {
  131. console.log(res, 'res--save')
  132. if (res.status + '' === '200') {
  133. this.$message.success(res.message ? res.message : '保存成功')
  134. this.$emit('refresh')
  135. setTimeout(function () {
  136. _this.cancel()
  137. }, 300)
  138. } else {
  139. // this.$message.warning(res.message)
  140. }
  141. })
  142. }
  143. })
  144. },
  145. // 取消
  146. handleCancel () {
  147. const _this = this
  148. this.$confirm({
  149. title: '提示',
  150. content: '确定取消吗?',
  151. okText: '确定',
  152. cancelText: '取消',
  153. onOk () {
  154. _this.clear()
  155. _this.cancel()
  156. }
  157. })
  158. },
  159. // 重置
  160. clear () {
  161. this.form.resetFields()
  162. delete this.formData.id
  163. this.formData.name = ''
  164. this.formData.code = ''
  165. this.formData.sort = ''
  166. this.formData.isEnable = ''
  167. this.formData.remarks = ''
  168. }
  169. },
  170. beforeCreate () {
  171. this.form = this.$form.createForm(this, { name: 'miniForm' })
  172. },
  173. watch: {
  174. visible (newValue, oldValue) {
  175. this.isshow = newValue
  176. },
  177. isshow (newValue, oldValue) {
  178. if (newValue) {
  179. if (this.data.id) { // 编辑
  180. this.formData.titleText = '编辑字典'
  181. this.formData = Object.assign({}, this.data)
  182. delete this.formData.no
  183. this.formData.isEnable = Number(this.formData.isEnable)
  184. console.log(this.formData, 'this.formData')
  185. } else {
  186. this.formData.titleText = '添加字典'
  187. }
  188. } else {
  189. this.cancel()
  190. }
  191. }
  192. }
  193. }
  194. </script>
  195. <style >
  196. .modalBox{
  197. }
  198. .ant-modal-footer {
  199. display: none;
  200. }
  201. </style>