Merge branch 'yaooo' into dev
This commit is contained in:
commit
07e8420fd9
|
@ -5,9 +5,13 @@ export function getUserList(params: any) {
|
||||||
return request.get({ url: '/user.user/lists', params }, { ignoreCancelToken: true })
|
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) {
|
export function apiLandLists(params: any) {
|
||||||
console.log(params)
|
|
||||||
return request.get({ url: '/land.land/lists', params })
|
return request.get({ url: '/land.land/lists', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,4 +33,9 @@ export function apiLandDelete(params: any) {
|
||||||
// 土地表详情
|
// 土地表详情
|
||||||
export function apiLandDetail(params: any) {
|
export function apiLandDetail(params: any) {
|
||||||
return request.get({ url: '/land.land/detail', params })
|
return request.get({ url: '/land.land/detail', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定产品
|
||||||
|
export function apiLandBind(params: any) {
|
||||||
|
return request.post({ url: '/land.land/bind', params })
|
||||||
}
|
}
|
|
@ -7,7 +7,6 @@ export function getUserList(params: any) {
|
||||||
|
|
||||||
// 土地表列表
|
// 土地表列表
|
||||||
export function apiLandLists(params: any) {
|
export function apiLandLists(params: any) {
|
||||||
console.log(params)
|
|
||||||
return request.get({ url: '/land.land/lists', params })
|
return request.get({ url: '/land.land/lists', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,6 @@ export function getUserList(params: any) {
|
||||||
|
|
||||||
// 土地表列表
|
// 土地表列表
|
||||||
export function apiLandLists(params: any) {
|
export function apiLandLists(params: any) {
|
||||||
console.log(params)
|
|
||||||
return request.get({ url: '/land.land/lists', params })
|
return request.get({ url: '/land.land/lists', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +15,12 @@ export function apiProductLists(params: any) {
|
||||||
return request.get({ url: '/land.product/lists', params })
|
return request.get({ url: '/land.product/lists', params })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监测设备列表
|
||||||
|
export function apiDeviceLists(params: any) {
|
||||||
|
return request.get({ url: '/device.device/lists', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 添加产品列表
|
// 添加产品列表
|
||||||
export function apiProductAdd(params: any) {
|
export function apiProductAdd(params: any) {
|
||||||
return request.post({ url: '/land.product/add', params })
|
return request.post({ url: '/land.product/add', params })
|
||||||
|
@ -34,4 +39,9 @@ export function apiProductDelete(params: any) {
|
||||||
// 产品列表详情
|
// 产品列表详情
|
||||||
export function apiProductDetail(params: any) {
|
export function apiProductDetail(params: any) {
|
||||||
return request.get({ url: '/land.product/detail', params })
|
return request.get({ url: '/land.product/detail', params })
|
||||||
|
}
|
||||||
|
|
||||||
|
// 绑定设备
|
||||||
|
export function apiProductBind(params: any) {
|
||||||
|
return request.post({ url: '/land.product/bind', params })
|
||||||
}
|
}
|
|
@ -46,12 +46,6 @@
|
||||||
<dict-value :options="dictData.device_online_status" :value="deviceData.device.is_online" />
|
<dict-value :options="dictData.device_online_status" :value="deviceData.device.is_online" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="w-1/2 md:w-1/6 mb-4">
|
|
||||||
<div class="leading-10">是否绑定产品:</div>
|
|
||||||
<div class="text-3xl text-tx-secondary">
|
|
||||||
<dict-value :options="dictData.device_bind_status" :value="deviceData.device.is_bind" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
|
|
||||||
|
|
|
@ -9,25 +9,20 @@
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
||||||
<el-form-item label="用户ID" prop="user_id">
|
<el-form-item label="设备名称" prop="name">
|
||||||
<el-select
|
<el-input v-model="formData.name" clearable placeholder="请输入设备名称" />
|
||||||
v-model="formData.user_id"
|
|
||||||
filterable
|
|
||||||
remote
|
|
||||||
reserve-keyword
|
|
||||||
placeholder="请输入用户信息"
|
|
||||||
:remote-method="queryUser"
|
|
||||||
:loading="loading"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in userOptions"
|
|
||||||
:key="item.value"
|
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="产品ID" prop="product_id">
|
<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.device_type"
|
||||||
|
:key="index"
|
||||||
|
:label="item.name"
|
||||||
|
:value="parseInt(item.value)"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="所属产品" prop="product_id">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="formData.product_id"
|
v-model="formData.product_id"
|
||||||
filterable
|
filterable
|
||||||
|
@ -45,21 +40,8 @@
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="设备编码" prop="code">
|
<el-form-item label="设备编码" prop="code">
|
||||||
<el-input v-model="formData.code" clearable placeholder="请输入设备编码" />
|
<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="type">
|
|
||||||
<el-select class="flex-1" v-model="formData.type" clearable placeholder="请选择设备类型">
|
|
||||||
<el-option
|
|
||||||
v-for="(item, index) in dictData.device_type"
|
|
||||||
:key="index"
|
|
||||||
:label="item.name"
|
|
||||||
:value="parseInt(item.value)"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="监测项" prop="monitor_item">
|
<el-form-item label="监测项" prop="monitor_item">
|
||||||
<el-select class="flex-1" v-model="formData.monitor_item" multiple clearable placeholder="请选择设备监测项">
|
<el-select class="flex-1" v-model="formData.monitor_item" multiple clearable placeholder="请选择设备监测项">
|
||||||
|
@ -93,16 +75,6 @@
|
||||||
:value="parseInt(item.value)"
|
:value="parseInt(item.value)"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="是否绑定土地" prop="is_bind">
|
|
||||||
<el-select class="flex-1" v-model="formData.is_bind" clearable placeholder="请选择是否绑定土地">
|
|
||||||
<el-option
|
|
||||||
v-for="(item, index) in dictData.device_bind_status"
|
|
||||||
:key="index"
|
|
||||||
:label="item.name"
|
|
||||||
:value="parseInt(item.value)"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-form>
|
</el-form>
|
||||||
</popup>
|
</popup>
|
||||||
|
@ -135,7 +107,6 @@ const popupTitle = computed(() => {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
user_id: '',
|
|
||||||
product_id: '',
|
product_id: '',
|
||||||
code: '',
|
code: '',
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -144,22 +115,10 @@ const formData = reactive({
|
||||||
monitor_item: '',
|
monitor_item: '',
|
||||||
status: '',
|
status: '',
|
||||||
is_online: '',
|
is_online: '',
|
||||||
is_bind: '',
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
user_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户ID',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
product_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入产品id',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
code: [{
|
code: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入设备编码',
|
message: '请输入设备编码',
|
||||||
|
@ -185,11 +144,6 @@ const formRules = reactive<any>({
|
||||||
message: '请选择是否在线',
|
message: '请选择是否在线',
|
||||||
trigger: ['blur']
|
trigger: ['blur']
|
||||||
}],
|
}],
|
||||||
is_bind: [{
|
|
||||||
required: true,
|
|
||||||
message: '请选择是否绑定土地',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,29 +162,8 @@ interface ListItem {
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
const productOptions = ref<ListItem[]>([])
|
const productOptions = ref<ListItem[]>([])
|
||||||
const userOptions = ref<ListItem[]>([])
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const queryUser = async (query: string) => {
|
|
||||||
if (query) {
|
|
||||||
loading.value = true
|
|
||||||
const userList = await getUserList({
|
|
||||||
keyword: query
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
if (userList.count > 0) {
|
|
||||||
userOptions.value = userList.lists.map((user: any) => {
|
|
||||||
return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` }
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
loading.value = false
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryProduct = async (query: string) => {
|
const queryProduct = async (query: string) => {
|
||||||
if (query) {
|
if (query) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
|
@ -58,17 +58,6 @@
|
||||||
:value="item.value"
|
:value="item.value"
|
||||||
/>
|
/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="是否绑定土地" prop="is_bind">
|
|
||||||
<el-select class="w-[280px]" v-model="queryParams.is_bind" clearable placeholder="请选择是否绑定土地">
|
|
||||||
<el-option label="全部" value=""></el-option>
|
|
||||||
<el-option
|
|
||||||
v-for="(item, index) in dictData.device_bind_status"
|
|
||||||
:key="index"
|
|
||||||
:label="item.name"
|
|
||||||
:value="item.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item>
|
<el-form-item>
|
||||||
<el-button type="primary" @click="resetPage">查询</el-button>
|
<el-button type="primary" @click="resetPage">查询</el-button>
|
||||||
|
@ -128,11 +117,6 @@
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<dict-value :options="dictData.device_online_status" :value="row.is_online" />
|
<dict-value :options="dictData.device_online_status" :value="row.is_online" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="是否绑定土地" width="150" align="center" prop="is_bind">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<dict-value :options="dictData.device_bind_status" :value="row.is_bind" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="创建时间" width="160" align="center" prop="create_time">
|
<el-table-column label="创建时间" width="160" align="center" prop="create_time">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
|
@ -162,7 +146,7 @@
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
查看详情
|
详情
|
||||||
</router-link>
|
</router-link>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
|
@ -178,7 +162,7 @@
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
查看报警
|
报警
|
||||||
</router-link>
|
</router-link>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
|
@ -229,8 +213,7 @@ const queryParams = reactive({
|
||||||
name: '',
|
name: '',
|
||||||
type: '',
|
type: '',
|
||||||
status: '',
|
status: '',
|
||||||
is_online: '',
|
is_online: ''
|
||||||
is_bind: ''
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// 选中数据
|
// 选中数据
|
||||||
|
|
|
@ -0,0 +1,150 @@
|
||||||
|
<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')
|
||||||
|
}
|
||||||
|
|
||||||
|
const setProduct = async (data: Record<any, any>) => {
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
open,
|
||||||
|
setFormData,
|
||||||
|
setProduct
|
||||||
|
})
|
||||||
|
</script>
|
|
@ -9,7 +9,7 @@
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
||||||
<el-form-item label="用户ID" prop="user_id">
|
<el-form-item v-if="formData.root == 1" label="用户ID" prop="user_id">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="formData.user_id"
|
v-model="formData.user_id"
|
||||||
filterable
|
filterable
|
||||||
|
@ -29,6 +29,9 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="土地名称" prop="title">
|
<el-form-item label="土地名称" prop="title">
|
||||||
<el-input v-model="formData.title" clearable placeholder="请输入土地名称" />
|
<el-input v-model="formData.title" clearable placeholder="请输入土地名称" />
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="详细地址" prop="address">
|
||||||
|
<el-input v-model="formData.address" clearable placeholder="请输入详细地址" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="土地面积" prop="total_area">
|
<el-form-item label="土地面积" prop="total_area">
|
||||||
<el-input v-model="formData.total_area" clearable placeholder="请输入土地面积" />
|
<el-input v-model="formData.total_area" clearable placeholder="请输入土地面积" />
|
||||||
|
@ -71,12 +74,6 @@
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="组名称" prop="group_name">
|
<el-form-item label="组名称" prop="group_name">
|
||||||
<el-input v-model="formData.group_name" clearable placeholder="请输入组名称" />
|
<el-input v-model="formData.group_name" clearable placeholder="请输入组名称" />
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="经度" prop="longitude">
|
|
||||||
<el-input v-model="formData.longitude" clearable placeholder="请输入经度" />
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="纬度" prop="latitude">
|
|
||||||
<el-input v-model="formData.latitude" clearable placeholder="请输入纬度" />
|
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="土地负责人" prop="master_name">
|
<el-form-item label="土地负责人" prop="master_name">
|
||||||
<el-input v-model="formData.master_name" clearable placeholder="请输入土地负责人" />
|
<el-input v-model="formData.master_name" clearable placeholder="请输入土地负责人" />
|
||||||
|
@ -118,6 +115,7 @@ const popupTitle = computed(() => {
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
user_id: '',
|
user_id: '',
|
||||||
|
root: 0,
|
||||||
title: '',
|
title: '',
|
||||||
total_area: '',
|
total_area: '',
|
||||||
residual_area: '',
|
residual_area: '',
|
||||||
|
@ -133,25 +131,24 @@ const formData = reactive({
|
||||||
village_name: '',
|
village_name: '',
|
||||||
group_code: '',
|
group_code: '',
|
||||||
group_name: '',
|
group_name: '',
|
||||||
longitude: '',
|
|
||||||
latitude: '',
|
|
||||||
master_name: '',
|
master_name: '',
|
||||||
master_phone: '',
|
master_phone: '',
|
||||||
|
address: '',
|
||||||
pic: ''
|
pic: ''
|
||||||
})
|
})
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
user_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户ID',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
title: [{
|
title: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入土地名称',
|
message: '请输入土地名称',
|
||||||
trigger: ['blur']
|
trigger: ['blur']
|
||||||
}],
|
}],
|
||||||
|
address: [{
|
||||||
|
required: true,
|
||||||
|
message: '请输入详细地址',
|
||||||
|
trigger: ['blur']
|
||||||
|
}],
|
||||||
master_name: [{
|
master_name: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入土地负责人',
|
message: '请输入土地负责人',
|
||||||
|
|
|
@ -49,16 +49,12 @@
|
||||||
<el-tag class="mr-2" type="info">账户: {{ row.user.account }}</el-tag>
|
<el-tag class="mr-2" type="info">账户: {{ row.user.account }}</el-tag>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column> -->
|
</el-table-column> -->
|
||||||
<el-table-column label="土地名称">
|
<el-table-column label="土地名称" prop="title" show-overflow-tooltip />
|
||||||
<template #default="{ row }">
|
|
||||||
<el-tag class="mr-2" type="info">{{ row.title }}</el-tag>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="土地面积" prop="total_area" 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="residual_area" show-overflow-tooltip />
|
||||||
<el-table-column label="土地负责人" prop="master_name" 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="负责人电话" 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 }">
|
<template #default="{ row }">
|
||||||
<el-button
|
<el-button
|
||||||
v-perms="['land.land/edit']"
|
v-perms="['land.land/edit']"
|
||||||
|
@ -68,6 +64,14 @@
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-perms="['land.land/bind']"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleBind(row)"
|
||||||
|
>
|
||||||
|
绑定产品
|
||||||
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-perms="['land.product/lists']"
|
v-perms="['land.product/lists']"
|
||||||
type="primary"
|
type="primary"
|
||||||
|
@ -121,6 +125,7 @@
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
|
<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>
|
</div>
|
||||||
|
|
||||||
<el-dialog v-model="dialogPicVisible" title="土地图片" center>
|
<el-dialog v-model="dialogPicVisible" title="土地图片" center>
|
||||||
|
@ -148,11 +153,14 @@ import { apiLandLists, apiLandDelete } from '@/api/land'
|
||||||
import { timeFormat } from '@/utils/util'
|
import { timeFormat } from '@/utils/util'
|
||||||
import feedback from '@/utils/feedback'
|
import feedback from '@/utils/feedback'
|
||||||
import EditPopup from './edit.vue'
|
import EditPopup from './edit.vue'
|
||||||
|
import BindPopup from './bind.vue'
|
||||||
|
|
||||||
const { query } = useRoute()
|
const { query } = useRoute()
|
||||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||||
|
const bindRef = shallowRef<InstanceType<typeof BindPopup>>()
|
||||||
// 是否显示编辑框
|
// 是否显示编辑框
|
||||||
const showEdit = ref(false)
|
const showEdit = ref(false)
|
||||||
|
const bindEdit = ref(false)
|
||||||
|
|
||||||
let user_id = query.user_id
|
let user_id = query.user_id
|
||||||
if (typeof user_id == 'undefined') {
|
if (typeof user_id == 'undefined') {
|
||||||
|
@ -215,6 +223,15 @@ const handleEdit = async (data: any) => {
|
||||||
editRef.value?.setFormData(data)
|
editRef.value?.setFormData(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 绑定
|
||||||
|
const handleBind = async (data: any) => {
|
||||||
|
bindEdit.value = true
|
||||||
|
await nextTick()
|
||||||
|
bindRef.value?.open('bind')
|
||||||
|
bindRef.value?.setFormData(data)
|
||||||
|
bindRef.value?.setProduct(data)
|
||||||
|
}
|
||||||
|
|
||||||
// 删除
|
// 删除
|
||||||
const handleDelete = async (id: number | any[]) => {
|
const handleDelete = async (id: number | any[]) => {
|
||||||
await feedback.confirm('确定要删除?')
|
await feedback.confirm('确定要删除?')
|
||||||
|
|
|
@ -9,25 +9,6 @@
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||||
|
|
||||||
<el-form-item label="用户ID" prop="user_id">
|
|
||||||
<el-select
|
|
||||||
v-model="formData.user_id"
|
|
||||||
filterable
|
|
||||||
remote
|
|
||||||
reserve-keyword
|
|
||||||
placeholder="请输入用户信息"
|
|
||||||
:remote-method="queryUser"
|
|
||||||
:loading="loading"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in userOptions"
|
|
||||||
:key="item.value"
|
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="土地ID" prop="land_id">
|
<el-form-item label="土地ID" prop="land_id">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="formData.land_id"
|
v-model="formData.land_id"
|
||||||
|
@ -116,7 +97,6 @@ const popupTitle = computed(() => {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
user_id: '',
|
|
||||||
land_id: '',
|
land_id: '',
|
||||||
kind: '',
|
kind: '',
|
||||||
breed: '',
|
breed: '',
|
||||||
|
@ -132,11 +112,6 @@ const formData = reactive({
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
user_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户ID',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
land_id: [{
|
land_id: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入土地id',
|
message: '请输入土地id',
|
||||||
|
@ -198,29 +173,8 @@ interface ListItem {
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
const landOptions = ref<ListItem[]>([])
|
const landOptions = ref<ListItem[]>([])
|
||||||
const userOptions = ref<ListItem[]>([])
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const queryUser = async (query: string) => {
|
|
||||||
if (query) {
|
|
||||||
loading.value = true
|
|
||||||
const userList = await getUserList({
|
|
||||||
keyword: query
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
if (userList.count > 0) {
|
|
||||||
userOptions.value = userList.lists.map((user: any) => {
|
|
||||||
return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` }
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
loading.value = false
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryLand = async (query: string) => {
|
const queryLand = async (query: string) => {
|
||||||
if (query) {
|
if (query) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
|
@ -9,25 +9,6 @@
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||||
|
|
||||||
<el-form-item label="用户ID" prop="user_id">
|
|
||||||
<el-select
|
|
||||||
v-model="formData.user_id"
|
|
||||||
filterable
|
|
||||||
remote
|
|
||||||
reserve-keyword
|
|
||||||
placeholder="请输入用户信息"
|
|
||||||
:remote-method="queryUser"
|
|
||||||
:loading="loading"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in userOptions"
|
|
||||||
:key="item.value"
|
|
||||||
:label="item.label"
|
|
||||||
:value="item.value"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="种植ID" prop="land_id">
|
<el-form-item label="种植ID" prop="land_id">
|
||||||
<el-select
|
<el-select
|
||||||
v-model="formData.plant_id"
|
v-model="formData.plant_id"
|
||||||
|
@ -93,7 +74,6 @@ const popupTitle = computed(() => {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
user_id: '',
|
|
||||||
plant_id: '',
|
plant_id: '',
|
||||||
type: '',
|
type: '',
|
||||||
type_text: '',
|
type_text: '',
|
||||||
|
@ -103,11 +83,6 @@ const formData = reactive({
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
user_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户ID',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
plant_id: [{
|
plant_id: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入种植ID',
|
message: '请输入种植ID',
|
||||||
|
@ -145,29 +120,8 @@ interface ListItem {
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
const landPlantOptions = ref<ListItem[]>([])
|
const landPlantOptions = ref<ListItem[]>([])
|
||||||
const userOptions = ref<ListItem[]>([])
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
|
|
||||||
const queryUser = async (query: string) => {
|
|
||||||
if (query) {
|
|
||||||
loading.value = true
|
|
||||||
const userList = await getUserList({
|
|
||||||
keyword: query
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
if (userList.count > 0) {
|
|
||||||
userOptions.value = userList.lists.map((user: any) => {
|
|
||||||
return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` }
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
loading.value = false
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const queryLandPlant = async (query: string) => {
|
const queryLandPlant = async (query: string) => {
|
||||||
if (query) {
|
if (query) {
|
||||||
loading.value = true
|
loading.value = true
|
||||||
|
|
|
@ -0,0 +1,148 @@
|
||||||
|
<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="name">
|
||||||
|
<el-input
|
||||||
|
v-model="formData.name"
|
||||||
|
disabled
|
||||||
|
clearable
|
||||||
|
placeholder="请输入产品名称"
|
||||||
|
/>
|
||||||
|
</el-form-item>
|
||||||
|
<el-form-item label="绑定设备" prop="product_id">
|
||||||
|
<el-select
|
||||||
|
v-model="formData.device_id"
|
||||||
|
filterable
|
||||||
|
multiple
|
||||||
|
remote
|
||||||
|
reserve-keyword
|
||||||
|
placeholder="请输入设备信息"
|
||||||
|
:remote-method="queryDevice"
|
||||||
|
:loading="loading"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in deviceOptions"
|
||||||
|
: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 { apiProductBind, apiDeviceLists } from '@/api/product'
|
||||||
|
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: '',
|
||||||
|
name: '',
|
||||||
|
device_id: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
// 表单验证
|
||||||
|
const formRules = reactive<any>({
|
||||||
|
device_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 deviceOptions = ref<ListItem[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
|
const queryDevice = async (query: string) => {
|
||||||
|
if (query) {
|
||||||
|
loading.value = true
|
||||||
|
const deviceList = await apiDeviceLists({
|
||||||
|
name: query
|
||||||
|
})
|
||||||
|
loading.value = false
|
||||||
|
if (deviceList.count > 0) {
|
||||||
|
deviceOptions.value = deviceList.lists.map((device: any) => {
|
||||||
|
return { value: `${device.id}`, label: `ID: ${device.id} / 名称: ${device.name}` }
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
deviceOptions.value = []
|
||||||
|
}
|
||||||
|
loading.value = false
|
||||||
|
} else {
|
||||||
|
deviceOptions.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 提交按钮
|
||||||
|
const handleSubmit = async () => {
|
||||||
|
await formRef.value?.validate()
|
||||||
|
const data = { ...formData, }
|
||||||
|
await apiProductBind(data)
|
||||||
|
popupRef.value?.close()
|
||||||
|
emit('success')
|
||||||
|
}
|
||||||
|
|
||||||
|
//打开弹窗
|
||||||
|
const open = (type = 'add') => {
|
||||||
|
mode.value = type
|
||||||
|
popupRef.value?.open()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 关闭回调
|
||||||
|
const handleClose = () => {
|
||||||
|
emit('close')
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
defineExpose({
|
||||||
|
open,
|
||||||
|
setFormData
|
||||||
|
})
|
||||||
|
</script>
|
|
@ -8,60 +8,31 @@
|
||||||
@confirm="handleSubmit"
|
@confirm="handleSubmit"
|
||||||
@close="handleClose"
|
@close="handleClose"
|
||||||
>
|
>
|
||||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||||
<el-form-item label="用户ID" prop="user_id">
|
<el-form-item label="产品名称" prop="name">
|
||||||
<el-select
|
<el-input v-model="formData.name" clearable placeholder="请输入产品名称" />
|
||||||
v-model="formData.user_id"
|
</el-form-item>
|
||||||
filterable
|
<el-form-item label="产品编号" prop="code">
|
||||||
remote
|
<el-input v-model="formData.code" clearable placeholder="请输入产品编号" />
|
||||||
reserve-keyword
|
</el-form-item>
|
||||||
placeholder="请输入用户信息"
|
<el-form-item label="所属土地" prop="land_id">
|
||||||
:remote-method="queryUser"
|
<el-select
|
||||||
:loading="loading"
|
v-model="formData.land_id"
|
||||||
>
|
filterable
|
||||||
<el-option
|
remote
|
||||||
v-for="item in userOptions"
|
reserve-keyword
|
||||||
:key="item.value"
|
placeholder="请输入土地信息"
|
||||||
:label="item.label"
|
:remote-method="queryLand"
|
||||||
:value="item.value"
|
:loading="loading"
|
||||||
/>
|
>
|
||||||
</el-select>
|
<el-option
|
||||||
</el-form-item>
|
v-for="item in landOptions"
|
||||||
|
:key="item.value"
|
||||||
<el-form-item label="土地ID" prop="land_id">
|
:label="item.label"
|
||||||
<el-select
|
:value="item.value"
|
||||||
v-model="formData.land_id"
|
/>
|
||||||
filterable
|
</el-select>
|
||||||
remote
|
</el-form-item>
|
||||||
reserve-keyword
|
|
||||||
placeholder="请输入土地信息"
|
|
||||||
:remote-method="queryLand"
|
|
||||||
:loading="loading"
|
|
||||||
>
|
|
||||||
<el-option
|
|
||||||
v-for="item in landOptions"
|
|
||||||
:key="item.value"
|
|
||||||
:label="item.label"
|
|
||||||
: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="请选择产品状态">
|
|
||||||
<el-option
|
|
||||||
v-for="(item, index) in dictData.product_status"
|
|
||||||
:key="index"
|
|
||||||
:label="item.name"
|
|
||||||
:value="parseInt(item.value)"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
</el-form>
|
||||||
</popup>
|
</popup>
|
||||||
</div>
|
</div>
|
||||||
|
@ -93,7 +64,6 @@ const popupTitle = computed(() => {
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const formData = reactive({
|
const formData = reactive({
|
||||||
id: '',
|
id: '',
|
||||||
user_id: '',
|
|
||||||
land_id: '',
|
land_id: '',
|
||||||
code: '',
|
code: '',
|
||||||
name: '',
|
name: '',
|
||||||
|
@ -103,16 +73,6 @@ const formData = reactive({
|
||||||
|
|
||||||
// 表单验证
|
// 表单验证
|
||||||
const formRules = reactive<any>({
|
const formRules = reactive<any>({
|
||||||
user_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入用户id',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
land_id: [{
|
|
||||||
required: true,
|
|
||||||
message: '请输入土地id',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
code: [{
|
code: [{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入产品编号',
|
message: '请输入产品编号',
|
||||||
|
@ -122,12 +82,7 @@ const formRules = reactive<any>({
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入产品名称',
|
message: '请输入产品名称',
|
||||||
trigger: ['blur']
|
trigger: ['blur']
|
||||||
}],
|
}]
|
||||||
status: [{
|
|
||||||
required: true,
|
|
||||||
message: '请选择产品状态',
|
|
||||||
trigger: ['blur']
|
|
||||||
}],
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,30 +110,9 @@ interface ListItem {
|
||||||
value: string
|
value: string
|
||||||
label: string
|
label: string
|
||||||
}
|
}
|
||||||
const userOptions = ref<ListItem[]>([])
|
|
||||||
const loading = ref(false)
|
|
||||||
|
|
||||||
const queryUser = async (query: string) => {
|
|
||||||
if (query) {
|
|
||||||
loading.value = true
|
|
||||||
const userList = await getUserList({
|
|
||||||
keyword: query
|
|
||||||
})
|
|
||||||
loading.value = false
|
|
||||||
if (userList.count > 0) {
|
|
||||||
userOptions.value = userList.lists.map((user: any) => {
|
|
||||||
return { value: `${user.id}`, label: `ID: ${user.id} / 账户: ${user.account}` }
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
loading.value = false
|
|
||||||
} else {
|
|
||||||
userOptions.value = []
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const landOptions = ref<ListItem[]>([])
|
const landOptions = ref<ListItem[]>([])
|
||||||
|
const loading = ref(false)
|
||||||
|
|
||||||
const queryLand = async (query: string) => {
|
const queryLand = async (query: string) => {
|
||||||
if (query) {
|
if (query) {
|
||||||
|
|
|
@ -84,9 +84,9 @@
|
||||||
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
|
<span>{{ row.create_time ? timeFormat(row.create_time, 'yyyy-mm-dd hh:MM:ss') : '' }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</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 }">
|
<template #default="{ row }">
|
||||||
<el-button
|
<el-button
|
||||||
v-perms="['land.product/edit']"
|
v-perms="['land.product/edit']"
|
||||||
type="primary"
|
type="primary"
|
||||||
link
|
link
|
||||||
|
@ -94,6 +94,14 @@
|
||||||
>
|
>
|
||||||
编辑
|
编辑
|
||||||
</el-button>
|
</el-button>
|
||||||
|
<el-button
|
||||||
|
v-perms="['land.product/bind']"
|
||||||
|
type="primary"
|
||||||
|
link
|
||||||
|
@click="handleBind(row)"
|
||||||
|
>
|
||||||
|
绑定设备
|
||||||
|
</el-button>
|
||||||
<el-button v-perms="['device.device/lists']" type="primary" link >
|
<el-button v-perms="['device.device/lists']" type="primary" link >
|
||||||
<router-link
|
<router-link
|
||||||
:to="{
|
:to="{
|
||||||
|
@ -103,8 +111,8 @@
|
||||||
}
|
}
|
||||||
}"
|
}"
|
||||||
>
|
>
|
||||||
查看设备
|
设备信息
|
||||||
</router-link>
|
</router-link>
|
||||||
</el-button>
|
</el-button>
|
||||||
<el-button
|
<el-button
|
||||||
v-perms="['land.product/delete']"
|
v-perms="['land.product/delete']"
|
||||||
|
@ -123,6 +131,7 @@
|
||||||
</div>
|
</div>
|
||||||
</el-card>
|
</el-card>
|
||||||
<edit-popup v-if="showEdit" ref="editRef" :dict-data="dictData" @success="getLists" @close="showEdit = false" />
|
<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>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -134,11 +143,15 @@ import { apiProductLists, apiProductDelete } from '@/api/product'
|
||||||
import { timeFormat } from '@/utils/util'
|
import { timeFormat } from '@/utils/util'
|
||||||
import feedback from '@/utils/feedback'
|
import feedback from '@/utils/feedback'
|
||||||
import EditPopup from './edit.vue'
|
import EditPopup from './edit.vue'
|
||||||
|
import BindPopup from './bind.vue'
|
||||||
|
|
||||||
const { query } = useRoute()
|
const { query } = useRoute()
|
||||||
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
|
||||||
|
|
||||||
|
const bindRef = shallowRef<InstanceType<typeof BindPopup>>()
|
||||||
// 是否显示编辑框
|
// 是否显示编辑框
|
||||||
const showEdit = ref(false)
|
const showEdit = ref(false)
|
||||||
|
const bindEdit = ref(false)
|
||||||
|
|
||||||
let land_id = query.land_id
|
let land_id = query.land_id
|
||||||
if (typeof land_id == 'undefined') {
|
if (typeof land_id == 'undefined') {
|
||||||
|
@ -188,6 +201,14 @@ const handleEdit = async (data: any) => {
|
||||||
editRef.value?.setFormData(data)
|
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[]) => {
|
const handleDelete = async (id: number | any[]) => {
|
||||||
await feedback.confirm('确定要删除?')
|
await feedback.confirm('确定要删除?')
|
||||||
|
|
|
@ -104,5 +104,18 @@ class LandController extends BaseAdminController
|
||||||
return $this->data($result);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,9 +16,9 @@
|
||||||
namespace app\adminapi\controller\land;
|
namespace app\adminapi\controller\land;
|
||||||
|
|
||||||
|
|
||||||
use app\adminapi\controller\BaseAdminController;
|
use app\adminapi\controller\BaseAdminController;
|
||||||
use app\adminapi\lists\land\ProductLists;
|
use app\adminapi\lists\land\ProductLists;
|
||||||
use app\adminapi\logic\land\ProductLogic;
|
use app\adminapi\logic\land\ProductLogic;
|
||||||
use app\adminapi\validate\land\ProductValidate;
|
use app\adminapi\validate\land\ProductValidate;
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,5 +104,17 @@ class ProductController extends BaseAdminController
|
||||||
return $this->data($result);
|
return $this->data($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 绑定产品
|
||||||
|
* @return \think\response\Json
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/11/22 16:35
|
||||||
|
*/
|
||||||
|
public function bind()
|
||||||
|
{
|
||||||
|
$params = (new ProductValidate())->post()->goCheck('bind');
|
||||||
|
ProductLogic::bind($params);
|
||||||
|
return $this->success('绑定成功', [], 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -68,11 +68,15 @@ class LandLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
|
|
||||||
return Land::where($this->searchWhere)->where($this->userSearch())->with('user')
|
return Land::where($this->searchWhere)->where($this->userSearch())->with('user')
|
||||||
->field(['id', 'user_id', 'title', 'total_area', 'residual_area', 'province_code', 'province_name', 'city_code', 'city_name', 'county_code', 'county_name', 'town_code', 'town_name', 'village_code', 'village_name', 'group_code', 'group_name', 'longitude', 'latitude', 'master_name', 'master_phone', 'pic'])
|
->field(['id', 'user_id', 'title', 'address', 'total_area', 'residual_area', 'province_code', 'province_name', 'city_code', 'city_name', 'county_code', 'county_name', 'town_code', 'town_name', 'village_code', 'village_name', 'group_code', 'group_name', 'master_name', 'master_phone', 'pic'])
|
||||||
->limit($this->limitOffset, $this->limitLength)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()
|
->select()->each(function($item, $key){
|
||||||
|
$item['root'] = $this->adminInfo['root'] ?? 0;
|
||||||
|
return $item;
|
||||||
|
})
|
||||||
->toArray();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,26 +43,31 @@ class DeviceLogic extends BaseLogic
|
||||||
} else {
|
} else {
|
||||||
$params['monitor_item'] = trim($params['monitor_item']);
|
$params['monitor_item'] = trim($params['monitor_item']);
|
||||||
}
|
}
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
if (!empty($params['product_id'])) {
|
||||||
|
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$device = Device::create([
|
$device = Device::create([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
'monitor_item' => $params['monitor_item'],
|
'monitor_item' => $params['monitor_item'],
|
||||||
'video_url' => $params['video_url'],
|
'video_url' => $params['video_url'],
|
||||||
'status' => $params['status'],
|
'status' => $params['status'],
|
||||||
'is_online' => $params['is_online'],
|
'is_online' => $params['is_online']
|
||||||
'is_bind' => $params['is_bind'],
|
|
||||||
]);
|
|
||||||
Db::name('product_device')->insert([
|
|
||||||
'product_id' => $params['product_id'],
|
|
||||||
'device_id' => $device['id'],
|
|
||||||
'device_type' => $params['type'],
|
|
||||||
'create_time' => time(),
|
|
||||||
'update_time' => time()
|
|
||||||
]);
|
]);
|
||||||
|
if (!empty($params['product_id'])) {
|
||||||
|
Db::name('product_device')->insert([
|
||||||
|
'product_id' => $params['product_id'],
|
||||||
|
'device_id' => $device['id'],
|
||||||
|
'device_type' => $params['type'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time()
|
||||||
|
]);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -87,27 +92,32 @@ class DeviceLogic extends BaseLogic
|
||||||
} else {
|
} else {
|
||||||
$params['monitor_item'] = trim($params['monitor_item']);
|
$params['monitor_item'] = trim($params['monitor_item']);
|
||||||
}
|
}
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
if (!empty($params['product_id'])) {
|
||||||
|
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$device = Device::where('id', $params['id'])->update([
|
$device = Device::where('id', $params['id'])->update([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
'monitor_item' => $params['monitor_item'],
|
'monitor_item' => $params['monitor_item'],
|
||||||
'video_url' => $params['video_url'],
|
'video_url' => $params['video_url'],
|
||||||
'status' => $params['status'],
|
'status' => $params['status'],
|
||||||
'is_online' => $params['is_online'],
|
'is_online' => $params['is_online']
|
||||||
'is_bind' => $params['is_bind'],
|
|
||||||
]);
|
]);
|
||||||
Db::name('product_device')->where('device_id', $params['id'])->delete();
|
Db::name('product_device')->where('device_id', $params['id'])->delete();
|
||||||
Db::name('product_device')->insert([
|
if (!empty($params['product_id'])) {
|
||||||
'product_id' => $params['product_id'],
|
Db::name('product_device')->insert([
|
||||||
'device_id' => $params['id'],
|
'product_id' => $params['product_id'],
|
||||||
'device_type' => $params['type'],
|
'device_id' => $params['id'],
|
||||||
'create_time' => time(),
|
'device_type' => $params['type'],
|
||||||
'update_time' => time()
|
'create_time' => time(),
|
||||||
]);
|
'update_time' => time()
|
||||||
|
]);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
|
@ -38,11 +38,16 @@ class LandLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
if (!empty($params['user_id'])) {
|
||||||
|
$userId = $params['user_id'];
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Land::create([
|
Land::create([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'title' => $params['title'],
|
'title' => $params['title'],
|
||||||
|
'address' => $params['address'],
|
||||||
'total_area' => $params['total_area'],
|
'total_area' => $params['total_area'],
|
||||||
'residual_area' => $params['residual_area'],
|
'residual_area' => $params['residual_area'],
|
||||||
'province_code' => $params['province_code'],
|
'province_code' => $params['province_code'],
|
||||||
|
@ -57,8 +62,6 @@ class LandLogic extends BaseLogic
|
||||||
'village_name' => $params['village_name'],
|
'village_name' => $params['village_name'],
|
||||||
'group_code' => $params['group_code'],
|
'group_code' => $params['group_code'],
|
||||||
'group_name' => $params['group_name'],
|
'group_name' => $params['group_name'],
|
||||||
'longitude' => $params['longitude'],
|
|
||||||
'latitude' => $params['latitude'],
|
|
||||||
'master_name' => $params['master_name'],
|
'master_name' => $params['master_name'],
|
||||||
'master_phone' => $params['master_phone'],
|
'master_phone' => $params['master_phone'],
|
||||||
'pic' => json_encode($params['pic']),
|
'pic' => json_encode($params['pic']),
|
||||||
|
@ -83,11 +86,16 @@ class LandLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
if (!empty($params['user_id'])) {
|
||||||
|
$userId = $params['user_id'];
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Land::where('id', $params['id'])->update([
|
Land::where('id', $params['id'])->update([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'title' => $params['title'],
|
'title' => $params['title'],
|
||||||
|
'address' => $params['address'],
|
||||||
'total_area' => $params['total_area'],
|
'total_area' => $params['total_area'],
|
||||||
'residual_area' => $params['residual_area'],
|
'residual_area' => $params['residual_area'],
|
||||||
'province_code' => $params['province_code'],
|
'province_code' => $params['province_code'],
|
||||||
|
@ -101,9 +109,7 @@ class LandLogic extends BaseLogic
|
||||||
'village_code' => $params['village_code'],
|
'village_code' => $params['village_code'],
|
||||||
'village_name' => $params['village_name'],
|
'village_name' => $params['village_name'],
|
||||||
'group_code' => $params['group_code'],
|
'group_code' => $params['group_code'],
|
||||||
'group_name' => $params['group_name'],
|
'group_name' => $params['group_name'],
|
||||||
'longitude' => $params['longitude'],
|
|
||||||
'latitude' => $params['latitude'],
|
|
||||||
'master_name' => $params['master_name'],
|
'master_name' => $params['master_name'],
|
||||||
'master_phone' => $params['master_phone'],
|
'master_phone' => $params['master_phone'],
|
||||||
'pic' => json_encode($params['pic']),
|
'pic' => json_encode($params['pic']),
|
||||||
|
@ -143,4 +149,33 @@ class LandLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
return Land::findOrEmpty($params['id'])->toArray();
|
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,
|
||||||
|
'status' => 2
|
||||||
|
]);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -38,10 +38,11 @@ class LandPlantActionLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = Db::name('land_plant')->where('id', $params['plant_id'])->value('user_id');
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
LandPlantAction::create([
|
LandPlantAction::create([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'plant_id' => $params['plant_id'],
|
'plant_id' => $params['plant_id'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
'type_text' => $params['type_text'],
|
'type_text' => $params['type_text'],
|
||||||
|
@ -67,10 +68,11 @@ class LandPlantActionLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = Db::name('land_plant')->where('id', $params['plant_id'])->value('user_id');
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
LandPlantAction::where('id', $params['id'])->update([
|
LandPlantAction::where('id', $params['id'])->update([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'plant_id' => $params['plant_id'],
|
'plant_id' => $params['plant_id'],
|
||||||
'type' => $params['type'],
|
'type' => $params['type'],
|
||||||
'type_text' => $params['type_text'],
|
'type_text' => $params['type_text'],
|
||||||
|
|
|
@ -28,7 +28,6 @@ use think\facade\Db;
|
||||||
class LandPlantLogic extends BaseLogic
|
class LandPlantLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 添加
|
* @notes 添加
|
||||||
* @param array $params
|
* @param array $params
|
||||||
|
@ -38,10 +37,11 @@ class LandPlantLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
LandPlant::create([
|
LandPlant::create([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'land_id' => $params['land_id'],
|
'land_id' => $params['land_id'],
|
||||||
'kind' => $params['kind'],
|
'kind' => $params['kind'],
|
||||||
'breed' => $params['breed'],
|
'breed' => $params['breed'],
|
||||||
|
@ -73,10 +73,11 @@ class LandPlantLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
LandPlant::where('id', $params['id'])->update([
|
LandPlant::where('id', $params['id'])->update([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'land_id' => $params['land_id'],
|
'land_id' => $params['land_id'],
|
||||||
'kind' => $params['kind'],
|
'kind' => $params['kind'],
|
||||||
'breed' => $params['breed'],
|
'breed' => $params['breed'],
|
||||||
|
|
|
@ -38,20 +38,28 @@ class ProductLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
$status = 1;
|
||||||
|
if (!empty($params['land_id'])) {
|
||||||
|
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
|
||||||
|
$status = 2;
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
$product = Product::create([
|
$product = Product::create([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'status' => $params['status'],
|
'status' => $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();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -71,21 +79,29 @@ class ProductLogic extends BaseLogic
|
||||||
*/
|
*/
|
||||||
public static function edit(array $params): bool
|
public static function edit(array $params): bool
|
||||||
{
|
{
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
$status = 1;
|
||||||
|
if (!empty($params['land_id'])) {
|
||||||
|
$userId = Db::name('land')->where('id', $params['land_id'])->value('user_id');
|
||||||
|
$status = 2;
|
||||||
|
}
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
Product::where('id', $params['id'])->update([
|
Product::where('id', $params['id'])->update([
|
||||||
'user_id' => $params['user_id'],
|
'user_id' => $userId,
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
'name' => $params['name'],
|
'name' => $params['name'],
|
||||||
'status' => $params['status'],
|
'status' => $status,
|
||||||
]);
|
]);
|
||||||
Db::name('land_product')->where('product_id', $params['id'])->delete();
|
Db::name('land_product')->where('product_id', $params['id'])->delete();
|
||||||
Db::name('land_product')->insert([
|
if (!empty($params['land_id'])) {
|
||||||
'land_id' => $params['land_id'],
|
Db::name('land_product')->insert([
|
||||||
'product_id' => $params['id'],
|
'land_id' => $params['land_id'],
|
||||||
'create_time' => time(),
|
'product_id' => $params['id'],
|
||||||
'update_time' => time()
|
'create_time' => time(),
|
||||||
]);
|
'update_time' => time()
|
||||||
|
]);
|
||||||
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
@ -122,4 +138,38 @@ class ProductLogic extends BaseLogic
|
||||||
{
|
{
|
||||||
return Product::findOrEmpty($params['id'])->toArray();
|
return Product::findOrEmpty($params['id'])->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function bind($params): bool
|
||||||
|
{
|
||||||
|
$userId = (request()->adminInfo)['user_id'];
|
||||||
|
if (!empty($params['id'])) {
|
||||||
|
$userId = Db::name('product')->where('id', $params['id'])->value('user_id');
|
||||||
|
}
|
||||||
|
Db::startTrans();
|
||||||
|
try {
|
||||||
|
Db::name('product_device')->whereIn('device_id', $params['device_id'])->delete();
|
||||||
|
Db::name('product_device')->where('product_id', $params['id'])->delete();
|
||||||
|
Db::name('device')->whereIn('id', $params['device_id'])->update([
|
||||||
|
'user_id' => $userId
|
||||||
|
]);
|
||||||
|
$deviceList = Db::name('device')->whereIn('id', $params['device_id'])->select()->toArray();
|
||||||
|
$insertData = [];
|
||||||
|
foreach($deviceList as $d) {
|
||||||
|
$insertData[] = [
|
||||||
|
'product_id' => $params['id'],
|
||||||
|
'device_id' => $d['id'],
|
||||||
|
'device_type' => $d['type'],
|
||||||
|
'create_time' => time(),
|
||||||
|
'update_time' => time()
|
||||||
|
];
|
||||||
|
}
|
||||||
|
Db::name('product_device')->insertAll($insertData);
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
self::setError($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -33,10 +33,10 @@ class LandValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
'user_id' => 'require',
|
'product_id' => 'require',
|
||||||
'title' => 'require',
|
'title' => 'require',
|
||||||
'total_area' => 'require',
|
'address' => 'require',
|
||||||
'residual_area' => 'require',
|
'residual_area' => 'checkArea',
|
||||||
'province_code' => 'require',
|
'province_code' => 'require',
|
||||||
'province_name' => 'require',
|
'province_name' => 'require',
|
||||||
'city_code' => 'require',
|
'city_code' => 'require',
|
||||||
|
@ -62,8 +62,8 @@ class LandValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
protected $field = [
|
protected $field = [
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'user_id' => '用户id',
|
|
||||||
'title' => '土地名称',
|
'title' => '土地名称',
|
||||||
|
'address' => '详细地址',
|
||||||
'total_area' => '土地面积',
|
'total_area' => '土地面积',
|
||||||
'residual_area' => '剩余面积',
|
'residual_area' => '剩余面积',
|
||||||
'province_code' => '省编码',
|
'province_code' => '省编码',
|
||||||
|
@ -82,7 +82,7 @@ class LandValidate extends BaseValidate
|
||||||
'latitude' => '纬度',
|
'latitude' => '纬度',
|
||||||
'master_name' => '土地负责人',
|
'master_name' => '土地负责人',
|
||||||
'master_phone' => '负责人电话',
|
'master_phone' => '负责人电话',
|
||||||
'status' => '土地状态1-未种植 2-部分种植 3-全部种植',
|
'status' => '土地状态',
|
||||||
'pic' => '土地图片',
|
'pic' => '土地图片',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ class LandValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['user_id','title','master_name','master_phone']);
|
return $this->only(['title','address','residual_area','master_name','master_phone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ class LandValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id','user_id','title','master_name','master_phone']);
|
return $this->only(['id','title','address','residual_area','master_name','master_phone']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,4 +143,25 @@ class LandValidate extends BaseValidate
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 绑定产品
|
||||||
|
* @return LandValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/11/22 16:35
|
||||||
|
*/
|
||||||
|
public function sceneBind()
|
||||||
|
{
|
||||||
|
return $this->only(['id', 'product_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkArea($value, $rule, $data)
|
||||||
|
{
|
||||||
|
if (!empty($data['total_area']) && !empty($data['residual_area'])) {
|
||||||
|
if ($data['residual_area'] > $data['total_area']) {
|
||||||
|
return '剩余面积不能大于总面积';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -32,23 +32,19 @@ class ProductValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'id' => 'require',
|
||||||
'user_id' => 'require',
|
'device_id' => 'require',
|
||||||
'code' => 'require',
|
'code' => 'require',
|
||||||
'name' => 'require',
|
'name' => 'require',
|
||||||
'status' => 'require',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 参数描述
|
* 参数描述
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
protected $field = [
|
protected $field = [
|
||||||
'id' => 'id',
|
'id' => 'id',
|
||||||
'user_id' => '用户id',
|
|
||||||
'code' => '产品编号',
|
'code' => '产品编号',
|
||||||
'name' => '产品名称',
|
'name' => '产品名称',
|
||||||
'status' => '产品状态',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +56,7 @@ class ProductValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
public function sceneAdd()
|
||||||
{
|
{
|
||||||
return $this->only(['user_id','code','name','status']);
|
return $this->only(['code','name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +68,7 @@ class ProductValidate extends BaseValidate
|
||||||
*/
|
*/
|
||||||
public function sceneEdit()
|
public function sceneEdit()
|
||||||
{
|
{
|
||||||
return $this->only(['id','user_id','code','name','status']);
|
return $this->only(['id','code','name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,4 +104,15 @@ class ProductValidate extends BaseValidate
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 绑定设备
|
||||||
|
* @return LandValidate
|
||||||
|
* @author likeadmin
|
||||||
|
* @date 2023/11/22 16:35
|
||||||
|
*/
|
||||||
|
public function sceneBind()
|
||||||
|
{
|
||||||
|
return $this->only(['id', 'device_id']);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue