123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <template>
- <a-modal
- centered
- class="storingLocationEdit-modal"
- :footer="null"
- :maskClosable="false"
- :title="modalTit"
- v-model="isShow"
- @cancle="isShow=false"
- :width="800">
- <!-- 表单 -->
- <div>
- <a-spin :spinning="spinning" tip="Loading...">
- <a-form-model
- id="storingLocationEdit-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="storingLocationEdit-name"
- :maxLength="30"
- v-model="form.name"
- placeholder="请输入仓位名称(最多30个字符)"
- allowClear />
- </a-form-model-item>
- <a-form-model-item label="所属仓库" prop="warehouseSn">
- <a-select id="storingLocationEdit-warehouseSn" disabled placeholder="请选择所属仓库" allowClear v-model="form.warehouseSn">
- <a-select-option v-for="item in warehouseList" :key="item.id" :value="item.warehouseSn">{{ item.name }}</a-select-option>
- </a-select>
- </a-form-model-item>
- </a-form-model>
- <div class="btn-cont">
- <a-button type="primary" id="storingLocation-edit-modal-save" @click="handleSave">保存</a-button>
- <a-button id="storingLocation-edit-modal-back" @click="isShow = false" style="margin-left: 15px;">返回列表</a-button>
- </div>
- </a-spin>
- </div>
- </a-modal>
- </template>
- <script>
- import { STable } from '@/components'
- import { warehouseLocSave, warehouseAllList } from '@/api/warehouse'
- export default {
- name: 'StoringLocationEditModal',
- components: { STable },
- 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: '', // 仓位名称
- warehouseSn: undefined // 所属仓库
- },
- rules: {
- name: [
- { required: true, message: '请输入仓位名称', trigger: 'blur' }
- ],
- warehouseSn: [
- { required: true, message: '请选择所属仓库', trigger: 'change' }
- ]
- },
- warehouseList: [] // 仓库 下拉数据
- }
- },
- methods: {
- // 获取仓库列表数据
- getWarehouseList () {
- warehouseAllList({}).then(res => {
- if (res.status == 200) {
- this.warehouseList = res.data
- } else {
- this.warehouseList = []
- }
- })
- },
- // 详情
- getDetail () {
- this.form = {
- name: this.nowData && this.nowData.name ? this.nowData.name : '',
- warehouseSn: this.nowData && this.nowData.warehouseSn ? this.nowData.warehouseSn : ''
- }
- },
- // 保存
- handleSave () {
- const _this = this
- this.$refs.ruleForm.validate(valid => {
- if (valid) {
- const params = {
- warehouseLocationSn: this.itemSn ? this.itemSn : undefined,
- warehouseSn: this.form.warehouseSn, // 所属仓库
- name: this.form.name // 仓库名称
- }
- _this.spinning = true
- warehouseLocSave(params).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.$refs.ruleForm.resetFields()
- this.form = {
- name: '',
- warehouseSn: ''
- }
- this.$emit('close')
- } else {
- this.getWarehouseList()
- this.form = {
- name: '',
- warehouseSn: this.nowData && this.nowData.warehouseSn ? this.nowData.warehouseSn : ''
- }
- }
- },
- itemSn (newValue, oldValue) {
- if (this.isShow && newValue) {
- this.getDetail()
- }
- }
- }
- }
- </script>
- <style lang="less">
- .storingLocationEdit-modal{
- .ant-modal-body {
- padding: 40px 40px 24px;
- }
- .btn-cont {
- text-align: center;
- margin: 35px 0 10px;
- }
- }
- </style>
|