editModal.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <a-modal
  3. centered
  4. class="warehouseEdit-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. :title="modalTit"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="800">
  11. <a-spin :spinning="spinning" tip="Loading...">
  12. <!-- 表单 -->
  13. <div>
  14. <a-form-model
  15. id="warehouseEdit-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="仓库名称" prop="name">
  23. <a-input
  24. id="warehouseEdit-name"
  25. :maxLength="30"
  26. v-model.trim="form.name"
  27. @change="filterEmpty"
  28. placeholder="请输入仓库名称(最多30个字符)"
  29. allowClear />
  30. </a-form-model-item>
  31. <a-form-model-item label="排序" prop="sort">
  32. <a-input-number
  33. v-model="form.sort"
  34. :min="0"
  35. :max="999999"
  36. :precision="0"
  37. :step="1"
  38. placeholder="请输入排序(0~999999)"
  39. style="width: 100%;" />
  40. </a-form-model-item>
  41. </a-form-model>
  42. <div class="btn-cont">
  43. <a-button type="primary" id="warehouse-edit-modal-save" @click="handleSave">保存</a-button>
  44. <a-button id="warehouse-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
  45. </div>
  46. </div>
  47. </a-spin>
  48. </a-modal>
  49. </template>
  50. <script>
  51. import { commonMixin } from '@/utils/mixin'
  52. import { STable } from '@/components'
  53. import { warehouseSave } from '@/api/warehouse'
  54. export default {
  55. name: 'WarehouseEditModal',
  56. components: { STable },
  57. mixins: [commonMixin],
  58. props: {
  59. openModal: { // 弹框显示状态
  60. type: Boolean,
  61. default: false
  62. },
  63. itemId: {
  64. type: [Number, String],
  65. default: ''
  66. },
  67. nowData: {
  68. type: Object,
  69. default: null
  70. }
  71. },
  72. computed: {
  73. modalTit () {
  74. return (this.itemId ? '编辑' : '新增') + '仓库'
  75. }
  76. },
  77. data () {
  78. return {
  79. spinning: false,
  80. isShow: this.openModal, // 是否打开弹框
  81. formItemLayout: {
  82. labelCol: { span: 6 },
  83. wrapperCol: { span: 16 }
  84. },
  85. form: {
  86. name: '', // 仓库名称
  87. sort: '' // 排序
  88. },
  89. rules: {
  90. name: [
  91. { required: true, message: '请输入仓库名称', trigger: 'blur' }
  92. ]
  93. }
  94. }
  95. },
  96. methods: {
  97. filterEmpty () {
  98. let str = this.form.name
  99. str = str.replace(/\ +/g, '')
  100. str = str.replace(/[ ]/g, '')
  101. str = str.replace(/[\r\n]/g, '')
  102. this.form.name = str
  103. },
  104. // 详情
  105. getDetail () {
  106. this.form = {
  107. name: this.nowData && this.nowData.name ? this.nowData.name : '',
  108. sort: this.nowData && (this.nowData.sort || this.nowData.sort == 0) ? this.nowData.sort : ''
  109. }
  110. },
  111. // 保存
  112. handleSave () {
  113. const _this = this
  114. this.$refs.ruleForm.validate(valid => {
  115. if (valid) {
  116. const params = {
  117. id: this.itemId ? this.itemId : undefined,
  118. name: this.form.name, // 仓库名称
  119. sort: this.form.sort // 排序
  120. }
  121. _this.spinning = true
  122. warehouseSave(params).then(res => {
  123. if (res.status == 200) {
  124. _this.$message.success(res.message)
  125. _this.$emit('ok')
  126. setTimeout(function () {
  127. _this.isShow = false
  128. _this.$refs.ruleForm.resetFields()
  129. _this.spinning = false
  130. }, 300)
  131. } else {
  132. _this.spinning = false
  133. }
  134. })
  135. } else {
  136. console.log('error submit!!')
  137. return false
  138. }
  139. })
  140. }
  141. },
  142. watch: {
  143. // 父页面传过来的弹框状态
  144. openModal (newValue, oldValue) {
  145. this.isShow = newValue
  146. },
  147. // 重定义的弹框状态
  148. isShow (newValue, oldValue) {
  149. if (!newValue) {
  150. this.$emit('close')
  151. } else {
  152. this.form = {
  153. name: '',
  154. sort: ''
  155. }
  156. }
  157. },
  158. itemId (newValue, oldValue) {
  159. if (this.isShow && newValue) {
  160. this.getDetail()
  161. }
  162. }
  163. }
  164. }
  165. </script>
  166. <style lang="less">
  167. .warehouseEdit-modal{
  168. .ant-modal-body {
  169. padding: 40px 40px 24px;
  170. }
  171. .btn-cont {
  172. text-align: center;
  173. margin: 35px 0 10px;
  174. }
  175. }
  176. </style>