| | |
| | | const app = getApp(); |
| | | const { get, post } = require('../../api/request'); |
| | | const { |
| | | get, |
| | | post |
| | | } = require('../../api/request'); |
| | | const dayjs = require('dayjs'); |
| | | |
| | | Page({ |
| | |
| | | */ |
| | | generatePlanCode: function () { |
| | | const now = dayjs(); |
| | | const dateStr = now.format('YYYYMMDD'); |
| | | const dateStr = now.format('YYYY-MM-DD'); |
| | | const randomNum = Math.floor(Math.random() * 10000).toString().padStart(4, '0'); |
| | | const planCode = `${dateStr}${randomNum}`; |
| | | this.setData({ planCode }); |
| | | const planCode = `${dateStr}${-randomNum}`; |
| | | this.setData({ |
| | | planCode |
| | | }); |
| | | }, |
| | | |
| | | /** |
| | | * 获取项目列表 |
| | | */ |
| | | fetchProjects: function () { |
| | | fetchProjects: function (isShowDiaolog) { |
| | | return get({ |
| | | url: '/wx/irrigation/getSimpleProjects', |
| | | isShowLoding: true |
| | |
| | | projectList, |
| | | projectOptions |
| | | }); |
| | | if (isShowDiaolog) { |
| | | this.setData({ |
| | | projectPickerVisible: true |
| | | }); |
| | | } |
| | | } else { |
| | | wx.showToast({ |
| | | title: res.msg || '获取项目列表失败', |
| | |
| | | isShowLoding: true |
| | | }).then(res => { |
| | | if (res.success) { |
| | | console.log('轮灌组数据:', res.content.obj); |
| | | console.log('轮灌组数据:', res.content); |
| | | |
| | | // 更新选中项目的轮灌组信息 |
| | | const projectList = this.data.projectList.map(project => { |
| | | if (project.id === projectId) { |
| | | return { |
| | | ...project, |
| | | groups: res.content.obj.map(group => ({ |
| | | groups: res.content.map(group => ({ |
| | | id: group.groupId, |
| | | name: group.groupCode, |
| | | duration: group.defaultDuration || 0, |
| | |
| | | * 时间选择器确认回调 |
| | | */ |
| | | onTimePickerConfirm: function (e) { |
| | | const { value } = e.detail; |
| | | const { |
| | | value |
| | | } = e.detail; |
| | | this.setData({ |
| | | timePickerVisible: false, |
| | | startTime: value |
| | |
| | | * 处理时长输入 |
| | | */ |
| | | onDurationInput: function (e) { |
| | | const { groupIndex } = e.currentTarget.dataset; |
| | | const { |
| | | groupIndex |
| | | } = e.currentTarget.dataset; |
| | | const duration = parseInt(e.detail.value) || 0; |
| | | |
| | | const selectedProject = { ...this.data.selectedProject }; |
| | | const selectedProject = { |
| | | ...this.data.selectedProject |
| | | }; |
| | | selectedProject.groups[groupIndex].duration = duration; |
| | | |
| | | this.setData({ |
| | |
| | | * 跳转到轮灌组详情页 |
| | | */ |
| | | navigateToGroupDetail: function (e) { |
| | | const { groupIndex } = e.currentTarget.dataset; |
| | | const { |
| | | groupIndex |
| | | } = e.currentTarget.dataset; |
| | | // TODO: 实现跳转逻辑 |
| | | }, |
| | | |
| | |
| | | * 确认按钮点击事件 |
| | | */ |
| | | onConfirm: function () { |
| | | const { planCode, startTime, selectedProject } = this.data; |
| | | const { |
| | | planCode, |
| | | startTime, |
| | | selectedProject |
| | | } = this.data; |
| | | |
| | | if (!planCode) { |
| | | wx.showToast({ |
| | |
| | | title: '创建成功', |
| | | icon: 'success' |
| | | }); |
| | | // 返回上一页 |
| | | // 返回上一页,并传递参数指示需要刷新列表并切换到当前计划列表 |
| | | setTimeout(() => { |
| | | wx.navigateBack(); |
| | | // 使用全局变量标记需要刷新 |
| | | const app = getApp(); |
| | | app.globalData.needRefreshIrrigationList = true; |
| | | |
| | | // 直接返回上一页 |
| | | wx.navigateBack({ |
| | | delta: 1 |
| | | }); |
| | | }, 1500); |
| | | } else { |
| | | wx.showToast({ |
| | |
| | | |
| | | // 显示项目选择器 |
| | | showProjectPicker() { |
| | | this.setData({ |
| | | projectPickerVisible: true |
| | | }); |
| | | this.fetchProjects(true) |
| | | |
| | | }, |
| | | |
| | | // 项目选择器确认 |
| | | onProjectPickerConfirm(e) { |
| | | const { value } = e.detail; |
| | | const { |
| | | value |
| | | } = e.detail; |
| | | console.log('选择的项目ID:', value[0]); // 添加日志查看数据 |
| | | const selectedProject = this.data.projectList.find(project => project.id === value[0]); |
| | | console.log('找到的项目:', selectedProject); // 添加日志查看数据 |
| | |
| | | */ |
| | | onGroupListRefresh: function () { |
| | | if (!this.data.selectedProject) { |
| | | this.setData({ isRefreshing: false }); |
| | | this.setData({ |
| | | isRefreshing: false |
| | | }); |
| | | return; |
| | | } |
| | | |
| | | this.setData({ isRefreshing: true }); |
| | | this.setData({ |
| | | isRefreshing: true |
| | | }); |
| | | |
| | | this.fetchGroups(this.data.selectedProject.id) |
| | | .then(() => { |
| | | this.setData({ isRefreshing: false }); |
| | | this.setData({ |
| | | isRefreshing: false |
| | | }); |
| | | }) |
| | | .catch(() => { |
| | | this.setData({ isRefreshing: false }); |
| | | this.setData({ |
| | | isRefreshing: false |
| | | }); |
| | | }); |
| | | }, |
| | | |