273 lines
7.1 KiB
Vue
273 lines
7.1 KiB
Vue
<template>
|
|
<div class="ele-body">
|
|
<a-card :bordered="false" style="margin-top: 10px">
|
|
<!-- 表格 -->
|
|
<ele-pro-table
|
|
ref="tableRef"
|
|
row-key="goodsId"
|
|
:columns="columns"
|
|
:datasource="datasource"
|
|
:customRow="customRow"
|
|
:expand-icon-column-index="1"
|
|
:scroll="{ x: 1200 }"
|
|
cache-key="towerModel"
|
|
>
|
|
<template #toolbar>
|
|
<a-space>
|
|
<!-- 搜索表单 -->
|
|
<a-input-search
|
|
allow-clear
|
|
v-model:value="searchText"
|
|
placeholder="请输入搜索关键词"
|
|
@search="search"
|
|
@pressEnter="search"
|
|
/>
|
|
</a-space>
|
|
</template>
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="column.key === 'userId'">
|
|
{{ `${record.nickname ? record.nickname : ''}` }}
|
|
</template>
|
|
<template v-if="column.key === 'files'">
|
|
<a-image-preview-group v-if="record.files">
|
|
<a-image
|
|
:width="70"
|
|
v-for="(item, index) in JSON.parse(record.files)"
|
|
:key="index"
|
|
:src="item.url"
|
|
/>
|
|
</a-image-preview-group>
|
|
</template>
|
|
<template v-if="column.key === 'stockLower'">
|
|
<a-tag v-if="record.stock < record.stockMin" color="red">是</a-tag>
|
|
<a-tag v-else>否</a-tag>
|
|
</template>
|
|
<template v-if="column.key === 'salePrice'">
|
|
<span class="ele-text-danger">¥{{ record.salePrice }}</span>
|
|
</template>
|
|
<template v-if="column.key === 'stockMoney'">
|
|
<span class="ele-text-warning">¥{{ record.stock * record.price }}</span>
|
|
</template>
|
|
<template v-if="column.key === 'status'">
|
|
<a-tag v-if="record.status == 0">正常</a-tag>
|
|
<a-tag v-if="record.status == 1" color="red">待修</a-tag>
|
|
<a-tag v-if="record.status == 2" color="green">异常已修</a-tag>
|
|
<a-tag v-if="record.status == 3" color="orange">异常未修</a-tag>
|
|
</template>
|
|
<template v-if="column.key === 'action'">
|
|
<a-space>
|
|
<!-- <a @click="openRecord(record)">保养记录</a>-->
|
|
<!-- <a-divider type="vertical" />-->
|
|
<a @click="openEdit(record)">修改</a>
|
|
<a-divider type="vertical" />
|
|
<a-popconfirm
|
|
placement="topRight"
|
|
title="确定要删除此记录吗?"
|
|
@confirm="remove(record)"
|
|
>
|
|
<a class="ele-text-danger">删除</a>
|
|
</a-popconfirm>
|
|
</a-space>
|
|
</template>
|
|
</template>
|
|
</ele-pro-table>
|
|
</a-card>
|
|
<!-- 编辑弹窗 -->
|
|
<GoodsEdit v-model:visible="showEdit" :data="current" @done="reload" />
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue';
|
|
import { message } from 'ant-design-vue/es';
|
|
import { PlusOutlined } from '@ant-design/icons-vue';
|
|
import type {
|
|
DatasourceFunction,
|
|
ColumnItem
|
|
} from 'ele-admin-pro/es/ele-pro-table/types';
|
|
import { messageLoading } from 'ele-admin-pro/es';
|
|
import type { EleProTable } from 'ele-admin-pro/es';
|
|
import type { Goods, GoodsParam } from '@/api/tower/part/goods/model';
|
|
import { pageGoods, removeGoods } from '@/api/tower/part/goods';
|
|
import GoodsEdit from './components/goods-edit.vue';
|
|
|
|
// 表格实例
|
|
const tableRef = ref<InstanceType<typeof EleProTable> | null>(null);
|
|
|
|
// 表格列配置
|
|
const columns = ref<ColumnItem[]>([
|
|
// {
|
|
// key: 'index',
|
|
// width: 48,
|
|
// align: 'center',
|
|
// fixed: 'left',
|
|
// hideInSetting: true,
|
|
// customRender: ({ index }) => index + (tableRef.value?.tableIndex ?? 0)
|
|
// },
|
|
{
|
|
title: '产品编码',
|
|
dataIndex: 'goodsCode',
|
|
key: 'goodsCode'
|
|
},
|
|
{
|
|
title: '类别',
|
|
dataIndex: 'category',
|
|
key: 'category'
|
|
},
|
|
{
|
|
title: '产品名称',
|
|
dataIndex: 'goodsName',
|
|
key: 'goodsName'
|
|
},
|
|
{
|
|
title: '产品规格',
|
|
dataIndex: 'specs',
|
|
key: 'specs'
|
|
},
|
|
{
|
|
title: '货架',
|
|
dataIndex: 'position',
|
|
key: 'position'
|
|
},
|
|
{
|
|
title: '期初库存'
|
|
},
|
|
{
|
|
title: '入库数量'
|
|
},
|
|
{
|
|
title: '出库数量'
|
|
},
|
|
{
|
|
title: '进货价格',
|
|
dataIndex: 'price',
|
|
key: 'price'
|
|
},
|
|
{
|
|
title: '库存数量',
|
|
dataIndex: 'stock',
|
|
key: 'stock'
|
|
},
|
|
{
|
|
title: '库存金额',
|
|
dataIndex: 'stockMoney',
|
|
key: 'stockMoney'
|
|
},
|
|
{
|
|
title: '最低库存',
|
|
dataIndex: 'stockMin',
|
|
key: 'stockMin'
|
|
},
|
|
{
|
|
title: '是否低于最低库存',
|
|
dataIndex: 'stockLower',
|
|
key: 'stockLower'
|
|
}
|
|
]);
|
|
|
|
// 当前编辑数据
|
|
const current = ref<Goods | null>(null);
|
|
const searchText = ref('');
|
|
// 是否显示编辑弹窗
|
|
const showEdit = ref(false);
|
|
const showRecord = ref(false);
|
|
|
|
// 日期范围选择
|
|
const dateRange = ref<[string, string]>(['', '']);
|
|
|
|
// 表格数据源
|
|
const datasource: DatasourceFunction = ({ where }) => {
|
|
if (searchText.value && searchText.value != '') {
|
|
where.keywords = searchText.value;
|
|
}
|
|
where.type = 1;
|
|
return pageGoods({ ...where });
|
|
};
|
|
|
|
/* 刷新表格 */
|
|
const reload = (where?: GoodsParam) => {
|
|
tableRef?.value?.reload({ where });
|
|
};
|
|
|
|
/* 打开编辑弹窗 */
|
|
const openEdit = (row?: Goods | null, id?: number) => {
|
|
current.value = row ?? null;
|
|
showEdit.value = true;
|
|
};
|
|
|
|
const openRecord = (row?: Goods, id?: number) => {
|
|
current.value = row ?? null;
|
|
showRecord.value = true;
|
|
};
|
|
|
|
const search = (searchText) => {
|
|
reload({ keywords: searchText });
|
|
};
|
|
|
|
const onStatus = (e: any) => {
|
|
console.log(e.target.value);
|
|
const status = e.target.value;
|
|
reload({ status });
|
|
};
|
|
|
|
/* 删除单个 */
|
|
const remove = (row: Goods) => {
|
|
const hide = messageLoading('请求中..', 0);
|
|
removeGoods(row.goodsId)
|
|
.then((msg) => {
|
|
hide();
|
|
message.success(msg);
|
|
reload();
|
|
})
|
|
.catch((e) => {
|
|
hide();
|
|
message.error(e.message);
|
|
});
|
|
};
|
|
|
|
/* 自定义行属性 */
|
|
const customRow = (record: Goods) => {
|
|
return {
|
|
// 行点击事件
|
|
onClick: () => {
|
|
// console.log(record);
|
|
},
|
|
// 行双击事件
|
|
onDblclick: () => {
|
|
openEdit(record);
|
|
}
|
|
};
|
|
};
|
|
</script>
|
|
|
|
<script lang="ts">
|
|
export default {
|
|
name: 'TowerGoods'
|
|
};
|
|
</script>
|
|
<style lang="less" scoped>
|
|
.count {
|
|
display: flex;
|
|
.btn {
|
|
margin: 0 12px;
|
|
padding: 6px 18px;
|
|
background-color: #f3f3f3;
|
|
border-radius: 4px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
font-size: 16px;
|
|
.divider {
|
|
width: 4px;
|
|
height: 15px;
|
|
border-radius: 8px;
|
|
margin-right: 8px;
|
|
background-color: #16a90b;
|
|
}
|
|
.active {
|
|
color: #16a90b;
|
|
}
|
|
}
|
|
}
|
|
</style>
|