抢单历史记录
This commit is contained in:
@@ -1,29 +1,513 @@
|
||||
<template>
|
||||
<div class="app-container">
|
||||
<el-card shadow="never">
|
||||
<div class="placeholder-title">抢单记录</div>
|
||||
<div class="placeholder-desc">
|
||||
页面入口已创建,可在此按业务需求补充抢单记录查询与展示功能。
|
||||
</div>
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :model="queryParams" :inline="true" label-width="120px">
|
||||
<el-form-item label="租户ID">
|
||||
<el-select
|
||||
v-model="queryParams.tenantId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择租户"
|
||||
style="width: 220px"
|
||||
:loading="tenantLoading"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in tenantOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="租户名称">
|
||||
<el-input v-model="queryParams.tenantName" clearable placeholder="租户名称" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="登录账号">
|
||||
<el-input v-model="queryParams.loginAccount" clearable placeholder="登录账号" style="width: 160px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="昵称">
|
||||
<el-input v-model="queryParams.nickname" clearable placeholder="昵称" style="width: 140px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="创建时间">
|
||||
<el-date-picker
|
||||
v-model="createTimeRange"
|
||||
type="datetimerange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始"
|
||||
end-placeholder="结束"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
:default-time="['00:00:00', '23:59:59']"
|
||||
style="width: 360px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="最后抢单时间">
|
||||
<el-date-picker
|
||||
v-model="lastRushBuyTimeRange"
|
||||
type="datetimerange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始"
|
||||
end-placeholder="结束"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
:default-time="['00:00:00', '23:59:59']"
|
||||
style="width: 360px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
|
||||
<el-button icon="el-icon-delete" @click="resetQuery">清空</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<el-card class="action-container" shadow="never">
|
||||
<el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
|
||||
</el-card>
|
||||
|
||||
<el-card class="table-container" shadow="never">
|
||||
<el-table v-loading="loading" :data="list" style="width: 100%">
|
||||
<el-table-column label="租户ID" prop="tenantId" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column label="租户名称" prop="tenantName" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="登录账号" prop="loginAccount" min-width="120" show-overflow-tooltip />
|
||||
<el-table-column label="昵称" prop="nickname" min-width="100" show-overflow-tooltip />
|
||||
<el-table-column label="成功抢单总金额" prop="maxGrabAmount" width="120" align="center" />
|
||||
<el-table-column label="抢单总次数" prop="maxGrabCount" width="100" align="center" />
|
||||
<el-table-column label="抢单失败次数" prop="rushBuyFailCount" width="110" align="center" />
|
||||
<el-table-column label="抢单结果" prop="rushBuyResult" min-width="160" show-overflow-tooltip />
|
||||
<el-table-column label="最后抢单时间" prop="lastRushBuyTime" min-width="160">
|
||||
<template slot-scope="scope">
|
||||
{{ formatDateTime(scope.row.lastRushBuyTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" prop="createTime" min-width="160">
|
||||
<template slot-scope="scope">
|
||||
{{ formatDateTime(scope.row.createTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="修改时间" prop="updateTime" min-width="160">
|
||||
<template slot-scope="scope">
|
||||
{{ formatDateTime(scope.row.updateTime) }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" fixed="right" width="140">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="text" @click="handleEdit(scope.row)">编辑</el-button>
|
||||
<el-button type="text" style="color:#F56C6C;" @click="handleDelete(scope.row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<el-pagination
|
||||
:current-page="queryParams.current"
|
||||
:page-size="queryParams.size"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="720px" top="5vh" @close="resetForm">
|
||||
<el-form ref="dataForm" :model="form" :rules="formRules" label-width="130px">
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="租户" prop="tenantId">
|
||||
<el-select
|
||||
v-model="form.tenantId"
|
||||
filterable
|
||||
clearable
|
||||
placeholder="请选择租户"
|
||||
style="width: 100%"
|
||||
:loading="tenantLoading"
|
||||
@change="handleTenantChange"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in tenantOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="租户名称" prop="tenantName">
|
||||
<el-input v-model="form.tenantName" placeholder="租户名称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="登录账号" prop="loginAccount">
|
||||
<el-input v-model="form.loginAccount" placeholder="登录账号" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="登录密码" prop="loginPassword">
|
||||
<el-input
|
||||
v-model="form.loginPassword"
|
||||
type="password"
|
||||
show-password
|
||||
:placeholder="isEdit ? '留空则不修改' : '登录密码'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="昵称" prop="nickname">
|
||||
<el-input v-model="form.nickname" placeholder="昵称" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="最后抢单时间" prop="lastRushBuyTime">
|
||||
<el-date-picker
|
||||
v-model="form.lastRushBuyTime"
|
||||
type="datetime"
|
||||
placeholder="选择时间"
|
||||
value-format="yyyy-MM-dd HH:mm:ss"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="16">
|
||||
<el-col :span="8">
|
||||
<el-form-item label="成功抢单总金额" prop="maxGrabAmount">
|
||||
<el-input-number
|
||||
v-model="form.maxGrabAmount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="抢单总次数" prop="maxGrabCount">
|
||||
<el-input-number
|
||||
v-model="form.maxGrabCount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="8">
|
||||
<el-form-item label="抢单失败次数" prop="rushBuyFailCount">
|
||||
<el-input-number
|
||||
v-model="form.rushBuyFailCount"
|
||||
:min="0"
|
||||
:step="1"
|
||||
controls-position="right"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-form-item label="抢单结果" prop="rushBuyResult">
|
||||
<el-input
|
||||
v-model="form.rushBuyResult"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="抢单结果"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">确定</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
addLbBuyAccountHistory,
|
||||
deleteLbBuyAccountHistory,
|
||||
getLbBuyAccountHistoryList,
|
||||
updateLbBuyAccountHistory
|
||||
} from '@/api/lb-buy-account-history'
|
||||
import { getAllTenantList } from '@/api/tenant'
|
||||
import { getBusinessHeaders } from '@/utils/business-headers'
|
||||
|
||||
const DEFAULT_FORM = () => ({
|
||||
id: '',
|
||||
tenantId: '',
|
||||
tenantName: '',
|
||||
loginAccount: '',
|
||||
loginPassword: '',
|
||||
nickname: '',
|
||||
maxGrabAmount: undefined,
|
||||
maxGrabCount: undefined,
|
||||
rushBuyFailCount: undefined,
|
||||
rushBuyResult: '',
|
||||
lastRushBuyTime: ''
|
||||
})
|
||||
|
||||
export default {
|
||||
name: 'LbRushOrderRecord'
|
||||
name: 'LbRushOrderRecord',
|
||||
data() {
|
||||
const validatePassword = (rule, value, callback) => {
|
||||
if (!this.isEdit && !value) {
|
||||
callback(new Error('请输入登录密码'))
|
||||
return
|
||||
}
|
||||
callback()
|
||||
}
|
||||
return {
|
||||
loading: false,
|
||||
submitLoading: false,
|
||||
tenantLoading: false,
|
||||
list: [],
|
||||
total: 0,
|
||||
tenantOptions: [],
|
||||
createTimeRange: [],
|
||||
lastRushBuyTimeRange: [],
|
||||
dialogVisible: false,
|
||||
dialogTitle: '',
|
||||
isEdit: false,
|
||||
queryParams: {
|
||||
current: 1,
|
||||
size: 10,
|
||||
tenantId: '',
|
||||
tenantName: '',
|
||||
loginAccount: '',
|
||||
nickname: ''
|
||||
},
|
||||
form: DEFAULT_FORM(),
|
||||
formRules: {
|
||||
tenantId: [{ required: true, message: '请选择租户', trigger: 'change' }],
|
||||
loginAccount: [{ required: true, message: '请输入登录账号', trigger: 'blur' }],
|
||||
loginPassword: [{ validator: validatePassword, trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.getTenantOptions()
|
||||
this.initDefaultTenantFilter()
|
||||
this.fetchList()
|
||||
},
|
||||
methods: {
|
||||
getTenantIdFromBusinessHeaders() {
|
||||
const headers = getBusinessHeaders()
|
||||
const value = headers && headers['X-Tenant-Id']
|
||||
return value ? String(value).trim() : ''
|
||||
},
|
||||
initDefaultTenantFilter() {
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (tenantId) this.queryParams.tenantId = tenantId
|
||||
},
|
||||
getTenantOptions() {
|
||||
this.tenantLoading = true
|
||||
getAllTenantList()
|
||||
.then((response) => {
|
||||
if (response && (response.code === 20000 || response.code === 200)) {
|
||||
const tenantList = Array.isArray(response.data) ? response.data : (response.data?.data || [])
|
||||
this.tenantOptions = tenantList.map((item) => ({
|
||||
value: item.id,
|
||||
label: item.tenantName ? `${item.tenantName} (${item.tenantCode || '-'})` : (item.tenantCode || item.id),
|
||||
tenantName: item.tenantName || ''
|
||||
}))
|
||||
} else {
|
||||
this.tenantOptions = []
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.tenantOptions = []
|
||||
})
|
||||
.finally(() => {
|
||||
this.tenantLoading = false
|
||||
})
|
||||
},
|
||||
handleTenantChange(tenantId) {
|
||||
const option = this.tenantOptions.find((item) => item.value === tenantId)
|
||||
if (option && option.tenantName) {
|
||||
this.form.tenantName = option.tenantName
|
||||
}
|
||||
},
|
||||
fetchList() {
|
||||
this.loading = true
|
||||
getLbBuyAccountHistoryList(this.buildListParams())
|
||||
.then((res) => {
|
||||
if (res && (res.code === 20000 || res.code === 200 || res.success === true)) {
|
||||
this.list = Array.isArray(res.data) ? res.data : []
|
||||
this.total = typeof res.total === 'number'
|
||||
? res.total
|
||||
: (res.page && typeof res.page.total === 'number' ? res.page.total : this.list.length)
|
||||
} else {
|
||||
this.list = []
|
||||
this.total = 0
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.list = []
|
||||
this.total = 0
|
||||
})
|
||||
.finally(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
buildListParams() {
|
||||
const params = {
|
||||
current: this.queryParams.current,
|
||||
size: this.queryParams.size,
|
||||
tenantId: this.queryParams.tenantId || undefined,
|
||||
tenantName: this.queryParams.tenantName || undefined,
|
||||
loginAccount: this.queryParams.loginAccount || undefined,
|
||||
nickname: this.queryParams.nickname || undefined
|
||||
}
|
||||
const createRange = this.createTimeRange || []
|
||||
if (createRange[0]) params.createTimeStart = createRange[0]
|
||||
if (createRange[1]) params.createTimeEnd = createRange[1]
|
||||
const rushRange = this.lastRushBuyTimeRange || []
|
||||
if (rushRange[0]) params.lastRushBuyTimeStart = rushRange[0]
|
||||
if (rushRange[1]) params.lastRushBuyTimeEnd = rushRange[1]
|
||||
Object.keys(params).forEach((key) => {
|
||||
if (params[key] === undefined || params[key] === '') delete params[key]
|
||||
})
|
||||
return params
|
||||
},
|
||||
handleQuery() {
|
||||
this.queryParams.current = 1
|
||||
this.fetchList()
|
||||
},
|
||||
resetQuery() {
|
||||
this.queryParams = {
|
||||
current: 1,
|
||||
size: 10,
|
||||
tenantId: '',
|
||||
tenantName: '',
|
||||
loginAccount: '',
|
||||
nickname: ''
|
||||
}
|
||||
this.createTimeRange = []
|
||||
this.lastRushBuyTimeRange = []
|
||||
this.initDefaultTenantFilter()
|
||||
this.fetchList()
|
||||
},
|
||||
handleSizeChange(size) {
|
||||
this.queryParams.size = size
|
||||
this.fetchList()
|
||||
},
|
||||
handleCurrentChange(current) {
|
||||
this.queryParams.current = current
|
||||
this.fetchList()
|
||||
},
|
||||
handleAdd() {
|
||||
this.dialogTitle = '新增抢单记录'
|
||||
this.isEdit = false
|
||||
this.resetFormData()
|
||||
const tenantId = this.getTenantIdFromBusinessHeaders()
|
||||
if (tenantId) {
|
||||
this.form.tenantId = tenantId
|
||||
this.handleTenantChange(tenantId)
|
||||
}
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
|
||||
})
|
||||
},
|
||||
handleEdit(row) {
|
||||
this.dialogTitle = '编辑抢单记录'
|
||||
this.isEdit = true
|
||||
const lastRushBuyTime = this.formatDateTime(row.lastRushBuyTime)
|
||||
this.form = {
|
||||
...DEFAULT_FORM(),
|
||||
...this.pickFormFields(row),
|
||||
id: row.id,
|
||||
loginPassword: '',
|
||||
lastRushBuyTime: lastRushBuyTime === '-' ? '' : lastRushBuyTime
|
||||
}
|
||||
this.dialogVisible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs.dataForm && this.$refs.dataForm.clearValidate()
|
||||
})
|
||||
},
|
||||
pickFormFields(row) {
|
||||
const fields = DEFAULT_FORM()
|
||||
Object.keys(fields).forEach((key) => {
|
||||
if (key === 'id' || key === 'loginPassword' || key === 'lastRushBuyTime') return
|
||||
if (row[key] !== undefined && row[key] !== null) {
|
||||
fields[key] = row[key]
|
||||
}
|
||||
})
|
||||
return fields
|
||||
},
|
||||
handleDelete(row) {
|
||||
this.$confirm('确定删除该抢单记录吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => deleteLbBuyAccountHistory(row.id))
|
||||
.then((res) => {
|
||||
this.$message.success((res && res.message) || '删除成功')
|
||||
this.fetchList()
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
handleSubmit() {
|
||||
this.$refs.dataForm.validate((valid) => {
|
||||
if (!valid) return
|
||||
const payload = this.buildPayload()
|
||||
this.submitLoading = true
|
||||
const req = this.isEdit ? updateLbBuyAccountHistory(payload) : addLbBuyAccountHistory(payload)
|
||||
req.then((res) => {
|
||||
this.$message.success((res && res.message) || (this.isEdit ? '更新成功' : '新增成功'))
|
||||
this.dialogVisible = false
|
||||
this.fetchList()
|
||||
}).finally(() => {
|
||||
this.submitLoading = false
|
||||
})
|
||||
})
|
||||
},
|
||||
buildPayload() {
|
||||
const payload = { ...this.form }
|
||||
if (this.isEdit) {
|
||||
if (!payload.loginPassword) delete payload.loginPassword
|
||||
}
|
||||
Object.keys(payload).forEach((key) => {
|
||||
if (payload[key] === undefined || payload[key] === '') delete payload[key]
|
||||
})
|
||||
return payload
|
||||
},
|
||||
resetForm() {
|
||||
this.$refs.dataForm && this.$refs.dataForm.resetFields()
|
||||
this.resetFormData()
|
||||
},
|
||||
resetFormData() {
|
||||
this.form = DEFAULT_FORM()
|
||||
},
|
||||
formatDateTime(dateTime) {
|
||||
if (!dateTime) return '-'
|
||||
const date = new Date(String(dateTime).replace('T', ' '))
|
||||
if (Number.isNaN(date.getTime())) return String(dateTime)
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.placeholder-title {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.app-container {
|
||||
.filter-container,
|
||||
.action-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.placeholder-desc {
|
||||
color: #606266;
|
||||
line-height: 22px;
|
||||
.table-container {
|
||||
.el-pagination {
|
||||
margin-top: 20px;
|
||||
text-align: right;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user