新功能

This commit is contained in:
2026-02-18 16:33:16 +08:00
parent e8089f60be
commit 765ae19fb2
47 changed files with 2881 additions and 172 deletions

View File

@ -79,7 +79,7 @@
>
<img
v-if="this.form.logo"
:src="imagePath + this.form.logo"
:src="getImageUrl(this.form.logo)"
class="list-img"
/>
<i v-if="!this.form.logo" class="el-icon-plus"></i>
@ -105,22 +105,13 @@
<el-row>
<el-col :span="24">
<el-form-item label="可预约时段" prop="dates">
<div class="add-item">
<el-button
type="danger"
size="mini"
icon="el-icon-plus"
@click="addTime()"
>添加</el-button
>
</div>
<div class="time-item" v-for="(time, index) in times">
<div class="time-item">
<el-time-select
placeholder="起始时间"
v-model="time.startTime"
v-model="timeRange.startTime"
:picker-options="{
start: '00:00',
step: '00:15',
step: '00:30',
end: '23:59',
}"
>
@ -128,27 +119,61 @@
-
<el-time-select
placeholder="结束时间"
v-model="time.endTime"
v-model="timeRange.endTime"
:picker-options="{
start: '06:00',
step: '00:15',
start: '00:00',
step: '00:30',
end: '23:59',
minTime: time.startTime,
}"
>
</el-time-select>
-
<el-input-number
style="width: 120px"
v-model="time.num"
:min="0"
v-model="timeRange.num"
:min="1"
/>
<span class="unit"></span>
</div>
<div class="form-tips">提示只需设置一个可预约时间范围例如 10:00-22:00</div>
</el-form-item>
</el-col>
</el-row>
<el-row>
<el-col :span="24">
<el-form-item label="预约费用" prop="priceRules">
<div class="add-item">
<el-button
type="primary"
size="mini"
icon="el-icon-plus"
@click="addPriceRule()"
>添加费用</el-button
>
</div>
<div class="time-item" v-for="(rule, index) in priceRules" :key="index">
<el-input-number
style="width: 140px"
v-model="rule.hours"
:min="0"
:precision="1"
controls-position="right"
/>
<span class="unit">小时</span>
<el-input-number
style="width: 140px; margin-left: 10px"
v-model="rule.price"
:min="0"
:precision="2"
controls-position="right"
/>
<span class="unit"></span>
<span
class="remove-item el-icon-remove"
@click="removeTime(index)"
@click="removePriceRule(index)"
></span>
</div>
<div class="form-tips">提示请填写起始时段可预约上限人数</div>
<div class="form-tips">提示可配置任意时长与费用 1小时/52小时/87小时/13</div>
</el-form-item>
</el-col>
</el-row>
@ -191,6 +216,7 @@
<script>
import { saveBook } from '@/api/book'
import { getToken } from '@/utils/auth'
import { getUploadFileName } from '@/utils/upload'
export default {
name: 'bookForm',
props: {
@ -229,24 +255,28 @@ export default {
}
if (this.form.serviceTimes) {
const times = this.form.serviceTimes.split(',')
let timeArr = []
for (let i = 0; i < times.length; i++) {
let am = times[i].split('-')
if (am && am.length == 3) {
let item = { startTime: am[0], endTime: am[1], num: am[2] }
timeArr.push(item)
const first = times[0].split('-')
if (first && first.length >= 2) {
this.timeRange = {
startTime: first[0],
endTime: first[1],
num: first[2] ? Number(first[2]) : 1,
}
}
if (timeArr.length > 0) {
this.times = timeArr
}
} else if (this.form.id) {
this.times = []
this.timeRange = { startTime: '', endTime: '', num: 1 }
} else {
this.times = [
{ startTime: '08:30', endTime: '12:00', num: 1 },
{ startTime: '14:00', endTime: '18:00', num: 1 },
]
this.timeRange = { startTime: '10:00', endTime: '22:00', num: 1 }
}
if (this.form.priceRules) {
try {
const parsed = JSON.parse(this.form.priceRules)
this.priceRules = Array.isArray(parsed) ? parsed : []
} catch (e) {
this.priceRules = []
}
} else {
this.priceRules = []
}
}
},
@ -255,10 +285,8 @@ export default {
return {
loading: false,
dates: [],
times: [
{ startTime: '08:30', endTime: '12:00', num: 1 },
{ startTime: '14:00', endTime: '18:00', num: 1 },
],
timeRange: { startTime: '10:00', endTime: '22:00', num: 1 },
priceRules: [],
total: 0,
// 上传地址
uploadAction: process.env.VUE_APP_SERVER_URL + 'backendApi/file/upload',
@ -282,16 +310,34 @@ export default {
}
},
methods: {
getImageUrl(path) {
if (!path) return ''
if (/^https?:\/\//i.test(path)) return path
return (this.imagePath || '') + path
},
addPriceRule() {
this.priceRules.push({ hours: 1, price: 0 })
},
removePriceRule(index) {
this.priceRules.splice(index, 1)
},
// 提交
doSubmit() {
const app = this
let param = app.form
param.times = app.times
param.times = [
{
startTime: app.timeRange.startTime,
endTime: app.timeRange.endTime,
num: app.timeRange.num,
},
]
if (app.dates && app.dates.length > 0) {
param.dates = app.dates.toString()
} else {
param.dates = ''
}
param.priceRules = app.priceRules && app.priceRules.length > 0 ? JSON.stringify(app.priceRules) : ''
saveBook(param).then((response) => {
if (response) {
app.$modal.msgSuccess('提交成功!')
@ -305,21 +351,10 @@ export default {
this.$emit('closeDialog', 'bookDialog')
},
// 上传成功回调
handleUploadSuccess(file) {
this.form.logo = file.data.fileName
},
// 添加时间段
addTime() {
this.times.push({ startTime: '', endTime: '', num: 1 })
},
removeTime(index) {
const newTimes = []
this.times.forEach(function (item, i) {
if (index !== i) {
newTimes.push(item)
}
})
this.times = newTimes
handleUploadSuccess(res) {
const fileName = getUploadFileName(res)
if (!fileName) return
this.form.logo = fileName
},
},
}