BaseForm.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. <a-form-item v-show="false" >
  11. <a-input v-decorator="['id']" type="hidden"/>
  12. </a-form-item>
  13. <a-form-item
  14. label="类代号"
  15. :labelCol="BaseTool.Constant.labelCol"
  16. :wrapperCol="BaseTool.Constant.wrapperCol"
  17. >
  18. <a-input
  19. v-decorator="['no', {rules: [{required: false, message: '代号不能为空'}]}]" />
  20. </a-form-item>
  21. <a-form-item
  22. label="类型名称"
  23. :labelCol="BaseTool.Constant.labelCol"
  24. :wrapperCol="BaseTool.Constant.wrapperCol"
  25. >
  26. <a-input
  27. v-decorator="['name', {rules: [{required: true, message: '设备名称不能为空'}]}]" />
  28. </a-form-item>
  29. <a-form-item
  30. label="设备类别"
  31. :labelCol="BaseTool.Constant.labelCol"
  32. :wrapperCol="BaseTool.Constant.wrapperCol"
  33. >
  34. <a-select @change="handleTypeChange" v-decorator="['type', {rules: [{required: true, message: '设备类别不能为空'}]}]" placeholder="请选择">
  35. <a-select-option
  36. v-for="(label,value) in typeMap"
  37. :key="value"
  38. :label="label"
  39. :value="parseInt(value)">{{ label }}
  40. </a-select-option>
  41. </a-select>
  42. </a-form-item>
  43. <a-form-item
  44. label="首字母"
  45. :labelCol="BaseTool.Constant.labelCol"
  46. :wrapperCol="BaseTool.Constant.wrapperCol"
  47. >
  48. <a-input
  49. v-decorator="['szm']" />
  50. </a-form-item>
  51. <a-form-item
  52. label="排序"
  53. :labelCol="BaseTool.Constant.labelCol"
  54. :wrapperCol="BaseTool.Constant.wrapperCol"
  55. >
  56. <a-input-number
  57. style="width: 100%"
  58. :min="1"
  59. v-decorator="['sort', {initialValue:1,rules: [{required: true, message: '排序不能为空'}]}]" />
  60. </a-form-item>
  61. <a-form-item
  62. label="是否删除"
  63. :labelCol="BaseTool.Constant.labelCol"
  64. :wrapperCol="BaseTool.Constant.wrapperCol"
  65. >
  66. <a-select v-decorator="['delFlag', {initialValue:DictCache.VALUE.DELFLAG.NORMAL, rules: [{required: true, message: '是否删除不能为空'}]}]" placeholder="请选择">
  67. <a-select-option
  68. v-for="(label,value) in delFlagMap"
  69. :key="value"
  70. :label="label"
  71. :value="parseInt(value)">{{ label }}
  72. </a-select-option>
  73. </a-select>
  74. </a-form-item>
  75. <a-form-item
  76. label="上层设备类型"
  77. :labelCol="BaseTool.Constant.labelCol"
  78. :wrapperCol="BaseTool.Constant.wrapperCol"
  79. v-show="isShowParent"
  80. >
  81. <a-tree-select
  82. style="width: 100%"
  83. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  84. :treeData="treeData"
  85. :treeNodeFilterProp="'title'"
  86. :showSearch="true"
  87. v-decorator="['parentId', {rules: [{required: isShowParent, message: '上层设备类型不能为空'}]}]"
  88. placeholder="请选择"
  89. >
  90. </a-tree-select>
  91. </a-form-item>
  92. <a-form-item
  93. label="备注"
  94. :labelCol="BaseTool.Constant.labelCol"
  95. :wrapperCol="BaseTool.Constant.wrapperCol"
  96. >
  97. <a-input
  98. v-decorator="['remark', {rules: [{required: false, message: '备注不能为空'}]}]" />
  99. </a-form-item>
  100. </a-form>
  101. <template slot="footer">
  102. <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
  103. </template>
  104. </a-modal>
  105. </template>
  106. <script>
  107. import pick from 'lodash.pick'
  108. import { addSbType, updateSbType, fetchSbTypeTree } from '@/api/sb/type'
  109. export default {
  110. name: 'BaseSbType',
  111. data () {
  112. return {
  113. confirmLoading: false,
  114. modalTitle: null,
  115. form: this.$form.createForm(this),
  116. visible: false,
  117. typeMap: {},
  118. delFlagMap: {},
  119. typeName: '',
  120. treeData: [],
  121. isShowParent: true
  122. }
  123. },
  124. props: {
  125. },
  126. created () {
  127. this.setTree()
  128. this.delFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DELFLAG)
  129. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_TYPE)
  130. },
  131. methods: {
  132. base (record) {
  133. this.setTree(record)
  134. this.visible = true
  135. // 如果是空标识添加
  136. const { form: { setFieldsValue } } = this
  137. if (this.BaseTool.Object.isBlank(record)) {
  138. this.modalTitle = '添加'
  139. return
  140. }
  141. this.modalTitle = '编辑'
  142. if (this.BaseTool.Object.isBlank(record.id)) {
  143. this.modalTitle = '复制'
  144. }
  145. this.$nextTick(() => {
  146. setFieldsValue(Object.assign(pick(record, [
  147. 'id',
  148. 'no',
  149. 'name',
  150. 'type',
  151. 'sort',
  152. 'delFlag',
  153. 'parentId',
  154. 'remark'
  155. ])))
  156. })
  157. this.isShowParent = record.type === this.DictCache.VALUE.SBTYPE_TYPE.SON
  158. },
  159. save () {
  160. const { form: { validateFieldsAndScroll } } = this
  161. this.confirmLoading = true
  162. validateFieldsAndScroll((errors, values) => {
  163. if (errors) {
  164. this.confirmLoading = false
  165. return
  166. }
  167. if (this.BaseTool.String.isBlank(values.id)) {
  168. addSbType(values)
  169. .then(() => {
  170. this.handleCancel(values)
  171. }).catch(() => {
  172. this.confirmLoading = false
  173. })
  174. } else {
  175. updateSbType(values)
  176. .then(() => {
  177. this.handleCancel(values)
  178. }).catch(() => {
  179. this.confirmLoading = false
  180. })
  181. }
  182. })
  183. },
  184. handleCancel (values) {
  185. this.visible = false
  186. this.confirmLoading = false
  187. this.form.resetFields()
  188. if (this.BaseTool.Object.isNotBlank(values)) {
  189. this.$emit('ok', values)
  190. }
  191. },
  192. setTree (record = {}) {
  193. fetchSbTypeTree({ type: 1 }).then((res) => {
  194. this.treeData = res.data
  195. })
  196. },
  197. handleTypeChange (val) {
  198. const { form: { setFieldsValue } } = this
  199. this.isShowParent = val === this.DictCache.VALUE.SBTYPE_TYPE.SON
  200. this.$nextTick(() => {
  201. setFieldsValue({
  202. 'parentId': ''
  203. })
  204. })
  205. }
  206. }
  207. }
  208. </script>