editModal.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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-form-model
  14. id="storingLocationEdit-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="storingLocationEdit-name"
  24. :maxLength="30"
  25. v-model="form.name"
  26. placeholder="请输入仓位名称(最多30个字符)"
  27. allowClear />
  28. </a-form-model-item>
  29. <a-form-model-item label="所属仓库" prop="warehouseSn">
  30. <a-select id="storingLocationEdit-warehouseSn" disabled placeholder="请选择所属仓库" allowClear v-model="form.warehouseSn">
  31. <a-select-option v-for="item in warehouseList" :key="item.id" :value="item.warehouseSn">{{ item.name }}</a-select-option>
  32. </a-select>
  33. </a-form-model-item>
  34. <a-form-model-item label="排序" prop="sort">
  35. <a-input-number
  36. v-model="form.sort"
  37. :min="0"
  38. :max="999999"
  39. :precision="0"
  40. :step="1"
  41. placeholder="请输入排序(0~999999)"
  42. style="width: 100%;" />
  43. </a-form-model-item>
  44. </a-form-model>
  45. <div class="btn-cont">
  46. <a-button type="primary" id="storingLocation-edit-modal-save" @click="handleSave">保存</a-button>
  47. <a-button id="storingLocation-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
  48. </div>
  49. </div>
  50. </a-modal>
  51. </template>
  52. <script>
  53. import { STable } from '@/components'
  54. import { warehouseLocSave, warehouseAllList } from '@/api/warehouse'
  55. export default {
  56. name: 'StoringLocationEditModal',
  57. components: { STable },
  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. isShow: this.openModal, // 是否打开弹框
  80. formItemLayout: {
  81. labelCol: { span: 6 },
  82. wrapperCol: { span: 16 }
  83. },
  84. form: {
  85. name: '', // 仓位名称
  86. warehouseSn: undefined, // 所属仓库
  87. sort: '' // 排序
  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. sort: this.nowData && (this.nowData.sort || this.nowData.sort == 0) ? this.nowData.sort : ''
  117. }
  118. },
  119. // 保存
  120. handleSave () {
  121. const _this = this
  122. this.$refs.ruleForm.validate(valid => {
  123. if (valid) {
  124. const params = {
  125. id: this.itemId ? this.itemId : undefined,
  126. warehouseSn: this.form.warehouseSn, // 所属仓库
  127. name: this.form.name, // 仓库名称
  128. sort: this.form.sort // 排序
  129. }
  130. warehouseLocSave(params).then(res => {
  131. if (res.status == 200) {
  132. _this.$message.success(res.message)
  133. _this.$emit('ok')
  134. setTimeout(function () {
  135. _this.isShow = false
  136. _this.$refs.ruleForm.resetFields()
  137. }, 300)
  138. } else {
  139. }
  140. })
  141. } else {
  142. console.log('error submit!!')
  143. return false
  144. }
  145. })
  146. }
  147. },
  148. watch: {
  149. // 父页面传过来的弹框状态
  150. openModal (newValue, oldValue) {
  151. this.isShow = newValue
  152. },
  153. // 重定义的弹框状态
  154. isShow (newValue, oldValue) {
  155. if (!newValue) {
  156. this.$refs.ruleForm.resetFields()
  157. this.form = {
  158. name: '',
  159. warehouseSn: '',
  160. sort: ''
  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. sort: ''
  169. }
  170. }
  171. },
  172. itemId (newValue, oldValue) {
  173. if (this.isShow && newValue) {
  174. this.getDetail()
  175. }
  176. }
  177. }
  178. }
  179. </script>
  180. <style lang="less">
  181. .storingLocationEdit-modal{
  182. .ant-modal-body {
  183. padding: 40px 40px 24px;
  184. }
  185. .btn-cont {
  186. text-align: center;
  187. margin: 35px 0 10px;
  188. }
  189. }
  190. </style>