更新土地操作

This commit is contained in:
yaooo 2023-11-23 17:26:14 +08:00
parent 8d1c86d475
commit 49c0bbe837
14 changed files with 826 additions and 10 deletions

View File

@ -6,7 +6,6 @@ export function apiLandLists(params: any) {
return request.get({ url: '/land.land/lists', params })
}
// 土地种植表列表
export function apiLandPlantLists(params: any) {
return request.get({ url: '/land.land_plant/lists', params })

View File

@ -0,0 +1,31 @@
import request from '@/utils/request'
// 土地种植表列表
export function apiLandPlantLists(params: any) {
return request.get({ url: '/land.land_plant/lists', params })
}
// 土地种植作物操作表列表
export function apiLandPlantActionLists(params: any) {
return request.get({ url: '/land.land_plant_action/lists', params })
}
// 添加土地种植作物操作表
export function apiLandPlantActionAdd(params: any) {
return request.post({ url: '/land.land_plant_action/add', params })
}
// 编辑土地种植作物操作表
export function apiLandPlantActionEdit(params: any) {
return request.post({ url: '/land.land_plant_action/edit', params })
}
// 删除土地种植作物操作表
export function apiLandPlantActionDelete(params: any) {
return request.post({ url: '/land.land_plant_action/delete', params })
}
// 土地种植作物操作表详情
export function apiLandPlantActionDetail(params: any) {
return request.get({ url: '/land.land_plant_action/detail', params })
}

View File

@ -111,7 +111,7 @@ const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑土地' : '新增土地'
return mode.value == 'edit' ? '编辑土地' : '新增土地'
})
//

View File

@ -97,7 +97,7 @@ const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑土地种植' : '新增土地种植'
return mode.value == 'edit' ? '编辑土地种植' : '新增土地种植'
})
//

View File

@ -73,8 +73,20 @@
<span>{{ row.plant_date ? timeFormat(row.plant_date, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right">
<el-table-column label="操作" width="200" fixed="right">
<template #default="{ row }">
<el-button v-perms="['land.land_plant_action/lists']" type="primary" link >
<router-link
:to="{
path: getRoutePath('land.land_plant_action/lists'),
query: {
plant_id: row.id
}
}"
>
种植操作
</router-link>
</el-button>
<el-button
v-perms="['land.land_plant/edit']"
type="primary"
@ -105,6 +117,7 @@
<script lang="ts" setup name="landPlantLists">
import { usePaging } from '@/hooks/usePaging'
import { getRoutePath } from '@/router'
import { useDictData } from '@/hooks/useDictOptions'
import { apiLandPlantLists, apiLandPlantDelete } from '@/api/land_plant'
import { timeFormat } from '@/utils/util'

View File

@ -0,0 +1,178 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
:title="popupTitle"
:async="true"
width="550px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<!-- <el-form-item label="种植ID" prop="plant_id">
<el-input v-model="formData.plant_id" clearable placeholder="请输入种植ID" />
</el-form-item> -->
<el-form-item label="种植ID" prop="land_id">
<el-select
v-model="formData.plant_id"
filterable
remote
reserve-keyword
placeholder="请输入种植信息"
:remote-method="queryLandPlant"
:loading="loading"
>
<el-option
v-for="item in landPlantOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="操作类型" prop="type">
<el-select class="flex-1" v-model="formData.type" clearable placeholder="请选择操作类型">
<el-option
v-for="(item, index) in dictData.land_plant_action"
:key="index"
:label="item.name"
:value="parseInt(item.value)"
/>
</el-select>
</el-form-item>
<el-form-item label="操作" prop="type_text">
<el-input v-model="formData.type_text" clearable placeholder="请输入操作" />
</el-form-item>
<el-form-item label="操作详情" prop="detail">
<el-input class="flex-1" v-model="formData.detail" type="textarea" rows="4" clearable placeholder="请输入操作详情" />
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="landPlantActionEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiLandPlantActionAdd, apiLandPlantActionEdit, apiLandPlantActionDetail, apiLandPlantLists } from '@/api/land_plant_action'
import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add')
//
const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑土地种植操作' : '新增土地种植操作'
})
//
const formData = reactive({
id: '',
plant_id: '',
type: '',
type_text: '',
detail: '',
})
//
const formRules = reactive<any>({
plant_id: [{
required: true,
message: '请输入种植ID',
trigger: ['blur']
}],
type: [{
required: true,
message: '请选择操作类型',
trigger: ['blur']
}],
})
//
const setFormData = async (data: Record<any, any>) => {
for (const key in formData) {
if (data[key] != null && data[key] != undefined) {
//@ts-ignore
formData[key] = data[key]
}
}
}
const getDetail = async (row: Record<string, any>) => {
const data = await apiLandPlantActionDetail({
id: row.id
})
setFormData(data)
}
interface ListItem {
value: string
label: string
}
const landPlantOptions = ref<ListItem[]>([])
const loading = ref(false)
const queryLandPlant = async (query: string) => {
if (query) {
loading.value = true
const landList = await apiLandPlantLists({
keyword: query
})
loading.value = false
if (landList.count > 0) {
landPlantOptions.value = landList.lists.map((landPlant: any) => {
return { value: `${landPlant.id}`, label: `ID: ${landPlant.id} / 土地: ${landPlant.land.title} / 种类: ${landPlant.kind} / 品牌: ${landPlant.breed}` }
})
} else {
landPlantOptions.value = []
}
loading.value = false
} else {
landPlantOptions.value = []
}
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
mode.value == 'edit'
? await apiLandPlantActionEdit(data)
: await apiLandPlantActionAdd(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData,
getDetail
})
</script>

View File

@ -0,0 +1,140 @@
<template>
<div>
<el-card class="!border-none mb-4" shadow="never">
<el-form
class="mb-[-16px]"
:model="queryParams"
inline
>
<el-form-item label="种植ID" prop="plant_id">
<el-input class="w-[280px]" v-model="queryParams.plant_id" clearable placeholder="请输入种植ID" />
</el-form-item>
<el-form-item label="操作类型" prop="type">
<el-select class="w-[280px]" v-model="queryParams.type" clearable placeholder="请选择操作类型">
<el-option label="全部" value=""></el-option>
<el-option
v-for="(item, index) in dictData.land_plant_action"
:key="index"
:label="item.name"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="resetPage">查询</el-button>
<el-button @click="resetParams">重置</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="!border-none" v-loading="pager.loading" shadow="never">
<div class="mt-4">
<el-table :data="pager.lists" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" />
<el-table-column label="ID" prop="id" show-overflow-tooltip />
<el-table-column label="种植操作类型" prop="type">
<template #default="{ row }">
<dict-value :options="dictData.land_plant_action" :value="row.type" />
</template>
</el-table-column>
<el-table-column label="种植操作" prop="type_text" show-overflow-tooltip />
<el-table-column label="种植ID" prop="plant_id" show-overflow-tooltip />
<el-table-column label="种植类型" prop="landPlant.kind" show-overflow-tooltip />
<el-table-column label="种植品牌" prop="landPlant.breed" show-overflow-tooltip />
<el-table-column label="种植面积" prop="landPlant.area" show-overflow-tooltip />
<el-table-column label="操作详情" prop="detail" show-overflow-tooltip />
<el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }">
<el-button
v-perms="['land.land_plant_action/edit']"
type="primary"
link
@click="handleEdit(row)"
>
编辑
</el-button>
<el-button
v-perms="['land.land_plant_action/delete']"
type="danger"
link
@click="handleDelete(row.id)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
<div class="flex mt-4 justify-end">
<pagination v-model="pager" @change="getLists" />
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
</div>
</template>
<script lang="ts" setup name="landPlantActionLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { apiLandPlantActionLists, apiLandPlantActionDelete } from '@/api/land_plant_action'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const { query } = useRoute()
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
//
const showEdit = ref(false)
var plant_id = query.plant_id
if (typeof(plant_id) == 'undefined') {
plant_id = ''
}
//
const queryParams = reactive({
plant_id: plant_id,
type: '',
})
//
const selectData = ref<any[]>([])
//
const handleSelectionChange = (val: any[]) => {
selectData.value = val.map(({ id }) => id)
}
//
const { dictData } = useDictData('land_plant_action')
//
const { pager, getLists, resetParams, resetPage } = usePaging({
fetchFun: apiLandPlantActionLists,
params: queryParams
})
//
const handleAdd = async () => {
showEdit.value = true
await nextTick()
editRef.value?.open('add')
}
//
const handleEdit = async (data: any) => {
showEdit.value = true
await nextTick()
editRef.value?.open('edit')
editRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')
await apiLandPlantActionDelete({ id })
getLists()
}
getLists()
</script>

View File

@ -0,0 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\controller\land;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\land\LandPlantActionLists;
use app\adminapi\logic\land\LandPlantActionLogic;
use app\adminapi\validate\land\LandPlantActionValidate;
/**
* LandPlantAction控制器
* Class LandPlantActionController
* @package app\adminapi\controller\land
*/
class LandPlantActionController extends BaseAdminController
{
/**
* @notes 获取列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function lists()
{
return $this->dataLists(new LandPlantActionLists());
}
/**
* @notes 添加
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function add()
{
$params = (new LandPlantActionValidate())->post()->goCheck('add');
$result = LandPlantActionLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(LandPlantActionLogic::getError());
}
/**
* @notes 编辑
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function edit()
{
$params = (new LandPlantActionValidate())->post()->goCheck('edit');
$result = LandPlantActionLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(LandPlantActionLogic::getError());
}
/**
* @notes 删除
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function delete()
{
$params = (new LandPlantActionValidate())->post()->goCheck('delete');
LandPlantActionLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function detail()
{
$params = (new LandPlantActionValidate())->goCheck('detail');
$result = LandPlantActionLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,77 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\lists\land;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\land\LandPlantAction;
use app\common\lists\ListsSearchInterface;
/**
* LandPlantAction列表
* Class LandPlantActionLists
* @package app\adminapi\listsland
*/
class LandPlantActionLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function setSearch(): array
{
return [
'=' => ['plant_id', 'type'],
];
}
/**
* @notes 获取列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function lists(): array
{
return LandPlantAction::where($this->searchWhere)->with('landPlant')
->field(['id', 'plant_id', 'type', 'type_text', 'detail'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取数量
* @return int
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function count(): int
{
return LandPlantAction::where($this->searchWhere)->count();
}
}

View File

@ -38,10 +38,25 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface
public function setSearch(): array
{
return [
'=' => ['land_id', 'kind', 'breed', 'user', 'status', 'plant_date'],
'%like%' => ['kind', 'breed'],
'=' => ['land_id', 'user', 'status', 'plant_date'],
];
}
/**
* @notes 搜索条件
* @author 段誉
* @date 2023/2/24 16:08
*/
public function queryWhere()
{
$where = [];
if (!empty($this->params['keyword'])) {
$where[] = ['kind|breed', 'like', '%' . $this->params['keyword'] . '%'];
}
return $where;
}
/**
* @notes 获取列表
@ -54,7 +69,7 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function lists(): array
{
return LandPlant::where($this->searchWhere)->with('land')
return LandPlant::where($this->queryWhere())->where($this->searchWhere)->with('land')
->field(['id', 'land_id', 'kind', 'breed', 'area', 'user', 'status', 'pic', 'qr_code', 'plant_date', 'remark'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
@ -71,7 +86,7 @@ class LandPlantLists extends BaseAdminDataLists implements ListsSearchInterface
*/
public function count(): int
{
return LandPlant::where($this->searchWhere)->count();
return LandPlant::where($this->queryWhere())->where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,112 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\logic\land;
use app\common\model\land\LandPlantAction;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* LandPlantAction逻辑
* Class LandPlantActionLogic
* @package app\adminapi\logic\land
*/
class LandPlantActionLogic extends BaseLogic
{
/**
* @notes 添加
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/23 14:53
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
LandPlantAction::create([
'plant_id' => $params['plant_id'],
'type' => $params['type'],
'type_text' => $params['type_text'],
'detail' => $params['detail'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/23 14:53
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
LandPlantAction::where('id', $params['id'])->update([
'plant_id' => $params['plant_id'],
'type' => $params['type'],
'type_text' => $params['type_text'],
'detail' => $params['detail'],
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/11/23 14:53
*/
public static function delete(array $params): bool
{
return LandPlantAction::destroy($params['id']);
}
/**
* @notes 获取详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/11/23 14:53
*/
public static function detail($params): array
{
return LandPlantAction::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\adminapi\validate\land;
use app\common\validate\BaseValidate;
/**
* LandPlantAction验证器
* Class LandPlantActionValidate
* @package app\adminapi\validate\land
*/
class LandPlantActionValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
'plant_id' => 'require',
'type' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'plant_id' => '种植ID',
'type' => '操作类型',
];
/**
* @notes 添加场景
* @return LandPlantActionValidate
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function sceneAdd()
{
return $this->only(['plant_id','type']);
}
/**
* @notes 编辑场景
* @return LandPlantActionValidate
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function sceneEdit()
{
return $this->only(['id','plant_id','type']);
}
/**
* @notes 删除场景
* @return LandPlantActionValidate
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return LandPlantActionValidate
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\model\land;
use app\common\model\BaseModel;
/**
* LandPlantAction模型
* Class LandPlantAction
* @package app\common\model\land
*/
class LandPlantAction extends BaseModel
{
protected $name = 'land_plant_action';
/**
* @notes 关联种植操作
* @return \think\model\relation\HasOne
* @author likeadmin
* @date 2023/11/23 14:53
*/
public function landPlant()
{
return $this->hasOne(\app\common\model\land\LandPlant::class, 'id', 'plant_id');
}
}