|
@@ -0,0 +1,226 @@
|
|
|
+<template>
|
|
|
+ <BasicDrawer
|
|
|
+ @ok="handleSubmit"
|
|
|
+ :destroyOnClose="true"
|
|
|
+ :maskClosable="false"
|
|
|
+ v-bind="$attrs"
|
|
|
+ @register="registerDrawer"
|
|
|
+ :title="getTitle"
|
|
|
+ :width="1002"
|
|
|
+ showFooter
|
|
|
+ >
|
|
|
+ <BasicTable @register="registerTable">
|
|
|
+ <template #action="{ index }">
|
|
|
+ <TableAction
|
|
|
+ :actions="[
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ onClick: handleDelete.bind(null, index),
|
|
|
+ },
|
|
|
+ ]"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template #discount="{ record }">
|
|
|
+ <a-input-number
|
|
|
+ :step="1"
|
|
|
+ :default-value="0"
|
|
|
+ :min="0"
|
|
|
+ placeholder="请输入折扣"
|
|
|
+ v-model:value="record.discount"
|
|
|
+ :disabled="record.inStockNum > 0"
|
|
|
+ @change="handleChangeDiscount(record)"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ <template #warehouseNumber="{ record }">
|
|
|
+ <a-input-number
|
|
|
+ :step="1"
|
|
|
+ :default-value="0"
|
|
|
+ :min="0"
|
|
|
+ placeholder="请输入数量"
|
|
|
+ v-model:value="record.warehouseNumber"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </BasicTable>
|
|
|
+ <a-button block type="primary" ghost @click="handleSelect">选择教材</a-button>
|
|
|
+ <TextbookSelect @register="textbookSelectRegister" @success="handleSuccess" />
|
|
|
+ </BasicDrawer>
|
|
|
+</template>
|
|
|
+<script setup lang="ts">
|
|
|
+ import { ref, computed, unref } from 'vue';
|
|
|
+ import { useMessage } from '/@/hooks/web/useMessage';
|
|
|
+ import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
|
|
|
+ import { useTable, BasicTable, TableAction } from '/@/components/Table';
|
|
|
+ import { requestMagicApi } from '/@/api/magicApi';
|
|
|
+ import TextbookSelect from '/@/views/teachingManager/textbookManagement/components/select.vue';
|
|
|
+ import { useModal } from '/@/components/Modal';
|
|
|
+ import { postTextbookWarehouseRecordTextbookWarehouse } from '/@/services/apis/TextbookWarehouseRecordController';
|
|
|
+
|
|
|
+ const isUpdate = ref(true);
|
|
|
+ const emit = defineEmits(['success', 'register']);
|
|
|
+ const { createMessage } = useMessage();
|
|
|
+ const [textbookSelectRegister, { openModal }] = useModal();
|
|
|
+
|
|
|
+ const [registerTable, { setTableData, getForm, getDataSource }] = useTable({
|
|
|
+ title: '',
|
|
|
+ rowKey: 'textbookId',
|
|
|
+ columns: [
|
|
|
+ {
|
|
|
+ title: '书名',
|
|
|
+ dataIndex: 'bookName',
|
|
|
+ align: 'left',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '书号(ISSN)',
|
|
|
+ dataIndex: 'issn',
|
|
|
+ align: 'left',
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '定价',
|
|
|
+ dataIndex: 'price',
|
|
|
+ align: 'left',
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '折扣',
|
|
|
+ dataIndex: 'discount',
|
|
|
+ align: 'left',
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '小计',
|
|
|
+ dataIndex: 'subtotal',
|
|
|
+ align: 'left',
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ title: '入库数量',
|
|
|
+ dataIndex: 'warehouseNumber',
|
|
|
+ align: 'left',
|
|
|
+ width: 100,
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ formConfig: {
|
|
|
+ labelWidth: 120,
|
|
|
+ schemas: [
|
|
|
+ {
|
|
|
+ label: '学期',
|
|
|
+ field: 'baseSemesterId',
|
|
|
+ component: 'ApiSelect',
|
|
|
+ componentProps: {
|
|
|
+ getPopupContainer: () => document.body,
|
|
|
+ api: requestMagicApi,
|
|
|
+ params: { url: 'baseData/semester/option' },
|
|
|
+ onChange: () => {
|
|
|
+ setTableData([]);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ colProps: { span: 23 },
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ showActionButtonGroup: false,
|
|
|
+ },
|
|
|
+ useSearchForm: true,
|
|
|
+ showTableSetting: false,
|
|
|
+ bordered: true,
|
|
|
+ immediate: false,
|
|
|
+ canResize: false,
|
|
|
+ pagination: false,
|
|
|
+ actionColumn: {
|
|
|
+ width: 100,
|
|
|
+ title: '操作',
|
|
|
+ dataIndex: 'action',
|
|
|
+ slots: { customRender: 'action' },
|
|
|
+ fixed: 'right',
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ const [registerDrawer, { closeDrawer, setDrawerProps }] = useDrawerInner(async () => {});
|
|
|
+
|
|
|
+ const getTitle = computed(() => (!unref(isUpdate) ? '教材入库' : '教材入库'));
|
|
|
+ const handleSubmit = async () => {
|
|
|
+ try {
|
|
|
+ const values = getForm().getFieldsValue();
|
|
|
+ if (!values.baseSemesterId) {
|
|
|
+ createMessage.warning('请选择学期');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ const dataSoruce = getDataSource();
|
|
|
+ const data: Recordable[] = [];
|
|
|
+ let isError = false;
|
|
|
+
|
|
|
+ dataSoruce.forEach((item) => {
|
|
|
+ if (item.warehouseNumber) {
|
|
|
+ data.push({
|
|
|
+ textbookId: item.textbookId,
|
|
|
+ price: item.price,
|
|
|
+ discount: item.discount,
|
|
|
+ warehouseNumber: item.warehouseNumber,
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ isError = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (isError) {
|
|
|
+ createMessage.warning('请选择入库数量');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ setDrawerProps({ confirmLoading: true });
|
|
|
+ const postParams = {
|
|
|
+ baseSemesterId: values.baseSemesterId,
|
|
|
+ textbookWarehouseTextbooksDtos: data,
|
|
|
+ };
|
|
|
+
|
|
|
+ await postTextbookWarehouseRecordTextbookWarehouse(postParams);
|
|
|
+
|
|
|
+ createMessage.success('操作成功');
|
|
|
+ closeDrawer();
|
|
|
+ emit('success');
|
|
|
+ } finally {
|
|
|
+ setDrawerProps({ confirmLoading: false });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleSelect = () => {
|
|
|
+ openModal(true, {});
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleChangeDiscount = (record) => {
|
|
|
+ if (!record.discount) {
|
|
|
+ record.subtotal = record.price;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (record.discount < 1) {
|
|
|
+ record.discount = 1;
|
|
|
+ }
|
|
|
+ if (record.discount > 10) {
|
|
|
+ record.discount = 10;
|
|
|
+ }
|
|
|
+ record.subtotal = Number((Number(record.price || 0) * record.discount) / 10).toFixed(2);
|
|
|
+ };
|
|
|
+ const handleSuccess = (data) => {
|
|
|
+ const dataSoruce = getDataSource();
|
|
|
+ data.forEach((item) => {
|
|
|
+ handleChangeDiscount(item),
|
|
|
+ dataSoruce.push({
|
|
|
+ textbookId: item.id,
|
|
|
+ bookName: item.bookName,
|
|
|
+ issn: item.issn,
|
|
|
+ price: item.price,
|
|
|
+ discount: item.discount,
|
|
|
+ subtotal: item.subtotal,
|
|
|
+ warehouseNumber: 1,
|
|
|
+ });
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ const handleDelete = (index) => {
|
|
|
+ const dataSoruce = getDataSource();
|
|
|
+ dataSoruce.splice(index, 1);
|
|
|
+ };
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="less"></style>
|