From 27ba504441037666e787ded85b4af2f65be65c17 Mon Sep 17 00:00:00 2001 From: schangxiang@126.com <schangxiang@126.com> Date: 周二, 29 4月 2025 18:06:07 +0800 Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/HIA24016N_PipeLineDemo --- HIAWms/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts | 258 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 258 insertions(+), 0 deletions(-) diff --git a/HIAWms/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts b/HIAWms/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts new file mode 100644 index 0000000..3684341 --- /dev/null +++ b/HIAWms/web/src/widgets/HIAWms/Controllers/WmsMaterial.ts @@ -0,0 +1,258 @@ +import { ref, onMounted, reactive, Ref, nextTick, computed } from 'vue' +import { injectModel } from '@/libs/Provider/Provider' +import { WmsMaterial } from '../Models/WmsMaterial' +import { ElMessage } from 'element-plus' +import { ConfirmBox } from '@/components/ConfirmBox/ConfirmBox' +import { useFile } from './File' + +interface CurrentType { + row: any + index: number +} +export const useWmsMaterial = (props: any, ctx?: any) => { + const wmsMaterial = injectModel<WmsMaterial>('wmsMaterial') + const { exportFile } = useFile() + /** + * 澶撮儴閰嶇疆 + */ + const headers = ref({}) + /** + * 鍔ㄦ�佸垪閰嶇疆 + */ + const wmsMaterialColumns = ref<Record<string, any>>([]) + /** + * 鎼滅储鍊� + */ + const search = ref('') + + /** + * 鎺掑簭 + */ + const sort = ref(0) + /** + * 閫夋嫨椤� + */ + const selection = ref([]) + /** + * 褰撳墠閫変腑鐨勮 + */ + const current = ref<any>(null) + /** + * 鏁版嵁婧� + */ + const dataSource: Ref<any[]> = ref([]) + + /** + * 琛ㄦ牸 + */ + const tableRef = ref() + const dialogConfig = reactive({ + visible: false, + title: '', + isAdd: false, + }) + + const dialogSettingConfig = reactive({ + visible: false, + title: '', + }) + + /** + * 鍒嗛〉鏁版嵁 + */ + const paginationParams = ref({}) + + /** + * 鎵撳紑璇︽儏 + * @param row + */ + const openDetail = (row: any) => { + current.value = row + dialogConfig.visible = true + dialogConfig.title = row.name + dialogConfig.isAdd = false + sort.value = row.sort + } + + const contextMenu = [ + { + label: '灞曞紑璇︽儏', + fn: (c: CurrentType) => { + current.value = null + sort.value = c.row.sort + nextTick(() => openDetail(c.row)) + }, + divided: true, + icon: 'o', + }, + // { + // label: '鍚戜笂娣诲姞', + // fn: (c: CurrentType, pageNum: number) => { + // current.value = null + // sort.value = c.index + 1 + (pageNum - 1) * 50 + // dialogConfig.visible = true + // dialogConfig.title = '娣诲姞' + // dialogConfig.isAdd = false + // }, + // divided: true, + // icon: 'up', + // }, + // { + // label: '鍚戜笅娣诲姞', + // fn: (c: CurrentType, pageNum: number) => { + // current.value = null + // sort.value = c.index + 2 + (pageNum - 1) * 50 + // dialogConfig.visible = true + // dialogConfig.title = '娣诲姞' + // dialogConfig.isAdd = false + // }, + // divided: true, + // icon: 'down', + // }, + // { + // label: '鍒涘缓鍓湰', + // fn: async ({ row }: CurrentType) => { + // await wmsMaterial.cloneData([row.id]) + // ElMessage.success('鍒涘缓鍓湰鎴愬姛') + // tableRef.value?.getList() + // }, + // divided: true, + // icon: 'copy', + // }, + { + label: '鍒犻櫎', + fn: async (c: CurrentType) => { + const names = selection.value.map((item: { name: string }) => item.name) + ConfirmBox( + `鏄惁鍒犻櫎${names.length ? names.join(',') : c.row.name}` + ).then(async () => { + const ids = selection.value.map((item: { id: string }) => item.id) + await wmsMaterial.deleteWmsMaterials(ids.length ? ids : [c.row.id]) + ElMessage.success('鍒犻櫎鎴愬姛') + tableRef.value.getList() + }) + }, + icon: 'close', + }, + ] + + const onCheck = (records: any) => { + selection.value = records + } + + const onAddWmsMaterial = () => { + const params = tableRef.value?.getPaginationParams() + current.value = null + dialogConfig.visible = true + dialogConfig.isAdd = true + dialogConfig.title = '娣诲姞' + sort.value = params.totalCount + 1 + } + + const onConfirmWmsMaterial = async () => { + dialogConfig.visible = false + if (dialogConfig.isAdd) { + tableRef.value?.scrollToRow({ + skip: true, + }) + } else { + await tableRef.value?.getList() + } + } + /** + * 琛岀偣鍑绘椂鏇存柊current + */ + const onRowClick = ({ row }: any) => { + if (dialogConfig.visible && current.value) { + current.value = row + } + } + /** + * 瀵煎嚭 + */ + const onExport = () => { + const params = tableRef.value?.getParams() + exportFile('/api/v1/hIAWms/wmsMaterial/export', params, 'hIAWms') + } + + /** + * 鍏抽敭瀛楁悳绱� + */ + const onSearch = () => { + tableRef.value?.getList({ + Filter: search.value, + }) + } + + /** + * 閲嶇疆琛ㄦ牸鏁版嵁 + */ + const reloadList = () => { + tableRef.value?.getList() + } + /** + * 涓婁紶鎴愬姛 + */ + const onSuccess = () => { + tableRef.value?.getList() + ElMessage.success('瀵煎叆鎴愬姛') + } + /** + * 澶辫触 + * @param err + */ + const onError = (err: any) => { + try { + const message = JSON.parse(err.message) + ElMessage.error(message.msg) + } catch (error) { + ElMessage.error('瀵煎叆澶辫触') + } + } + /** + * 涓婁紶閽╁瓙 + */ + const onBeforeUpload = (file: File) => { + const format = ['xlsx', 'xls', 'csv'] + if (!format.includes(file.name.split('.')[1])) { + ElMessage.error('瀵煎叆鏂囦欢鏍煎紡涓嶆纭紝璇峰鍏�.xlsx/.xls涓�.csv鏍煎紡鐨勬枃浠�') + return false + } + return true + } + + onMounted(() => { + headers.value = { + Authorization: `Bearer ${sessionStorage.getItem('Token')}`, + 'X-Project': sessionStorage.getItem('X-Project'), + } + }) + + ctx.expose({ + reloadList, + }) + + return { + dataSource, + contextMenu, + dialogConfig, + dialogSettingConfig, + tableRef, + current, + search, + sort, + wmsMaterialColumns, + paginationParams, + headers, + onBeforeUpload, + onError, + onSuccess, + openDetail, + onSearch, + onExport, + onRowClick, + onConfirmWmsMaterial, + onCheck, + onAddWmsMaterial, + } +} -- Gitblit v1.9.3