Quellcode durchsuchen

免车费规则联调

lishanshan vor 7 Monaten
Ursprung
Commit
7b7cf87464
6 geänderte Dateien mit 152 neuen und 33 gelöschten Zeilen
  1. 9 0
      src/api/index.js
  2. 1 1
      src/api/order.js
  3. 18 0
      src/api/staff.js
  4. 9 7
      src/pages/identify/identify.vue
  5. 114 24
      src/pages/settings/fare.vue
  6. 1 1
      src/pages/staff/index.vue

+ 9 - 0
src/api/index.js

@@ -39,6 +39,15 @@ export function getProjectList(data) {
     });
 }
 
+// 查询指定技师的项目
+export function getProjectByJsId(data) {
+    return request({
+        method: 'get',
+        url: '/api/xiangmu/v1/wx/getByJsId',
+        data
+    });
+}
+
 // 项目详情
 export function projectDetails(data) {
     return request({

+ 1 - 1
src/api/order.js

@@ -66,7 +66,7 @@ export function speedOrder(data) {
 // 获取技师可预约时间
 export function getStaffServiceTime(data) {
     return request({
-        method: 'post',
+        method: 'get',
         url: '/api/order/v1/wx/getTechnicianAvailability',
         data
     });

+ 18 - 0
src/api/staff.js

@@ -43,4 +43,22 @@ export function netStaffUpdate(data) {
         url: '/api/js/v1/wx/update',
         data
     });
+}
+
+// 获取免车费规则
+export function freeFareGet(data) {
+    return request({
+        method: 'get',
+        url: '/tFareSetting/fareFreeRule/list',
+        data
+    });
+}
+
+// 添加免车费规则
+export function freeFareAdd(data) {
+    return request({
+        method: 'post',
+        url: '/tFareSetting/fareFreeRule/add',
+        data
+    });
 }

+ 9 - 7
src/pages/identify/identify.vue

@@ -258,13 +258,15 @@
 		methods: {
 			getCity() {
 				getCityList().then(res => {
-					this.cityList = res.data.data.map(({
-						deptId,
-						deptName
-					}) => ({
-						value: deptId,
-						label: deptName
-					}))
+					if (res.data.code === 200) {
+						this.cityList = res.data.data.map(({
+							deptId,
+							deptName
+						}) => ({
+							value: deptId,
+							label: deptName
+						}))
+					}
 				});
 			},
 			onSelect(e) {

+ 114 - 24
src/pages/settings/fare.vue

@@ -16,7 +16,7 @@
 			<u-cell-group :border="false">
 				<u-cell 
 					title="服务项目" 
-					:value="formData.projectName || '请选择'" 
+					:value="formData.projectNames || '请选择'" 
 					isLink 
 					:border="true"
 					@click="showProjectPicker = true"
@@ -41,7 +41,7 @@
 				<u-cell title="订单距离" :border="false">
 					<view slot="value" class="input-slot">
 						<u-input
-							v-model="formData.distance"
+							v-model="formData.minDistance"
 							placeholder="请输入最高免除距离"
 							border="none"
 							inputAlign="right"
@@ -50,7 +50,7 @@
 							placeholderStyle="font-size: 14px; color: #c0c4cc;"
 						>
 							<template slot="suffix">
-								<text class="unit-text" v-if="formData.distance">km</text>
+								<text class="unit-text" v-if="formData.minDistance">km</text>
 							</template>
 						</u-input>
 					</view>
@@ -100,6 +100,8 @@
 </template>
 
 <script>
+import { getProjectByJsId } from '@/api/index';
+import { freeFareGet, freeFareAdd } from '@/api/staff';
 export default {
     data() {
         return {
@@ -107,10 +109,11 @@ export default {
             
             // 表单数据
             formData: {
-                projectName: '',
+                projectNames: '',
+                projectId: '',
                 timeRange1: '',
                 timeRange2: '',
-                distance: ''
+                minDistance: ''
             },
             
             // 弹窗控制
@@ -118,17 +121,45 @@ export default {
             showTimePicker: false,
             activeTimeField: '', // 当前正在编辑的时间字段名
             
-            // 数据源模拟
-            projectList: [['泰式唤醒', '精油SPA', '中医推拿']],
+            projectData: [],
+            projectList: [[]],
             // 复杂时间选择器数据列
             timeColumns: [],
+            openId: ''
         }
     },
     onLoad() {
         // 初始化时间选择器的数据
         this.initTimePickerData();
+        this.openId = uni.getStorageSync('wx_copenid');
+        if (this.openId) {
+            // 详情
+            this.getFreeFareRule(this.openId);
+            // 获取技师服务项目
+            this.getProject(this.openId);
+        }
     },
     methods: {
+        getFreeFareRule(openId) {
+            freeFareGet({ openId }).then(res => {
+                if (res.data.code === 200 && res.data.data) {
+                    this.formData = res.data.data;
+                    this.isFree = this.formData.enable == '1' ? true : false;
+                } else {
+                    this.isFree = false;
+                }
+            }).catch(err => {
+                console.error('获取免车费规则失败:', err);
+            });
+        },
+        getProject(id) {
+            getProjectByJsId({ openId: id }).then(res => {
+                if (res.data.code == 200) {
+                    this.projectData = res.data.data;
+                    this.projectList = [res.data.data.map(item => item.cTitle)];
+                }
+            })
+        },
         // 初始化 5 列时间数据
         initTimePickerData() {
             // 1. 生成小时 (00时 - 23时)
@@ -161,7 +192,9 @@ export default {
         },
         // 确认服务项目
         confirmProject(e) {
-            this.formData.projectName = e.value[0];
+            this.formData.projectNames = e.value[0];
+            const selectedProject = this.projectData.find(item => item.cTitle === e.value[0]);
+            if (selectedProject) this.formData.projectId = selectedProject.cId;
             this.showProjectPicker = false;
         },
 
@@ -188,37 +221,94 @@ export default {
             // 赋值给当前激活的字段
             if(this.activeTimeField) {
                 this.formData[this.activeTimeField] = timeString;
+                
+                // 检查时间重叠
+                this.checkTimeOverlap();
             }
             
             this.showTimePicker = false;
         },
+        
+        // 将时间范围字符串解析为开始和结束的分钟数
+        parseTimeRange(timeRange) {
+            if (!timeRange) return null;
+            
+            const [start, end] = timeRange.split('-');
+            const [startHour, startMinute] = start.split(':').map(Number);
+            const [endHour, endMinute] = end.split(':').map(Number);
+            
+            return {
+                start: startHour * 60 + startMinute,
+                end: endHour * 60 + endMinute
+            };
+        },
+        
+        // 检查两个时间范围是否重叠
+        checkTimeOverlap() {
+            const range1 = this.parseTimeRange(this.formData.timeRange1);
+            const range2 = this.parseTimeRange(this.formData.timeRange2);
+            
+            // 如果两个时间都已设置,则检查重叠
+            if (range1 && range2) {
+                // 检查是否重叠
+                const isOverlap = range1.start < range2.end && range2.start < range1.end;
+                
+                if (isOverlap) {
+                    uni.showToast({
+                        title: '两个服务时间不能重合',
+                        icon: 'none',
+                        duration: 2000
+                    });
+                    
+                    // 清空当前设置的时间
+                    this.formData[this.activeTimeField] = '';
+                }
+                
+                return isOverlap;
+            }
+            
+            return false;
+        },
 
         // 保存
         onSave() {
             if(this.isFree) {
-                // 简单校验
-                if(!this.formData.projectName || !this.formData.distance) {
+                if(!this.formData.projectNames || !this.formData.minDistance) {
                     uni.showToast({
                         title: '请完善配置信息',
                         icon: 'none'
                     });
                     return;
                 }
+                
+                // 校验服务时间
+                if (this.checkTimeOverlap()) {
+                    return;
+                }
             }
-            
-            console.log('保存数据:', {
-                isFree: this.isFree,
-                ...this.formData
-            });
-            
-            uni.showToast({
-                title: '保存成功',
-                icon: 'success'
-            });
-            
-            setTimeout(() => {
-                uni.navigateBack();
-            }, 1500);
+            const params = {
+                ...this.formData,
+                openId: this.openId,
+                enable: this.isFree ? '1' : '0'
+            };
+            freeFareAdd(params)
+                .then(res => {
+                    if (res.data.code === 200) {
+                        uni.showToast({
+                            title: '提交成功',
+                            icon: 'none'
+                        });
+                        
+                        setTimeout(() => {
+                            uni.navigateBack();
+                        }, 1000);
+                    } else {
+                        uni.showToast({
+                            title: res.data.msg,
+                            icon: 'none'
+                        });
+                    }
+                })
         }
     }
 }

+ 1 - 1
src/pages/staff/index.vue

@@ -352,7 +352,7 @@
 			},
 			goFree() {
 				uni.navigateTo({
-					url: '/pages/my/free_fare'
+					url: '/pages/settings/fare'
 				})
 			},
 			onTabChange(e) {