editModal.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <a-modal
  3. centered
  4. class="intelligentReplenishmentEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <!-- 表单 -->
  12. <div>
  13. <a-form-model
  14. id="intelligentReplenishmentEdit-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. :label-col="formItemLayout.labelCol"
  19. :wrapper-col="formItemLayout.wrapperCol"
  20. >
  21. <a-form-model-item label="客户类型名称" prop="name">
  22. <a-input
  23. id="intelligentReplenishmentEdit-name"
  24. :maxLength="30"
  25. v-model.trim="form.name"
  26. @change="filterEmpty"
  27. placeholder="请输入客户类型名称(最多30个字符)"
  28. allowClear />
  29. </a-form-model-item>
  30. </a-form-model>
  31. <div class="btn-cont">
  32. <a-button type="primary" id="customer-type-edit-modal-save" @click="handleSave">保存</a-button>
  33. <a-button id="customer-type-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
  34. </div>
  35. </div>
  36. </a-modal>
  37. </template>
  38. <script>
  39. import { STable } from '@/components'
  40. import { custTypeSave } from '@/api/custType'
  41. export default {
  42. name: 'CustomerTypeEditModal',
  43. components: { STable },
  44. props: {
  45. openModal: { // 弹框显示状态
  46. type: Boolean,
  47. default: false
  48. },
  49. itemId: {
  50. type: [Number, String],
  51. default: ''
  52. },
  53. nowData: {
  54. type: Object,
  55. default: null
  56. }
  57. },
  58. computed: {
  59. modalTit () {
  60. return (this.itemId ? '编辑' : '新增') + '客户类型'
  61. }
  62. },
  63. data () {
  64. return {
  65. isShow: this.openModal, // 是否打开弹框
  66. detailsData: null, // 品牌数据
  67. formItemLayout: {
  68. labelCol: { span: 6 },
  69. wrapperCol: { span: 16 }
  70. },
  71. form: {
  72. name: '' // 客户类型名称
  73. },
  74. rules: {
  75. name: [
  76. { required: true, message: '请输入客户类型名称', trigger: 'blur' }
  77. ]
  78. }
  79. }
  80. },
  81. methods: {
  82. filterEmpty () {
  83. let str = this.form.name
  84. str = str.replace(/\ +/g, '')
  85. str = str.replace(/[ ]/g, '')
  86. str = str.replace(/[\r\n]/g, '')
  87. this.form.name = str
  88. },
  89. // 保存
  90. handleSave () {
  91. const _this = this
  92. this.$refs.ruleForm.validate(valid => {
  93. if (valid) {
  94. const form = _this.form
  95. form.id = _this.itemId ? _this.itemId : null
  96. custTypeSave(form).then(res => {
  97. if (res.status == 200) {
  98. _this.$message.success(res.message)
  99. _this.isShow = false
  100. }
  101. })
  102. } else {
  103. console.log('error submit!!')
  104. return false
  105. }
  106. })
  107. }
  108. },
  109. watch: {
  110. // 父页面传过来的弹框状态
  111. openModal (newValue, oldValue) {
  112. this.isShow = newValue
  113. },
  114. // 重定义的弹框状态
  115. isShow (newValue, oldValue) {
  116. if (!newValue) {
  117. this.$emit('close')
  118. this.$refs.ruleForm.resetFields()
  119. }
  120. },
  121. itemId (newValue, oldValue) {
  122. if (this.isShow && newValue) { // 编辑
  123. this.form.name = this.nowData && this.nowData.name ? this.nowData.name : ''
  124. } else { // 添加
  125. this.form.name = ''
  126. }
  127. }
  128. }
  129. }
  130. </script>
  131. <style lang="less">
  132. .intelligentReplenishmentEdit-modal{
  133. .ant-modal-body {
  134. padding: 40px 40px 24px;
  135. }
  136. .btn-cont {
  137. text-align: center;
  138. margin: 35px 0 10px;
  139. }
  140. }
  141. </style>