第一次提交
This commit is contained in:
39
src/views/yunxinwei/index/components/category-select.vue
Normal file
39
src/views/yunxinwei/index/components/category-select.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<!-- 目录选择下拉框 -->
|
||||
<template>
|
||||
<a-tree-select
|
||||
allow-clear
|
||||
tree-default-expand-all
|
||||
:placeholder="placeholder"
|
||||
:value="value || undefined"
|
||||
:tree-data="data"
|
||||
:dropdown-style="{ maxHeight: '360px', overflow: 'auto' }"
|
||||
@update:value="updateValue"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import type { Equipment } from '@/api/apps/equipment/model';
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:value', value?: number): void;
|
||||
}>();
|
||||
|
||||
withDefaults(
|
||||
defineProps<{
|
||||
// 选中的数据(v-modal)
|
||||
value?: number;
|
||||
// 提示信息
|
||||
placeholder?: string;
|
||||
// 文章分类
|
||||
data: Equipment[];
|
||||
}>(),
|
||||
{
|
||||
placeholder: '请选择上级分类'
|
||||
}
|
||||
);
|
||||
|
||||
/* 更新选中数据 */
|
||||
const updateValue = (value?: number) => {
|
||||
emit('update:value', value);
|
||||
};
|
||||
</script>
|
||||
669
src/views/yunxinwei/index/components/equipment-edit.vue
Normal file
669
src/views/yunxinwei/index/components/equipment-edit.vue
Normal file
@@ -0,0 +1,669 @@
|
||||
<!-- 用户编辑弹窗 -->
|
||||
<template>
|
||||
<a-drawer
|
||||
:width="880"
|
||||
:visible="visible"
|
||||
:confirm-loading="loading"
|
||||
:maxable="maxAble"
|
||||
:title="isUpdate ? '编辑设备' : '添加设备'"
|
||||
:body-style="{ paddingBottom: '8px' }"
|
||||
:footer-style="{ textAlign: 'right' }"
|
||||
@update:visible="updateVisible"
|
||||
:maskClosable="isUpdate"
|
||||
@ok="save"
|
||||
>
|
||||
<a-form
|
||||
ref="formRef"
|
||||
:label-col="{ md: { span: 8 }, sm: { span: 24 } }"
|
||||
:wrapper-col="{ md: { span: 24 }, sm: { span: 24 } }"
|
||||
layout="vertical"
|
||||
:model="form"
|
||||
:rules="rules"
|
||||
>
|
||||
<a-row :gutter="16">
|
||||
<a-col
|
||||
v-bind="styleResponsive ? { md: 12, sm: 24, xs: 24 } : { span: 12 }"
|
||||
>
|
||||
<a-form-item label="所属商户" name="merchantCode">
|
||||
<MerchantSelect
|
||||
dict-code="merchantCode"
|
||||
placeholder="请选择所属商户"
|
||||
v-model:value="form.merchantCode"
|
||||
/>
|
||||
</a-form-item>
|
||||
<!-- 1锂电池租赁 3电动车租赁 -->
|
||||
<a-form-item label="设备名称" name="equipmentName">
|
||||
<DictSelect
|
||||
dict-code="equipmentName"
|
||||
placeholder="请选择设备"
|
||||
v-model:value="form.equipmentName"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="电池型号" name="batteryModel">
|
||||
<DictSelect
|
||||
dict-code="equipmentModel"
|
||||
placeholder="请选择电池型号"
|
||||
v-model:value="form.batteryModel"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="工作状态" name="workingStatus">
|
||||
<DictSelect
|
||||
dict-code="workingStatus"
|
||||
v-model:value="form.workingStatus"
|
||||
placeholder="选择工作状态"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="电池状态" name="batteryStatus">
|
||||
<DictSelect
|
||||
dict-code="batteryStatus"
|
||||
v-model:value="form.batteryStatus"
|
||||
placeholder="选择电池状态"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="是否在线" name="isOnline">
|
||||
<DictSelect
|
||||
dict-code="isOnline"
|
||||
v-model:value="form.isOnline"
|
||||
placeholder="是否在线"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="BMS板供应商" name="bmsBrand">
|
||||
<DictSelect
|
||||
dict-code="bmsBrand"
|
||||
v-model:value="form.bmsBrand"
|
||||
placeholder="选择供应商"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="ICCID" name="iccid">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入剩余容量"
|
||||
v-model:value="form.iccid"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="电池出厂时间" name="batteryDeliveryTime">
|
||||
<a-date-picker
|
||||
class="ele-fluid"
|
||||
placeholder="请选择时间"
|
||||
v-model:value="batteryDeliveryTime"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
<a-col
|
||||
v-bind="styleResponsive ? { md: 12, sm: 24, xs: 24 } : { span: 12 }"
|
||||
>
|
||||
<a-form-item label="设备编码" name="equipmentCode">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入设备编码"
|
||||
:disabled="isUpdate"
|
||||
v-model:value="form.equipmentCode"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="bms" name="bms">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入设备BMS"
|
||||
v-model:value="form.bms"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="是否激活" name="isCtive">
|
||||
<DictSelect
|
||||
dict-code="ctiveStatus"
|
||||
v-model:value="form.isCtive"
|
||||
placeholder="是否激活"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="租赁状态" name="leaseStatus">
|
||||
<DictSelect
|
||||
dict-code="leaseStatus"
|
||||
v-model:value="form.leaseStatus"
|
||||
placeholder="是否激活"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="电池电量" name="batteryPower">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入电池电量"
|
||||
v-model:value="form.batteryPower"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="总电压" name="totalVoltage">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入总电压"
|
||||
v-model:value="form.totalVoltage"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="剩余容量" name="surplusCapacity">
|
||||
<a-input
|
||||
allow-clear
|
||||
placeholder="请输入剩余容量"
|
||||
v-model:value="form.surplusCapacity"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="设备激活时间" name="ctiveTime">
|
||||
<a-date-picker
|
||||
class="ele-fluid"
|
||||
placeholder="请选择时间"
|
||||
v-model:value="ctiveTime"
|
||||
/>
|
||||
</a-form-item>
|
||||
<a-form-item label="设备开关" name="status">
|
||||
<a-switch :checked="form.status === 0" @change="editStatus" />
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
</a-row>
|
||||
<!-- <a-form-item label="设备图片" name="images">-->
|
||||
<!-- <ele-image-upload-->
|
||||
<!-- v-model:value="images"-->
|
||||
<!-- :limit="14"-->
|
||||
<!-- :drag="true"-->
|
||||
<!-- :multiple="true"-->
|
||||
<!-- :upload-handler="uploadHandler"-->
|
||||
<!-- @upload="onUpload"-->
|
||||
<!-- />-->
|
||||
<!-- </a-form-item>-->
|
||||
</a-form>
|
||||
<template #footer>
|
||||
<a-space>
|
||||
<a-button @click="onClose">取消</a-button>
|
||||
<a-button type="primary" @click="save">保存</a-button>
|
||||
</a-space>
|
||||
</template>
|
||||
<!-- <a-tabs v-model:activeKey="activeKey" type="card">-->
|
||||
<!-- <a-tab-pane key="1" tab="基本信息" />-->
|
||||
<!-- <a-tab-pane key="2" tab="设备详情">-->
|
||||
<!-- <a-form-->
|
||||
<!-- ref="formRef"-->
|
||||
<!-- :label-col="{ md: { span: 8 }, sm: { span: 24 } }"-->
|
||||
<!-- :wrapper-col="{ md: { span: 24 }, sm: { span: 24 } }"-->
|
||||
<!-- layout="vertical"-->
|
||||
<!-- :model="form"-->
|
||||
<!-- :rules="rules"-->
|
||||
<!-- >-->
|
||||
<!-- <a-form-item label="" name="content">-->
|
||||
<!-- <!– 编辑器 –>-->
|
||||
<!-- <tinymce-editor-->
|
||||
<!-- v-model:value="content"-->
|
||||
<!-- :disabled="disabled"-->
|
||||
<!-- :init="config"-->
|
||||
<!-- />-->
|
||||
<!-- </a-form-item>-->
|
||||
<!-- </a-form>-->
|
||||
<!-- </a-tab-pane>-->
|
||||
<!-- </a-tabs>-->
|
||||
</a-drawer>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, watch } from 'vue';
|
||||
import { message } from 'ant-design-vue';
|
||||
import type { Equipment } from '@/api/apps/equipment/model';
|
||||
import { addEquipment, updateEquipment } from '@/api/apps/equipment';
|
||||
import { FormInstance, Rule, RuleObject } from 'ant-design-vue/es/form';
|
||||
import { ItemType } from 'ele-admin-pro/es/ele-image-upload/types';
|
||||
import { uploadFile } from '@/api/system/file';
|
||||
import { FILE_SERVER, FILE_THUMBNAIL } from "@/config/setting";
|
||||
import useFormData from '@/utils/use-form-data';
|
||||
import TinymceEditor from '@/components/TinymceEditor/index.vue';
|
||||
import { Category } from '@/api/goods/category/model';
|
||||
import { useThemeStore } from '@/store/modules/theme';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import DictSelect from '@/components/DictSelect/index.vue';
|
||||
import MerchantSelect from '@/components/MerchantSelect/index.vue';
|
||||
import { createCode } from '@/utils/common';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
// import MultiSpec from './MultiSpec.vue';
|
||||
|
||||
const props = defineProps<{
|
||||
// 弹窗是否打开
|
||||
visible: boolean;
|
||||
// 修改回显的数据
|
||||
data?: Equipment | null;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
(e: 'done'): void;
|
||||
(e: 'update:visible', visible: boolean): void;
|
||||
}>();
|
||||
|
||||
// 是否是修改
|
||||
const isUpdate = ref(false);
|
||||
// 是否显示最大化切换按钮
|
||||
const maxAble = ref(true);
|
||||
const disabled = ref(false);
|
||||
// 选择日期
|
||||
const batteryDeliveryTime = ref<Dayjs>();
|
||||
const ctiveTime = ref<Dayjs>();
|
||||
|
||||
// 是否开启响应式布局
|
||||
const themeStore = useThemeStore();
|
||||
const { styleResponsive } = storeToRefs(themeStore);
|
||||
|
||||
// 提交状态
|
||||
const loading = ref(false);
|
||||
// 已上传数据
|
||||
const images = ref<ItemType[]>([]);
|
||||
|
||||
const formRef = ref<FormInstance | null>(null);
|
||||
// 选项卡位置
|
||||
// const activeKey = ref('1');
|
||||
// 编辑器内容,双向绑定
|
||||
const content = ref<any>('');
|
||||
/* 更新visible */
|
||||
const updateVisible = (value: boolean) => {
|
||||
emit('update:visible', value);
|
||||
};
|
||||
|
||||
// 表单数据
|
||||
const { form, resetFields, assignFields } = useFormData<Equipment>({
|
||||
equipmentType: 1,
|
||||
equipmentName: undefined,
|
||||
equipmentCode: `E${createCode()}`,
|
||||
batteryModel: undefined,
|
||||
equipmentCategory: undefined,
|
||||
bms: undefined,
|
||||
isCtive: undefined,
|
||||
workingStatus: undefined,
|
||||
leaseStatus: undefined,
|
||||
batteryStatus: undefined,
|
||||
batteryPower: undefined,
|
||||
isOnline: undefined,
|
||||
totalVoltage: undefined,
|
||||
bmsBrand: undefined,
|
||||
surplusCapacity: undefined,
|
||||
iccid: undefined,
|
||||
ctiveTime: undefined,
|
||||
batteryDeliveryTime: undefined,
|
||||
image: '',
|
||||
files: '',
|
||||
createTime: '',
|
||||
comments: '',
|
||||
sortNumber: 100,
|
||||
status: 0,
|
||||
equipmentId: 0,
|
||||
content: '',
|
||||
merchantCode: undefined,
|
||||
batteryRent: 300,
|
||||
batteryDeposit: 300,
|
||||
batteryInsurance: 0,
|
||||
batteryPrice: 0,
|
||||
tenantId: Number(localStorage.getItem('tenantId'))
|
||||
});
|
||||
|
||||
/* 上传事件 */
|
||||
const uploadHandler = (file: File) => {
|
||||
const item: ItemType = {
|
||||
file,
|
||||
uid: (file as any).uid,
|
||||
name: file.name
|
||||
};
|
||||
if (!file.type.startsWith('image')) {
|
||||
message.error('只能选择图片');
|
||||
return;
|
||||
}
|
||||
if (file.size / 1024 / 1024 > 2) {
|
||||
message.error('大小不能超过 2MB');
|
||||
return;
|
||||
}
|
||||
onUpload(item);
|
||||
};
|
||||
|
||||
// 上传文件
|
||||
const onUpload = (item) => {
|
||||
const { file } = item;
|
||||
uploadFile(file)
|
||||
.then((data) => {
|
||||
images.value.push({
|
||||
uid: data.id,
|
||||
url: FILE_THUMBNAIL + data.path,
|
||||
status: 'done'
|
||||
});
|
||||
message.success('上传成功');
|
||||
})
|
||||
.catch((e) => {
|
||||
message.error(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
// 表单验证规则
|
||||
const rules = reactive<Record<string, Rule[]>>({
|
||||
merchantCode: [
|
||||
{
|
||||
required: true,
|
||||
message: '请选择商户',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
equipmentName: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入设备名称',
|
||||
type: 'string',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
batteryModel: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请选择电池型号',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
batteryPrice: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入销售价格',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
batteryRent: [
|
||||
{
|
||||
required: true,
|
||||
message: '请输入租金金额',
|
||||
type: 'number',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
equipmentCategory: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请选择设备分类',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
equipmentCode: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请填写设备编号',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
isCtive: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请选择是否激活',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
equipmentType: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择设备类型',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
deliveryType: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择配送方式',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
equipmentPriceMin: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请输入设备价格',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
stockTotal: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请输入设备库存',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
specType: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择规格类型',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
deliveryId: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择运费模板',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
status: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择设备状态',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
sortNumber: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请输入排序号',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
deductStockType: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请设置库存计算方式',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
purchaseLimit: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请设置是否限购',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
// images: [
|
||||
// {
|
||||
// required: true,
|
||||
// type: 'string',
|
||||
// message: '请选择设备图片',
|
||||
// trigger: 'blur',
|
||||
// validator: async (_rule: RuleObject, value: string) => {
|
||||
// if (images.value.length == 0) {
|
||||
// return Promise.reject('请上传设备图片');
|
||||
// }
|
||||
// return Promise.resolve();
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
customerId: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请选择客户'
|
||||
}
|
||||
],
|
||||
linePriceMin: [
|
||||
{
|
||||
required: true,
|
||||
type: 'number',
|
||||
message: '请输入设备划线价',
|
||||
trigger: 'blur'
|
||||
}
|
||||
],
|
||||
content: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请输入文章内容',
|
||||
trigger: 'blur',
|
||||
validator: async (_rule: RuleObject, value: string) => {
|
||||
if (content.value == '') {
|
||||
return Promise.reject('请输入文字内容');
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
],
|
||||
brand: [
|
||||
{
|
||||
required: true,
|
||||
type: 'string',
|
||||
message: '请选项设备厂商',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
const editorRef = ref<InstanceType<typeof TinymceEditor> | null>(null);
|
||||
const config = ref({
|
||||
height: 500,
|
||||
// 自定义文件上传(这里使用把选择的文件转成 blob 演示)
|
||||
file_picker_callback: (callback: any, _value: any, meta: any) => {
|
||||
const input = document.createElement('input');
|
||||
input.setAttribute('type', 'file');
|
||||
// 设定文件可选类型
|
||||
if (meta.filetype === 'image') {
|
||||
input.setAttribute('accept', 'image/*');
|
||||
} else if (meta.filetype === 'media') {
|
||||
input.setAttribute('accept', 'video/*');
|
||||
}
|
||||
input.onchange = () => {
|
||||
const file = input.files?.[0];
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
if (meta.filetype === 'media') {
|
||||
if (!file.type.startsWith('video/')) {
|
||||
editorRef.value?.alert({ content: '只能选择视频文件' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (file.size / 1024 / 1024 > 20) {
|
||||
editorRef.value?.alert({ content: '大小不能超过 20MB' });
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
if (e.target?.result != null) {
|
||||
const blob = new Blob([e.target.result], { type: file.type });
|
||||
callback(URL.createObjectURL(blob));
|
||||
}
|
||||
};
|
||||
reader.readAsArrayBuffer(file);
|
||||
};
|
||||
input.click();
|
||||
}
|
||||
});
|
||||
|
||||
/* 控制放店开关 */
|
||||
const editStatus = () => {
|
||||
if (form.status == 0) {
|
||||
form.status = 1;
|
||||
} else {
|
||||
form.status = 0;
|
||||
}
|
||||
updateEquipment(form)
|
||||
.then(() => {
|
||||
message.success('操作成功');
|
||||
})
|
||||
.catch((e) => {
|
||||
message.error(e.message);
|
||||
});
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
updateVisible(false);
|
||||
};
|
||||
|
||||
/* 保存编辑 */
|
||||
const save = () => {
|
||||
if (!formRef.value) {
|
||||
return;
|
||||
}
|
||||
formRef.value
|
||||
.validate()
|
||||
.then(() => {
|
||||
loading.value = true;
|
||||
// 获取第一张图片作为封面图
|
||||
images.value.map((d, i) => {
|
||||
if (i === 0) {
|
||||
form.image = d.url;
|
||||
}
|
||||
});
|
||||
const equipmentForm = {
|
||||
...form,
|
||||
files: JSON.stringify(images.value),
|
||||
content: content.value,
|
||||
batteryDeliveryTime: batteryDeliveryTime.value?.format(
|
||||
'YYYY-MM-DD HH:mm:ss'
|
||||
),
|
||||
ctiveTime: ctiveTime.value?.format('YYYY-MM-DD HH:mm:ss')
|
||||
};
|
||||
console.log(equipmentForm, 'equipmentForm');
|
||||
const saveOrUpdate = isUpdate.value ? updateEquipment : addEquipment;
|
||||
saveOrUpdate(equipmentForm)
|
||||
.then((msg) => {
|
||||
loading.value = false;
|
||||
message.success(msg);
|
||||
updateVisible(false);
|
||||
emit('done');
|
||||
})
|
||||
.catch((e) => {
|
||||
loading.value = false;
|
||||
message.error(e.message);
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.visible,
|
||||
(visible) => {
|
||||
if (visible) {
|
||||
if (props.data) {
|
||||
loading.value = false;
|
||||
assignFields({
|
||||
...props.data
|
||||
});
|
||||
if (props.data.batteryDeliveryTime) {
|
||||
batteryDeliveryTime.value = dayjs(
|
||||
props.data.batteryDeliveryTime,
|
||||
'YYYY-MM-DD'
|
||||
);
|
||||
ctiveTime.value = dayjs(props.data.ctiveTime, 'YYYY-MM-DD');
|
||||
} else {
|
||||
batteryDeliveryTime.value = undefined;
|
||||
ctiveTime.value = undefined;
|
||||
}
|
||||
// images.value = JSON.parse(String(props.data.files));
|
||||
content.value = props.data.content;
|
||||
isUpdate.value = true;
|
||||
} else {
|
||||
isUpdate.value = false;
|
||||
}
|
||||
} else {
|
||||
resetFields();
|
||||
formRef.value?.clearValidate();
|
||||
}
|
||||
}
|
||||
);
|
||||
</script>
|
||||
<style lang="less">
|
||||
.tab-pane {
|
||||
min-height: 300px;
|
||||
}
|
||||
.ml-10 {
|
||||
margin-left: 5px;
|
||||
}
|
||||
</style>
|
||||
145
src/views/yunxinwei/index/components/search.vue
Normal file
145
src/views/yunxinwei/index/components/search.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<!-- 搜索表单 -->
|
||||
<template>
|
||||
<a-space>
|
||||
<a-button type="primary" class="ele-btn-icon" @click="add">
|
||||
<template #icon>
|
||||
<PlusOutlined />
|
||||
</template>
|
||||
<span>新建</span>
|
||||
</a-button>
|
||||
<a-button
|
||||
danger
|
||||
type="primary"
|
||||
class="ele-btn-icon"
|
||||
:v-role="`dev`"
|
||||
@click="removeBatch"
|
||||
:disabled="props.selection.length === 0"
|
||||
>
|
||||
<template #icon>
|
||||
<DeleteOutlined />
|
||||
</template>
|
||||
<span>批量删除</span>
|
||||
</a-button>
|
||||
<!-- <a-radio-group v-model:value="listType" @change="handleTabs">-->
|
||||
<!-- <a-radio-button value="all">全部</a-radio-button>-->
|
||||
<!-- <a-radio-button value="onSale">出售中</a-radio-button>-->
|
||||
<!-- <a-radio-button value="offSale">已下架</a-radio-button>-->
|
||||
<!-- <a-radio-button value="soldOut">已售罄</a-radio-button>-->
|
||||
<!-- </a-radio-group>-->
|
||||
<a-input-search
|
||||
allow-clear
|
||||
v-model:value="searchText"
|
||||
placeholder="请输入搜索关键词"
|
||||
@search="search"
|
||||
@pressEnter="search"
|
||||
>
|
||||
<template #addonBefore>
|
||||
<a-select v-model:value="type" style="width: 120px; margin: -5px -12px">
|
||||
<a-select-option value="equipmentCode">设备编号</a-select-option>
|
||||
<a-select-option value="equipmentName">设备名称</a-select-option>
|
||||
<a-select-option value="merchantCode">商户编号</a-select-option>
|
||||
</a-select>
|
||||
</template>
|
||||
</a-input-search>
|
||||
<!-- <CustomerSelect-->
|
||||
<!-- v-model:value="where.equipmentId"-->
|
||||
<!-- :placeholder="`按设备筛选`"-->
|
||||
<!-- @select="onSelect"-->
|
||||
<!-- @clear="onClear"-->
|
||||
<!-- />-->
|
||||
</a-space>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import {
|
||||
PlusOutlined,
|
||||
EditOutlined,
|
||||
DeleteOutlined
|
||||
} from '@ant-design/icons-vue';
|
||||
import useSearch from '@/utils/use-search';
|
||||
import type { EquipmentParam } from '@/api/apps/equipment/model';
|
||||
// import CustomerSelect from '@/components/CustomerSelect/index.vue';
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'search', where?: EquipmentParam): void;
|
||||
(e: 'add'): void;
|
||||
(e: 'remove'): void;
|
||||
}>();
|
||||
|
||||
const props = defineProps<{
|
||||
// 勾选的项目
|
||||
selection?: [];
|
||||
}>();
|
||||
|
||||
// 表单数据
|
||||
const { where } = useSearch<EquipmentParam>({
|
||||
equipmentId: undefined,
|
||||
equipmentName: '',
|
||||
equipmentCode: '',
|
||||
merchantCode: ''
|
||||
});
|
||||
|
||||
// 下来选项
|
||||
const type = ref('equipmentCode');
|
||||
// tabType
|
||||
// const listType = ref('all');
|
||||
// 搜索内容
|
||||
const searchText = ref('');
|
||||
|
||||
/* 搜索 */
|
||||
const search = () => {
|
||||
where.equipmentName = undefined;
|
||||
where.equipmentCode = undefined;
|
||||
where.merchantCode = undefined;
|
||||
if (type.value == 'equipmentName') {
|
||||
where.equipmentName = searchText.value;
|
||||
}
|
||||
if (type.value == 'equipmentCode') {
|
||||
where.equipmentCode = searchText.value;
|
||||
}
|
||||
if (type.value == 'merchantCode') {
|
||||
where.merchantCode = searchText.value;
|
||||
}
|
||||
emit('search', where);
|
||||
};
|
||||
|
||||
// const handleTabs = (e) => {
|
||||
// listType.value = e.target.value;
|
||||
// if (listType.value == 'all') {
|
||||
// resetFields();
|
||||
// }
|
||||
// if (listType.value == 'onSale') {
|
||||
// where.status = 0;
|
||||
// }
|
||||
// if (listType.value == 'offSale') {
|
||||
// where.status = 1;
|
||||
// }
|
||||
// if (listType.value == 'soldOut') {
|
||||
// where.stockTotal = 0;
|
||||
// }
|
||||
// emit('search', where);
|
||||
// };
|
||||
|
||||
// 新增
|
||||
const add = () => {
|
||||
emit('add');
|
||||
};
|
||||
|
||||
// 批量删除
|
||||
const removeBatch = () => {
|
||||
emit('remove');
|
||||
};
|
||||
|
||||
/* 重置 */
|
||||
// const reset = () => {
|
||||
// resetFields();
|
||||
// search();
|
||||
// };
|
||||
|
||||
// 监听字典id变化
|
||||
watch(
|
||||
() => props.selection,
|
||||
() => {}
|
||||
);
|
||||
</script>
|
||||
377
src/views/yunxinwei/index/index.vue
Normal file
377
src/views/yunxinwei/index/index.vue
Normal file
@@ -0,0 +1,377 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<a-page-header :ghost="false" title="设备管理">
|
||||
<div class="ele-text-secondary"> 设备管理,云芯威电池管理定制模块。 </div>
|
||||
</a-page-header>
|
||||
<div class="ele-body">
|
||||
<a-card :bordered="false">
|
||||
<!-- 表格 -->
|
||||
<ele-pro-table
|
||||
ref="tableRef"
|
||||
row-key="equipmentId"
|
||||
:columns="columns"
|
||||
:height="tableHeight"
|
||||
:datasource="datasource"
|
||||
v-model:selection="selection"
|
||||
:scroll="{ x: 3000 }"
|
||||
>
|
||||
<template #toolbar>
|
||||
<search
|
||||
:selection="selection"
|
||||
@search="reload"
|
||||
@add="openEdit"
|
||||
@remove="removeBatch"
|
||||
/>
|
||||
</template>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'image'">
|
||||
<a-image :src="record.image" :width="40" />
|
||||
</template>
|
||||
<template v-if="column.key === 'equipmentCode'">
|
||||
<span>{{ record.equipmentCode }}</span>
|
||||
</template>
|
||||
<template v-if="column.key === 'equipmentName'">
|
||||
{{ record.equipmentName }}
|
||||
</template>
|
||||
<template v-if="column.key === 'merchantName'">
|
||||
<div style="display: flex; flex-direction: column">
|
||||
<span>{{ record.merchantName }}</span>
|
||||
<span class="ele-text-placeholder">
|
||||
商户编号:{{ record.merchantCode }}
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="column.key === 'user'">
|
||||
<User v-if="record.user" :record="record.user" />
|
||||
</template>
|
||||
<template v-if="column.key === 'qrcode'">
|
||||
<a-image :src="record.qrcode" :width="50" />
|
||||
</template>
|
||||
<template v-if="column.key === 'batteryPrice'">
|
||||
<strong class="ele-text-danger">
|
||||
¥{{ record.batteryPrice }}
|
||||
</strong>
|
||||
</template>
|
||||
<template v-if="column.key === 'batteryRent'">
|
||||
<strong class="ele-text-danger">
|
||||
¥{{ record.batteryRent }}/月
|
||||
</strong>
|
||||
</template>
|
||||
<template v-if="column.key === 'batteryDeposit'">
|
||||
<strong class="ele-text-danger">
|
||||
¥{{ record.batteryDeposit }}
|
||||
</strong>
|
||||
</template>
|
||||
<template v-if="column.key === 'batteryInsurance'">
|
||||
<strong class="ele-text-danger">
|
||||
¥{{ record.batteryInsurance }}
|
||||
</strong>
|
||||
</template>
|
||||
<template v-if="column.key === 'isOnline'">
|
||||
<a-tag v-if="record.status === 0" color="green">正常</a-tag>
|
||||
<a-tag v-if="record.status === 1" color="orange">异常</a-tag>
|
||||
</template>
|
||||
<template v-if="column.key === 'comments'">
|
||||
<a-tooltip :title="record.comments" placement="topLeft">
|
||||
{{ record.comments }}
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<template v-if="column.key === 'userId'">
|
||||
<a-tag v-if="record.userId === 0" color="orange">未绑定</a-tag>
|
||||
<a-tag v-else color="green">已绑定</a-tag>
|
||||
</template>
|
||||
<template v-if="column.key === 'createTime'">
|
||||
<a-tooltip :title="`${toDateString(record.createTime)}`">
|
||||
{{ timeAgo(record.createTime) }}
|
||||
</a-tooltip>
|
||||
</template>
|
||||
<template v-if="column.key === 'action'">
|
||||
<a-space>
|
||||
<a-button @click="openEdit(record)">修改</a-button>
|
||||
<!-- <a-divider type="vertical" />-->
|
||||
<!-- <a-popconfirm-->
|
||||
<!-- title="确定要删除此记录吗?"-->
|
||||
<!-- @confirm="remove(record)"-->
|
||||
<!-- >-->
|
||||
<!-- <a class="ele-text-danger">删除</a>-->
|
||||
<!-- </a-popconfirm>-->
|
||||
</a-space>
|
||||
</template>
|
||||
</template>
|
||||
</ele-pro-table>
|
||||
</a-card>
|
||||
<!-- 编辑弹窗 -->
|
||||
<equipment-edit
|
||||
v-model:visible="showEdit"
|
||||
:data="current"
|
||||
@done="reload"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!--suppress TypeScriptValidateTypes -->
|
||||
<script lang="ts" setup>
|
||||
import { timeAgo } from 'ele-admin-pro';
|
||||
import { createVNode, computed, ref } from 'vue';
|
||||
import { message, Modal } from 'ant-design-vue';
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
|
||||
import type { EleProTable } from 'ele-admin-pro';
|
||||
import type {
|
||||
DatasourceFunction,
|
||||
ColumnItem
|
||||
} from 'ele-admin-pro/es/ele-pro-table/types';
|
||||
import { toDateString } from 'ele-admin-pro';
|
||||
import Search from './components/search.vue';
|
||||
import EquipmentEdit from './components/equipment-edit.vue';
|
||||
import { pageEquipment, removeBatchEquipment } from '@/api/apps/equipment';
|
||||
import type { Equipment, EquipmentParam } from '@/api/apps/equipment/model';
|
||||
// import { Category } from '@/api/goods/category/model';
|
||||
// import { getDictionaryOptions } from '@/utils/common';
|
||||
// import { useUserStore } from '@/store/modules/user';
|
||||
|
||||
// 表格实例
|
||||
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
||||
|
||||
// 当前用户信息
|
||||
// const brand = getDictionaryOptions('serverBrand');
|
||||
|
||||
// 表格列配置
|
||||
const columns = ref<ColumnItem[]>([
|
||||
{
|
||||
key: 'index',
|
||||
width: 48,
|
||||
align: 'center',
|
||||
fixed: 'left',
|
||||
hideInSetting: true,
|
||||
customRender: ({ index }) => index + (tableRef.value?.tableIndex ?? 0)
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 90,
|
||||
fixed: 'left',
|
||||
align: 'center',
|
||||
hideInSetting: true
|
||||
},
|
||||
{
|
||||
title: '二维码',
|
||||
dataIndex: 'qrcode',
|
||||
key: 'qrcode',
|
||||
fixed: 'left',
|
||||
align: 'center',
|
||||
width: 80
|
||||
},
|
||||
{
|
||||
title: '设备编号',
|
||||
dataIndex: 'equipmentCode',
|
||||
key: 'equipmentCode'
|
||||
},
|
||||
{
|
||||
title: '所属商户',
|
||||
dataIndex: 'merchantName',
|
||||
key: 'merchantName',
|
||||
sorter: true,
|
||||
width: 220,
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '用户信息',
|
||||
dataIndex: 'user',
|
||||
key: 'user'
|
||||
},
|
||||
{
|
||||
title: '设备名称',
|
||||
dataIndex: 'equipmentName',
|
||||
key: 'equipmentName'
|
||||
},
|
||||
{
|
||||
title: '激活状态',
|
||||
dataIndex: 'isCtive',
|
||||
sorter: true
|
||||
},
|
||||
{
|
||||
title: '在线状态',
|
||||
dataIndex: 'isOnline',
|
||||
sorter: true,
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '电池型号',
|
||||
dataIndex: 'batteryModel',
|
||||
sorter: true,
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: 'BMS',
|
||||
dataIndex: 'bms',
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '工作状态',
|
||||
dataIndex: 'workingStatus',
|
||||
sorter: true,
|
||||
ellipsis: true
|
||||
},
|
||||
{
|
||||
title: '租赁状态',
|
||||
dataIndex: 'leaseStatus',
|
||||
sorter: true,
|
||||
key: 'leaseStatus'
|
||||
},
|
||||
{
|
||||
title: '电池状态',
|
||||
dataIndex: 'batteryStatus',
|
||||
sorter: true,
|
||||
key: 'batteryStatus',
|
||||
showSorterTooltip: false,
|
||||
customRender: ({ text }) => ['上架', '下架'][text]
|
||||
},
|
||||
{
|
||||
title: '电池电量',
|
||||
dataIndex: 'batteryPower',
|
||||
sorter: true,
|
||||
key: 'batteryPower'
|
||||
},
|
||||
{
|
||||
title: '排序',
|
||||
dataIndex: 'sortNumber',
|
||||
sorter: true
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createTime',
|
||||
key: 'createTime',
|
||||
sorter: true,
|
||||
ellipsis: true,
|
||||
hideInTable: true,
|
||||
customRender: ({ text }) => toDateString(text)
|
||||
},
|
||||
{
|
||||
title: '绑定状态',
|
||||
dataIndex: 'userId',
|
||||
key: 'userId',
|
||||
fixed: 'right',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
sorter: true
|
||||
}
|
||||
]);
|
||||
|
||||
// 表格选中数据
|
||||
const selection = ref<Equipment[]>([]);
|
||||
// 当前编辑数据
|
||||
const current = ref<Equipment | null>(null);
|
||||
// 是否显示编辑弹窗
|
||||
const showEdit = ref(false);
|
||||
// 树形数据
|
||||
// const data = ref<Category[]>([]);
|
||||
|
||||
// 表格数据源
|
||||
const datasource: DatasourceFunction = ({
|
||||
page,
|
||||
limit,
|
||||
where,
|
||||
orders,
|
||||
filters
|
||||
}) => {
|
||||
// if (filters) {
|
||||
// where.brand = filters.brand;
|
||||
// }
|
||||
return pageEquipment({ ...where, ...orders, ...filters, page, limit });
|
||||
};
|
||||
|
||||
/* 搜索 */
|
||||
const reload = (where?: EquipmentParam) => {
|
||||
selection.value = [];
|
||||
tableRef?.value?.reload({ where: where });
|
||||
};
|
||||
|
||||
// 搜索是否展开
|
||||
const searchExpand = ref(false);
|
||||
|
||||
// 表格固定高度
|
||||
const fixedHeight = ref(false);
|
||||
|
||||
// 表格高度
|
||||
const tableHeight = computed(() => {
|
||||
return fixedHeight.value
|
||||
? searchExpand.value
|
||||
? 'calc(100vh - 618px)'
|
||||
: 'calc(100vh - 562px)'
|
||||
: void 0;
|
||||
});
|
||||
|
||||
/* 打开编辑弹窗 */
|
||||
const openEdit = (row?: Equipment) => {
|
||||
current.value = row ?? null;
|
||||
showEdit.value = true;
|
||||
};
|
||||
|
||||
/* 打开用户详情弹窗 */
|
||||
// const openInfo = (row?: Equipment) => {
|
||||
// current.value = row ?? null;
|
||||
// showEdit.value = true;
|
||||
// };
|
||||
|
||||
/* 删除单个 */
|
||||
// const remove = (row: Equipment) => {
|
||||
// const hide = message.loading('请求中..', 0);
|
||||
// removeEquipment(row.equipmentId)
|
||||
// .then((msg) => {
|
||||
// hide();
|
||||
// message.success(msg);
|
||||
// reload();
|
||||
// })
|
||||
// .catch((e) => {
|
||||
// hide();
|
||||
// message.error(e.message);
|
||||
// });
|
||||
// };
|
||||
|
||||
/* 批量删除 */
|
||||
const removeBatch = () => {
|
||||
if (!selection.value.length) {
|
||||
message.error('请至少选择一条数据');
|
||||
return;
|
||||
}
|
||||
Modal.confirm({
|
||||
title: '提示',
|
||||
content: '确定要删除选中的记录吗?',
|
||||
icon: createVNode(ExclamationCircleOutlined),
|
||||
maskClosable: true,
|
||||
onOk: () => {
|
||||
const hide = message.loading('请求中..', 0);
|
||||
removeBatchEquipment(selection.value.map((d) => d.equipmentId))
|
||||
.then((msg) => {
|
||||
hide();
|
||||
message.success(msg);
|
||||
reload();
|
||||
})
|
||||
.catch((e) => {
|
||||
hide();
|
||||
message.error(e.message);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
export default {
|
||||
name: 'EquipmentIndex'
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
// 文字超出隐藏(两行)
|
||||
// 需要设置文字容器的宽度
|
||||
.twoline-hide {
|
||||
width: 320px;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
white-space: normal;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user