addDialog.vue
10.5 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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<!-- 新增提现弹窗 -->
<template>
<baseDialog :config="config" :dialog-config="dialogConfig" :is-show.sync="visible" class="accountDailog"
@handleClick="handleCashConfirm">
<el-form ref="formRef" :model="infoForm" :rules="cashRules" label-width="120px">
<el-form-item label="门店名称:" prop="merchantId">
<el-select v-model="infoForm.merchant" value-key="merchantId" filterable style="width: 310px"
placeholder="请选择门店">
<el-option v-for="(item, index) in baseData.merchantList" :key="index" :label="item.merchantName"
:value="item" />
</el-select>
</el-form-item>
<el-form-item label="日期:" prop="month">
<el-date-picker style="width: 310px" v-model="infoForm.month" type="month" :picker-options="monthPickerOptions"
placeholder="选择月份">
</el-date-picker>
</el-form-item>
<el-form-item label="摘要:" prop="summary">
<el-input v-model="infoForm.summary" placeholder="请输入摘要" style="width: 310px" maxLength="200" />
</el-form-item>
<el-form-item label="收款金额:" prop="receiveAmount">
<el-input v-model="infoForm.receiveAmount" disabled style="width: 310px" />
</el-form-item>
<el-form-item label="流量费:" prop="trafficFee">
<el-input v-model="infoForm.trafficFee" placeholder="请输入流量费" style="width: 310px" @input="handleUpgradeNum" />
</el-form-item>
<el-form-item label="我司收益:" prop="ourIncome">
<el-input v-model="infoForm.ourIncome" disabled style="width: 310px" />
</el-form-item>
<el-form-item label="可抵收益日期:" prop="deductibleMonth">
<el-date-picker style="width: 310px" v-model="infoForm.deductibleMonth" type="month"
:picker-options="deductibleMonthPickerOptions" placeholder="选择月份">
</el-date-picker>
</el-form-item>
<el-form-item label="备注:" prop="remark">
<el-input v-model="infoForm.remark" placeholder="请输入备注" style="width: 310px" maxLength="200"></el-input>
</el-form-item>
</el-form>
<!-- </d2-dialog> -->
</baseDialog>
</template>
<script>
import { deepClone } from "@/common/util"
import { tradeTypeList } from "@/common/constant/vehicle"
import { advancePaymentMerchantPage, trafficAdd, getMerchantMonthPayInfo } from "@api/prepaymentManage"
import dayjs from "dayjs"
import { limitPrice } from "@/common/format"
export default {
// name: 'AddDialog',
data() {
return {
dialogConfig: {
title: "新增流量方/我司收益",
width: "600px"
},
config: {
showClose: true,
appendToBody: true, // 是否将自身插入至 body 元素,有嵌套的弹窗时一定要设置
isShowFooter: true,
cancel_name: "取 消",
confirm_name: "确 定"
},
infoForm: {
merchant: null,
merchantId: "",
month: "",
summary: "",
trafficFee: "",
deductibleMonth: "",
remark: "",
ourIncome: "",
receiveAmount: ""
},
oldVal: {
trafficFee: ""
},
cashRules: {
merchantId: [
{ required: true, message: "请选择门店", trigger: "change" }
],
month: [
{
required: true,
message: "请选择月份",
trigger: "change"
},
{ validator: (rule, value, callback) => this.validateMonth(rule, value, callback), trigger: "change" }
],
summary: [
{ required: true, message: "请输入摘要", trigger: "change" }
],
trafficFee: [
{
required: true,
message: "请输入流量费,支持输入0~99999999的数字,支持小数点后2位",
trigger: "change"
}
],
deductibleMonth: [
{ validator: (rule, value, callback) => this.validateDeductibleMonth(rule, value, callback), trigger: "change" }
]
},
// 基本数据
baseData: {
tradeTypeList: tradeTypeList,
// administratorsList: [],
merchantList: []
},
balance: "",
// totalAmountDisabled: true
}
},
props: {
addVisible: {
type: Boolean,
default: false
}
},
computed: {
visible: {
get() {
return this.addVisible
},
set(newVal) {
this.$emit("update:addVisible", newVal)
}
},
monthPickerOptions() {
return {
disabledDate: (date) => {
const a = dayjs(date).startOf('month').valueOf()
const now = dayjs().startOf('month').valueOf()
const start = this.infoForm.merchant && this.infoForm.merchant.startDate
const min = start ? dayjs(start).startOf('month').valueOf() : -Infinity
return a < min || a > now
}
}
},
deductibleMonthPickerOptions() {
return {
disabledDate: (date) => {
const m = this.infoForm.month
if (!m) return false
const a = dayjs(date).startOf('month').valueOf()
const b = dayjs(m).startOf('month').valueOf()
return a < b
}
}
}
},
watch: {
'infoForm.merchant'(val) {
this.infoForm.merchantId = val ? val.merchantId : ''
this.infoForm.merchantName = val ? val.merchantName : ''
this.infoForm.month = ''
}
,
'infoForm.merchantId'(val) {
this.triggerMonthFetch()
},
'infoForm.month'(val) {
this.triggerMonthFetch()
}
},
mounted() {
this.getMerchantList()
},
methods: {
validateMonth(rule, value, callback) {
if (value) {
const a = dayjs(value).startOf('month').valueOf()
const now = dayjs().startOf('month').valueOf()
if (a > now) return callback(new Error('不能选择未来月份'))
const start = this.infoForm.merchant && this.infoForm.merchant.startDate
if (start) {
const min = dayjs(start).startOf('month').valueOf()
if (a < min) return callback(new Error('不可早于门店开始日期'))
}
}
callback()
},
// validateDeductibleMonth(rule, value, callback) {
// const m = this.infoForm.month
// if (m && value) {
// const a = dayjs(value).startOf('month').valueOf()
// const b = dayjs(m).startOf('month').valueOf()
// if (a < b) return callback(new Error('不可早于上方选择的月份'))
// }
// callback()
// },
triggerMonthFetch() {
if (this.infoForm.merchantId && this.infoForm.month) {
// this.getMerchantMonthPayInfo()
const params = {
merchantId: this.infoForm.merchantId,
month: dayjs(this.infoForm.month).format("YYYY-MM")
}
// const params = deepClone(this.infoForm)
// if (params.month) {
// params.month = dayjs(params.month).format("YYYY-MM")
// }
getMerchantMonthPayInfo(params).then(res => {
// this.monthPayInfo = res.data
console.log(res, 'res')
this.infoForm.receiveAmount = res?.receiveAmount ?? ''
// 收益等于 收款金额-流量费用 如果两个值有一个为空,那么收益为空
if (this.canCompute(this.infoForm.receiveAmount) && this.canCompute(this.infoForm.trafficFee)) {
this.infoForm.ourIncome = this.calcIncome(this.infoForm.receiveAmount, this.infoForm.trafficFee)
} else {
this.infoForm.ourIncome = ''
}
// this.infoForm.ourIncome = res.data.ourIncome
})
}
},
getMerchantMonthPayInfo() {
this.$emit('fetchMerchantMonthPayInfo', { merchantId: this.infoForm.merchantId, month: this.infoForm.month })
},
validateDeductibleMonth(rule, value, callback) {
const m = this.infoForm.month
if (m && value) {
const a = dayjs(value).startOf('month').valueOf()
const b = dayjs(m).startOf('month').valueOf()
if (a < b) return callback(new Error('不可早于上方日期的月份'))
}
callback()
},
canCompute(val) {
const n = Number(val)
return typeof val !== 'undefined' && val !== '' && isFinite(n)
},
calcIncome(received, fee) {
const x = Number(received)
const y = Number(fee)
const m = 100
const res = (Math.round(x * m) - Math.round(y * m)) / m
return Number(res.toFixed(2))
},
getMerchantList() {
var params = {}
params.currentPage = 1
params.pageSize = 100
advancePaymentMerchantPage(params).then((res) => {
this.baseData.merchantList = res.list
})
},
handleUpgradeNum(newVal) {
var maxVal = 999999999
if (this.balance) {
maxVal = this.balance
}
// else {
// newVal = ''
// }
this.infoForm.trafficFee = limitPrice(
newVal,
this.oldVal.trafficFee,
13,
2,
-999999999,
maxVal,
'priceReg_negative_input'
)
this.oldVal.trafficFee = this.infoForm.trafficFee
if (this.canCompute(this.infoForm.receiveAmount) && this.canCompute(this.infoForm.trafficFee)) {
this.infoForm.ourIncome = this.calcIncome(this.infoForm.receiveAmount, this.infoForm.trafficFee)
} else {
this.infoForm.ourIncome = ''
}
},
handleCashConfirm() {
this.$refs.formRef.validate((valid) => {
if (valid) {
var params = deepClone(this.infoForm)
// params.
if (params.month) {
params.month = dayjs(params.month).format("YYYY-MM")
}
if (params.deductibleMonth) {
params.deductibleMonth = dayjs(params.deductibleMonth).format("YYYY-MM")
}
// params.remark = this.infoForm.remark
// params.smsCode = this.infoForm.smsCode
// params.phone = this.infoForm.administrators
// params.merchantId = this.infoForm.merchantId
// if (this.infoForm.totalAmount > 0) {
// params.totalAmount = this.infoForm.totalAmount
// } else {
// this.$message({
// message: "提现金额必须大于0",
// type: "warning",
// showClose: true
// })
// return
// }
console.log(params)
trafficAdd(params).then((res) => {
this.notice.okTips("新增成功")
this.visible = false
this.$emit("addDialogSuccess")
})
}
})
},
}
}
</script>
<style scoped>
p {
margin: 0 0;
}
.cash-btn {
margin-left: 20px;
}
</style>