addHWModal.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div>
  3. <a-modal
  4. centered
  5. wrapClassName="addHWModal-modal"
  6. :footer="null"
  7. :maskClosable="false"
  8. :title="textTitle"
  9. v-model="isshow"
  10. @cancle="isshow=false"
  11. :width="500">
  12. <a-spin :spinning="spinning" tip="Loading...">
  13. <a-form-model
  14. id="addHWModal-form"
  15. ref="ruleForm"
  16. :model="form"
  17. :rules="rules"
  18. >
  19. <a-row :gutter="20">
  20. <a-col :span="24">
  21. <a-form-model-item label="货位号" prop="shelfPlaceCode" :label-col="{span: 5}" :wrapper-col="{span: 18}">
  22. <a-input id="addHWModal-shelfPlaceCode" v-model.trim="form.shelfPlaceCode" allowClear placeholder="请输入货位号"/>
  23. </a-form-model-item>
  24. </a-col>
  25. </a-row>
  26. <a-form-model-item :label-col="{span: 0}" :wrapper-col="{span: 24}" style="text-align: center;">
  27. <a-button type="primary" @click="handleSubmit()" :style="{ marginRight: '8px' }" id="addHWModal-handleSubmit">保存</a-button>
  28. <a-button :style="{ marginLeft: '8px' }" @click="isshow=false" id="addHWModal-close">取消</a-button>
  29. </a-form-model-item>
  30. </a-form-model>
  31. </a-spin>
  32. </a-modal>
  33. </div>
  34. </template>
  35. <script>
  36. import { saveHw, shelfHWDetail } from '@/api/shelf.js'
  37. export default {
  38. name: 'AddHWModal',
  39. props: {
  40. openHWModal: {
  41. type: Boolean,
  42. default: false
  43. },
  44. shelfSn: {
  45. type: [String, Number],
  46. default: ''
  47. },
  48. nowData: {
  49. type: Object,
  50. default: function () {
  51. return {}
  52. }
  53. }
  54. // shelfPlaceSn: {
  55. // type: [String, Number],
  56. // default: ''
  57. // }
  58. },
  59. data () {
  60. return {
  61. spinning: false,
  62. isshow: this.openHWModal,
  63. textTitle: '新增货位',
  64. roleList: [],
  65. pageInfo: null,
  66. form: {
  67. shelfPlaceCode: '' // 货位号
  68. },
  69. rules: {
  70. shelfPlaceCode: [ { required: true, message: '请输入货位号', trigger: 'blur' }]
  71. }
  72. }
  73. },
  74. methods: {
  75. // 过滤空格
  76. filterEmpty () {
  77. let str = this.form.name
  78. str = str.replace(/\ +/g, '')
  79. str = str.replace(/[ ]/g, '')
  80. str = str.replace(/[\r\n]/g, '')
  81. this.form.name = str
  82. },
  83. // 查询货位详情
  84. getShelfHWDetail () {
  85. this.spinning = true
  86. shelfHWDetail({ shelfPlaceSn: this.nowData.shelfPlaceSn }).then(res => {
  87. if (res.status == 200) {
  88. this.form = Object.assign({}, res.data)
  89. }
  90. this.spinning = false
  91. })
  92. },
  93. // 保存提交
  94. handleSubmit () {
  95. const _this = this
  96. this.$refs.ruleForm.validate(valid => {
  97. if (valid) {
  98. const params = JSON.parse(JSON.stringify(_this.form))
  99. params.shelfSn = _this.shelfSn ? _this.shelfSn : null
  100. console.log(params.id, params.shelfSn, '------------编辑新增')
  101. _this.spinning = true
  102. saveHw(params).then(res => {
  103. if (res.status == 200) {
  104. _this.$message.success(res.message)
  105. _this.$emit('refresh')
  106. setTimeout(function () {
  107. _this.isshow = false
  108. _this.spinning = false
  109. }, 300)
  110. } else {
  111. _this.spinning = false
  112. }
  113. })
  114. } else {
  115. console.log('error submit!!')
  116. return false
  117. }
  118. })
  119. }
  120. },
  121. watch: {
  122. openHWModal (newValue, oldValue) {
  123. console.log(newValue, 'newValue')
  124. this.isshow = newValue
  125. },
  126. isshow (newValue, oldValue) {
  127. if (!newValue) {
  128. console.log(!newValue, newValue)
  129. this.$refs.ruleForm.resetFields()
  130. this.form = {}
  131. this.textTitle = '新增货位'
  132. this.$emit('close')
  133. } else {
  134. if (this.nowData && this.nowData.id) { // 编辑
  135. console.log(this.shelfPlaceSn, 'this.shelfPlaceSn')
  136. this.textTitle = '编辑货位'
  137. this.getShelfHWDetail()
  138. }
  139. }
  140. }
  141. // nowData: {
  142. // handler (newValue, oldValue) {
  143. // if (this.isshow && newValue) {
  144. // console.log(this.isshow, newValue, 'newValue')
  145. // if (this.nowData.id) { // 编辑
  146. // console.log(this.shelfPlaceSn, 'this.shelfPlaceSn')
  147. // this.textTitle = '编辑货位'
  148. // // this.getShelfHWDetail()
  149. // }
  150. // }
  151. // },
  152. // deep: true
  153. // }
  154. }
  155. }
  156. </script>
  157. <style lang="less">
  158. </style>