| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <template>
- <div class="m-4 modals">
- <div>
- <XTTitle title="耗材管理" :right-data="titleData" @click="callTitleClick" />
- <div class="flex items-center justify-between my-4">
- <XTTab
- type="illness"
- :width="180"
- :selected="tabSelected"
- :data="typeOptions"
- @item-click="callTab"
- />
- <XTForm :form-data="formData" @change="callForm" />
- </div>
- </div>
- <BasicTable @register="registerTable">
- <template #bodyCell="{ column, record }">
- <template v-if="column.key === 'disable'">
- <span
- :class="['table-dot']"
- :style="{ backgroundColor: formatDictPreColor(responseTypeOptions, record.disable) }"
- />
- <span> {{ formatDictValue(responseTypeOptions, record.disable) }}</span>
- </template>
- <template v-if="column.key === 'supplierCategory'">
- <span>
- {{ formatDictValue(responsesupplierCategoryOptions, record.supplierCategory) }}</span
- >
- </template>
- <template v-if="column.key === 'action'">
- <TableAction
- :actions="[
- {
- auth: 'biz:consumable:edit',
- icon: 'icon-xt-details_edit_default|iconfont',
- tooltip: '编辑',
- onClick: handleEdit.bind(null, record),
- },
- {
- auth: 'biz:consumable:updateStatus',
- icon: 'icon-tingyong-moren|iconfont',
- tooltip: '停用',
- ifShow: record.disable === 0,
- popConfirm: {
- title: '是否确认停用',
- placement: 'left',
- confirm: handleDelete.bind(null, record),
- },
- },
- {
- auth: 'biz:consumable:updateStatus',
- icon: 'icon-xt-revocation_default|iconfont',
- tooltip: '启用',
- ifShow: record.disable === 1,
- popConfirm: {
- title: '是否确认启用',
- placement: 'left',
- confirm: handleDelete.bind(null, record),
- },
- },
- ]"
- />
- </template>
- </template>
- </BasicTable>
- <FormModal @register="registerModal" @success="callSuccess" @cancel="handleCancel" />
- <ImportModal @register="registerImpModal" />
- </div>
- </template>
- <script lang="ts" setup>
- import { onBeforeMount, ref } from 'vue';
- import { BasicTable, useTable, TableAction } from '/@/components/TableCard';
- import { useMessage } from '/@/hooks/web/useMessage';
- import FormModal from './formModal.vue';
- import { ImportModal } from '/@/components/XTImport/index';
- import { formatDictValue, formatDictPreColor } from '/@/utils';
- import { columns } from './data';
- import {
- getsuppliesList,
- suppliesDel,
- getStatusNumber,
- suppliesExport,
- suppliesImportBatch,
- } from '/@/api/biz/inventory/suppliesApi';
- import { listDictModel } from '/@/api/common';
- import { useModal } from '/@/components/Modal';
- import { XTTitle } from '/@/components/XTTitle/index';
- import { XTTab } from '/@/components/XTTab/index';
- import { XTForm } from '/@/components/XTForm/index';
- import dayjs from 'dayjs';
- // 标题数据
- const titleData = [
- {
- type: 'print',
- icon: 'icon-xt-print_default',
- },
- {
- type: 'import',
- auth: ['archives:consumable:import'],
- icon: 'icon-xt-import_default',
- },
- {
- type: 'add',
- btnIcon: 'icon-xt-add_default',
- auth: ['biz:consumable:add'],
- btnText: '新增耗材',
- },
- ];
- // formdata
- const formData = [
- {
- name: 'shiftDate',
- componentType: 'RangePicker',
- format: 'YYYY-MM-DD',
- valueFormat: 'YYYY-MM-DD',
- placeholder: '请选择日期',
- width: 240,
- },
- {
- name: 'searchNames',
- componentType: 'Input',
- prefix: 'icon-xt-search',
- placeholder: '请输入助记码',
- width: 240,
- },
- ];
- // tab 切换选中
- const tabSelected = ref();
- // 操作名称
- const searchNames = ref('');
- const shiftDate = ref([]);
- const typeOptions = ref();
- const responseTypeOptions = ref();
- const responsesupplierCategoryOptions = ref();
- onBeforeMount(async () => {
- responseTypeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
- responsesupplierCategoryOptions.value = await listDictModel({ dictCode: 'pht' });
- getTab();
- });
- const { createMessage } = useMessage();
- const [registerModal, { openModal }] = useModal();
- const [registerImpModal, { openModal: openImpModal }] = useModal();
- const tableSort = ref([
- {
- field: 'create_time',
- direction: 'DESC',
- },
- ]) as any;
- const [registerTable, { reload, clearSelectedRowKeys }] = useTable({
- api: getsuppliesList,
- batchDelApi: suppliesDel,
- // batchExportApi: suppliesExport,
- delAuthList: ['biz:consumable:remove'],
- rowKey: 'id',
- columns,
- showIndexColumn: true,
- bordered: true,
- actionColumn: {
- width: 200,
- title: '操作',
- dataIndex: 'action',
- },
- beforeFetch: handleBeforeFetch,
- sortFn: handleSortFn,
- });
- // 详情按钮事件
- function handleEdit(record) {
- openModal(true, {
- record,
- isUpdate: true,
- });
- }
- // 新增按钮事件
- function callTitleClick(data) {
- if (data.type == 'add') {
- openModal(true, {
- isUpdate: false,
- record: data,
- });
- } else if (data.type == 'print') {
- console.log('打印中...');
- } else if (data.type == 'import') {
- openImpModal(true, {
- title: '导入耗材数据',
- importUrl: suppliesImportBatch,
- exportUrl: suppliesExport,
- });
- }
- }
- // 删除按钮事件
- async function handleDelete(record: Recordable) {
- if (record) {
- await suppliesDel(record.id);
- createMessage.success('停用成功!');
- clearSelectedRowKeys();
- await reload();
- await getTab();
- }
- }
- // 表格点击字段排序
- function handleSortFn(sortInfo) {
- if (sortInfo?.order && sortInfo?.columnKey) {
- // 默认单列排序
- tableSort.value = [
- {
- field: sortInfo.columnKey,
- direction: sortInfo.order.replace(/(\w+)(end)/g, '$1').toUpperCase(),
- },
- ];
- }
- }
- // 表格请求之前,对参数进行处理, 添加默认 排序
- async function handleBeforeFetch(params) {
- const shiftTimes = [];
- if (shiftDate.value && shiftDate.value.length > 0) {
- shiftTimes.push(shiftDate.value[0]);
- shiftTimes.push(shiftDate.value[1]);
- shiftTimes[1] = dayjs(shiftTimes[1]).add(1, 'day').format('YYYY-MM-DD');
- }
- return {
- ...params,
- orders: tableSort.value,
- name: searchNames.value == '' ? undefined : searchNames.value,
- status: tabSelected.value == '' ? undefined : tabSelected.value,
- time: shiftTimes.length <= 0 ? undefined : shiftTimes,
- };
- }
- async function getTab() {
- typeOptions.value = await listDictModel({ dictCode: 'sys_disable_type' });
- const typeNums = await getStatusNumber(); // 获取各类型数量
- let typeList = [];
- typeOptions.value.forEach(ele => {
- // 变量各类型放置对应数量
- let typeData = {};
- Object.keys(typeNums).forEach(numKey => {
- if (ele.value == numKey) {
- typeData = {
- key: ele.value,
- label: ele.label,
- value: typeNums[numKey],
- hasValue: true,
- prefixColor: ele.prefixColor,
- hasBracket: true,
- };
- typeList.push(typeData);
- }
- });
- });
- typeList = typeList.reverse();
- typeList.splice(0, 0, {
- key: '',
- label: '全部',
- value: typeNums.total,
- hasValue: true,
- hasBracket: true,
- });
- typeOptions.value = typeList;
- tabSelected.value = typeOptions.value[0].key;
- }
- //取消按钮事件
- async function handleCancel() {
- clearSelectedRowKeys();
- await reload();
- await getTab();
- }
- // 弹窗回调事件
- async function callSuccess({ isUpdate, values }) {
- console.log(isUpdate);
- console.log(values);
- await reload();
- await getTab();
- }
- // 选项卡组件回调
- async function callTab(data) {
- tabSelected.value = data.value;
- await reload();
- }
- // 查询组件回调
- async function callForm(data) {
- shiftDate.value = data.shiftDate ? data.shiftDate : '';
- searchNames.value = data.searchNames ? data.searchNames : '';
- console.log('callForm:::', searchNames.value);
- await reload();
- }
- </script>
- <style lang="less" scoped>
- .table-dot {
- display: inline-block;
- width: 10px;
- height: 10px;
- margin-right: 6px;
- border-radius: 50%;
- }
- ::v-deep(.ant-btn-link) {
- color: #3d4155;
- }
- ::v-deep(.ant-input-prefix) {
- color: #8a99ac;
- }
- .colUpdateAvatar {
- display: flex;
- justify-content: center;
- text-align: center;
- line-height: 28px;
- }
- .colImg {
- width: 28px;
- height: 28px;
- margin-right: 5px;
- }
- </style>
|