editModal.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <a-modal
  3. centered
  4. class="transferTypeManagementEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancel="isShow=false"
  10. :width="800">
  11. <!-- 表单 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  14. <a-form-model
  15. id="transferTypeManagementEdit-form"
  16. ref="ruleForm"
  17. :model="form"
  18. :rules="rules"
  19. :label-col="formItemLayout.labelCol"
  20. :wrapper-col="formItemLayout.wrapperCol"
  21. >
  22. <a-form-model-item label="父类型">
  23. {{ parentName }}
  24. </a-form-model-item>
  25. <a-form-model-item label="调拨类型名称" prop="name">
  26. <a-input
  27. id="transferTypeManagementEdit-name"
  28. :maxLength="30"
  29. v-model.trim="form.name"
  30. @change="filterEmpty"
  31. placeholder="请输入调拨类型名称(最多30个字符)"
  32. allowClear />
  33. </a-form-model-item>
  34. <a-form-model-item label="价格类型" prop="erpPriceType">
  35. <v-select
  36. code="ERP_PRICE_TYPE"
  37. ref="erpPriceType"
  38. id="transferTypeManagementEdit-erpPriceType"
  39. placeholder="请选择价格类型"
  40. v-model="form.erpPriceType"
  41. ></v-select>
  42. </a-form-model-item>
  43. </a-form-model>
  44. <div class="btn-cont">
  45. <a-button id="transferTypeManagementEdit-cancel" @click="isShow = false" style="margin-right: 15px;">取消</a-button>
  46. <a-button type="primary" id="transferTypeManagementEdit-save" @click="handleSave">保存</a-button>
  47. </div>
  48. </a-spin>
  49. </div>
  50. </a-modal>
  51. </template>
  52. <script>
  53. import { commonMixin } from '@/utils/mixin'
  54. // 组件
  55. import { VSelect } from '@/components'
  56. // 接口
  57. import { allocateTypeSave } from '@/api/allocateType'
  58. export default {
  59. name: 'TransferTypeManagementEditModal',
  60. mixins: [commonMixin],
  61. components: { VSelect },
  62. props: {
  63. openModal: { // 弹框显示状态
  64. type: Boolean,
  65. default: false
  66. },
  67. itemSn: {
  68. type: [Number, String],
  69. default: ''
  70. },
  71. nowData: {
  72. type: Object,
  73. default: null
  74. }
  75. },
  76. computed: {
  77. // 弹窗标题
  78. modalTit () {
  79. return (this.itemSn ? '编辑' : this.nowData ? '添加子级' : '添加一级') + '调拨类型'
  80. },
  81. parentName () {
  82. return this.nowData && this.nowData.superior ? this.nowData.superior.name : '--'
  83. }
  84. },
  85. data () {
  86. return {
  87. isShow: this.openModal, // 是否打开弹框
  88. spinning: false,
  89. // form 表单
  90. formItemLayout: {
  91. labelCol: { span: 6 },
  92. wrapperCol: { span: 16 }
  93. },
  94. // 提交参数
  95. form: {
  96. name: '', // 调拨类型名称
  97. allocateCategory: undefined, // 父节点sn
  98. erpPriceType: undefined // 价格类型
  99. },
  100. // 表单验证规则
  101. rules: {
  102. name: [
  103. { required: true, message: '请输入调拨类型名称', trigger: 'change' }
  104. ],
  105. erpPriceType: [
  106. { required: true, message: '请选择价格类型', trigger: 'change' }
  107. ]
  108. }
  109. }
  110. },
  111. methods: {
  112. // 调拨类型名称 去空格
  113. filterEmpty () {
  114. let str = this.form.name
  115. str = str.replace(/\ +/g, '')
  116. str = str.replace(/[ ]/g, '')
  117. str = str.replace(/[\r\n]/g, '')
  118. this.form.name = str
  119. },
  120. // 保存
  121. handleSave () {
  122. const _this = this
  123. this.$refs.ruleForm.validate(valid => {
  124. if (valid) {
  125. const form = _this.form
  126. form.allocateTypeSn = _this.itemSn ? _this.itemSn : null
  127. _this.spinning = true
  128. allocateTypeSave(form).then(res => {
  129. if (res.status == 200) {
  130. _this.$message.success(res.message)
  131. _this.$emit('close', 1)
  132. _this.spinning = false
  133. } else {
  134. _this.spinning = false
  135. }
  136. })
  137. } else {
  138. return false
  139. }
  140. })
  141. }
  142. },
  143. watch: {
  144. // 父页面传过来的弹框状态
  145. openModal (newValue, oldValue) {
  146. this.isShow = newValue
  147. },
  148. // 重定义的弹框状态
  149. isShow (newValue, oldValue) {
  150. if (!newValue) {
  151. this.$emit('close', 0)
  152. this.$refs.ruleForm.resetFields()
  153. } else {
  154. if (this.nowData) { // 编辑 或 添加子级
  155. this.form.name = this.nowData && this.nowData.name ? this.nowData.name : ''
  156. this.form.allocateCategory = this.nowData && this.nowData.allocateCategory ? this.nowData.allocateCategory : ''
  157. this.form.erpPriceType = this.nowData && this.nowData.erpPriceType ? this.nowData.erpPriceType : undefined
  158. this.form.treeLevel = this.nowData && this.nowData.treeLevel ? this.nowData.treeLevel : ''
  159. } else { // 添加一级分类
  160. this.form.name = ''
  161. this.form.allocateCategory = 0
  162. this.form.erpPriceType = undefined
  163. this.form.treeLevel = 1
  164. }
  165. }
  166. },
  167. itemSn (newValue, oldValue) {
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="less">
  173. .transferTypeManagementEdit-modal{
  174. .ant-modal-body {
  175. padding: 40px 40px 24px;
  176. }
  177. .btn-cont {
  178. text-align: center;
  179. margin: 35px 0 10px;
  180. }
  181. }
  182. </style>