Merge branch 'temp' of https://gitea.peidikeji.cn/zhouhui/lcny-vue3-antd-admin into temp
commit
f8d35946cb
|
|
@ -248,17 +248,17 @@ export function editPassword(id: string, data, mode: ErrorMessageMode = 'modal')
|
|||
/**
|
||||
* @description:获取农作物
|
||||
*/
|
||||
export function getCrops(data, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.get(
|
||||
{
|
||||
url: `/api/crops`,
|
||||
data,
|
||||
},
|
||||
{
|
||||
errorMessageMode: mode,
|
||||
},
|
||||
)
|
||||
}
|
||||
// export function getCrops(data, mode: ErrorMessageMode = 'modal') {
|
||||
// return defHttp.get(
|
||||
// {
|
||||
// url: `/api/crops`,
|
||||
// data,
|
||||
// },
|
||||
// {
|
||||
// errorMessageMode: mode,
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
|
||||
/**
|
||||
* @description:新增区域数据
|
||||
|
|
@ -357,10 +357,13 @@ export function addcrops(data, mode: ErrorMessageMode = 'modal') {
|
|||
)
|
||||
}
|
||||
|
||||
export function getCropYields(data, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.post(
|
||||
/**
|
||||
* @description:修改农作物
|
||||
*/
|
||||
export function editcrops(id: string, data, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.put(
|
||||
{
|
||||
url: `/api/crops`,
|
||||
url: `/api/crops/${id}`,
|
||||
data,
|
||||
},
|
||||
{
|
||||
|
|
@ -368,3 +371,31 @@ export function getCropYields(data, mode: ErrorMessageMode = 'modal') {
|
|||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description:删除农作物
|
||||
*/
|
||||
export function deleteCrops(id: string, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.delete(
|
||||
{
|
||||
url: `/api/crops/${id}`,
|
||||
},
|
||||
{
|
||||
errorMessageMode: mode,
|
||||
},
|
||||
)
|
||||
}
|
||||
/**
|
||||
* @description:稻虾价格 - 列表
|
||||
*/
|
||||
export function getShrimpPrices(params, mode: ErrorMessageMode = 'modal') {
|
||||
return defHttp.get(
|
||||
{
|
||||
url: `/api/rice-shrimp-prices`,
|
||||
params,
|
||||
},
|
||||
{
|
||||
errorMessageMode: mode,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ const main: AppRouteModule = {
|
|||
{
|
||||
path: 'basics-crop',
|
||||
name: 'BasicsCrop',
|
||||
component: () => import('/@/views/base/base-data/index.vue'),
|
||||
component: () => import('/@/views/base/crops/base-crops/index.vue'),
|
||||
meta: {
|
||||
title: '基地农作物',
|
||||
},
|
||||
|
|
@ -74,7 +74,7 @@ const main: AppRouteModule = {
|
|||
{
|
||||
path: 'town-yield',
|
||||
name: 'TownYield',
|
||||
component: () => import('/@/views/base/city-data/index.vue'),
|
||||
component: () => import('/@/views/base/ranking-list/index1.vue'),
|
||||
meta: {
|
||||
title: '城镇产量',
|
||||
},
|
||||
|
|
@ -82,7 +82,7 @@ const main: AppRouteModule = {
|
|||
{
|
||||
path: 'basics-yield',
|
||||
name: 'BasicsYield',
|
||||
component: () => import('/@/views/base/base-data/index.vue'),
|
||||
component: () => import('/@/views/base/ranking-list/index1.vue'),
|
||||
meta: {
|
||||
title: '基地产量',
|
||||
},
|
||||
|
|
@ -90,17 +90,17 @@ const main: AppRouteModule = {
|
|||
],
|
||||
},
|
||||
{
|
||||
path: 'industry',
|
||||
name: 'Industry',
|
||||
path: 'estate',
|
||||
name: 'estate',
|
||||
meta: {
|
||||
title: '重点产业',
|
||||
// icon: 'ion:key-outline',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: 'industry-price',
|
||||
name: 'IndustryPrice',
|
||||
component: () => import('/@/views/base/city-data/index.vue'),
|
||||
path: 'estate-price',
|
||||
name: 'EstatePrice',
|
||||
component: () => import('/@/views/base/estate/shrim-price/index.vue'),
|
||||
meta: {
|
||||
title: '稻虾价格',
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { BasicColumn } from '/@/components/Table'
|
||||
import { FormSchema } from '/@/components/Table'
|
||||
import { getCrops } from '/@/api/sys/user'
|
||||
import { getcrops, getTownAgriculturalBasic } from '/@/api/sys/user'
|
||||
export const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '基地名称',
|
||||
|
|
@ -66,12 +66,7 @@ export const accountFormSchema: FormSchema[] = [
|
|||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'address',
|
||||
label: '基地地址',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
|
||||
{
|
||||
field: 'person',
|
||||
label: '基地负责人',
|
||||
|
|
@ -90,6 +85,20 @@ export const accountFormSchema: FormSchema[] = [
|
|||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'parent_id',
|
||||
label: '城镇',
|
||||
required: true,
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: async () => {
|
||||
const res = await getTownAgriculturalBasic({ type: 2 })
|
||||
return res
|
||||
},
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'crops_ids',
|
||||
label: '基地农作物',
|
||||
|
|
@ -97,11 +106,11 @@ export const accountFormSchema: FormSchema[] = [
|
|||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: async () => {
|
||||
const res = await getCrops({ type: 'all', crop_type: 1 })
|
||||
const res = await getcrops({ type: 'all', crop_type: 1 })
|
||||
return res.map((e) => {
|
||||
return {
|
||||
...e,
|
||||
disabled: e.is_end === 1,
|
||||
disabled: e.is_end === 0,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
|
@ -110,7 +119,12 @@ export const accountFormSchema: FormSchema[] = [
|
|||
mode: 'multiple',
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
field: 'address',
|
||||
label: '基地地址',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
label: '基地介绍',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,216 @@
|
|||
<template>
|
||||
<BasicDrawer
|
||||
v-bind="$attrs"
|
||||
@register="registerDrawer"
|
||||
showFooter
|
||||
:title="getTitle"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<!-- <BasicForm @register="registerForm"> </BasicForm> -->
|
||||
<Form class="w-full" :label-col="{ span: 4 }" ref="formRef" :model="modelRef">
|
||||
<FormItem
|
||||
label="产业"
|
||||
name="category_id"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请选择产业',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Select
|
||||
v-model:value="modelRef.category_id"
|
||||
placeholder="请选择产业"
|
||||
class="w-full"
|
||||
:options="categoryDate"
|
||||
:fieldNames="{ label: 'name', value: 'id' }"
|
||||
></Select>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="名称"
|
||||
name="name"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入名称',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.name" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="上级">
|
||||
<Select
|
||||
:options="parentDate"
|
||||
:fieldNames="{ label: 'name', value: 'id' }"
|
||||
v-model:value="modelRef.parent_id"
|
||||
placeholder="请选择"
|
||||
class="w-full"
|
||||
></Select>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="单位"
|
||||
name="unit"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入单位',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.unit" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="排序"
|
||||
name="sort"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入排序',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.sort" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="是否是结点" name="is_end">
|
||||
<Switch v-model:checked="modelRef.is_end" placeholder="请选择"></Switch>
|
||||
</FormItem>
|
||||
<!-- -->
|
||||
<template v-if="modelRef.is_end">
|
||||
<Space
|
||||
v-for="(sight, index) in modelRef.extends"
|
||||
:key="index"
|
||||
style="display: flex; margin-bottom: 8px"
|
||||
align="baseline"
|
||||
>
|
||||
<FormItem
|
||||
label="名称"
|
||||
:name="['extends', index, 'name']"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入名称',
|
||||
trigger: 'change',
|
||||
}"
|
||||
:label-col="{ span: 8 }"
|
||||
>
|
||||
<Input v-model:value="sight.name" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="单位"
|
||||
:name="['extends', index, 'unit']"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入单位',
|
||||
trigger: 'change',
|
||||
}"
|
||||
:label-col="{ span: 8 }"
|
||||
>
|
||||
<Input v-model:value="sight.unit" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<MinusCircleOutlined
|
||||
@click="removeSight(sight)"
|
||||
v-if="modelRef.extends.length > 1"
|
||||
:disabled="modelRef.extends.length === 1"
|
||||
/>
|
||||
</Space>
|
||||
<FormItem>
|
||||
<div class="flex items-center justify-center w-full px-80px">
|
||||
<Button type="dashed" block @click="addSight">
|
||||
<PlusOutlined />
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</FormItem>
|
||||
</template>
|
||||
</Form>
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'
|
||||
import { Form, Select, FormItem, Input, Switch, Button, Space } from 'ant-design-vue'
|
||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { getCropCate, addcrops, getcrops, editcrops } from '/@/api/sys/user'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
const formRef = ref<FormInstance>()
|
||||
const categoryDate = ref([])
|
||||
const parentDate = ref([])
|
||||
const modelRef = ref({
|
||||
id: null,
|
||||
category_id: undefined, //产业ID
|
||||
name: '', //名称
|
||||
parent_id: undefined, //上级
|
||||
unit: '', //单位
|
||||
is_end: false, //是否是结点
|
||||
extends: [{ name: '', unit: '' }],
|
||||
sort: '', //排序
|
||||
})
|
||||
|
||||
const addSight = () => {
|
||||
modelRef?.value.extends.push({
|
||||
name: '',
|
||||
unit: '',
|
||||
})
|
||||
}
|
||||
const removeSight = (item: any) => {
|
||||
let index = modelRef.value.extends.indexOf(item)
|
||||
if (index !== -1) {
|
||||
modelRef.value.extends.splice(index, 1)
|
||||
}
|
||||
}
|
||||
const emits = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(false)
|
||||
const getTitle = computed(() => (!isUpdate.value ? '新增农作物' : '编辑农作物'))
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||
formRef.value?.resetFields()
|
||||
// 获取产业
|
||||
const res = await getCropCate()
|
||||
categoryDate.value = res
|
||||
//获取上级数据
|
||||
const resDate = await getcrops({ page: 1, per_page: 99999, crop_type: 1, type: 'all' })
|
||||
parentDate.value = resDate.filter((e) => !e.is_end)
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
isUpdate.value = data?.isUpdate
|
||||
if (unref(isUpdate)) {
|
||||
modelRef.value = {
|
||||
category_id: data.category_id,
|
||||
name: data.name,
|
||||
parent_id: data.parent_id == 0 ? undefined : data.parent_id,
|
||||
unit: data.unit,
|
||||
is_end: data.is_end == 1 ? true : false,
|
||||
extends: data.extends.length ? JSON.parse(data.extends) : [],
|
||||
sort: data.sort,
|
||||
id: data.id,
|
||||
}
|
||||
} else {
|
||||
modelRef.value = {
|
||||
id: null,
|
||||
category_id: undefined, //产业ID
|
||||
name: '', //名称
|
||||
parent_id: undefined, //上级
|
||||
unit: '', //单位
|
||||
is_end: false, //是否是结点
|
||||
extends: [{ name: '', unit: '' }],
|
||||
sort: '', //排序
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const values = await formRef.value?.validate()
|
||||
const params = {
|
||||
crop_type: 1,
|
||||
...values,
|
||||
}
|
||||
setDrawerProps({ confirmLoading: true })
|
||||
if (modelRef.value.id) {
|
||||
// 修改
|
||||
await editcrops(modelRef.value.id, params)
|
||||
} else {
|
||||
// 新增
|
||||
await addcrops(params)
|
||||
}
|
||||
closeDrawer()
|
||||
emits('success')
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
import { BasicColumn } from '/@/components/Table'
|
||||
import { FormSchema } from '/@/components/Table'
|
||||
export const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '单位',
|
||||
dataIndex: 'unit',
|
||||
},
|
||||
{
|
||||
title: '是否是结点',
|
||||
dataIndex: 'is_end',
|
||||
customRender: ({ text }) => {
|
||||
return text == 1 ? '是' : '否'
|
||||
},
|
||||
},
|
||||
{
|
||||
width: 180,
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
align: 'center',
|
||||
fixed: undefined,
|
||||
},
|
||||
]
|
||||
|
||||
export const searchFormSchema: FormSchema[] = []
|
||||
|
||||
export const accountFormSchema: FormSchema[] = []
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<template>
|
||||
<div class="pt-20px">
|
||||
<BasicTable @register="registerTable">
|
||||
<template #toolbar>
|
||||
<a-button type="primary" @click="handleCreate"> 新增农作物 </a-button>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<div class="flex items-center justify-center">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{ label: '编辑', onClick: handleEdit.bind(null, record) },
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
placement: 'topRight',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="column.key === 'crops'">
|
||||
<Button
|
||||
class="mx-2px"
|
||||
v-for="(item, index) in record['crops']"
|
||||
:key="index"
|
||||
type="link"
|
||||
>{{ item.name }}</Button
|
||||
>
|
||||
</template>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<TownDrawer @register="registerDrawer" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table'
|
||||
import { deleteCrops, getcrops } from '/@/api/sys/user'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useDrawer } from '/@/components/Drawer'
|
||||
import TownDrawer from './BaseDrawer.vue'
|
||||
import { Button } from 'ant-design-vue'
|
||||
import { columns, searchFormSchema } from './base.data'
|
||||
const [registerDrawer, { openDrawer }] = useDrawer()
|
||||
const [registerTable, { reload }] = useTable({
|
||||
title: '基地农作物列表',
|
||||
api: async (e) => {
|
||||
const res = await getcrops({ type: 'all', ...e, crop_type: 1 })
|
||||
return res
|
||||
},
|
||||
rowKey: 'id',
|
||||
columns,
|
||||
formConfig: {
|
||||
labelWidth: 120,
|
||||
schemas: searchFormSchema,
|
||||
},
|
||||
useSearchForm: false,
|
||||
showTableSetting: true,
|
||||
bordered: true,
|
||||
showIndexColumn: true,
|
||||
})
|
||||
|
||||
const handleSuccess = () => {
|
||||
message.success('操作成功')
|
||||
reload()
|
||||
}
|
||||
const handleCreate = () => {
|
||||
openDrawer(true, {
|
||||
isUpdate: false,
|
||||
})
|
||||
}
|
||||
const handleEdit = (record: Recordable) => {
|
||||
openDrawer(true, {
|
||||
...record,
|
||||
isUpdate: true,
|
||||
})
|
||||
}
|
||||
const handleDelete = async (record: Recordable) => {
|
||||
await deleteCrops(record.id)
|
||||
message.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
</script>
|
||||
|
|
@ -8,108 +8,209 @@
|
|||
@ok="handleSubmit"
|
||||
>
|
||||
<!-- <BasicForm @register="registerForm"> </BasicForm> -->
|
||||
<Form> </Form>
|
||||
<Form class="w-full" :label-col="{ span: 4 }" ref="formRef" :model="modelRef">
|
||||
<FormItem
|
||||
label="产业"
|
||||
name="category_id"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请选择产业',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Select
|
||||
v-model:value="modelRef.category_id"
|
||||
placeholder="请选择产业"
|
||||
class="w-full"
|
||||
:options="categoryDate"
|
||||
:fieldNames="{ label: 'name', value: 'id' }"
|
||||
></Select>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="名称"
|
||||
name="name"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入名称',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.name" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="上级">
|
||||
<Select
|
||||
:options="parentDate"
|
||||
:fieldNames="{ label: 'name', value: 'id' }"
|
||||
v-model:value="modelRef.parent_id"
|
||||
placeholder="请选择"
|
||||
class="w-full"
|
||||
></Select>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="单位"
|
||||
name="unit"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入单位',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.unit" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="排序"
|
||||
name="sort"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入排序',
|
||||
trigger: 'change',
|
||||
}"
|
||||
>
|
||||
<Input v-model:value="modelRef.sort" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem label="是否是结点" name="is_end">
|
||||
<Switch v-model:checked="modelRef.is_end" placeholder="请选择"></Switch>
|
||||
</FormItem>
|
||||
<!-- -->
|
||||
<template v-if="modelRef.is_end">
|
||||
<Space
|
||||
v-for="(sight, index) in modelRef.extends"
|
||||
:key="index"
|
||||
style="display: flex; margin-bottom: 8px"
|
||||
align="baseline"
|
||||
>
|
||||
<FormItem
|
||||
label="名称"
|
||||
:name="['extends', index, 'name']"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入名称',
|
||||
trigger: 'change',
|
||||
}"
|
||||
:label-col="{ span: 8 }"
|
||||
>
|
||||
<Input v-model:value="sight.name" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<FormItem
|
||||
label="单位"
|
||||
:name="['extends', index, 'unit']"
|
||||
:rules="{
|
||||
required: true,
|
||||
message: '请输入单位',
|
||||
trigger: 'change',
|
||||
}"
|
||||
:label-col="{ span: 8 }"
|
||||
>
|
||||
<Input v-model:value="sight.unit" placeholder="请输入" class="w-full"></Input>
|
||||
</FormItem>
|
||||
<MinusCircleOutlined
|
||||
@click="removeSight(sight)"
|
||||
v-if="modelRef.extends.length > 1"
|
||||
:disabled="modelRef.extends.length === 1"
|
||||
/>
|
||||
</Space>
|
||||
<FormItem>
|
||||
<div class="flex items-center justify-center w-full px-80px">
|
||||
<Button type="dashed" block @click="addSight">
|
||||
<PlusOutlined />
|
||||
添加
|
||||
</Button>
|
||||
</div>
|
||||
</FormItem>
|
||||
</template>
|
||||
</Form>
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref, reactive } from 'vue'
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'
|
||||
import { Form } from 'ant-design-vue'
|
||||
const useForm = Form.useForm
|
||||
const modelRef = reactive({
|
||||
category_id: '', //产业ID
|
||||
import { Form, Select, FormItem, Input, Switch, Button, Space } from 'ant-design-vue'
|
||||
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons-vue'
|
||||
import { getCropCate, addcrops, getcrops, editcrops } from '/@/api/sys/user'
|
||||
import type { FormInstance } from 'ant-design-vue'
|
||||
const formRef = ref<FormInstance>()
|
||||
const categoryDate = ref([])
|
||||
const parentDate = ref([])
|
||||
const modelRef = ref({
|
||||
id: null,
|
||||
category_id: undefined, //产业ID
|
||||
name: '', //名称
|
||||
parent_id: '', //上级
|
||||
parent_id: undefined, //上级
|
||||
unit: '', //单位
|
||||
is_end: '', //是否是结点
|
||||
extends: [],
|
||||
is_end: false, //是否是结点
|
||||
extends: [{ name: '', unit: '' }],
|
||||
sort: '', //排序
|
||||
})
|
||||
const rulesRef = reactive({
|
||||
category_id: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择',
|
||||
},
|
||||
],
|
||||
name: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入',
|
||||
},
|
||||
],
|
||||
unit: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入',
|
||||
},
|
||||
],
|
||||
sort: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入',
|
||||
},
|
||||
],
|
||||
})
|
||||
const { resetFields, validate, validateInfos } = useForm(modelRef, rulesRef)
|
||||
|
||||
// import { BasicForm, useForm } from '/@/components/Form/index'
|
||||
// import { accountFormSchema } from './town.data'
|
||||
|
||||
// import { addcrops, editGriculturalBasic } from '/@/api/sys/user'
|
||||
|
||||
const addSight = () => {
|
||||
modelRef?.value.extends.push({
|
||||
name: '',
|
||||
unit: '',
|
||||
})
|
||||
}
|
||||
const removeSight = (item: any) => {
|
||||
let index = modelRef.value.extends.indexOf(item)
|
||||
if (index !== -1) {
|
||||
modelRef.value.extends.splice(index, 1)
|
||||
}
|
||||
}
|
||||
const emits = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(false)
|
||||
const getTitle = computed(() => (!isUpdate.value ? '新增农作物' : '编辑农作物'))
|
||||
// const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
||||
// labelWidth: 90,
|
||||
// baseColProps: { span: 24 },
|
||||
// schemas: accountFormSchema,
|
||||
// showActionButtonGroup: false,
|
||||
// })
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||
// resetFields()
|
||||
formRef.value?.resetFields()
|
||||
// 获取产业
|
||||
const res = await getCropCate()
|
||||
categoryDate.value = res
|
||||
//获取上级数据
|
||||
const resDate = await getcrops({ page: 1, per_page: 99999, crop_type: 2, type: 'all' })
|
||||
parentDate.value = resDate.filter((e) => !e.is_end)
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
isUpdate.value = data?.isUpdate
|
||||
if (unref(isUpdate)) {
|
||||
// setFieldsValue({
|
||||
// ...data,
|
||||
// crops_ids: data.crops.map((e) => e.id),
|
||||
// })
|
||||
modelRef.value = {
|
||||
category_id: data.category_id,
|
||||
name: data.name,
|
||||
parent_id: data.parent_id == 0 ? undefined : data.parent_id,
|
||||
unit: data.unit,
|
||||
is_end: data.is_end ? true : false,
|
||||
extends: data.extends.length ? JSON.parse(data.extends) : [],
|
||||
sort: data.sort,
|
||||
id: data.id,
|
||||
}
|
||||
} else {
|
||||
modelRef.value = {
|
||||
id: null,
|
||||
category_id: undefined, //产业ID
|
||||
name: '', //名称
|
||||
parent_id: undefined, //上级
|
||||
unit: '', //单位
|
||||
is_end: false, //是否是结点
|
||||
extends: [{ name: '', unit: '' }],
|
||||
sort: '', //排序
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const handleSubmit = async () => {
|
||||
// try {
|
||||
// const values = await validate()
|
||||
// values.crop_type = 2
|
||||
// values.is_end = values?.is_end ?? false
|
||||
// const params = {
|
||||
// ...values,
|
||||
// extends: {
|
||||
// name: '',
|
||||
// unit: '',
|
||||
// },
|
||||
// }
|
||||
// if (values.is_end) {
|
||||
// params.extends.name = values.endName
|
||||
// params.extends.unit = values.endUnit
|
||||
// } else {
|
||||
// delete params.extends
|
||||
// }
|
||||
// console.log(params)
|
||||
// setDrawerProps({ confirmLoading: true })
|
||||
// if (values.id) {
|
||||
// // 修改
|
||||
// await editGriculturalBasic(values.id, values)
|
||||
// } else {
|
||||
// // 新增
|
||||
// await addcrops(params)
|
||||
// }
|
||||
// closeDrawer()
|
||||
// emits('success')
|
||||
// } finally {
|
||||
// setDrawerProps({ confirmLoading: false })
|
||||
// }
|
||||
try {
|
||||
const values = await formRef.value?.validate()
|
||||
const params = {
|
||||
crop_type: 2,
|
||||
...values,
|
||||
}
|
||||
setDrawerProps({ confirmLoading: true })
|
||||
if (modelRef.value.id) {
|
||||
// 修改
|
||||
await editcrops(modelRef.value.id, params)
|
||||
} else {
|
||||
// 新增
|
||||
await addcrops(params)
|
||||
}
|
||||
closeDrawer()
|
||||
emits('success')
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table'
|
||||
import { deleteGriculturalBasic, getTownAgriculturalBasic } from '/@/api/sys/user'
|
||||
import { deleteCrops, getcrops } from '/@/api/sys/user'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useDrawer } from '/@/components/Drawer'
|
||||
import TownDrawer from './TownDrawer.vue'
|
||||
|
|
@ -46,9 +46,9 @@
|
|||
import { columns, searchFormSchema } from './town.data'
|
||||
const [registerDrawer, { openDrawer }] = useDrawer()
|
||||
const [registerTable, { reload }] = useTable({
|
||||
title: '农作物列表',
|
||||
title: '城镇农作物列表',
|
||||
api: async (e) => {
|
||||
const res = await getTownAgriculturalBasic({ type: 1, ...e })
|
||||
const res = await getcrops({ type: 'all', ...e, crop_type: 2 })
|
||||
return res
|
||||
},
|
||||
rowKey: 'id',
|
||||
|
|
@ -79,7 +79,7 @@
|
|||
})
|
||||
}
|
||||
const handleDelete = async (record: Recordable) => {
|
||||
await deleteGriculturalBasic(record.id)
|
||||
await deleteCrops(record.id)
|
||||
message.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,42 +1,20 @@
|
|||
import { BasicColumn } from '/@/components/Table'
|
||||
import { FormSchema } from '/@/components/Table'
|
||||
import { getCropCate, getcrops } from '/@/api/sys/user'
|
||||
export const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '基地名称',
|
||||
title: '名称',
|
||||
dataIndex: 'name',
|
||||
},
|
||||
{
|
||||
title: '基地负责人',
|
||||
dataIndex: 'person',
|
||||
title: '单位',
|
||||
dataIndex: 'unit',
|
||||
},
|
||||
{
|
||||
title: '基地农作物',
|
||||
dataIndex: 'crops',
|
||||
},
|
||||
{
|
||||
title: '基地经度',
|
||||
dataIndex: 'address_lat',
|
||||
},
|
||||
{
|
||||
title: '基地纬度',
|
||||
dataIndex: 'address_lng',
|
||||
},
|
||||
{
|
||||
title: '基地地址',
|
||||
dataIndex: 'address',
|
||||
},
|
||||
{
|
||||
title: '基地面积',
|
||||
dataIndex: 'areas',
|
||||
},
|
||||
{
|
||||
title: '基地就业人数',
|
||||
dataIndex: 'workforce',
|
||||
},
|
||||
{
|
||||
title: '基地描述',
|
||||
dataIndex: 'description',
|
||||
title: '是否是结点',
|
||||
dataIndex: 'is_end',
|
||||
customRender: ({ text }) => {
|
||||
return text == 1 ? '是' : '否'
|
||||
},
|
||||
},
|
||||
{
|
||||
width: 180,
|
||||
|
|
@ -49,83 +27,4 @@ export const columns: BasicColumn[] = [
|
|||
|
||||
export const searchFormSchema: FormSchema[] = []
|
||||
|
||||
export const accountFormSchema: FormSchema[] = [
|
||||
{
|
||||
field: 'id',
|
||||
label: '基地ID',
|
||||
required: false,
|
||||
dynamicDisabled: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!values.id
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'category_id',
|
||||
label: '产业',
|
||||
required: true,
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getCropCate,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'name',
|
||||
label: '名称',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'parent_id',
|
||||
label: '上级',
|
||||
required: false,
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: async () => {
|
||||
const res = await getcrops({ page: 1, per_page: 99999, crop_type: 2, type: 'all' })
|
||||
return res.filter((e) => !e.is_end)
|
||||
},
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'unit',
|
||||
label: '单位',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'sort',
|
||||
label: '排序',
|
||||
required: true,
|
||||
component: 'InputNumber',
|
||||
},
|
||||
{
|
||||
field: 'is_end',
|
||||
label: '是否是结点',
|
||||
required: false,
|
||||
component: 'Switch',
|
||||
},
|
||||
{
|
||||
field: 'endName',
|
||||
label: '名称',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return values.is_end
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
field: 'endUnit',
|
||||
label: '单位',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return values.is_end
|
||||
},
|
||||
},
|
||||
]
|
||||
export const accountFormSchema: FormSchema[] = []
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
<template>
|
||||
<BasicDrawer
|
||||
v-bind="$attrs"
|
||||
@register="registerDrawer"
|
||||
showFooter
|
||||
:title="getTitle"
|
||||
width="500px"
|
||||
@ok="handleSubmit"
|
||||
>
|
||||
<BasicForm @register="registerForm"> </BasicForm>
|
||||
</BasicDrawer>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed, unref } from 'vue'
|
||||
import { BasicForm, useForm } from '/@/components/Form/index'
|
||||
import { accountFormSchema } from './shrim-price'
|
||||
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer'
|
||||
import { defaultsDeep } from 'lodash-es'
|
||||
import { createDevice, getDeviceTypes, updateDevice } from '/@/api/sys/other'
|
||||
const emits = defineEmits(['success', 'register'])
|
||||
const isUpdate = ref(false)
|
||||
const getTitle = computed(() => (!isUpdate.value ? '新增设备' : '编辑设备'))
|
||||
const [registerForm, { resetFields, setFieldsValue, validate }] = useForm({
|
||||
labelWidth: 120,
|
||||
baseColProps: { span: 24 },
|
||||
schemas: accountFormSchema,
|
||||
showActionButtonGroup: false,
|
||||
})
|
||||
const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
|
||||
resetFields()
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
isUpdate.value = data?.isUpdate
|
||||
if (unref(isUpdate)) {
|
||||
const obj = Object.assign({}, { ...data, ...data?.extends })
|
||||
const deviceTypes = await getDeviceTypes()
|
||||
await setFieldsValue({
|
||||
...obj,
|
||||
agricultural_base_id: obj.base_id,
|
||||
type: formatDataByObject(deviceTypes).find((e) => e.label == obj.type)?.value,
|
||||
})
|
||||
}
|
||||
})
|
||||
const formatDataByObject = (obj) => {
|
||||
const arr: any[] = []
|
||||
Object.keys(obj).forEach((e) => {
|
||||
arr.push({
|
||||
label: obj[e],
|
||||
value: e,
|
||||
})
|
||||
})
|
||||
return arr
|
||||
}
|
||||
const setValue = (keys: any, value: any) => {
|
||||
const object = {}
|
||||
var last = keys.pop()
|
||||
keys.reduce((o, k) => (o[k] = o[k] || {}), object)[last] = value
|
||||
return object
|
||||
}
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
const values = await validate()
|
||||
let params = {}
|
||||
for (const key in values) {
|
||||
params = defaultsDeep({}, params, setValue(key.split('.'), values[key]))
|
||||
}
|
||||
setDrawerProps({ confirmLoading: true })
|
||||
if (values.id) {
|
||||
// 修改
|
||||
await updateDevice(values.id, params)
|
||||
} else {
|
||||
// 新增
|
||||
await createDevice(params)
|
||||
}
|
||||
closeDrawer()
|
||||
emits('success')
|
||||
} finally {
|
||||
setDrawerProps({ confirmLoading: false })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
<template>
|
||||
<div>
|
||||
<BasicTable @register="registerTable">
|
||||
<template #toolbar>
|
||||
<a-button type="primary" @click="handleCreate"> 新增设备 </a-button>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'action'">
|
||||
<div class="flex items-center justify-center">
|
||||
<TableAction
|
||||
:actions="[
|
||||
{ label: '编辑', onClick: handleEdit.bind(null, record) },
|
||||
{
|
||||
label: '删除',
|
||||
popConfirm: {
|
||||
title: '是否确认删除',
|
||||
placement: 'topRight',
|
||||
confirm: handleDelete.bind(null, record),
|
||||
},
|
||||
},
|
||||
]"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
</BasicTable>
|
||||
<PriceDrawer @register="registerDrawer" @success="handleSuccess" />
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import { BasicTable, useTable, TableAction } from '/@/components/Table'
|
||||
// import { getShrimpPrices, deleteDevice } from '/@/api/sys/other'
|
||||
import { getShrimpPrices } from '/@/api/sys/user'
|
||||
import { message } from 'ant-design-vue'
|
||||
import { useDrawer } from '/@/components/Drawer'
|
||||
import PriceDrawer from './PriceDrawer.vue'
|
||||
import { columns, searchFormSchema } from './shrim-price'
|
||||
const [registerDrawer, { openDrawer }] = useDrawer()
|
||||
const [registerTable, { reload }] = useTable({
|
||||
title: '稻虾价格 - 列表',
|
||||
api: getShrimpPrices,
|
||||
rowKey: 'id',
|
||||
columns,
|
||||
formConfig: {
|
||||
labelWidth: 120,
|
||||
schemas: searchFormSchema,
|
||||
},
|
||||
useSearchForm: true,
|
||||
showTableSetting: true,
|
||||
bordered: true,
|
||||
showIndexColumn: true,
|
||||
})
|
||||
|
||||
const handleSuccess = () => {
|
||||
message.success('操作成功')
|
||||
reload()
|
||||
}
|
||||
const handleCreate = () => {
|
||||
openDrawer(true, {
|
||||
id: false,
|
||||
})
|
||||
}
|
||||
const handleEdit = (record: Recordable) => {
|
||||
openDrawer(true, {
|
||||
...record,
|
||||
isUpdate: true,
|
||||
})
|
||||
}
|
||||
const handleDelete = async (record: Recordable) => {
|
||||
await deleteDevice(record.id)
|
||||
message.success('删除成功')
|
||||
reload()
|
||||
}
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
:deep(.ant-picker) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
import { BasicColumn } from '/@/components/Table'
|
||||
import { FormSchema } from '/@/components/Table'
|
||||
import { getAgriculturalBasic } from '/@/api/sys/user'
|
||||
import { getDeviceTypes } from '/@/api/sys/other'
|
||||
import { h } from 'vue'
|
||||
import { DatePicker } from 'ant-design-vue'
|
||||
function formatDataByObject(obj): any[] {
|
||||
const arr: any[] = []
|
||||
Object.keys(obj).forEach((e) => {
|
||||
arr.push({
|
||||
label: obj[e],
|
||||
value: e,
|
||||
})
|
||||
})
|
||||
return arr
|
||||
}
|
||||
export const columns: BasicColumn[] = [
|
||||
{
|
||||
title: '年份',
|
||||
dataIndex: 'year',
|
||||
customRender: ({ text }) => {
|
||||
return text + '年'
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '季度',
|
||||
dataIndex: 'quarter',
|
||||
},
|
||||
{
|
||||
title: '价格',
|
||||
dataIndex: 'price',
|
||||
},
|
||||
{
|
||||
title: '创建人',
|
||||
dataIndex: 'name',
|
||||
customRender: ({ record: { created_by } }) => {
|
||||
return created_by.name
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
width: 180,
|
||||
title: '操作',
|
||||
dataIndex: 'action',
|
||||
align: 'center',
|
||||
fixed: undefined,
|
||||
},
|
||||
]
|
||||
|
||||
export const searchFormSchema: FormSchema[] = [
|
||||
{
|
||||
field: 'year',
|
||||
label: '年份',
|
||||
component: 'Input',
|
||||
render: ({ model, field }) => {
|
||||
return h(DatePicker, {
|
||||
placeholder: '请选择年份',
|
||||
picker: 'year',
|
||||
mode: 'year',
|
||||
onChange: (e) => {
|
||||
model[field] = e['$y']
|
||||
},
|
||||
})
|
||||
},
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
{
|
||||
field: 'quarter',
|
||||
label: '季度',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '第一季度', value: '1' },
|
||||
{ label: '第二季度', value: '2' },
|
||||
{ label: '第三季度', value: '3' },
|
||||
{ label: '第四季度', value: '4' },
|
||||
],
|
||||
},
|
||||
colProps: { span: 6 },
|
||||
},
|
||||
]
|
||||
|
||||
export const accountFormSchema: FormSchema[] = [
|
||||
{
|
||||
field: 'id',
|
||||
label: '设备ID',
|
||||
required: false,
|
||||
dynamicDisabled: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!values.id
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'type',
|
||||
label: '设备类型',
|
||||
required: true,
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: async () => {
|
||||
const res = await getDeviceTypes()
|
||||
return formatDataByObject(res)
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'agricultural_base_id',
|
||||
label: '基地',
|
||||
required: true,
|
||||
component: 'ApiSelect',
|
||||
componentProps: {
|
||||
api: getAgriculturalBasic,
|
||||
labelField: 'name',
|
||||
valueField: 'id',
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'sn',
|
||||
label: '设备编号',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'monitoring_point',
|
||||
label: '监控点',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
},
|
||||
{
|
||||
field: 'extends.ip',
|
||||
label: '设备IP',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'extends.port',
|
||||
label: '设备端口',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'extends.rtsp_url',
|
||||
label: 'RTSP地址',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
field: 'extends.username',
|
||||
label: '设备登录名',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'extends.password',
|
||||
label: '设备登录密码',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'extends.passage',
|
||||
label: '设备播放通道',
|
||||
required: true,
|
||||
component: 'Input',
|
||||
ifShow: ({ values }) => {
|
||||
return !!(values.type == 1)
|
||||
},
|
||||
},
|
||||
]
|
||||
Loading…
Reference in New Issue