kllay 14 hours ago
parent
commit
12140b418d

+ 130 - 0
src/views/system/Inventorycount/InventoryDialog/index.vue

@@ -0,0 +1,130 @@
+<template>
+    <el-dialog v-model="visible" title="开始盘点" width="800px" @open="onOpen" @close="onClose">
+      <div class="form-row">
+        <el-input v-model="device_code" placeholder="设备ID" @keyup.enter="handleAdd" />
+        <el-input v-model="check_no" placeholder="设备编码" @keyup.enter="handleAdd" />
+        <el-button type="primary" @click="handleAdd">添加</el-button>
+      </div>
+  
+      <el-table :data="deviceList" style="margin-top: 20px">
+        <el-table-column type="index" label="序号" width="60" />
+        <el-table-column prop="id" label="盘点id" width="60" />
+        <el-table-column prop="device_code" label="设备ID" />
+        <el-table-column prop="check_no" label="设备编码" />
+        <el-table-column prop="status_display" label="状态" />
+        <!-- <el-table-column prop="productName" label="商品名称" /> -->
+        <el-table-column label="操作" width="180">
+          <template #default="{ row }">
+            <el-button type="success" size="small" @click="completeScan(row)" >完成盘点</el-button>
+            <el-button type="danger" size="small" @click="cancelScan(row)" >取消盘点</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+    </el-dialog>
+  </template>
+  
+  <script setup lang="ts" >
+  import { ref } from 'vue';
+  import * as api from '../api';
+  import { ElMessage } from 'element-plus';
+
+  const visible = ref(false);
+  const device_code = ref('');
+  const check_no = ref('');
+  const deviceList = ref<any[]>([]);
+//   const btflag=ref(true);
+  
+  const setCheckNo = (val: string) => {
+    console.log("val::::::",val)
+    check_no.value = val;
+};
+  const onOpen = () => {
+    device_code.value = '';
+    // check_no.value = '';
+    deviceList.value = [];
+  };
+  
+  const findCheckRecord = (checkNo: string, list: any[]) => {
+        console.log("lists::::",list)
+        if (!Array.isArray(list)) return null;
+        return list.find(item => item.check_no === checkNo);
+    };
+
+        
+
+  const handleAdd = async () => {
+    if (!device_code.value || !check_no.value) return;
+
+    const payload = {
+        device_code: device_code.value,
+        check_no: check_no.value,
+    };
+  
+    const res = await api.ScanDevice(payload);
+    if (res?.code===2000) {
+        const reslist=await api.GetPermission();
+        if (reslist?.code===2000) {
+            const record = findCheckRecord(check_no.value, reslist.data.results);
+            deviceList.value.push({
+                ...payload,
+                productName: res.data?.productName || '未知商品',
+                id: record?.id||0,
+                status_display:record?.status_display||'',
+                // record,
+            });
+            device_code.value = '';
+        //   check_no.value = '';
+        }
+    }
+  };
+  
+  const completeScan = async (row: any) => {
+    const res=await api.CompleteScan({ check_no: row.check_no });
+    if (res?.code===2000) {
+        // const payload = {
+        //     device_code: device_code.value,
+        //     check_no: check_no.value,
+        // };
+        // const reslist=await api.GetPermission();
+        // const record = findCheckRecord(check_no.value, reslist.data.results);
+        // deviceList.value.push({
+        //     ...payload,
+        //     productName: res.data?.productName || '未知商品',
+        //     id: record?.id||0,
+        //     status_display:record?.status_display||'',
+        //     // record,
+        // });
+        // btflag.value=false;
+        ElMessage.success('完成盘点!');
+        visible.value = false
+    }
+  };
+  
+  const cancelScan = async (row: any) => {
+    const res=await api.CancelScan(row.id);
+    if (res?.code===2000) {
+        console.log("deviceList.value::",deviceList.value)
+        deviceList.value = deviceList.value.filter(item => item.id !== row.id);
+        console.log("deviceList.value22222::",deviceList.value)
+        ElMessage.success('取消盘点成功!');
+        visible.value = false
+    }
+  };
+  
+  defineExpose({ visible,setCheckNo});
+
+  const onClose = () => {
+  check_no.value = '';
+    };
+
+
+  </script>
+  
+  <style scoped>
+  .form-row {
+    display: flex;
+    gap: 10px;
+    margin-bottom: 10px;
+  }
+  </style>
+  

+ 83 - 0
src/views/system/Inventorycount/api.ts

@@ -0,0 +1,83 @@
+import { AddReq,EditReq, DelReq,UserPageQuery } from '@fast-crud/fast-crud';
+import { request } from '/@/utils/service';
+
+export const apiPrefix = '/api/system/inventory/check-records/list/';
+export function GetList(query: UserPageQuery) {
+	return request({
+		url: apiPrefix,
+		method: 'get',
+		params: query,
+	});
+}
+// export function GetObj(id: InfoReq) {
+// 	return request({
+// 		url: apiPrefix + id,
+// 		method: 'get',
+// 	});
+// }
+
+export function AddObj(obj: AddReq) {
+	return request({
+		url: apiPrefix,
+		method: 'post',
+		data: obj,
+	});
+}
+
+export function UpdateObj(obj: EditReq) {
+	return request({
+		url: apiPrefix + obj.id + '/',
+		method: 'put',
+		data: obj,
+	});
+}
+
+export function DelObj(id: DelReq) {
+	return request({
+		url: apiPrefix + id + '/',
+		method: 'delete',
+		data: { id },
+	});
+}
+
+export function GetPermission() {
+    return request({
+        url: apiPrefix,
+        method: 'get',
+    });
+}
+
+
+export function StartScan(obj: object) {
+	return request({
+		url: '/api/system/device/scan/start/',
+		method: 'post',
+		data: obj,
+	});
+}
+
+export function ScanDevice(obj: object) {
+	return request({
+		url: '/api/system/device/scan/',
+		method: 'post',
+		data: obj,
+	});
+}
+
+
+export function CompleteScan(obj: object) {
+	return request({
+		url: '/api/system/device/scan/complete/',
+		method: 'post',
+		data: obj,
+	});
+}
+export function CancelScan(id: number) {
+	return request({
+		url: `/api/system/inventory/check-records/${id}/cancel/`,
+		method: 'post',
+		// data: obj,
+	});
+}
+
+

+ 189 - 0
src/views/system/Inventorycount/crud.tsx

@@ -0,0 +1,189 @@
+import { AddReq, CreateCrudOptionsProps, dict,CreateCrudOptionsRet, UserPageQuery } from '@fast-crud/fast-crud';
+import * as api from './api';
+import { auth } from '/@/utils/authFunction';
+import dayjs from 'dayjs';
+import { Ref } from 'vue';
+
+export const createCrudOptions = function ({ crudExpose , inventoryDialog}: CreateCrudOptionsProps& { inventoryDialog: Ref<any> }): CreateCrudOptionsRet {
+	const pageRequest = async (query: UserPageQuery) => {
+		return await api.GetList(query);
+	};
+	const editRequest = async ({ form, row }: EditReq) => {
+		form.id = row.id;
+		return await api.UpdateObj(form);
+	};
+	const delRequest = async ({ row }: DelReq) => {
+		return await api.DelObj(row.id);
+	};
+	const addRequest = async ({ form }: AddReq) => {
+		return await api.AddObj(form);
+	};
+
+	return {
+		crudOptions: {
+			request: {
+				pageRequest,
+				addRequest,
+				editRequest,
+				delRequest,
+
+			},
+			form:{
+				wrapper: {
+					buttons: {
+						ok:{
+							text:'提交'
+						}
+					}
+				}
+			},
+			actionbar: {
+				buttons: {
+					// add: {
+					// 	show: auth('area:Create'),
+					// },
+					startTaking: {
+						text: '开始盘点',
+						// icon: 'el-icon-document',
+						click: async () => {
+						const res =await api.StartScan({ remark: '例行盘点' });
+						if (res?.code === 2000) {
+							inventoryDialog.value.setCheckNo(res.data.check_no); 
+							inventoryDialog.value.visible = true; 
+						}
+					},
+					},
+
+				},
+			},
+			toolbar:{
+				show:true,
+			},
+			rowHandle:{
+				fixed: 'right',
+				width: 220,
+				buttons:{
+					view:{
+						show:false
+					},
+					remove:{
+						show:false,
+					},
+					edit:{
+						show:false,
+					}
+
+				}
+
+			},
+			pagination: {
+				show: false,
+			},		
+			columns: {
+				_index: {
+					title: '序号',
+					form: { show: false },
+					column: {
+						type: 'index',
+						align: 'center',
+						width: '70px',
+						columnSetDisabled: true, //禁止在列设置中选择
+					},
+				},
+				check_no: {
+					title: '编号',
+					search: {
+						show: false,
+					},
+					treeNode: true,
+					type: 'input',
+					column: {
+						minWidth: 120,
+					},
+					form: {
+						show:true,
+						rules: [
+							// 表单校验规则
+							{ required: true, message: '名称必填项' },
+						],
+						component: {
+							placeholder: '请输入',
+						},
+					},
+					viewForm:{
+						component: { placeholder: '' },
+						rules: [{ required: true, message: '' }],
+					}
+				},
+				start_time:{
+					title: '维护日期',
+					type: 'datetime',
+					column: {
+						minWidth: 120,
+						// formatter: ({ value }) => (value ? dayjs(value).format('YYYY-MM-DD') : ''),
+					},
+					form: {
+						show:false,
+						component: { placeholder: '请填写维护日期' },
+						rules: [{ required: true, message: '请填写维护日期' }],
+					},
+					viewForm:{
+						component: { placeholder: '' },
+						rules: [{ required: true, message: '' }],
+					},
+					valueResolve({ form, value }) {
+						form.start_time = value ? dayjs(value).format('YYYY-MM-DD HH:mm:ss') : null;
+					},
+					// valueBuilder({ form, value }) {
+					// 	console.log("valuessss::",value)
+					// 	form.start_time =  value ;
+					// },
+				},
+				checker_name:{
+					title: '盘点人',
+					type: 'input',
+					column: {
+						minWidth: 120,
+					},
+					form: {
+						show:false,
+						component: { placeholder: '请填写盘点人' },
+						rules: [{ required: false, message: '请填写盘点人' }],
+					},
+					viewForm:{
+						component: { placeholder: '' },
+						rules: [{ required: false, message: '' }],
+					}
+				},
+				status_display: {
+					title: '状态',
+					search: {
+						show: false,
+					},
+					treeNode: true,
+					type: 'input',
+					column: {
+						minWidth: 120,
+					},
+					form: {
+						show:false,
+						rules: [
+							// 表单校验规则
+							{ required: true, message: '维护标题必填项' },
+						],
+						component: {
+							placeholder: '请输入维护标题',
+						},
+					},
+					viewForm:{
+						component: { placeholder: '' },
+						rules: [{ required: true, message: '' }],
+					}
+				},	
+				
+
+			
+			},
+		},
+	};
+};

+ 31 - 0
src/views/system/Inventorycount/index.vue

@@ -0,0 +1,31 @@
+<template>
+	<fs-page>
+		<fs-crud ref="crudRef" v-bind="crudBinding"> </fs-crud>
+		<InventoryDialog ref="inventoryDialog" />
+	</fs-page>
+</template>
+
+<script lang="ts" setup name="Inventorycount">
+import { useFs } from '@fast-crud/fast-crud';
+import { onMounted,ref } from 'vue';
+import { GetPermission } from './api';
+import { createCrudOptions } from './crud';
+import { handleColumnPermission } from '/@/utils/columnPermission';
+import InventoryDialog from './InventoryDialog/index.vue';
+
+
+const inventoryDialog = ref();
+const { crudBinding, crudRef, crudExpose, crudOptions, resetCrudOptions } = useFs({ 
+		createCrudOptions: (ctx) => createCrudOptions({ ...ctx, inventoryDialog }) 
+	});
+
+// 页面打开后获取列表数据
+onMounted(async () => {
+	// 设置列权限
+	const newOptions = await handleColumnPermission(GetPermission, crudOptions);
+	//重置crudBinding
+	resetCrudOptions(newOptions);
+	// 刷新
+	crudExpose.doRefresh();
+});
+</script>

+ 21 - 21
src/views/system/device/crud.tsx

@@ -109,7 +109,7 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
 				delRequest,
 			},
 			toolbar:{
-				show:false,
+				show:true,
 			},
 			rowHandle: {
 				fixed: 'right',
@@ -130,26 +130,26 @@ export const createCrudOptions = function ({ crudExpose }: CreateCrudOptionsProp
                     add: {
                         show: auth('user:Create')
                     },
-					batchimport:{
-						text: "批量导入",
-                        title: "导入",
-                        // show: auth('user:batchimport'),
-					},
-                    export: {
-                        text: "导出",
-                        title: "导出",
-                        show: auth('user:Export'),
-                    },
-					downloadtemplate: {
-                        text: "下载模板",
-                        title: "下载模板",
-                        // show: auth('user:Export'),
-                    },
-					batchdelete: {
-                        text: "批量删除",
-                        title: "批量删除",
-                        // show: auth('user:Export'),
-                    },
+					// batchimport:{
+					// 	text: "批量导入",
+                    //     title: "导入",
+                    //     // show: auth('user:batchimport'),
+					// },
+                    // export: {
+                    //     text: "导出",
+                    //     title: "导出",
+                    //     show: auth('user:Export'),
+                    // },
+					// downloadtemplate: {
+                    //     text: "下载模板",
+                    //     title: "下载模板",
+                    //     // show: auth('user:Export'),
+                    // },
+					// batchdelete: {
+                    //     text: "批量删除",
+                    //     title: "批量删除",
+                    //     // show: auth('user:Export'),
+                    // },
                 }
             },
 			columns: {