|
@@ -1,5 +1,6 @@
|
|
|
<script lang="ts" setup>
|
|
|
import { ref, onMounted, watch, reactive } from 'vue';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
|
|
|
interface Props {
|
|
|
data: number[][];
|
|
@@ -25,51 +26,52 @@ const WeekMap = {
|
|
|
6: '星期日',
|
|
|
};
|
|
|
const dialogVisible = ref(false);
|
|
|
-const bid = ref(0);
|
|
|
+const bid = ref(1.00);
|
|
|
const selectedItems = ref({});
|
|
|
|
|
|
+const form = ref({
|
|
|
+ bid: 1.00, // 将 bid 添加到 form 对象中
|
|
|
+});
|
|
|
+
|
|
|
+const rules = ref({
|
|
|
+ bid: [
|
|
|
+ { required: true, message: '请输入数值小于100的数值,可精确到小数点后2位', trigger: 'blur' },
|
|
|
+ {
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (Number(value) > 100) {
|
|
|
+ return callback(new Error('请输入数值小于100的数值,可精确到小数点后2位'));
|
|
|
+ }
|
|
|
+ return callback();
|
|
|
+ },
|
|
|
+ trigger: 'blur'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+});
|
|
|
+const formRef = ref(null);
|
|
|
+
|
|
|
+//根据 props.disabled 和 info.selected 来返回一个包含样式的对象,用于设置单元格的样式
|
|
|
function getTdStyle(info: any) {
|
|
|
if (props.disabled) {
|
|
|
- return { cursor: 'not-allowed', background: '#fff' };
|
|
|
+ return {cursor: 'not-allowed', background: '#fff'};
|
|
|
}
|
|
|
- return { background: info.selected ? '#ccdbff' : '' };
|
|
|
+ return {background: info.selected ? '#ccdbff' : ''};
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
selectedItems.value[i] = [];
|
|
|
const tmp = [];
|
|
|
for (let j = 0; j < 24; j++) {
|
|
|
- tmp.push({ value: bidData.value.length === 0 ? 0 : bidData.value[i][j], selected: false });
|
|
|
+ tmp.push({value: bidData.value.length === 0 ? 0 : bidData.value[i][j], selected: false});
|
|
|
}
|
|
|
items.value.push(tmp);
|
|
|
}
|
|
|
|
|
|
-watch(
|
|
|
- () => props.data,
|
|
|
- () => {
|
|
|
- // console.log(100, 'watch', props.data)
|
|
|
- if (props.data.length === 0) {
|
|
|
- for (let i = 0; i < 7; i++) {
|
|
|
- const tmp = [];
|
|
|
- for (let j = 0; j < 24; j++) {
|
|
|
- tmp.push(0);
|
|
|
- }
|
|
|
- props.data.push(tmp);
|
|
|
- }
|
|
|
- }
|
|
|
- for (let i = 0; i < 7; i++) {
|
|
|
- for (let j = 0; j < 24; j++) {
|
|
|
- items.value[i][j].value = props.data[i][j];
|
|
|
- }
|
|
|
- }
|
|
|
- bidData.value = props.data;
|
|
|
- },
|
|
|
- { immediate: true }
|
|
|
-);
|
|
|
-
|
|
|
+//在单元格上按下鼠标时触发的函数
|
|
|
function handleMouseDown(rowIndex: number, colIndex: number, event: any) {
|
|
|
if (props.disabled) return;
|
|
|
if (event.button === 0) {
|
|
|
+ clearCellBackgroundColor();
|
|
|
+
|
|
|
mouseDown.value = true;
|
|
|
startRowIndex.value = rowIndex;
|
|
|
startColIndex.value = colIndex;
|
|
@@ -88,13 +90,18 @@ function handleMouseUp(event: any) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//在单元格上移动鼠标时触发的函数,用于选择多个单元格。
|
|
|
function handleMouseMove(rowIndex: number, colIndex: number) {
|
|
|
if (props.disabled) return;
|
|
|
+ //if (info.selected) {
|
|
|
+ // info.selected = false;
|
|
|
+ //}
|
|
|
if (mouseDown.value) {
|
|
|
selectCell(rowIndex, colIndex);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//选择多个单元格
|
|
|
function selectCell(rowIndex: number, colIndex: number) {
|
|
|
if (props.disabled) return;
|
|
|
const rowStart = Math.min(startRowIndex.value, rowIndex);
|
|
@@ -110,12 +117,12 @@ function selectCell(rowIndex: number, colIndex: number) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//提交出价,将选中的单元格的值设置为 bid,并清除选中状态和单元格背景色。
|
|
|
function submitBid() {
|
|
|
- // console.log(151, 'submitBid', bidData)
|
|
|
for (const row of Object.keys(selectedItems.value)) {
|
|
|
for (const col of selectedItems.value[row]) {
|
|
|
- items.value[row][col].value = bid.value;
|
|
|
- bidData.value[row][col] = bid.value;
|
|
|
+ items.value[row][col].value = Number(form.value.bid);
|
|
|
+ bidData.value[row][col] = Number(form.value.bid);
|
|
|
}
|
|
|
}
|
|
|
clearSelectedItems();
|
|
@@ -123,12 +130,29 @@ function submitBid() {
|
|
|
dialogVisible.value = false;
|
|
|
}
|
|
|
|
|
|
+const submitForm = async (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return;
|
|
|
+ await formEl.validate((valid, fields) => {
|
|
|
+ if (valid) {
|
|
|
+ submitBid();
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+const resetForm = (formEl: FormInstance | undefined) => {
|
|
|
+ if (!formEl) return
|
|
|
+ cancelBid()
|
|
|
+ formEl.resetFields()
|
|
|
+}
|
|
|
+
|
|
|
+//取消出价
|
|
|
function cancelBid() {
|
|
|
clearSelectedItems();
|
|
|
clearCellBackgroundColor();
|
|
|
dialogVisible.value = false;
|
|
|
}
|
|
|
|
|
|
+//清除所有单元格的背景色。
|
|
|
function clearCellBackgroundColor() {
|
|
|
for (const hoursList of items.value) {
|
|
|
for (const info of hoursList) {
|
|
@@ -143,6 +167,7 @@ function clearSelectedItems() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//重置所有单元格的出价为 1,并清除选中状态。
|
|
|
function resetAllBid() {
|
|
|
for (let i = 0; i < 7; i++) {
|
|
|
for (let j = 0; j < 24; j++) {
|
|
@@ -158,56 +183,124 @@ function closeDialog(done: Function) {
|
|
|
cancelBid();
|
|
|
done();
|
|
|
}
|
|
|
+
|
|
|
+const applyBid = (timeRangeValue: string, scheduleValue: string, bidValue: number) => {
|
|
|
+ const timeRangeMap = {
|
|
|
+ 'Option1': {start: 0, end: 23},
|
|
|
+ 'Option2': {start: 0, end: 6},
|
|
|
+ 'Option3': {start: 7, end: 11},
|
|
|
+ 'Option4': {start: 9, end: 16},
|
|
|
+ 'Option5': {start: 12, end: 16},
|
|
|
+ 'Option6': {start: 17, end: 20},
|
|
|
+ 'Option7': {start: 21, end: 23},
|
|
|
+ };
|
|
|
+
|
|
|
+ const scheduleMap = {
|
|
|
+ 'Option1': [0, 1, 2, 3, 4, 5, 6],
|
|
|
+ 'Option2': [0, 1, 2, 3, 4],
|
|
|
+ 'Option3': [5, 6],
|
|
|
+ };
|
|
|
+
|
|
|
+ const {start, end} = timeRangeMap[timeRangeValue];
|
|
|
+ const days = scheduleMap[scheduleValue];
|
|
|
+
|
|
|
+ days.forEach(day => {
|
|
|
+ for (let hour = start; hour <= end; hour++) {
|
|
|
+ items.value[day][hour].value = bidValue;
|
|
|
+ items.value[day][hour].selected = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+};
|
|
|
+
|
|
|
+defineExpose({
|
|
|
+ applyBid,
|
|
|
+});
|
|
|
+
|
|
|
+watch(
|
|
|
+ () => props.data,
|
|
|
+ () => {
|
|
|
+ if (props.data.length === 0) {
|
|
|
+ for (let i = 0; i < 7; i++) {
|
|
|
+ const tmp = [];
|
|
|
+ for (let j = 0; j < 24; j++) {
|
|
|
+ tmp.push(0);
|
|
|
+ }
|
|
|
+ props.data.push(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (let i = 0; i < 7; i++) {
|
|
|
+ for (let j = 0; j < 24; j++) {
|
|
|
+ items.value[i][j].value = props.data[i][j];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ bidData.value = props.data;
|
|
|
+ console.log('watch', props.data);
|
|
|
+ },
|
|
|
+ {immediate: true}
|
|
|
+);
|
|
|
+
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="calendar">
|
|
|
<table class="calendar-table calendar-table-hour">
|
|
|
<thead class="calendar-head">
|
|
|
- <tr>
|
|
|
- <th rowspan="8" class="week-td">星期 / 时间</th>
|
|
|
- <th colspan="12">00:00 - 12:00</th>
|
|
|
- <th colspan="12">12:00 - 24:00</th>
|
|
|
- <th colspan="4" rowspan="2" class="week-td" style="display: none">小时</th>
|
|
|
- </tr>
|
|
|
- <tr>
|
|
|
- <th colspan="1" v-for="(_, i) in 24" :key="i">{{ i }}</th>
|
|
|
- </tr>
|
|
|
+ <tr>
|
|
|
+ <th class="week-td" rowspan="8">星期 / 时间</th>
|
|
|
+ <th colspan="12">00:00 - 12:00</th>
|
|
|
+ <th colspan="12">12:00 - 24:00</th>
|
|
|
+ <th class="week-td" colspan="4" rowspan="2" style="display: none">小时</th>
|
|
|
+ </tr>
|
|
|
+ <tr>
|
|
|
+ <th v-for="(_, i) in 24" :key="i" colspan="1">{{ i }}</th>
|
|
|
+ </tr>
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
- <template v-for="(hoursList, week) in items">
|
|
|
- <tr>
|
|
|
- <th>{{ WeekMap[week] }}</th>
|
|
|
- <td
|
|
|
+ <template v-for="(hoursList, week) in items">
|
|
|
+ <tr>
|
|
|
+ <th>{{ WeekMap[week] }}</th>
|
|
|
+ <td
|
|
|
v-for="(info, hour) in hoursList"
|
|
|
:key="hour"
|
|
|
+ :style="getTdStyle(info)"
|
|
|
@mousedown="handleMouseDown(week, hour, $event)"
|
|
|
@mouseover="handleMouseMove(week, hour)"
|
|
|
- @mouseup="handleMouseUp"
|
|
|
- :style="getTdStyle(info)">
|
|
|
- <span class="cell-text"> {{ info.value ? info.value : '' }} </span>
|
|
|
- </td>
|
|
|
- </tr>
|
|
|
- </template>
|
|
|
- <tr>
|
|
|
- <th colspan="28" class="clear-bar">
|
|
|
- <span class="middle">可拖动鼠标选择时间段</span>
|
|
|
- <el-button class="hover-link fr" link @click="resetAllBid" :disabled="disabled">全部重置</el-button>
|
|
|
- </th>
|
|
|
+ @mouseup="handleMouseUp">
|
|
|
+ <span class="cell-text"> {{
|
|
|
+ info.value || info.value == 0 ? Number(info.value).toFixed(2) : '0.00'
|
|
|
+ }} </span>
|
|
|
+ </td>
|
|
|
</tr>
|
|
|
+ </template>
|
|
|
+ <tr>
|
|
|
+ <th class="clear-bar" colspan="28">
|
|
|
+ <span class="middle">可拖动鼠标选择时间段</span>
|
|
|
+ <el-button :disabled="disabled" class="hover-link fr" link @click="resetAllBid">全部重置</el-button>
|
|
|
+ </th>
|
|
|
+ </tr>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
-
|
|
|
- <el-dialog v-model="dialogVisible" title="修改出价系数" width="30%" :close-on-click-modal="false" :before-close="closeDialog">
|
|
|
- <el-input-number v-model="bid" :min="0" :max="100" :step="0.1" controls-position="right" />
|
|
|
- <template #footer>
|
|
|
+ </div>
|
|
|
+ <el-dialog v-model="dialogVisible" :before-close="closeDialog" :close-on-click-modal="false" title="修改出价系数"
|
|
|
+ width="30%">
|
|
|
+ <el-form ref="formRef" :model="form" :rules="rules" style="display: inline-block;">
|
|
|
+ <el-form-item label="Bid" prop="bid" label-width="80px">
|
|
|
+ <el-input
|
|
|
+ v-model="form.bid"
|
|
|
+ clearable
|
|
|
+ oninput="value=value.replace(/[^\d.]/g, '').replace(/\.{2,}/g, '.').replace('.', '$#$').replace(/\./g, '').replace('$#$', '.').replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3').replace(/^\./g, '')"
|
|
|
+ placeholder="1.0"
|
|
|
+ style="width: 150px;"
|
|
|
+ ></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <template #footer>
|
|
|
<span class="dialog-footer">
|
|
|
- <el-button @click="cancelBid">取消</el-button>
|
|
|
- <el-button type="primary" @click="submitBid">确认</el-button>
|
|
|
+ <el-button @click="resetForm(formRef)">取消</el-button>
|
|
|
+ <el-button type="primary" @click="submitForm(formRef)">确认</el-button>
|
|
|
</span>
|
|
|
- </template>
|
|
|
- </el-dialog>
|
|
|
- </div>
|
|
|
+ </template>
|
|
|
+ </el-dialog>
|
|
|
</template>
|
|
|
|
|
|
<style lang="scss" scoped>
|