123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <template>
- <a-modal
- centered
- class="warehouseEdit-modal"
- :footer="null"
- :maskClosable="false"
- :title="modalTit"
- v-model="isShow"
- @cancel="isShow=false"
- :width="800">
- <!-- 表单 -->
- <div>
- <a-spin :spinning="spinning" tip="Loading...">
- <a-form-model
- id="warehouseEdit-form"
- ref="ruleForm"
- :model="form"
- :rules="rules"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol"
- >
- <a-form-model-item label="仓库名称" prop="name">
- <a-input
- id="warehouseEdit-name"
- :maxLength="30"
- v-model.trim="form.name"
- @change="filterEmpty"
- placeholder="请输入仓库名称(最多30个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="地址" prop="addressInfo">
- <AreaList
- id="warehouseEdit-areaList"
- :value="form.addressInfo"
- changeOnSelect
- ref="areaList"
- @change="areaChange"
- defValKey="id"></AreaList>
- </a-form-model-item>
- <a-form-model-item prop="address" :wrapper-col="{ span: 16, offset: 6 }">
- <a-input
- id="warehouseEdit-desc"
- v-model.trim="form.address"
- placeholder="请输入详细地址"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="ERP仓库编码" prop="erpWarehouseCode">
- <a-input
- id="warehouseEdit-code"
- v-model.trim="form.erpWarehouseCode"
- placeholder="请输入ERP仓库编码"
- allowClear />
- </a-form-model-item>
- </a-form-model>
- <div class="btn-cont">
- <a-button type="primary" id="warehouse-edit-modal-save" @click="handleSave">保存</a-button>
- <a-button id="warehouse-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
- </div>
- </a-spin>
- </div>
- </a-modal>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { STable } from '@/components'
- import { warehouseSave } from '@/api/warehouse'
- import AreaList from '@/views/common/areaList.js'
- export default {
- name: 'WarehouseEditModal',
- mixins: [commonMixin],
- components: { STable, AreaList },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- itemSn: {
- type: [Number, String],
- default: ''
- },
- nowData: {
- type: Object,
- default: null
- }
- },
- computed: {
- modalTit () {
- return (this.itemSn ? '编辑' : '新增') + '仓库'
- }
- },
- data () {
- return {
- isShow: this.openModal, // 是否打开弹框
- spinning: false,
- formItemLayout: {
- labelCol: { span: 6 },
- wrapperCol: { span: 16 }
- },
- form: {
- name: '', // 仓库名称
- address: '',
- addressInfo: undefined,
- provinceSn: undefined,
- provinceName: undefined,
- citySn: undefined,
- cityName: undefined,
- districtSn: undefined,
- districtName: undefined,
- erpWarehouseCode: undefined// ERP仓库编码
- },
- rules: {
- name: [
- { required: true, message: '请输入仓库名称', trigger: 'blur' }
- ],
- addressInfo: [
- { required: true, message: '请选择省市区', trigger: 'change' }
- ],
- address: [
- { required: true, message: '请输入详细地址', trigger: 'blur' }
- ],
- erpWarehouseCode: [
- { required: true, message: '请输入ERP仓库编码', trigger: 'blur' }
- ]
- }
- }
- },
- methods: {
- filterEmpty () {
- let str = this.form.name
- str = str.replace(/\ +/g, '')
- str = str.replace(/[ ]/g, '')
- str = str.replace(/[\r\n]/g, '')
- this.form.name = str
- },
- areaChange (val, row) {
- this.form.addressInfo = val
- this.form.provinceSn = val[0] ? val[0] : ''
- this.form.provinceName = row[0] ? row[0].name ? row[0].name : '' : ''
- this.form.citySn = val[1] ? val[1] : ''
- this.form.cityName = row[1] ? row[1].name ? row[1].name : '' : ''
- this.form.districtSn = val[2] ? val[2] : ''
- this.form.districtName = row[2] ? row[2].name ? row[2].name : '' : ''
- },
- // 详情
- getDetail () {
- if (this.nowData) {
- const addressVal = [this.nowData.provinceSn ? this.nowData.provinceSn : '', this.nowData.citySn ? this.nowData.citySn : '', this.nowData.districtSn ? this.nowData.districtSn : '']
- this.form = {
- name: this.nowData.name ? this.nowData.name : '',
- address: this.nowData.address ? this.nowData.address : '',
- provinceSn: this.nowData.provinceSn ? this.nowData.provinceSn : '',
- provinceName: this.nowData.provinceName ? this.nowData.provinceName : '',
- citySn: this.nowData.citySn ? this.nowData.citySn : '',
- cityName: this.nowData.cityName ? this.nowData.cityName : '',
- districtSn: this.nowData.districtSn ? this.nowData.districtSn : '',
- districtName: this.nowData.districtName ? this.nowData.districtName : '',
- erpWarehouseCode: this.nowData.erpWarehouseCode ? this.nowData.erpWarehouseCode : '', // ERP仓库编码
- addressInfo: addressVal
- }
- }
- },
- // 保存
- handleSave () {
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const params = {
- warehouseSn: this.itemSn ? this.itemSn : undefined
- }
- const newParams = Object.assign(this.form, params)
- delete newParams.addressInfo
- _this.spinning = true
- warehouseSave(newParams).then(res => {
- if (res.status == 200) {
- _this.$message.success(res.message)
- _this.$emit('ok')
- setTimeout(function () {
- _this.isShow = false
- _this.$refs.ruleForm.resetFields()
- _this.spinning = false
- }, 300)
- } else {
- _this.spinning = false
- }
- })
- } else {
- console.log('error submit!!')
- return false
- }
- })
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- } else {
- this.form = {
- name: '',
- address: '',
- addressInfo: undefined,
- provinceSn: undefined,
- provinceName: undefined,
- citySn: undefined,
- cityName: undefined,
- districtSn: undefined,
- districtName: undefined,
- erpWarehouseCode: undefined// ERP仓库编码
- }
- }
- },
- itemSn (newValue, oldValue) {
- if (this.isShow && newValue) {
- this.getDetail()
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .warehouseEdit-modal{
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- }
- </style>
|