更新土地绑定产品

This commit is contained in:
yaooo 2023-11-30 12:00:50 +08:00
parent a9f6facd04
commit 924a7c35e8
9 changed files with 285 additions and 46 deletions

View File

@ -5,6 +5,11 @@ export function getUserList(params: any) {
return request.get({ url: '/user.user/lists', params }, { ignoreCancelToken: true })
}
// 产品列表列表
export function apiProductLists(params: any) {
return request.get({ url: '/land.product/lists', params })
}
// 土地表列表
export function apiLandLists(params: any) {
console.log(params)
@ -29,4 +34,9 @@ export function apiLandDelete(params: any) {
// 土地表详情
export function apiLandDetail(params: any) {
return request.get({ url: '/land.land/detail', params })
}
// 绑定产品
export function apiLandBind(params: any) {
return request.post({ url: '/land.land/bind', params })
}

View File

@ -0,0 +1,147 @@
<template>
<div class="edit-popup">
<popup
ref="popupRef"
:title="popupTitle"
:async="true"
width="650px"
@confirm="handleSubmit"
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
<el-form-item label="土地ID" prop="id">
<el-input v-model="formData.id" disabled clearable placeholder="请输入土地ID" />
</el-form-item>
<el-form-item label="土地名称" prop="title">
<el-input
v-model="formData.title"
disabled
clearable
placeholder="请输入土地名称"
/>
</el-form-item>
<el-form-item label="绑定产品" prop="product_id">
<el-select
v-model="formData.product_id"
filterable
remote
reserve-keyword
placeholder="请输入产品信息"
:remote-method="queryProduct"
:loading="loading"
>
<el-option
v-for="item in productOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-form>
</popup>
</div>
</template>
<script lang="ts" setup name="landEdit">
import type { FormInstance } from 'element-plus'
import Popup from '@/components/popup/index.vue'
import { apiLandBind, apiProductLists } from '@/api/land'
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 = '绑定产品')
})
//
const formData = reactive({
id: '',
title: '',
product_id: ''
})
//
const formRules = reactive<any>({
product_id: [{
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]
}
}
}
interface ListItem {
value: string
label: string
}
const productOptions = ref<ListItem[]>([])
const loading = ref(false)
const queryProduct = async (query: string) => {
if (query) {
loading.value = true
const productList = await apiProductLists({
name: query
})
loading.value = false
if (productList.count > 0) {
productOptions.value = productList.lists.map((product: any) => {
return { value: `${product.id}`, label: `ID: ${product.id} / 名称: ${product.name}` }
})
} else {
productOptions.value = []
}
loading.value = false
} else {
productOptions.value = []
}
}
//
const handleSubmit = async () => {
await formRef.value?.validate()
const data = { ...formData, }
await apiLandBind(data)
popupRef.value?.close()
emit('success')
}
//
const open = (type = 'add') => {
mode.value = type
popupRef.value?.open()
}
//
const handleClose = () => {
emit('close')
}
defineExpose({
open,
setFormData
})
</script>

View File

@ -49,16 +49,12 @@
<el-tag class="mr-2" type="info">账户: {{ row.user.account }}</el-tag>
</template>
</el-table-column> -->
<el-table-column label="土地名称">
<template #default="{ row }">
<el-tag class="mr-2" type="info">{{ row.title }}</el-tag>
</template>
</el-table-column>
<el-table-column label="土地名称" prop="title" show-overflow-tooltip />
<el-table-column label="土地面积" prop="total_area" show-overflow-tooltip />
<el-table-column label="剩余面积" prop="residual_area" show-overflow-tooltip />
<el-table-column label="土地负责人" prop="master_name" show-overflow-tooltip />
<el-table-column label="负责人电话" prop="master_phone" show-overflow-tooltip />
<el-table-column label="操作" width="350" align="center" fixed="right">
<el-table-column label="操作" width="400" align="center" fixed="right">
<template #default="{ row }">
<el-button
v-perms="['land.land/edit']"
@ -68,6 +64,14 @@
>
编辑
</el-button>
<el-button
v-perms="['land.land/bind']"
type="primary"
link
@click="handleBind(row)"
>
绑定产品
</el-button>
<el-button
v-perms="['land.product/lists']"
type="primary"
@ -121,6 +125,7 @@
</div>
</el-card>
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
<bind-popup v-if="bindEdit" ref="bindRef" :dict-data="dictData" @success="getLists" @close="bindEdit = false" />
</div>
<el-dialog v-model="dialogPicVisible" title="土地图片" center>
@ -148,11 +153,14 @@ import { apiLandLists, apiLandDelete } from '@/api/land'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
import BindPopup from './bind.vue'
const { query } = useRoute()
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const bindRef = shallowRef<InstanceType<typeof BindPopup>>()
//
const showEdit = ref(false)
const bindEdit = ref(false)
let user_id = query.user_id
if (typeof user_id == 'undefined') {
@ -215,6 +223,14 @@ const handleEdit = async (data: any) => {
editRef.value?.setFormData(data)
}
//
const handleBind = async (data: any) => {
bindEdit.value = true
await nextTick()
bindRef.value?.open('bind')
bindRef.value?.setFormData(data)
}
//
const handleDelete = async (id: number | any[]) => {
await feedback.confirm('确定要删除?')

View File

@ -9,7 +9,13 @@
@close="handleClose"
>
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
<el-form-item label="土地ID" prop="land_id">
<el-form-item label="产品编号" prop="code">
<el-input v-model="formData.code" clearable placeholder="请输入产品编号" />
</el-form-item>
<el-form-item label="产品名称" prop="name">
<el-input v-model="formData.name" clearable placeholder="请输入产品名称" />
</el-form-item>
<el-form-item label="所属土地" prop="land_id">
<el-select
v-model="formData.land_id"
filterable
@ -26,12 +32,6 @@
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="产品编号" prop="code">
<el-input v-model="formData.code" clearable placeholder="请输入产品编号" />
</el-form-item>
<el-form-item label="产品名称" prop="name">
<el-input v-model="formData.name" clearable placeholder="请输入产品名称" />
</el-form-item>
<el-form-item label="产品状态" prop="status">
<el-select class="flex-1" v-model="formData.status" clearable placeholder="请选择产品状态">
@ -83,11 +83,6 @@ const formData = reactive({
//
const formRules = reactive<any>({
land_id: [{
required: true,
message: '请输入土地id',
trigger: ['blur']
}],
code: [{
required: true,
message: '请输入产品编号',

View File

@ -84,9 +84,9 @@
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
</template>
</el-table-column>
<el-table-column label="操作" width="200" align="center" fixed="right">
<el-table-column label="操作" width="260" align="center" fixed="right">
<template #default="{ row }">
<el-button
<el-button
v-perms="['land.product/edit']"
type="primary"
link
@ -94,6 +94,14 @@
>
编辑
</el-button>
<el-button
v-perms="['land.product/edit']"
type="primary"
link
@click="handleEdit(row)"
>
绑定设备
</el-button>
<el-button v-perms="['device.device/lists']" type="primary" link >
<router-link
:to="{
@ -103,8 +111,8 @@
}
}"
>
查看设备
</router-link>
设备信息
</router-link>
</el-button>
<el-button
v-perms="['land.product/delete']"

View File

@ -104,5 +104,18 @@ class LandController extends BaseAdminController
return $this->data($result);
}
/**
* @notes 绑定产品
* @return \think\response\Json
* @author likeadmin
* @date 2023/11/22 16:35
*/
public function bind()
{
$params = (new LandValidate())->post()->goCheck('bind');
LandLogic::bind($params);
return $this->success('绑定成功', [], 1, 1);
}
}

View File

@ -38,13 +38,14 @@ class LandLogic extends BaseLogic
*/
public static function add(array $params): bool
{
if ((request()->adminInfo)['root'] != 1) {
$params['user_id'] = (request()->adminInfo)['user_id'];
$userId = (request()->adminInfo)['user_id'];
if (!empty($params['user_id'])) {
$userId = $params['user_id'];
}
Db::startTrans();
try {
Land::create([
'user_id' => $params['user_id'],
'user_id' => $userId,
'title' => $params['title'],
'total_area' => $params['total_area'],
'residual_area' => $params['residual_area'],
@ -86,13 +87,14 @@ class LandLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
if ((request()->adminInfo)['root'] != 1) {
$params['user_id'] = (request()->adminInfo)['user_id'];
$userId = (request()->adminInfo)['user_id'];
if (!empty($params['user_id'])) {
$userId = $params['user_id'];
}
Db::startTrans();
try {
Land::where('id', $params['id'])->update([
'user_id' => $params['user_id'],
'user_id' => $userId,
'title' => $params['title'],
'total_area' => $params['total_area'],
'residual_area' => $params['residual_area'],
@ -149,4 +151,32 @@ class LandLogic extends BaseLogic
{
return Land::findOrEmpty($params['id'])->toArray();
}
public static function bind($params): bool
{
$userId = (request()->adminInfo)['user_id'];
if (!empty($params['id'])) {
$userId = Db::name('land')->where('id', $params['id'])->value('user_id');
}
Db::startTrans();
try {
Db::name('product')->where('id', $params['product_id'])->update([
'user_id' => $userId
]);
Db::name('land_product')->where('land_id', $params['id'])->delete();
Db::name('land_product')->where('product_id', $params['product_id'])->delete();
Db::name('land_product')->insert([
'land_id' => $params['id'],
'product_id' => $params['product_id'],
'create_time' => time(),
'update_time' => time()
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
}

View File

@ -38,7 +38,10 @@ class ProductLogic extends BaseLogic
*/
public static function add(array $params): bool
{
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
$userId = (request()->adminInfo)['user_id'];
if (!empty($params['land_id'])) {
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
}
Db::startTrans();
try {
$product = Product::create([
@ -47,12 +50,14 @@ class ProductLogic extends BaseLogic
'name' => $params['name'],
'status' => $params['status'],
]);
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $product['id'],
'create_time' => time(),
'update_time' => time()
]);
if (!empty($params['land_id'])) {
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $product['id'],
'create_time' => time(),
'update_time' => time()
]);
}
Db::commit();
return true;
} catch (\Exception $e) {
@ -72,7 +77,10 @@ class ProductLogic extends BaseLogic
*/
public static function edit(array $params): bool
{
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
$userId = (request()->adminInfo)['user_id'];
if (!empty($params['land_id'])) {
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
}
Db::startTrans();
try {
Product::where('id', $params['id'])->update([
@ -82,12 +90,14 @@ class ProductLogic extends BaseLogic
'status' => $params['status'],
]);
Db::name('land_product')->where('product_id', $params['id'])->delete();
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $params['id'],
'create_time' => time(),
'update_time' => time()
]);
if (!empty($params['land_id'])) {
Db::name('land_product')->insert([
'land_id' => $params['land_id'],
'product_id' => $params['id'],
'create_time' => time(),
'update_time' => time()
]);
}
Db::commit();
return true;
} catch (\Exception $e) {

View File

@ -33,7 +33,7 @@ class LandValidate extends BaseValidate
*/
protected $rule = [
'id' => 'require',
'user_id' => 'require',
'product_id' => 'require',
'title' => 'require',
'total_area' => 'require',
'residual_area' => 'require',
@ -62,7 +62,6 @@ class LandValidate extends BaseValidate
*/
protected $field = [
'id' => 'id',
'user_id' => '用户id',
'title' => '土地名称',
'total_area' => '土地面积',
'residual_area' => '剩余面积',
@ -95,7 +94,7 @@ class LandValidate extends BaseValidate
*/
public function sceneAdd()
{
return $this->only(['user_id','title','master_name','master_phone']);
return $this->only(['title','master_name','master_phone']);
}
@ -107,7 +106,7 @@ class LandValidate extends BaseValidate
*/
public function sceneEdit()
{
return $this->only(['id','user_id','title','master_name','master_phone']);
return $this->only(['id','title','master_name','master_phone']);
}
@ -143,4 +142,15 @@ class LandValidate extends BaseValidate
return true;
}
/**
* @notes 绑定产品
* @return LandValidate
* @author likeadmin
* @date 2023/11/22 16:35
*/
public function sceneBind()
{
return $this->only(['id', 'product_id']);
}
}