|
@@ -0,0 +1,152 @@
|
|
1
|
+<template>
|
|
2
|
+ <el-dialog
|
|
3
|
+ :visible.sync="dialogVisible"
|
|
4
|
+ :before-close="handleCancel"
|
|
5
|
+ class="addAccount-dialog"
|
|
6
|
+ :title="dialogTitle"
|
|
7
|
+ width="450px"
|
|
8
|
+ >
|
|
9
|
+ <div class="form-wrap" v-loading="loading">
|
|
10
|
+ <div class="form-item">
|
|
11
|
+ <span class="lable"><em>*</em>账号</span>
|
|
12
|
+ <el-input v-model="form.accountNumber" size="small" placeholder="请输入账号" clearable />
|
|
13
|
+ </div>
|
|
14
|
+ </div>
|
|
15
|
+ <div slot="footer" class="dialog-footer">
|
|
16
|
+ <el-button size="mini" @click="handleCancel">取 消</el-button>
|
|
17
|
+ <el-button size="mini" type="primary" @click="handleConfirm" :disabled="loading">确 定</el-button>
|
|
18
|
+ </div>
|
|
19
|
+ </el-dialog>
|
|
20
|
+</template>
|
|
21
|
+
|
|
22
|
+<script>
|
|
23
|
+export default {
|
|
24
|
+ name: "addAccountDialog",
|
|
25
|
+ props: {
|
|
26
|
+ // 控制弹框是否显示
|
|
27
|
+ dialogVisible: {
|
|
28
|
+ type: Boolean,
|
|
29
|
+ default: () => false
|
|
30
|
+ },
|
|
31
|
+ // 账号所属的平台id
|
|
32
|
+ platformId: {
|
|
33
|
+ type: [String, Number],
|
|
34
|
+ default: () => ''
|
|
35
|
+ },
|
|
36
|
+ },
|
|
37
|
+ data() {
|
|
38
|
+ return {
|
|
39
|
+ loading: false,
|
|
40
|
+ form: {
|
|
41
|
+ accountNumber: '', // 账号
|
|
42
|
+ }
|
|
43
|
+ }
|
|
44
|
+ },
|
|
45
|
+ computed: {
|
|
46
|
+ // 当前操作是否为"编辑"
|
|
47
|
+ isEdit() {
|
|
48
|
+ return false // 暂时只有新建
|
|
49
|
+ },
|
|
50
|
+ // 弹框标题
|
|
51
|
+ dialogTitle() {
|
|
52
|
+ return this.isEdit ? '编辑账号' : '添加账号'
|
|
53
|
+ }
|
|
54
|
+ },
|
|
55
|
+ watch: {
|
|
56
|
+ dialogVisible(isShow) {
|
|
57
|
+ // 弹框显示 => 初始化表单数据
|
|
58
|
+ isShow && this.handleInitData()
|
|
59
|
+ },
|
|
60
|
+ },
|
|
61
|
+ methods: {
|
|
62
|
+ // 获取弹框表单数据
|
|
63
|
+ handleInitData() {
|
|
64
|
+ this.loading = false
|
|
65
|
+ if (this.isEdit) { // 编辑
|
|
66
|
+
|
|
67
|
+ } else { // 新建
|
|
68
|
+ this.form.accountNumber = ''
|
|
69
|
+ }
|
|
70
|
+ },
|
|
71
|
+ async handleConfirm() {
|
|
72
|
+ console.log('handleConfirm => ')
|
|
73
|
+ try {
|
|
74
|
+ // 表单校验
|
|
75
|
+ await this.handleFormValidate()
|
|
76
|
+ let url = `${this.URL.BASEURL}${this.URL.xxx}`
|
|
77
|
+ const params = {
|
|
78
|
+ ...this.form,
|
|
79
|
+ platformId: this.platformId
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ // if (this.isEdit) { // 编辑操作
|
|
83
|
+ // url = `${this.URL.BASEURL}${this.URL.xxx}`
|
|
84
|
+ // params.id = this.platformInfo.id
|
|
85
|
+ // }
|
|
86
|
+
|
|
87
|
+ console.log('url => ', url)
|
|
88
|
+ console.log('params => ', params)
|
|
89
|
+ this.$emit('confirm') // mock
|
|
90
|
+ return // mock
|
|
91
|
+
|
|
92
|
+ this.loading = true
|
|
93
|
+ const { data: res = {} } = await this.$axios.post(url, params)
|
|
94
|
+ if (res && res.errno == 0) {
|
|
95
|
+ this.$message.success('操作成功')
|
|
96
|
+ this.$emit('confirm')
|
|
97
|
+ } else if (res.errno != 4002) {
|
|
98
|
+ this.$message.warning(res.err || '操作失败')
|
|
99
|
+ }
|
|
100
|
+ } catch (error) {
|
|
101
|
+ console.log('error => ', error)
|
|
102
|
+ } finally {
|
|
103
|
+ this.loading = false
|
|
104
|
+ }
|
|
105
|
+ },
|
|
106
|
+ handleCancel() {
|
|
107
|
+ this.$emit('cancel')
|
|
108
|
+ },
|
|
109
|
+ // 执行表单校验
|
|
110
|
+ handleFormValidate() {
|
|
111
|
+ return new Promise((resolve, reject) => {
|
|
112
|
+ const { accountNumber } = this.form
|
|
113
|
+ if (!accountNumber) {
|
|
114
|
+ this.$message.warning('请输入账号')
|
|
115
|
+ reject('表单校验未通过')
|
|
116
|
+ } else {
|
|
117
|
+ resolve('表单校验通过')
|
|
118
|
+ }
|
|
119
|
+ })
|
|
120
|
+ },
|
|
121
|
+ },
|
|
122
|
+};
|
|
123
|
+</script>
|
|
124
|
+
|
|
125
|
+<style lang="scss" scoped>
|
|
126
|
+.addAccount-dialog {
|
|
127
|
+ .form-wrap {
|
|
128
|
+ padding: 0 10px;
|
|
129
|
+ .form-item {
|
|
130
|
+ display: flex;
|
|
131
|
+ align-items: center;
|
|
132
|
+ margin-top: 16px;
|
|
133
|
+ &:first-child {
|
|
134
|
+ margin-top: 0;
|
|
135
|
+ }
|
|
136
|
+ .lable {
|
|
137
|
+ width: 70px;
|
|
138
|
+ margin-right: 16px;
|
|
139
|
+ font-weight: 500;
|
|
140
|
+ flex-shrink: 0;
|
|
141
|
+ text-align: right;
|
|
142
|
+ em {
|
|
143
|
+ color: red;
|
|
144
|
+ }
|
|
145
|
+ }
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+ .dialog-footer {
|
|
149
|
+ text-align: center;
|
|
150
|
+ }
|
|
151
|
+}
|
|
152
|
+</style>
|