更新绑定状态及数据处理
This commit is contained in:
parent
c3c734f595
commit
c54325c428
|
@ -9,7 +9,20 @@
|
|||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" label-width="120px" :rules="formRules">
|
||||
<el-form-item label="产品ID" prop="product_id">
|
||||
<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 label="所属产品" prop="product_id">
|
||||
<el-select
|
||||
v-model="formData.product_id"
|
||||
filterable
|
||||
|
@ -27,21 +40,8 @@
|
|||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="设备编码" prop="code">
|
||||
<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="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="monitor_item">
|
||||
<el-select class="flex-1" v-model="formData.monitor_item" multiple clearable placeholder="请选择设备监测项">
|
||||
|
@ -75,16 +75,6 @@
|
|||
:value="parseInt(item.value)"
|
||||
/>
|
||||
</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>
|
||||
</popup>
|
||||
|
@ -125,17 +115,10 @@ const formData = reactive({
|
|||
monitor_item: '',
|
||||
status: '',
|
||||
is_online: '',
|
||||
is_bind: '',
|
||||
})
|
||||
|
||||
|
||||
// 表单验证
|
||||
const formRules = reactive<any>({
|
||||
product_id: [{
|
||||
required: true,
|
||||
message: '请输入产品id',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
code: [{
|
||||
required: true,
|
||||
message: '请输入设备编码',
|
||||
|
@ -161,11 +144,6 @@ const formRules = reactive<any>({
|
|||
message: '请选择是否在线',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
is_bind: [{
|
||||
required: true,
|
||||
message: '请选择是否绑定土地',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -58,17 +58,6 @@
|
|||
:value="item.value"
|
||||
/>
|
||||
</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-button type="primary" @click="resetPage">查询</el-button>
|
||||
|
@ -128,11 +117,6 @@
|
|||
<template #default="{ row }">
|
||||
<dict-value :options="dictData.device_online_status" :value="row.is_online" />
|
||||
</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 label="创建时间" width="160" align="center" prop="create_time">
|
||||
<template #default="{ row }">
|
||||
|
@ -229,8 +213,7 @@ const queryParams = reactive({
|
|||
name: '',
|
||||
type: '',
|
||||
status: '',
|
||||
is_online: '',
|
||||
is_bind: ''
|
||||
is_online: ''
|
||||
})
|
||||
|
||||
// 选中数据
|
||||
|
|
|
@ -8,41 +8,31 @@
|
|||
@confirm="handleSubmit"
|
||||
@close="handleClose"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||
<el-form-item label="产品编号" prop="code">
|
||||
<el-input v-model="formData.code" clearable placeholder="请输入产品编号" />
|
||||
</el-form-item>
|
||||
<el-form-item label="产品名称" prop="name">
|
||||
<el-input v-model="formData.name" clearable placeholder="请输入产品名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="所属土地" prop="land_id">
|
||||
<el-select
|
||||
v-model="formData.land_id"
|
||||
filterable
|
||||
remote
|
||||
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="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 ref="formRef" :model="formData" label-width="90px" :rules="formRules">
|
||||
<el-form-item label="产品名称" prop="name">
|
||||
<el-input v-model="formData.name" clearable placeholder="请输入产品名称" />
|
||||
</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="land_id">
|
||||
<el-select
|
||||
v-model="formData.land_id"
|
||||
filterable
|
||||
remote
|
||||
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>
|
||||
</popup>
|
||||
</div>
|
||||
|
@ -92,12 +82,7 @@ const formRules = reactive<any>({
|
|||
required: true,
|
||||
message: '请输入产品名称',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
status: [{
|
||||
required: true,
|
||||
message: '请选择产品状态',
|
||||
trigger: ['blur']
|
||||
}],
|
||||
}]
|
||||
})
|
||||
|
||||
|
||||
|
|
|
@ -43,7 +43,10 @@ class DeviceLogic extends BaseLogic
|
|||
} else {
|
||||
$params['monitor_item'] = trim($params['monitor_item']);
|
||||
}
|
||||
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||
$userId = (request()->adminInfo)['user_id'];
|
||||
if (!empty($params['product_id'])) {
|
||||
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$device = Device::create([
|
||||
|
@ -54,16 +57,17 @@ class DeviceLogic extends BaseLogic
|
|||
'monitor_item' => $params['monitor_item'],
|
||||
'video_url' => $params['video_url'],
|
||||
'status' => $params['status'],
|
||||
'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()
|
||||
'is_online' => $params['is_online']
|
||||
]);
|
||||
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();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
|
@ -88,7 +92,10 @@ class DeviceLogic extends BaseLogic
|
|||
} else {
|
||||
$params['monitor_item'] = trim($params['monitor_item']);
|
||||
}
|
||||
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||
$userId = (request()->adminInfo)['user_id'];
|
||||
if (!empty($params['product_id'])) {
|
||||
$userId = Db::name('product')->where('id', $params['product_id'])->value('user_id');
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
$device = Device::where('id', $params['id'])->update([
|
||||
|
@ -99,17 +106,18 @@ class DeviceLogic extends BaseLogic
|
|||
'monitor_item' => $params['monitor_item'],
|
||||
'video_url' => $params['video_url'],
|
||||
'status' => $params['status'],
|
||||
'is_online' => $params['is_online'],
|
||||
'is_bind' => $params['is_bind'],
|
||||
'is_online' => $params['is_online']
|
||||
]);
|
||||
Db::name('product_device')->where('device_id', $params['id'])->delete();
|
||||
Db::name('product_device')->insert([
|
||||
'product_id' => $params['product_id'],
|
||||
'device_id' => $params['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' => $params['id'],
|
||||
'device_type' => $params['type'],
|
||||
'create_time' => time(),
|
||||
'update_time' => time()
|
||||
]);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
|
|
|
@ -39,8 +39,10 @@ class ProductLogic extends BaseLogic
|
|||
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();
|
||||
try {
|
||||
|
@ -48,7 +50,7 @@ class ProductLogic extends BaseLogic
|
|||
'user_id' => $userId,
|
||||
'code' => $params['code'],
|
||||
'name' => $params['name'],
|
||||
'status' => $params['status'],
|
||||
'status' => $status,
|
||||
]);
|
||||
if (!empty($params['land_id'])) {
|
||||
Db::name('land_product')->insert([
|
||||
|
@ -78,8 +80,10 @@ class ProductLogic extends BaseLogic
|
|||
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();
|
||||
try {
|
||||
|
@ -87,7 +91,7 @@ class ProductLogic extends BaseLogic
|
|||
'user_id' => $userId,
|
||||
'code' => $params['code'],
|
||||
'name' => $params['name'],
|
||||
'status' => $params['status'],
|
||||
'status' => $status,
|
||||
]);
|
||||
Db::name('land_product')->where('product_id', $params['id'])->delete();
|
||||
if (!empty($params['land_id'])) {
|
||||
|
|
|
@ -35,7 +35,6 @@ class ProductValidate extends BaseValidate
|
|||
'device_id' => 'require',
|
||||
'code' => 'require',
|
||||
'name' => 'require',
|
||||
'status' => 'require',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -46,7 +45,6 @@ class ProductValidate extends BaseValidate
|
|||
'id' => 'id',
|
||||
'code' => '产品编号',
|
||||
'name' => '产品名称',
|
||||
'status' => '产品状态',
|
||||
];
|
||||
|
||||
|
||||
|
@ -58,7 +56,7 @@ class ProductValidate extends BaseValidate
|
|||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['code','name','status']);
|
||||
return $this->only(['code','name']);
|
||||
}
|
||||
|
||||
|
||||
|
@ -70,7 +68,7 @@ class ProductValidate extends BaseValidate
|
|||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','code','name','status']);
|
||||
return $this->only(['id','code','name']);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue