editModal.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. @cancel="isShow=false"
  10. :width="800">
  11. <!-- 表单 -->
  12. <div>
  13. <a-spin :spinning="spinning" tip="Loading...">
  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="addressInfo">
  32. <AreaList
  33. id="warehouseEdit-areaList"
  34. :value="form.addressInfo"
  35. changeOnSelect
  36. ref="areaList"
  37. @change="areaChange"
  38. defValKey="id"></AreaList>
  39. </a-form-model-item>
  40. <a-form-model-item prop="address" :wrapper-col="{ span: 16, offset: 6 }">
  41. <a-input
  42. id="warehouseEdit-desc"
  43. v-model.trim="form.address"
  44. placeholder="请输入详细地址"
  45. allowClear />
  46. </a-form-model-item>
  47. <a-form-model-item label="仓库类型" prop="warehouseType">
  48. <v-select
  49. v-model="form.warehouseType"
  50. ref="state"
  51. id="warehouseEdit-state"
  52. code="WAREHOUSE_TYPE"
  53. placeholder="请选择仓库类型"
  54. allowClear
  55. ></v-select>
  56. </a-form-model-item>
  57. <a-form-model-item label="ERP仓库编码" prop="erpWarehouseCode">
  58. <a-input
  59. id="warehouseEdit-code"
  60. v-model.trim="form.erpWarehouseCode"
  61. placeholder="请输入ERP仓库编码"
  62. allowClear />
  63. </a-form-model-item>
  64. </a-form-model>
  65. <div class="btn-cont">
  66. <a-button id="warehouse-edit-modal-back" @click="isShow = false" style="margin-right: 15px;">取消</a-button>
  67. <a-button type="primary" id="warehouse-edit-modal-save" @click="handleSave">保存</a-button>
  68. </div>
  69. </a-spin>
  70. </div>
  71. </a-modal>
  72. </template>
  73. <script>
  74. import { commonMixin } from '@/utils/mixin'
  75. // 组件
  76. import { STable, VSelect } from '@/components'
  77. import AreaList from '@/views/common/areaList.js'
  78. // 接口
  79. import { warehouseSave } from '@/api/warehouse'
  80. export default {
  81. name: 'WarehouseEditModal',
  82. mixins: [commonMixin],
  83. components: { STable, AreaList, VSelect },
  84. props: {
  85. openModal: { // 弹框显示状态
  86. type: Boolean,
  87. default: false
  88. },
  89. itemSn: {
  90. type: [Number, String],
  91. default: ''
  92. },
  93. nowData: {
  94. type: Object,
  95. default: null
  96. }
  97. },
  98. computed: {
  99. modalTit () {
  100. return (this.itemSn ? '编辑' : '新增') + '仓库'
  101. }
  102. },
  103. data () {
  104. return {
  105. isShow: this.openModal, // 是否打开弹框
  106. spinning: false,
  107. // 表单 label 布局
  108. formItemLayout: {
  109. labelCol: { span: 6 },
  110. wrapperCol: { span: 16 }
  111. },
  112. // 提交参数
  113. form: {
  114. name: '', // 仓库名称
  115. address: '', // 详细地址
  116. addressInfo: undefined, // 选择省市区
  117. provinceSn: undefined, // 省份sn
  118. provinceName: undefined, // 省份名称
  119. citySn: undefined, // 市sn
  120. cityName: undefined, // 市名称
  121. districtSn: undefined, // 区sn
  122. districtName: undefined, // 区名称
  123. erpWarehouseCode: undefined, // ERP仓库编码
  124. warehouseType: undefined// 仓库类型
  125. },
  126. rules: {
  127. name: [
  128. { required: true, message: '请输入仓库名称', trigger: 'blur' }
  129. ],
  130. addressInfo: [
  131. { required: true, message: '请选择省市区', trigger: 'change' }
  132. ],
  133. address: [
  134. { required: true, message: '请输入详细地址', trigger: 'blur' }
  135. ],
  136. erpWarehouseCode: [
  137. { required: true, message: '请输入ERP仓库编码', trigger: 'blur' }
  138. ],
  139. warehouseType: [
  140. { required: true, message: '请选择仓库类型', trigger: 'change' }
  141. ]
  142. }
  143. }
  144. },
  145. methods: {
  146. // 仓库名称 去除空格
  147. filterEmpty () {
  148. let str = this.form.name
  149. str = str.replace(/\ +/g, '')
  150. str = str.replace(/[ ]/g, '')
  151. str = str.replace(/[\r\n]/g, '')
  152. this.form.name = str
  153. },
  154. // 地区
  155. areaChange (val, row) {
  156. this.form.addressInfo = val
  157. this.form.provinceSn = val[0] ? val[0] : ''
  158. this.form.provinceName = row[0] ? row[0].name ? row[0].name : '' : ''
  159. this.form.citySn = val[1] ? val[1] : ''
  160. this.form.cityName = row[1] ? row[1].name ? row[1].name : '' : ''
  161. this.form.districtSn = val[2] ? val[2] : ''
  162. this.form.districtName = row[2] ? row[2].name ? row[2].name : '' : ''
  163. },
  164. // 详情
  165. getDetail () {
  166. if (this.nowData) {
  167. const addressVal = [this.nowData.provinceSn ? this.nowData.provinceSn : '', this.nowData.citySn ? this.nowData.citySn : '', this.nowData.districtSn ? this.nowData.districtSn : '']
  168. this.form = {
  169. name: this.nowData.name ? this.nowData.name : '',
  170. address: this.nowData.address ? this.nowData.address : '',
  171. provinceSn: this.nowData.provinceSn ? this.nowData.provinceSn : '',
  172. provinceName: this.nowData.provinceName ? this.nowData.provinceName : '',
  173. citySn: this.nowData.citySn ? this.nowData.citySn : '',
  174. cityName: this.nowData.cityName ? this.nowData.cityName : '',
  175. districtSn: this.nowData.districtSn ? this.nowData.districtSn : '',
  176. districtName: this.nowData.districtName ? this.nowData.districtName : '',
  177. erpWarehouseCode: this.nowData.erpWarehouseCode ? this.nowData.erpWarehouseCode : '', // ERP仓库编码
  178. warehouseType: this.nowData.warehouseType ? this.nowData.warehouseType : '',
  179. addressInfo: addressVal
  180. }
  181. }
  182. },
  183. // 保存
  184. handleSave () {
  185. const _this = this
  186. this.$refs.ruleForm.validate(valid => {
  187. if (valid) {
  188. const params = {
  189. warehouseSn: this.itemSn ? this.itemSn : undefined
  190. }
  191. const newParams = Object.assign(this.form, params)
  192. delete newParams.addressInfo
  193. _this.spinning = true
  194. warehouseSave(newParams).then(res => {
  195. if (res.status == 200) {
  196. _this.$message.success(res.message)
  197. _this.$emit('ok')
  198. setTimeout(function () {
  199. _this.isShow = false
  200. _this.$refs.ruleForm.resetFields()
  201. _this.spinning = false
  202. }, 300)
  203. } else {
  204. _this.spinning = false
  205. }
  206. })
  207. } else {
  208. console.log('error submit!!')
  209. return false
  210. }
  211. })
  212. }
  213. },
  214. watch: {
  215. // 父页面传过来的弹框状态
  216. openModal (newValue, oldValue) {
  217. this.isShow = newValue
  218. },
  219. // 重定义的弹框状态
  220. isShow (newValue, oldValue) {
  221. if (!newValue) {
  222. this.$emit('close')
  223. } else {
  224. this.form = {
  225. name: '',
  226. address: '',
  227. addressInfo: undefined,
  228. provinceSn: undefined,
  229. provinceName: undefined,
  230. citySn: undefined,
  231. cityName: undefined,
  232. districtSn: undefined,
  233. districtName: undefined,
  234. erpWarehouseCode: undefined, // ERP仓库编码
  235. warehouseType: undefined
  236. }
  237. }
  238. },
  239. itemSn (newValue, oldValue) {
  240. if (this.isShow && newValue) {
  241. this.getDetail()
  242. }
  243. }
  244. }
  245. }
  246. </script>
  247. <style lang="less" scoped>
  248. .warehouseEdit-modal{
  249. .ant-modal-body {
  250. padding: 40px 40px 24px;
  251. }
  252. .btn-cont {
  253. text-align: center;
  254. margin: 35px 0 10px;
  255. }
  256. }
  257. </style>