editModal.vue 5.0 KB

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