dialog.vue
5.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<template>
<div>
<el-dialog :title="openStatus == 'add'?'新 增':'导出Excel'" :visible.sync="open" width="25%"
:close-on-click-modal="false" :show-close="false" append-to-body center>
<el-form class="form-header" :model="formData" size="small" ref="addForm" label-width="auto"
label-position="left" style="margin-bottom:10px" :rules="rules" @submit.native.prevent>
<div v-if="openStatus == 'add'">
<el-form-item label="货站名称" prop="goodsStation">
<el-input type="text" v-model="formData.goodsStation" maxlength="25" placeholder="请输入货站名称">
</el-input>
</el-form-item>
<el-form-item label="品名" prop="goodsList">
<el-input type="textarea" v-model="formData.goodsList" rows="4" maxlength="125"
placeholder="请输入品名,多个用“;”隔开">
</el-input>
</el-form-item>
</div>
<div v-else>
<el-form-item label="货站名称" prop="goodsStation">
<el-select class="selectWidth100" v-model.lazy="formData.goodsStation" filterable
:loading="goodsStationLoading" placeholder="不限">
<el-option v-for="(item, index) in goodsStationList" :label="item" :value="item"
:key="item">
</el-option>
</el-select>
</el-form-item>
</div>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button v-if='openStatus == "add"' type="primary" :loading="loading" @click="submit">确 定</el-button>
<el-button v-else type="primary" :loading="downloading" @click="download">导出Excel</el-button>
<el-button @click="close">取 消</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { batchAddGoods, findStationName } from "@/api/goodsStation"
import { downLoadXlsx } from "@/utils/zipdownload";
export default {
name: '',
props: {
open: {
type: Boolean,
default: false
},
openStatus: {
type: String,
default: 'add'
}
},
data() {
return {
formData: {
goodsStation: null,
goodsList: ''
},
goodsStationList: [],
rules: {
goodsStation: [
{
required: true,
message: "货站名称不能为空",
trigger: "change",
},
],
goodsList: [
{
required: true,
message: "品名不能为空",
trigger: "blur",
},
],
},
goodsStationLoading: false,
downloading: false,
loading: false,
}
},
watch: {
open(val) {
if (val && this.openStatus == 'downloadExcel') {
this.getgoods()
}
}
},
methods: {
//查询货站
getgoods() {
this.goodsStationLoading = true
findStationName().then(res => {
this.goodsStationLoading = false
if (res.code === 200) {
this.goodsStationList = res.data.list
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.goodsStationLoading = false
console.log(err)
})
},
//提交
submit() {
let obj = {}
obj.goodsStation = this.formData.goodsStation
this.formData.goodsList = this.formData.goodsList.replace(/;/g, ";")
if (this.formData.goodsList != null && this.formData.goodsList != '') {
obj.goodsList = this.formData.goodsList.split(';')
}
this.$refs['addForm'].validate(val => {
if (val) {
this.loading = true
batchAddGoods(obj).then(res => {
this.loading = false
if (res.code === 200) {
this.msgSuccess('添加成功')
this.close()
} else {
this.msgWarning(res.msg)
}
}).catch(err => {
this.loading = false
console.log(err)
})
}
})
},
//导出Excel
download() {
this.$refs['addForm'].validate(val => {
if (val) {
this.downloading = true
let data = { goodsStation: this.formData.goodsStation }
downLoadXlsx("/goods/exportGoods", data, "货站表")
.then(() => {
this.downloading = false
this.close()
})
.catch(() => {
this.downloading = false
});
}
})
},
//取消
close() {
this.formData = {
goodsStation: null,
goodsList: null
}
this.$refs["addForm"].clearValidate();
this.$emit('close')
}
}
}
</script>
<style lang="scss" scoped>
</style>