+
下架
-
-
-
+
+
+
+
+ 一键下架
+
+
+
@@ -67,44 +75,43 @@ const {
import Selecter from '../../components/selecter'
import {
- ref
+ ref,
+ reactive,
+ computed,
+ watch
} from 'vue';
import {
- carList, carAddDownTime, carDeleteDownTime
+ carList, carAddDownTime, carDeleteDownTime, carBatchDownTimes
} from '../../api/cars';
import {
useSystemInfo,
useUserInfo
} from '@/store'
import {
- onShow
+ onShow,
+ onLoad
} from '@dcloudio/uni-app';
-import {
- completeTime,
- addHours
-} from '../../utils/date.js'
const systemInfo = useSystemInfo()
const userInfo = useUserInfo()
const carListVal = ref('')
-
const carListOptions = ref([])
const dateOptions = ref([])
const carListAll = ref([])
-
const dateShow = ref(false)
-const min = new Date(2020, 0, 1)
-const max = new Date(2025, 10, 1)
const dateVal = ref([])
-
const carOrderList = ref([]);
+
const yellostatue = ref({
backgroundColor: '#FFD243'
})
const greenstatue = ref({
backgroundColor: '#00D237'
})
+const grayStatue = ref({
+ backgroundColor: '#CCCCCC'
+})
const postData = reactive({
age: null,
@@ -116,6 +123,31 @@ const postData = reactive({
uid: userInfo.getUid
})
+// 添加浮动按钮的状态
+const floatingButtonPosition = reactive({
+ x: 40, // 初始右侧位置(单位rpx)
+ y: 280, // 初始底部位置(单位rpx)
+ isDragging: false,
+ startX: 0,
+ startY: 0,
+ startLeft: 0,
+ startTop: 0
+})
+
+// 计算是否显示一键下架按钮
+const showBatchAction = computed(() => {
+ if (!carOrderList.value || carOrderList.value.length === 0) {
+ return false;
+ }
+
+ // 检查所有时间段是否符合条件
+ return carOrderList.value.every(item => {
+ // occupy值为"未占用"或"已下架",且dispatch值为"未派单"
+ return (item.occupy === '未占用' || item.occupy === '已下架') &&
+ item.dispatch === '未派单';
+ });
+});
+
//页面数据初始化
onLoad(() => {
// init()
@@ -137,6 +169,7 @@ onShow(() => {
})
}
+ loadButtonPosition(); // 加载保存的位置
})
function init() {
@@ -163,13 +196,112 @@ function init() {
carListVal.value = carListOptions.value[0].value
}
carOrderList.value = findCarDispatchList(carListAll.value, dateVal.value[0], carListVal.value)
+ } else {
+ uni.showModal({
+ title: '提示',
+ content: res.msg || '订单排单出现异常,请联系管理员',
+ showCancel: false
+ })
}
})
}
-//冻结
-function handleDateItem(car) {
+// 一键下架功能
+function handleBatchDown() {
+ // 如果是拖动操作,则不触发点击事件
+ if (floatingButtonPosition.isDragging) {
+ floatingButtonPosition.isDragging = false;
+ return;
+ }
+ if (!showBatchAction.value) {
+ uni.showToast({
+ title: '不符合一键下架条件',
+ icon: 'none',
+ duration: 2000
+ });
+ return;
+ }
+
+ // 获取所有符合条件的时段
+ const eligibleTimes = carOrderList.value
+ .filter(item => item.occupy === '未占用' && item.dispatch === '未派单')
+ .map(item => {
+ const hour = parseInt(item.time.split(':')[0], 10);
+ return {
+ time: item.time,
+ hour: hour
+ };
+ });
+
+ if (eligibleTimes.length === 0) {
+ uni.showToast({
+ title: '没有可下架的时段',
+ icon: 'none',
+ duration: 2000
+ });
+ return;
+ }
+
+ uni.showModal({
+ title: '确认一键下架',
+ // content: `确定要下架选中的${eligibleTimes.length}个时段吗?`,
+ success: (res) => {
+ if (res.confirm) {
+ batchDownTimes(eligibleTimes);
+ }
+ }
+ });
+}
+
+// 批量下架API调用
+async function batchDownTimes(times) {
+ try {
+ // // 可以一次性请求或循环请求
+ uni.showLoading({
+ title: '正在下架...'
+ });
+ const params = {
+ "allDay": true,
+ "carId": parseInt(carListVal.value),
+ "downDate": dateVal.value[0],
+ "downHour": 0,
+ "pageNum": 0,
+ "pageSize": 0
+ }
+ carBatchDownTimes(params).then(res => {
+ if (res.code == 200) {
+ uni.showToast({
+ title: `成功下架`,
+ icon: 'success',
+ duration: 2000
+ });
+ // 重新加载数据
+ init();
+ } else {
+ uni.showToast({
+ title: '部分时段下架失败',
+ icon: 'error',
+ duration: 2000
+ });
+ }
+ })
+ uni.hideLoading();
+
+
+ } catch (error) {
+ console.error('批量下架失败:', error);
+ uni.hideLoading();
+ uni.showToast({
+ title: '下架失败,请稍后重试',
+ icon: 'error',
+ duration: 2000
+ });
+ }
+}
+
+//单个冻结
+function handleDateItem(car) {
let params = {
carId: parseInt(carListVal.value),
pageNum: 0,
@@ -177,7 +309,6 @@ function handleDateItem(car) {
downDate: dateVal.value[0],
downHour: parseInt(car.time.split(':')[0], 10)
}
- console.log(params, '>>>>>111>')
carAddDownTime(params).then(res => {
if (res.code == 200) {
uni.showToast({
@@ -189,7 +320,7 @@ function handleDateItem(car) {
} else {
uni.showToast({
title: '下架失败,请稍后重试',
- icon: 'success',
+ icon: 'error',
duration: 2000
})
}
@@ -204,7 +335,6 @@ function handleDeleteDateItem(car) {
downDate: dateVal.value[0],
downHour: parseInt(car.time.split(':')[0], 10)
}
- console.log(params, '>>>>>111>')
carDeleteDownTime(params).then(res => {
if (res.code == 200) {
uni.showToast({
@@ -216,26 +346,20 @@ function handleDeleteDateItem(car) {
} else {
uni.showToast({
title: '解冻失败,请稍后重试',
- icon: 'success',
+ icon: 'error',
duration: 2000
})
}
})
}
-function search(res) {
- console.log('search', text)
-}
-
//车辆选择
function carChoose(val) {
- console.log('=========', val)
carListVal.value = val
carOrderList.value = findCarDispatchList(carListAll.value, dateVal.value[0], carListVal.value)
}
-
-const scroll_list_height = systemInfo.getscreenheight - systemInfo.getnavbarheight - 46
+const scroll_list_height = systemInfo.getscreenheight - systemInfo.getnavbarheight - 46 - (showBatchAction.value ? 50 : 0)
const scrollTop = ref(0)
function upper(e) {
@@ -252,46 +376,132 @@ function scroll(e) {
}
//日期选择
-
function confirm({
selectedValue,
selectedOptions
}) {
- console.log(selectedValue[0], selectedOptions[0])
dateShow.value = false
dateVal.value = [selectedValue[0]]
const dateItem = carListAll.value.find(item => item.serviceDate === selectedValue[0]);
carListOptions.value = dateItem.carDispatchList.map(item => {
- console.log(item, '=====item')
return {
text: item.carNo,
value: item.carId,
-
};
});
carListVal.value = carListOptions.value[0].value
carOrderList.value = findCarDispatchList(carListAll.value, selectedValue[0], carListVal.value)
}
-
//派单数据处理
function findCarDispatchList(data, targetDate, targetCarNo) {
- // 1. 先按 serviceDate 查找日期项
const dateItem = data.find(item => item.serviceDate === targetDate);
- if (!dateItem) return null; // 如果日期不存在,返回 null
- // 2. 在 carDispatchList 中按 carNo 查找车辆
+ if (!dateItem) return null;
const carItem = dateItem.carDispatchList.find(car => car.carId === targetCarNo);
- console.log('1=========', carItem)
- return carItem.dispatchResults || null; // 返回找到的车辆数据(或 null)
+ return carItem.dispatchResults || null;
}
+
+// 监听车辆和日期变化,重新计算scroll高度
+watch([carListVal, dateVal, showBatchAction], () => {
+ scroll_list_height.value = systemInfo.getscreenheight - systemInfo.getnavbarheight - 46 - (showBatchAction.value ? 50 : 0);
+});
+
+
+// 计算浮动按钮的样式
+const floatingButtonStyle = computed(() => {
+ return {
+ left: `${floatingButtonPosition.x}rpx`,
+ bottom: `${floatingButtonPosition.y}rpx`,
+ transition: floatingButtonPosition.isDragging ? 'none' : 'all 0.2s ease'
+ }
+})
+
+// 触摸开始事件
+function handleTouchStart(e) {
+ const touch = e.touches[0];
+ floatingButtonPosition.isDragging = true;
+ floatingButtonPosition.startX = touch.clientX;
+ floatingButtonPosition.startY = touch.clientY;
+ floatingButtonPosition.startLeft = floatingButtonPosition.x;
+ floatingButtonPosition.startTop = floatingButtonPosition.y;
+}
+
+// 触摸移动事件
+function handleTouchMove(e) {
+ if (!floatingButtonPosition.isDragging) return;
+
+ const touch = e.touches[0];
+ const deltaX = touch.clientX - floatingButtonPosition.startX;
+ const deltaY = touch.clientY - floatingButtonPosition.startY;
+
+ // 转换为rpx(假设设计稿750rpx对应屏幕宽度)
+ const screenWidth = uni.getSystemInfoSync().screenWidth;
+ const rpxRatio = 750 / screenWidth;
+
+ const newX = floatingButtonPosition.startLeft + deltaX * rpxRatio;
+ const newY = floatingButtonPosition.startTop - deltaY * rpxRatio; // 注意Y轴方向相反
+
+ // 限制在屏幕范围内
+ const buttonWidth = 120; // 按钮宽度120rpx
+
+ floatingButtonPosition.x = Math.max(0, Math.min(newX, 750 - buttonWidth));
+ floatingButtonPosition.y = Math.max(150, Math.min(newY, 1200)); // 限制在适当范围内
+}
+
+// 触摸结束事件
+function handleTouchEnd() {
+ if (!floatingButtonPosition.isDragging) return;
+
+ floatingButtonPosition.isDragging = false;
+
+ // 添加吸附到边缘的效果
+ const screenWidth = 750; // rpx单位
+ const buttonWidth = 120;
+
+ // 如果距离左右边缘较近,则吸附到边缘
+ if (floatingButtonPosition.x < screenWidth / 2) {
+ floatingButtonPosition.x = 20; // 吸附到左边缘
+ } else {
+ floatingButtonPosition.x = screenWidth - buttonWidth - 20; // 吸附到右边缘
+ }
+
+ // 保存位置到本地存储(可选)
+ // saveButtonPosition();
+}
+
+// 保存按钮位置到本地存储(可选功能)
+function saveButtonPosition() {
+ try {
+ uni.setStorageSync('floatingButtonPosition', {
+ x: floatingButtonPosition.x,
+ y: floatingButtonPosition.y
+ });
+ } catch (e) {
+ console.error('保存按钮位置失败:', e);
+ }
+}
+
+// 加载保存的按钮位置(在onLoad或onShow中调用)
+function loadButtonPosition() {
+ try {
+ const savedPosition = uni.getStorageSync('floatingButtonPosition');
+ if (savedPosition) {
+ floatingButtonPosition.x = savedPosition.x;
+ floatingButtonPosition.y = savedPosition.y;
+ }
+ } catch (e) {
+ console.error('加载按钮位置失败:', e);
+ }
+}
+
+
\ No newline at end of file
diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue
index 28bce37..da6bd5a 100644
--- a/src/pages/index/index.vue
+++ b/src/pages/index/index.vue
@@ -183,11 +183,11 @@ function init(isadd) {
refreshKey.value++
}
})
- systemConfigInfo({}).then(res => {
- if (res.code === 200) {
- phoneNumber.value = res.data.systemInfos.find(x => x.name === '客服电话')
- }
- })
+ // systemConfigInfo({}).then(res => {
+ // if (res.code === 200) {
+ // phoneNumber.value = res.data.systemInfos.find(x => x.name === '客服电话')
+ // }
+ // })
} catch (error) {
console.error('加载订单失败:', error)
showOrderList.value = []
diff --git a/src/pages/orderDispatch/index.vue b/src/pages/orderDispatch/index.vue
index 14eb269..3ff08f6 100644
--- a/src/pages/orderDispatch/index.vue
+++ b/src/pages/orderDispatch/index.vue
@@ -212,6 +212,12 @@
orderServiceTimeList.info.push(result)
}
console.log(orderServiceTimeList, 'res.data.times')
+ }else{
+ uni.showModal({
+ title: '提示',
+ content: res.msg || '订单排单出现异常,请联系管理员',
+ showCancel: false
+ })
}
})
}
diff --git a/src/pages/orderEdit/index.vue b/src/pages/orderEdit/index.vue
index 5bc9649..d06022b 100644
--- a/src/pages/orderEdit/index.vue
+++ b/src/pages/orderEdit/index.vue
@@ -190,6 +190,12 @@ function getorderServiceTime() {
orderServiceTimeList.info.push(result)
}
console.log(orderServiceTimeList, 'res.data.times')
+ }else{
+ uni.showModal({
+ title: '提示',
+ content: res.msg || '订单排单出现异常,请联系管理员',
+ showCancel: false
+ })
}
})
}
diff --git a/src/static/images/down-button.png b/src/static/images/down-button.png
new file mode 100644
index 0000000..0547640
Binary files /dev/null and b/src/static/images/down-button.png differ