form-dialog.vue
4.8 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
167
168
169
170
171
172
173
<template>
<el-dialog :title="!dataForm.id ? '新增清洗商' : '编辑清洗商'" :close-on-click-modal="false"
:visible.sync="visible" class="NCC-dialog NCC-dialog_center" lock-scroll width="600px">
<el-form ref="elForm" :model="dataForm" size="small" label-width="120px" label-position="right" :rules="rules">
<el-row :gutter="15">
<el-col :span="24">
<el-form-item label="清洗商名称" prop="supplierName">
<el-input v-model="dataForm.supplierName" placeholder="请输入清洗商名称" clearable
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="产品类型" prop="productType">
<el-select v-model="dataForm.productType" placeholder="请选择产品类型" clearable filterable
:style='{"width":"100%"}'>
<el-option v-for="item in productTypeOptions" :key="item.Value" :label="item.Name" :value="item.Name" />
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="清洗价格" prop="laundryPrice">
<el-input-number v-model="dataForm.laundryPrice" placeholder="请输入清洗价格" :min="0" :precision="2"
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="备注" prop="remark">
<el-input v-model="dataForm.remark" type="textarea" :rows="4" placeholder="请输入备注信息" clearable
:style='{"width":"100%"}' />
</el-form-item>
</el-col>
</el-row>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import request from '@/utils/request'
export default {
data() {
return {
visible: false,
btnLoading: false,
productTypeOptions: [],
dataForm: {
id: undefined,
supplierName: '',
productType: '',
laundryPrice: 0,
remark: ''
},
rules: {
supplierName: [
{ required: true, message: '请输入清洗商名称', trigger: 'blur' }
],
productType: [
{ required: true, message: '请选择产品类型', trigger: 'change' }
],
laundryPrice: [
{ required: true, message: '请输入清洗价格', trigger: 'blur' },
{ type: 'number', min: 0, message: '清洗价格不能小于0', trigger: 'blur' }
]
}
}
},
methods: {
init(id) {
this.visible = true
this.dataForm = {
id: undefined,
supplierName: '',
productType: '',
laundryPrice: 0,
remark: ''
}
this.loadProductTypeOptions()
if (id) {
// 编辑模式,获取详情
this.getDetail(id)
}
},
// 加载产品类型选项
loadProductTypeOptions() {
request({
url: '/api/Extend/LqStoreConsumableInventory/consumable-product-type',
method: 'GET'
}).then(res => {
if (res.code == 200 && res.data && Array.isArray(res.data)) {
this.productTypeOptions = res.data
} else {
this.productTypeOptions = []
}
}).catch(() => {
this.productTypeOptions = []
})
},
// 获取详情
getDetail(id) {
request({
url: `/api/Extend/LqLaundrySupplier/${id}`,
method: 'GET'
}).then(res => {
if (res.code == 200 && res.data) {
const data = res.data
this.dataForm = {
id: data.id,
supplierName: data.supplierName || '',
productType: data.productType || '',
laundryPrice: data.laundryPrice || 0,
remark: data.remark || ''
}
}
}).catch(() => {
this.$message({
type: 'error',
message: '获取详情失败'
})
})
},
// 提交表单
dataFormSubmit() {
this.$refs.elForm.validate((valid) => {
if (!valid) {
return false
}
this.btnLoading = true
const url = this.dataForm.id ? '/api/Extend/LqLaundrySupplier/Update' : '/api/Extend/LqLaundrySupplier/Create'
const method = this.dataForm.id ? 'PUT' : 'POST'
const data = this.dataForm.id
? {
id: this.dataForm.id,
supplierName: this.dataForm.supplierName,
productType: this.dataForm.productType,
laundryPrice: this.dataForm.laundryPrice,
remark: this.dataForm.remark
}
: {
supplierName: this.dataForm.supplierName,
productType: this.dataForm.productType,
laundryPrice: this.dataForm.laundryPrice,
remark: this.dataForm.remark
}
request({
url: url,
method: method,
data: data
}).then(res => {
this.btnLoading = false
this.$message({
type: 'success',
message: res.msg || (this.dataForm.id ? '编辑成功' : '创建成功'),
onClose: () => {
this.visible = false
this.$emit('refresh')
}
})
}).catch(() => {
this.btnLoading = false
})
})
}
}
}
</script>
<style lang="scss" scoped>
</style>