OffAdd.vue
8.85 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
<template>
<div class="add-wrap">
<div class="container gl-form-page">
<el-form ref="configRef" label-width="154px" :rules="configRules" :model="configForm">
<el-form-item label="活动名称:" prop="activityName" class="m-t-20">
<el-input :size="size" v-model="configForm.activityName" placeholder="请输入" maxlength="25" :disabled="disabled"></el-input>
</el-form-item>
<el-form-item label="所属渠道:" prop="merchantId" class="m-t-20">
<el-select :size="size" v-model="configForm.merchantId" placeholder="请选择" :disabled="disabled" filterable remote :remote-method="remoteMethod" v-reachbottom="onReachBottom" @focus="selectFocus" :loading="loading">
<el-option v-for="item in merchantObj.data" :key="item.confId" :label="item.confName" :value="item.confId"></el-option>
<template v-if="merchantObj.nothing">
<div class="nothing">到底了!</div>
</template>
</el-select>
</el-form-item>
<el-form-item label="活动时间:" prop="activityTime" class="m-t-20">
<el-date-picker :size="size" v-model="configForm.activityTime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="afterRangePickerOptions"></el-date-picker>
</el-form-item>
<el-form-item label="活动形式:" prop="activityType" class="m-t-20">
<el-radio-group :size="size" v-model="configForm.activityType" style="width: 400px" :disabled="disabled">
<el-radio :label="0">随机红包</el-radio>
<el-radio :label="1">九宫格</el-radio>
<el-radio :label="2">翻牌</el-radio>
<el-radio :label="3">大转盘</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="导入链接:" prop="exportUrl" class="m-t-20">
<div class="activity-link">
<div class="upload-btn">
<el-button size="small">
<i class="el-icon-plus"></i>
上传文件
</el-button>
<input type="file" style="opacity: 0" ref="file" accept="*" @change="uploadFile" />
</div>
<a href="https://img01.glsx.com.cn/weapp/resource/saas/scrm/xlsx/红包链接.xlsx" target="_blank">下载导入模板</a>
<template v-if="configForm.exportUrl">
<div class="file-info flex">
{{ fileName }}
<div class="el-icon-success"></div>
</div>
</template>
<template v-if="fileError">
<div class="file-info flex error">
<a :href="fileError" target="_blank">下载失败列表</a>
<div class="el-icon-error"></div>
</div>
</template>
</div>
</el-form-item>
</el-form>
</div>
<GLFooter>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" @click="handleConfirm">提交</el-button>
</GLFooter>
</div>
</template>
<script type='text/ecmascript-6'>
export const afterRangePickerOptions = {
disabledDate(date) {
const yesterday = new Date(new Date().setDate(new Date().getDate() - 1))
if (date < yesterday) {
return true
}
return false
}
}
import commonFun from '../common/fun.js'
import * as dayjs from 'dayjs'
import { getMerchantListMixin } from '@/mixins'
export default {
mixins: [getMerchantListMixin],
name: '',
props: {
editObj: {
type: Object,
default: () => {}
}
},
data() {
return {
id: this.$route.query.id,
afterRangePickerOptions,
disabled: false,
configForm: {
activityName: '',
merchantId: '',
activityTime: '',
activityType: 0,
exportUrl: ''
},
configRules: {
activityName: [
{
required: true,
message: '请输入活动名称',
trigger: 'blur'
}
],
merchantId: [
{
required: true,
message: '请选择所属渠道',
trigger: 'blur'
}
],
activityTime: [
{
required: true,
message: '请输入活动时间',
trigger: 'blur'
}
],
activityType: [
{
required: true
}
],
exportUrl: [
{
required: true,
message: '请导入链接'
}
]
},
fileName: '',
fileError: ''
}
},
created() {
if (this.id) this.getRedEnvelopeActivityDetail()
},
methods: {
async getRedEnvelopeActivityDetail() {
let { id } = this
try {
const { configForm } = this,
res = await this.$apis.redenvelope.getRedEnvelopeActivityDetail({ id }),
merchantId = String(res.merchantId)
this.configForm = {
...configForm,
activityName: res.activityName,
activityType: res.activityType,
merchantId,
activityTime: [dayjs(res.activityStartTime).toDate(), dayjs(res.activityEndTime).toDate()],
id
}
this.merchantObj.data = [
{
confId: merchantId,
confName: res.merchantName
}
]
this.disabled = true
this.configRules.exportUrl[0].required = false
} catch (error) {
this.$message.error(error)
}
},
handleClose() {
// this.configForm = this.$options.data.call(this).configForm
// this.disabled = false
// this.fileError = ''
// this.$refs.configRef.resetFields()
// this.merchantObj.data = []
// this.$emit('update:editObj', {})
this.$router.push('/redEnvelope/index')
},
handleConfirm() {
this.$refs.configRef.validate(async valid => {
if (valid) {
try {
const { configForm, merchantObj } = this
let params = this.$common.utils.deepClone(configForm),
targetName = params.id ? 'updateActivityRedEnvelope' : 'createActivityRedEnvelope'
params.sourceType = 1
params.activityStartTime = dayjs(params.activityTime[0]).format('YYYY-MM-DD')
params.activityEndTime = dayjs(params.activityTime[1]).format('YYYY-MM-DD')
params.merchantName = merchantObj.data.find(e => e.confId == params.merchantId).confName
delete params.activityTime
console.log(JSON.parse(JSON.stringify(params)))
const res = await this.$apis.redenvelope[targetName](params)
if (res) {
this.$message({
message: params.id ? '编辑成功' : '创建成功',
type: 'success'
})
this.handleClose()
} else throw params.id ? '编辑失败' : '创建失败'
} catch (error) {
this.$message.error(error)
}
}
})
},
async uploadFile(e) {
const { id } = this.configForm,
target = id ? 'updateCheckFile' : 'createCheckFile'
try {
const { url, name } = await commonFun.uploadFile(e, this),
params = { exportUrl: url }
if (id) params.id = id
this.$refs.file.value = ''
const res = await this.$apis.redenvelope[target](params)
if (res) {
if (res.totalCount == 0 || res.failCount > 0) {
this.fileError = res.errorUrl
this.$message.error('红包链接导入失败')
this.configForm.exportUrl = ''
return
}
this.$message({
message: '导入成功',
type: 'success'
})
this.fileError = ''
this.configForm.exportUrl = url
this.fileName = name
}
} catch (error) {
console.log(error)
if (error) this.$message.error(error)
this.$refs.file.value = ''
}
}
}
}
</script>
<style scoped lang='scss'>
.container {
padding: 32px 20px;
background: #ffffff;
border-radius: 0 4px 4px 4px;
margin: 16px;
}
.activity-link {
display: flex;
width: 500px;
.upload-btn {
position: relative;
width: 110px;
height: 32px;
.el-button--small {
width: 100%;
height: 100%;
}
input {
cursor: pointer;
position: absolute;
height: 100%;
width: 100%;
top: 0px;
left: 0px;
font-size: 0px;
}
}
a,
.error {
margin-left: 8px;
color: #5850ff;
font-size: 14px;
cursor: pointer;
}
.file-info {
margin-left: 8px;
.el-icon-success {
margin-left: 8px;
color: #67c23a;
}
.el-icon-error {
margin-left: 8px;
color: red;
}
}
}
.nothing {
font-size: 14px;
padding: 0 20px;
white-space: nowrap;
color: #606266;
height: 34px;
line-height: 34px;
text-align: center;
}
</style>