payment-method-form-dialog.vue
3.33 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
<template>
<el-dialog
:title="!dataForm.id ? '新增支付方式' : (isDetail ? '支付方式详情' : '编辑支付方式')"
:close-on-click-modal="false"
:visible.sync="visible"
class="NCC-dialog NCC-dialog_center"
lock-scroll
width="520px"
append-to-body
>
<el-form
ref="elForm"
:model="dataForm"
size="small"
label-width="100px"
label-position="right"
:disabled="!!isDetail"
:rules="rules"
>
<el-form-item label="名称" prop="methodName">
<el-input v-model.trim="dataForm.methodName" placeholder="请输入支付方式名称" clearable maxlength="50" show-word-limit />
</el-form-item>
<el-form-item label="排序" prop="sortCode">
<el-input-number v-model="dataForm.sortCode" :min="0" :max="9999" controls-position="right" style="width: 100%" />
</el-form-item>
<el-form-item label="备注" prop="remark">
<el-input v-model.trim="dataForm.remark" type="textarea" :rows="3" placeholder="无" maxlength="500" show-word-limit />
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button @click="visible = false">取 消</el-button>
<el-button v-if="!isDetail" type="primary" :loading="submitLoading" @click="dataFormSubmit()">确 定</el-button>
</span>
</el-dialog>
</template>
<script>
import {
createPaymentMethod,
getPaymentMethodInfo,
updatePaymentMethod
} from '@/api/extend/paymentMethod'
function defaultForm() {
return {
id: '',
methodName: '',
sortCode: 0,
remark: ''
}
}
export default {
name: 'PaymentMethodFormDialog',
data() {
return {
visible: false,
isDetail: false,
submitLoading: false,
dataForm: defaultForm(),
rules: {
methodName: [{ required: true, message: '请输入支付方式名称', trigger: 'blur' }]
}
}
},
methods: {
init(id, isDetail) {
this.dataForm = defaultForm()
this.dataForm.id = id || ''
this.visible = true
this.isDetail = !!isDetail
this.$nextTick(() => {
this.$refs.elForm && this.$refs.elForm.clearValidate()
if (this.dataForm.id) {
getPaymentMethodInfo(this.dataForm.id).then(res => {
const data = res.data || {}
this.dataForm = {
id: data.id || this.dataForm.id,
methodName: data.methodName || data.name || '',
sortCode: data.sortCode != null ? data.sortCode : 0,
remark: data.remark || ''
}
})
}
})
},
dataFormSubmit() {
this.$refs.elForm.validate(valid => {
if (!valid) return
this.submitLoading = true
const payload = {
name: this.dataForm.methodName,
sortCode: this.dataForm.sortCode,
remark: this.dataForm.remark || ''
}
const req = this.dataForm.id
? updatePaymentMethod(this.dataForm.id, payload)
: createPaymentMethod(payload)
req.then(res => {
this.$message({
type: 'success',
message: res.msg || '保存成功',
onClose: () => {
this.visible = false
this.$emit('refresh', true)
}
})
}).finally(() => {
this.submitLoading = false
})
})
}
}
}
</script>