editModal.vue 5.2 KB

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