editModal.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <a-modal
  3. centered
  4. class="productBrandEdit-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="productBrandEdit-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="brandName">
  22. <a-input
  23. id="productBrandEdit-brandName"
  24. :maxLength="30"
  25. v-model.trim="form.brandName"
  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="product-brand-edit-modal-save" @click="handleSave">保存</a-button>
  33. <a-button id="product-brand-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 { dealerProductBrandSave } from '@/api/dealerProductBrand'
  41. export default {
  42. name: 'ProductBrandEditModal',
  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. formItemLayout: {
  67. labelCol: { span: 6 },
  68. wrapperCol: { span: 16 }
  69. },
  70. form: {
  71. brandName: '' // 产品品牌名称
  72. },
  73. rules: {
  74. brandName: [
  75. { required: true, message: '请输入产品品牌名称', trigger: 'blur' }
  76. ]
  77. }
  78. }
  79. },
  80. methods: {
  81. filterEmpty () {
  82. let str = this.form.brandName
  83. str = str.replace(/\ +/g, '')
  84. str = str.replace(/[ ]/g, '')
  85. str = str.replace(/[\r\n]/g, '')
  86. this.form.brandName = str
  87. },
  88. // 保存
  89. handleSave () {
  90. const _this = this
  91. _this.$refs.ruleForm.validate(valid => {
  92. if (valid) {
  93. const formData = JSON.parse(JSON.stringify(_this.form))
  94. formData.id = _this.itemId ? _this.itemId : undefined
  95. dealerProductBrandSave(formData).then(res => {
  96. if (res.status == 200) {
  97. _this.$message.success(res.message)
  98. _this.$emit('ok')
  99. _this.isShow = false
  100. }
  101. })
  102. } else {
  103. return false
  104. }
  105. })
  106. }
  107. },
  108. watch: {
  109. // 父页面传过来的弹框状态
  110. openModal (newValue, oldValue) {
  111. this.isShow = newValue
  112. },
  113. // 重定义的弹框状态
  114. isShow (newValue, oldValue) {
  115. if (!newValue) {
  116. this.$emit('close')
  117. this.$refs.ruleForm.resetFields()
  118. } else {
  119. this.form.brandName = this.nowData && this.nowData.brandName ? this.nowData.brandName : ''
  120. }
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="less">
  126. .productBrandEdit-modal{
  127. .ant-modal-body {
  128. padding: 40px 40px 24px;
  129. }
  130. .btn-cont {
  131. text-align: center;
  132. margin: 35px 0 10px;
  133. }
  134. }
  135. </style>