feat: 增加点击菜地作物可编辑功能

This commit is contained in:
2026-09-10 19:44:57 +08:00
parent d1edbd52bd
commit 115bc6cf06
4 changed files with 36 additions and 9 deletions

View File

@@ -5,6 +5,7 @@
:safe-area-inset-bottom="true" :safe-area-inset-bottom="true"
:close-on-click-modal="true" :close-on-click-modal="true"
custom-style="border-radius: 32rpx 32rpx 0 0; padding: 40rpx 32rpx" custom-style="border-radius: 32rpx 32rpx 0 0; padding: 40rpx 32rpx"
@close="handeClosePopup"
> >
<view class="mb-5 text-center text-base text-gray-700 font-semibold"> <view class="mb-5 text-center text-base text-gray-700 font-semibold">
{{ patchStore.cropApiType === 'ADD' ? '新增作物' : '编辑作物' }} {{ patchStore.cropApiType === 'ADD' ? '新增作物' : '编辑作物' }}
@@ -59,7 +60,7 @@
</view> </view>
<wd-datetime-picker <wd-datetime-picker
:model-value="new Date(patchStore.recordForm.date).getTime()" :model-value="new Date(patchStore.cropForm.date).getTime()"
v-model:visible="showTimePicker" v-model:visible="showTimePicker"
type="date" type="date"
:max-date="Date.now()" :max-date="Date.now()"
@@ -77,14 +78,21 @@ import { formatDate } from "@/utils";
const patchStore = usePatchStore() const patchStore = usePatchStore()
const showTimePicker = ref(false) const showTimePicker = ref(false)
function onDateConfirm({ value }){ function onDateConfirm({ value }){
patchStore.recordForm.date = formatDate(new Date(value)) patchStore.cropForm.date = formatDate(new Date(value))
showTimePicker.value = false showTimePicker.value = false
} }
function handeClosePopup() {
setTimeout(() => {
patchStore.showPatchFab = true
patchStore.showRecordFab = true
}, 300)
}
function cancelClick() { function cancelClick() {
patchStore.showRecordPopup = false patchStore.showCropPopup = false
handeClosePopup()
} }
async function deleteClick() { async function deleteClick() {
@@ -112,13 +120,16 @@ async function saveClick() {
if (patchStore.cropApiType === 'ADD') { if (patchStore.cropApiType === 'ADD') {
await patchStore.addCropApi() await patchStore.addCropApi()
await patchStore.queryPatch(patchStore.currentPatch.id) await patchStore.queryPatch(patchStore.currentPatch.id)
await patchStore.queryPatchList()
uni.showToast({ title: '新增作物成功', icon: 'none' }) uni.showToast({ title: '新增作物成功', icon: 'none' })
} else if (patchStore.cropApiType === 'UPDATE') { } else if (patchStore.cropApiType === 'UPDATE') {
await patchStore.updateCropApi(patchStore.cropForm.id) await patchStore.updateCropApi(patchStore.cropForm.id)
await patchStore.queryPatch(patchStore.currentPatch.id) await patchStore.queryPatch(patchStore.currentPatch.id)
await patchStore.queryPatchList()
uni.showToast({ title: '更新作物成功', icon: 'none' }) uni.showToast({ title: '更新作物成功', icon: 'none' })
} }
patchStore.showCropPopup = false patchStore.showCropPopup = false
handeClosePopup()
} }
</script> </script>

View File

@@ -15,10 +15,14 @@
<view class="p-3"> <view class="p-3">
<wd-search v-model="patchStore.patchSearch" <wd-search v-model="patchStore.patchSearch"
:maxlength="20" :placeholder-left="true" :hide-cancel="true" :maxlength="20" :placeholder-left="true"
placeholder="请输入菜地名称或者菜地地点" placeholder="请输入菜地名称或者菜地地点"
@change="patchStore.queryPatchList()" @change="patchStore.queryPatchList()"
@clear="patchStore.queryPatchList()"/> @clear="patchStore.queryPatchList()">
<template #suffix>
<wd-button type="primary" icon="refresh" round @click="patchStore.queryPatchList()"/>
</template>
</wd-search>
</view> </view>
<wd-card v-for="(item, index) in patchStore.patchList" :key="item.id"> <wd-card v-for="(item, index) in patchStore.patchList" :key="item.id">
@@ -38,7 +42,7 @@
<template #footer> <template #footer>
<view class="flex-1 flex justify-between items-center"> <view class="flex-1 flex justify-between items-center">
<view v-if="item.crop" class="flex flex-col gap-1"> <view v-if="item.crop" class="flex flex-col gap-1" @click="updateCropClick(item)">
<view class="text-base font-medium"> <view class="text-base font-medium">
{{ item.crop.name }} {{ item.crop.name }}
<text class="text-sm text-gray-400 font-normal ml-1">{{ item.crop.variety }}</text> <text class="text-sm text-gray-400 font-normal ml-1">{{ item.crop.variety }}</text>
@@ -65,6 +69,7 @@
</liu-drag-button> </liu-drag-button>
<patch-popup /> <patch-popup />
<crop-popup />
<view class="h-[10px]"></view> <view class="h-[10px]"></view>
</view> </view>
</template> </template>
@@ -76,6 +81,7 @@ import appLogo from '@/static/logo.png'
import { usePatchStore } from "@/stores/patch"; import { usePatchStore } from "@/stores/patch";
import type { ICrop, IPatch } from "@/types"; import type { ICrop, IPatch } from "@/types";
import PatchPopup from "@/components/PatchPopup.vue"; import PatchPopup from "@/components/PatchPopup.vue";
import CropPopup from "@/components/CropPopup.vue";
defineOptions({ name: 'Home' }) defineOptions({ name: 'Home' })
@@ -144,4 +150,12 @@ function handlePreview(crop: ICrop) {
const fullUrls = crop.images?.map(url => `${patchStore.baseUrl}/${url}`) as string[] const fullUrls = crop.images?.map(url => `${patchStore.baseUrl}/${url}`) as string[]
uni.previewImage({ urls: fullUrls, current: fullUrls[0] }) uni.previewImage({ urls: fullUrls, current: fullUrls[0] })
} }
function updateCropClick(patch: IPatch) {
patchStore.currentPatch = patch
patchStore.showPatchFab = false
patchStore.cropForm = JSON.parse(JSON.stringify(patch.crop))
patchStore.cropApiType = 'UPDATE'
patchStore.showCropPopup = true
}
</script> </script>

File diff suppressed because one or more lines are too long

View File

@@ -38,12 +38,14 @@ export const usePatchStore = defineStore('patch', {
}), }),
actions: { actions: {
async queryPatchList() { async queryPatchList() {
this.patchList = []
this.patchList = await this.queryPatchListApi() this.patchList = await this.queryPatchListApi()
}, },
async queryPatch(patchId: number) { async queryPatch(patchId: number) {
this.currentPatch = await this.queryPatchApi(patchId) this.currentPatch = await this.queryPatchApi(patchId)
}, },
async queryRecordList(cropId: number) { async queryRecordList(cropId: number) {
this.recordList = []
this.recordList = await this.queryRecordListApi(cropId) this.recordList = await this.queryRecordListApi(cropId)
}, },
async queryPatchListApi() { async queryPatchListApi() {