update 栏舍管理
This commit is contained in:
parent
16121d7260
commit
685f965d5a
|
@ -28,6 +28,9 @@
|
|||
<el-form-item label="栏舍名称" prop="fence_house_name">
|
||||
<el-input v-model="formData.fence_house_name" clearable placeholder="请输入栏舍名称" />
|
||||
</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-select class="flex-1" v-model="formData.animal_type" clearable placeholder="请选择动物类型">
|
||||
<el-option
|
||||
|
@ -55,10 +58,38 @@
|
|||
<el-input v-model="formData.master" clearable placeholder="请输入负责人" />
|
||||
</el-form-item>
|
||||
<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 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>
|
||||
|
@ -72,19 +103,37 @@ import Popup from '@/components/popup/index.vue'
|
|||
import {apiFenceHouseAdd, apiFenceHouseEdit, apiFenceHouseDetail, apiFenceHouseLists, apiFarmLists} from '@/api/fence_house'
|
||||
import { timeFormat } from '@/utils/util'
|
||||
import type { PropType } from 'vue'
|
||||
import {useDictOptions} from "@/hooks/useDictOptions";
|
||||
import {ref} from "vue";
|
||||
import {useDictOptions} from "@/hooks/useDictOptions"
|
||||
import {ref} from "vue"
|
||||
import config from "@/config";
|
||||
import useUserStore from "@/stores/modules/user";
|
||||
import {ElMessage, type UploadProps} from "element-plus";
|
||||
|
||||
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 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(() => {
|
||||
|
@ -95,6 +144,7 @@ const popupTitle = computed(() => {
|
|||
const formData = reactive({
|
||||
id: '',
|
||||
farm_id: '',
|
||||
animal_name: '',
|
||||
fence_house_name: '',
|
||||
animal_type: '',
|
||||
fence_house_type: '',
|
||||
|
@ -102,6 +152,7 @@ const formData = reactive({
|
|||
master: '',
|
||||
status: '',
|
||||
qr_code: '',
|
||||
image: '',
|
||||
|
||||
})
|
||||
|
||||
|
@ -130,7 +181,6 @@ const queryFarm= async (query: string) => {
|
|||
optionsData.farmList = farmList
|
||||
loading.value = false
|
||||
}
|
||||
console.log(optionsData)
|
||||
|
||||
|
||||
// 获取详情
|
||||
|
@ -183,3 +233,35 @@ defineExpose({
|
|||
getDetail
|
||||
})
|
||||
</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>
|
|
@ -47,7 +47,11 @@
|
|||
</el-table-column>
|
||||
<el-table-column label="容量" prop="capacity" 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">
|
||||
<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({
|
||||
|
|
|
@ -39,6 +39,7 @@ class FenceHouseLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||
{
|
||||
return [
|
||||
'=' => ['fence_house_name'],
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -55,7 +56,6 @@ class FenceHouseLists extends BaseAdminDataLists implements ListsSearchInterface
|
|||
public function lists(): array
|
||||
{
|
||||
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)
|
||||
->order(['id' => 'desc'])
|
||||
->select()
|
||||
|
|
|
@ -43,6 +43,7 @@ class FenceHouseLogic extends BaseLogic
|
|||
try {
|
||||
FenceHouse::create([
|
||||
'farm_id' => $params['farm_id'],
|
||||
'animal_name' => $params['animal_name'],
|
||||
'fence_house_name' => $params['fence_house_name'],
|
||||
'animal_type' => $params['animal_type'],
|
||||
'fence_house_type' => $params['fence_house_type'],
|
||||
|
@ -50,6 +51,7 @@ class FenceHouseLogic extends BaseLogic
|
|||
'master' => $params['master'],
|
||||
'status' => $params['status'],
|
||||
'qr_code' => $params['qr_code'],
|
||||
'image' => $params['image'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -75,6 +77,7 @@ class FenceHouseLogic extends BaseLogic
|
|||
try {
|
||||
FenceHouse::where('id', $params['id'])->update([
|
||||
'farm_id' => $params['farm_id'],
|
||||
'animal_name' => $params['animal_name'],
|
||||
'fence_house_name' => $params['fence_house_name'],
|
||||
'animal_type' => $params['animal_type'],
|
||||
'fence_house_type' => $params['fence_house_type'],
|
||||
|
@ -82,6 +85,7 @@ class FenceHouseLogic extends BaseLogic
|
|||
'master' => $params['master'],
|
||||
'status' => $params['status'],
|
||||
'qr_code' => $params['qr_code'],
|
||||
'image' => $params['image'],
|
||||
]);
|
||||
|
||||
Db::commit();
|
||||
|
@ -123,14 +127,14 @@ class FenceHouseLogic extends BaseLogic
|
|||
public static function datas($params)
|
||||
{
|
||||
$queryWhere = [];
|
||||
if (!empty($params['fence_house_name'])) {
|
||||
$queryWhere[] = ['fence_house_name', 'like', '%' . $params['fence_house_name'] . '%'];
|
||||
if (!empty($params['keyword'])) {
|
||||
$queryWhere[] = ['fence_house_name', 'like', '%' . $params['keyword'] . '%'];
|
||||
}
|
||||
if (!empty($params['user_id'])) {
|
||||
$farmIds = Farm::where('user_id', $params['user_id'])->column('id');
|
||||
$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) {
|
||||
$item['fencehouseinfo'] = 'ID:' . $item['id'] . ' / 名称:' . $item['fence_house_name'];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue