ChooseRefundOrderDialog.vue
12.3 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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!-- 选择订单 -->
<template>
<baseDialog :dialog-config="dialogConfig" :is-show.sync="visible" @handleClick="handleAddConfirm">
<d2-search ref="showSearch" class="show-search" :search-form="searchForm" :label-width="labelWidth" :form-data="showFormData">
<template slot="orderCodeKeyword">
<el-input v-model="searchForm.orderCodeKeyword" maxlength="50" placeholder="请输入订单编码" @input="handleOrderCode"></el-input>
</template>
</d2-search>
<div class="up-btns">
<el-button @click="handleSearch" size="small" type="primary">
查询
</el-button>
<el-button size="small" @click="handleReset">
重置
</el-button>
</div>
<el-table ref="orderTable" :data="tableData" class="order_table" border @select="handleChange" @select-all="handleAll">
<el-table-column type="selection" width="55" align="center" />
<el-table-column align="center" width="60px" label="序号" type="index" :index="
(index) =>
index +
((page.pageNum
? page.pageNum
: page.pageNum) -
1) * page.pageSize + 1
" />
<el-table-column label="订单编号" prop="orderCode" align="center"></el-table-column>
<el-table-column label="客户名称" prop="customerName" align="center"></el-table-column>
<el-table-column label="商品名称" prop="" align="center">
<template slot-scope="scope">
<div v-for="(item, index) in scope.row.goodsNameList" class="goods-name-item" :key="index">
<el-tooltip class="item" :content="item" placement="right">
<span>
{{ item ? (item.length > 10 ? item.substring(0, 10) + '...' : item) : '-' }}
</span>
</el-tooltip>
</div>
</template>
</el-table-column>
<el-table-column label="订单总价" align="center">
<template slot-scope="scope">
<span>{{ scope.row.totalPrice ? `¥${scope.row.totalPrice}` : '-' }}</span>
</template>
</el-table-column>
<el-table-column label="支付方式" align="center">
<template slot-scope="scope">
<span>{{ payTypeOptions[scope.row.payType] }}</span>
</template>
</el-table-column>
<el-table-column label="支付时间" prop="successDate" align="center"></el-table-column>
<el-table-column label="流量方" prop="merchantName" align="center"></el-table-column>
<el-table-column label="服务对接" prop="sellerMerchantName" align="center"></el-table-column>
<el-table-column label="流量方总金额" align="center">
<template slot-scope="scope">
<el-input class="wid_120" @input="event => { handleInput(event, scope.$index, scope.row) }" placeholder="请输入" v-model="scope.row.shopDivisionMoneyInput" v-if="isShowInput(scope.row)"></el-input>
<span v-else>{{ scope.row.shopDivisionMoney ? `¥${scope.row.shopDivisionMoney}` : '-' }}</span>
</template>
</el-table-column>
</el-table>
<el-pagination background @current-change="jumpPage" :current-page.sync="page.pageNum" :page-size="page.pageSize" layout="total, prev, pager, next" :total="tableTotal" />
<div class="selected_box" v-if="selectedData.length">
<span>已选订单:</span>
<el-tooltip class="item" :content="formatSelected(selectedData, 'all')" placement="right">
<span v-html="formatSelected(selectedData)"></span>
</el-tooltip>
<span class="totle_price">{{ selectedTotalPrice ? `共${selectedTotalPrice}元` : '--元' }}</span>
</div>
</baseDialog>
</template>
<script>
import { payTypeList, payType } from "@/common/constants"
// import * as api from "@api/finance"
import { getRefundOrderPage } from "@api/accountManage"
import { Util, deepClone } from '@/common/util'
import BigNumber from 'bignumber.js'
import { limitPrice } from '@/common/format'
export default {
name: 'ChooseRefundOrderDialog',
props: {
chooseVisible: {
type: Boolean,
default: false
},
infoForm: {
type: Object,
default: () => { }
},
chooseData: {
type: Array,
default: () => []
}
},
data() {
return {
labelWidth: '90px',
dialogConfig: {
title: '选择订单',
width: '75%'
},
tableData: [],
searchForm: {
orderCodeKeyword: '',
customerName: '',
payDate: '',
payType: '',
orderGoodsName: ''
},
showFormData: [{
label: '订单编码',
name: '',
type: 'slot',
addHtml: 'orderCodeKeyword'
}, {
label: '客户名称',
name: 'customerName',
type: 'input',
maxlength: '20',
isClear: true
}, {
label: '支付时间',
name: 'payDate',
type: 'datePicker',
isClear: true,
pickerOptions: 'rangePickerOptions'
}, {
label: '商品名称',
name: 'orderGoodsName',
type: 'input',
maxlength: '50',
isClear: true
}],
selectedData: [],
tableTotal: 0,
page: {
pageSize: 10,
pageNum: 1
},
baseData: {
searchPayTypeList: deepClone(payTypeList)
},
payTypeOptions: deepClone(payType),
selectedTotalPrice: 0
}
},
watch: {
selectedData: {
handler(newVal) {
const numberList = newVal?.map(val => { return val.shopDivisionMoneyInput }) || []
if (numberList?.length) {
this.selectedTotalPrice = numberList.reduce((preVal, curVal) => {
return `${new BigNumber(preVal || 0).plus(new BigNumber(curVal || 0)).toNumber()}`
})
}
},
deep: true
}
},
computed: {
visible: {
get() {
return this.chooseVisible
},
set(newVal) {
this.$emit('dialogClose', { flag: newVal, attrName: 'chooseVisible' })
}
}
},
mounted() {
// this.selectedData = deepClone(this.infoForm.orderCodeScope)
this.selectedData = []
this.getOrderList()
this.getOptionsList()
},
methods: {
getOptionsList() {
this.showFormData.forEach((item, index) => {
if (item.type === 'select') {
if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
const temp = {}
temp[this.showFormData[index].optionId] = ''
temp[this.showFormData[index].optionLabel] = '全部'
this.baseData[item.optionsName].unshift(temp)
}
this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
}
})
},
// 订单编号查询条件 仅输入数字
handleOrderCode(e) {
let newValue = e.replace(/[^\d.]/g, '')
this.searchForm.orderCodeKeyword = newValue
},
handleChange(selection, row) {
// 不再选中后将输入框的值重置
if (!selection?.map(val => val.orderCode)?.includes(row?.orderCode)) {
row.shopDivisionMoneyInput = row.shopDivisionMoneyInput || row.shopDivisionMoney
row.oldshopDivisionMoneyInput = row.shopDivisionMoney
}
var addOrDelete = !!selection.find(
(item) => item.orderCode === row.orderCode
)
addOrDelete
? this.selectedData.push(row)
: (this.selectedData = this.selectedData.filter(
(item) => item.orderCode !== row.orderCode
))
},
handleAll(selection) {
// 不再选中后将输入框的值重置
if (!selection?.length) {
this.tableData?.forEach(row => {
row.shopDivisionMoneyInput = row.shopDivisionMoney
row.oldshopDivisionMoneyInput = row.shopDivisionMoney
})
}
this.tableData.forEach((item) => {
var isExit = this.selectedData.findIndex(
(subItem) => subItem.orderCode === item.orderCode
)
if (selection.length && isExit === -1) {
this.selectedData.push(item)
} else if (!selection.length && isExit !== -1) {
this.selectedData.splice(isExit, 1)
}
})
},
// 处理显示已选的订单
formatSelected(data, all) {
let text = data?.map(val => { return val.orderCode })?.join(' / ')
return all ? text : text?.length > 40 ? `<span>${text.substring(0, 40)}... <span style="color: #999;">共${data.length}个订单</span></span>` : `<span>${text}</span>`
},
// 输入框输入限制
handleInput(e, index, row) {
var max = Math.abs(row.totalPrice)
var min = -max
let newValue = e
let oldValue = this.tableData[index].oldshopDivisionMoneyInput
this.$set(this.tableData[index], 'shopDivisionMoneyInput', limitPrice(newValue, oldValue, 20, 2, min, max, 'priceReg_negative_input'))
this.$set(this.tableData[index], 'oldshopDivisionMoneyInput', this.tableData[index].shopDivisionMoneyInput)
const selIndex = this.selectedData?.findIndex(val => val.orderCode == row.orderCode)
if (selIndex > -1) {
this.$set(this.selectedData[selIndex], 'shopDivisionMoneyInput', this.tableData[index].shopDivisionMoneyInput)
}
},
// 获取订单列表
getOrderList() {
const params = this.getParams()
getRefundOrderPage(params).then(res => {
res?.list?.forEach(val => {
val.shopDivisionMoneyInput = val.shopDivisionMoney
val.oldshopDivisionMoneyInput = val.shopDivisionMoney
})
this.tableData = res?.list || []
this.tableTotal = res?.total
this.$nextTick(() => {
this.recoverySelection()
})
})
},
// 翻页时设置选中状态
recoverySelection() {
var exitIds = this.selectedData.map((item) => item.orderCode)
this.tableData?.forEach((item) => {
if (exitIds.includes(item.orderCode)) {
this.$refs.orderTable && this.$refs.orderTable.toggleRowSelection(item, true)
let obj = this.selectedData?.find(val => val.orderCode == item.orderCode)
item.shopDivisionMoneyInput = obj?.shopDivisionMoneyInput || obj?.shopDivisionMoney
}
})
},
// 处理接口请求参数
getParams() {
const searchFormSearch = deepClone(this.searchForm)
if (searchFormSearch.payDate) {
searchFormSearch.paySuccessStartDate = Util.dateFormate(searchFormSearch.payDate[0], 'YYYY-MM-DD HH:mm:ss')
searchFormSearch.paySuccessEndDate = Util.dateFormate(searchFormSearch.payDate[1], 'YYYY-MM-DD') + ' 23:59:59'
delete searchFormSearch.payDate
}
return {
sceneType: this.infoForm?.sceneType,
ymerchantId: this.infoForm?.yqMerchantId, // 对账园区店
merchantId: this.infoForm?.shopMerchantId, // 对账流量方
...searchFormSearch,
pageNum: this.page.pageNum,
pageSize: this.page.pageSize,
// filterTransferAccounts: true, // 固定传参
// shopTrafficMoneyFlag: 'Y', // 固定传参
orderStatuses: [4, 6]
}
},
jumpPage(page) {
this.page.pageNum = page
this.getOrderList()
},
handleSearch() {
this.getOrderList()
},
handleReset() {
this.searchForm = {
orderCodeKeyword: '',
customerName: '',
payDate: '',
payType: '',
orderGoodsName: ''
}
this.page.pageNum = 1
this.handleSearch()
},
handleAddConfirm() {
if (!this.selectedData?.length) return this.$message.warning('请选择订单')
if (this.checkPriceEmpty(this.selectedData, 'shopDivisionMoneyInput')) {
return this.$message.warning('请完整输入流量方总金额')
}
this.$emit('chooseOrderConfirm', this.selectedData)
},
// 校验流量方金额
checkPriceEmpty(arr, propName) {
const hasEmpty = arr.some(item => {
return (item[propName] ?? '') === ''
})
if (hasEmpty) {
return true
}
return false
},
isShowInput(item) {
return this.selectedData?.map(val => { return val.orderCode })?.includes(item.orderCode)
}
}
}
</script>
<style lang="scss" scoped>
.goods-name-item {
margin-top: 10px;
}
.order_table {
margin-bottom: 10px;
}
.wid_120 {
display: inline-block;
width: 120px;
}
.selected_box {
position: absolute;
left: 30px;
bottom: 30px;
.totle_price {
margin-left: 10px;
color: #999;
}
}
</style>