update 栏舍管理

This commit is contained in:
chenbo 2024-01-18 11:21:28 +08:00
parent 16121d7260
commit 685f965d5a
4 changed files with 177 additions and 87 deletions

View File

@ -28,6 +28,9 @@
<el-form-item label="栏舍名称" prop="fence_house_name"> <el-form-item label="栏舍名称" prop="fence_house_name">
<el-input v-model="formData.fence_house_name" clearable placeholder="请输入栏舍名称" /> <el-input v-model="formData.fence_house_name" clearable placeholder="请输入栏舍名称" />
</el-form-item> </el-form-item>
<el-form-item label="动物名称" prop="animal_name">
<el-input v-model="formData.animal_name" clearable placeholder="请输入栏舍名称" />
</el-form-item>
<el-form-item label="动物类型" prop="animal_type"> <el-form-item label="动物类型" prop="animal_type">
<el-select class="flex-1" v-model="formData.animal_type" clearable placeholder="请选择动物类型"> <el-select class="flex-1" v-model="formData.animal_type" clearable placeholder="请选择动物类型">
<el-option <el-option
@ -55,10 +58,38 @@
<el-input v-model="formData.master" clearable placeholder="请输入负责人" /> <el-input v-model="formData.master" clearable placeholder="请输入负责人" />
</el-form-item> </el-form-item>
<el-form-item label="状态" prop="status"> <el-form-item label="状态" prop="status">
<el-input v-model="formData.status" clearable placeholder="请输入状态" /> <el-select class="flex-1" v-model="formData.status" clearable placeholder="请选择状态">
<el-option
v-for="(item, index) in dictData.system_disable"
:key="index"
:label="item.name"
:value="parseInt(item.value)"
/>
</el-select>
</el-form-item> </el-form-item>
<el-form-item label="二维码" prop="qr_code">
<el-input v-model="formData.qr_code" clearable placeholder="请输入二维码" /> <el-form-item label="图片" prop="image">
<el-upload
class="avatar-uploader"
:accept="acceptFileTypes"
v-model="formData.image"
:data="{ cid: 1 }"
:headers="{ Token: userStore.token }"
:action="action"
:show-file-list="false"
:on-success="handleAvatarSuccessAvatar"
>
<img
v-if="formData.image"
:src="formData.image"
class="avatar"
/>
<div v-else class="avatar-uploader-icon">
<el-icon>
<Plus />
</el-icon>
</div>
</el-upload>
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -72,19 +103,37 @@ import Popup from '@/components/popup/index.vue'
import {apiFenceHouseAdd, apiFenceHouseEdit, apiFenceHouseDetail, apiFenceHouseLists, apiFarmLists} from '@/api/fence_house' import {apiFenceHouseAdd, apiFenceHouseEdit, apiFenceHouseDetail, apiFenceHouseLists, apiFarmLists} from '@/api/fence_house'
import { timeFormat } from '@/utils/util' import { timeFormat } from '@/utils/util'
import type { PropType } from 'vue' import type { PropType } from 'vue'
import {useDictOptions} from "@/hooks/useDictOptions"; import {useDictOptions} from "@/hooks/useDictOptions"
import {ref} from "vue"; import {ref} from "vue"
import config from "@/config";
import useUserStore from "@/stores/modules/user";
import {ElMessage, type UploadProps} from "element-plus";
defineProps({ defineProps({
dictData: { dictData: {
type: Object as PropType<Record<string, any[]>>, type: Object as PropType<Record<string, any[]>>,
default: () => ({}) default: () => ({})
} }
}) })
const emit = defineEmits(['success', 'close']) const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>() const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>() const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add') const mode = ref('add')
const acceptFileTypes = ref(".png, .jpg, .jpeg, image/png, image/jpeg")
const action = ref(`${config.baseUrl}${config.urlPrefix}/upload/image`)
const userStore = useUserStore()
const handleAvatarSuccessAvatar: UploadProps["onSuccess"] = (
response,
uploadFile
) => {
if (response.code == 0) {
ElMessage.error(response.msg);
return;
}
formData.image = response.data.uri;
}
// //
const popupTitle = computed(() => { const popupTitle = computed(() => {
@ -95,6 +144,7 @@ const popupTitle = computed(() => {
const formData = reactive({ const formData = reactive({
id: '', id: '',
farm_id: '', farm_id: '',
animal_name: '',
fence_house_name: '', fence_house_name: '',
animal_type: '', animal_type: '',
fence_house_type: '', fence_house_type: '',
@ -102,6 +152,7 @@ const formData = reactive({
master: '', master: '',
status: '', status: '',
qr_code: '', qr_code: '',
image: '',
}) })
@ -130,7 +181,6 @@ const queryFarm= async (query: string) => {
optionsData.farmList = farmList optionsData.farmList = farmList
loading.value = false loading.value = false
} }
console.log(optionsData)
// //
@ -183,3 +233,35 @@ defineExpose({
getDetail getDetail
}) })
</script> </script>
<style scoped>
.avatar-uploader .avatar {
width: 178px;
height: 178px;
display: block;
}
</style>
<style>
.avatar-uploader .el-upload {
width: 200px;
height: 130px;
border: 1px dashed var(--el-border-color);
border-radius: 6px;
cursor: pointer;
position: relative;
overflow: hidden;
transition: var(--el-transition-duration-fast);
}
.avatar-uploader .el-upload:hover {
border-color: var(--el-color-primary);
}
.el-icon.avatar-uploader-icon {
font-size: 28px;
color: #8c939d;
width: 178px;
height: 178px;
text-align: center;
}
</style>

View File

@ -47,7 +47,11 @@
</el-table-column> </el-table-column>
<el-table-column label="容量" prop="capacity" show-overflow-tooltip /> <el-table-column label="容量" prop="capacity" show-overflow-tooltip />
<el-table-column label="负责人" prop="master" show-overflow-tooltip /> <el-table-column label="负责人" prop="master" show-overflow-tooltip />
<el-table-column label="状态" prop="status" show-overflow-tooltip /> <el-table-column label="状态" prop="status">
<template #default="{ row }">
<dict-value :options="dictData.system_disable" :value="row.status" />
</template>
</el-table-column>
<el-table-column label="操作" width="120" fixed="right"> <el-table-column label="操作" width="120" fixed="right">
<template #default="{ row }"> <template #default="{ row }">
@ -106,7 +110,7 @@ const handleSelectionChange = (val: any[]) => {
} }
// //
const { dictData } = useDictData('animal_type,fence_house_type') const { dictData } = useDictData('animal_type,fence_house_type,system_disable')
// //
const { pager, getLists, resetParams, resetPage } = usePaging({ const { pager, getLists, resetParams, resetPage } = usePaging({

View File

@ -39,6 +39,7 @@ class FenceHouseLists extends BaseAdminDataLists implements ListsSearchInterface
{ {
return [ return [
'=' => ['fence_house_name'], '=' => ['fence_house_name'],
]; ];
} }
@ -55,7 +56,6 @@ class FenceHouseLists extends BaseAdminDataLists implements ListsSearchInterface
public function lists(): array public function lists(): array
{ {
return FenceHouse::where($this->searchWhere) return FenceHouse::where($this->searchWhere)
->field(['id', 'farm_id', 'fence_house_name', 'animal_type', 'fence_house_type', 'capacity', 'master', 'status'])
->limit($this->limitOffset, $this->limitLength) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select() ->select()

View File

@ -43,6 +43,7 @@ class FenceHouseLogic extends BaseLogic
try { try {
FenceHouse::create([ FenceHouse::create([
'farm_id' => $params['farm_id'], 'farm_id' => $params['farm_id'],
'animal_name' => $params['animal_name'],
'fence_house_name' => $params['fence_house_name'], 'fence_house_name' => $params['fence_house_name'],
'animal_type' => $params['animal_type'], 'animal_type' => $params['animal_type'],
'fence_house_type' => $params['fence_house_type'], 'fence_house_type' => $params['fence_house_type'],
@ -50,6 +51,7 @@ class FenceHouseLogic extends BaseLogic
'master' => $params['master'], 'master' => $params['master'],
'status' => $params['status'], 'status' => $params['status'],
'qr_code' => $params['qr_code'], 'qr_code' => $params['qr_code'],
'image' => $params['image'],
]); ]);
Db::commit(); Db::commit();
@ -75,6 +77,7 @@ class FenceHouseLogic extends BaseLogic
try { try {
FenceHouse::where('id', $params['id'])->update([ FenceHouse::where('id', $params['id'])->update([
'farm_id' => $params['farm_id'], 'farm_id' => $params['farm_id'],
'animal_name' => $params['animal_name'],
'fence_house_name' => $params['fence_house_name'], 'fence_house_name' => $params['fence_house_name'],
'animal_type' => $params['animal_type'], 'animal_type' => $params['animal_type'],
'fence_house_type' => $params['fence_house_type'], 'fence_house_type' => $params['fence_house_type'],
@ -82,6 +85,7 @@ class FenceHouseLogic extends BaseLogic
'master' => $params['master'], 'master' => $params['master'],
'status' => $params['status'], 'status' => $params['status'],
'qr_code' => $params['qr_code'], 'qr_code' => $params['qr_code'],
'image' => $params['image'],
]); ]);
Db::commit(); Db::commit();
@ -123,14 +127,14 @@ class FenceHouseLogic extends BaseLogic
public static function datas($params) public static function datas($params)
{ {
$queryWhere = []; $queryWhere = [];
if (!empty($params['fence_house_name'])) { if (!empty($params['keyword'])) {
$queryWhere[] = ['fence_house_name', 'like', '%' . $params['fence_house_name'] . '%']; $queryWhere[] = ['fence_house_name', 'like', '%' . $params['keyword'] . '%'];
} }
if (!empty($params['user_id'])) { if (!empty($params['user_id'])) {
$farmIds = Farm::where('user_id', $params['user_id'])->column('id'); $farmIds = Farm::where('user_id', $params['user_id'])->column('id');
$queryWhere[] = ['farm_id', 'in', $farmIds]; $queryWhere[] = ['farm_id', 'in', $farmIds];
} }
$lists = Db::name('fence_house')->where($queryWhere)->order(['id' => 'desc'])->select()->toArray(); $lists = FenceHouse::where($queryWhere)->order(['id' => 'desc'])->select()->toArray();
foreach ($lists as &$item) { foreach ($lists as &$item) {
$item['fencehouseinfo'] = 'ID' . $item['id'] . ' / 名称:' . $item['fence_house_name']; $item['fencehouseinfo'] = 'ID' . $item['id'] . ' / 名称:' . $item['fence_house_name'];
} }