<!--
|
* @Description: 通用组合页面,左边是表格,右边是自定义
|
* @Author: Ben Lin
|
* @version:
|
* @Date: 2024-06-18 23:30:30
|
* @LastEditors: Ben Lin
|
* @LastEditTime: 2024-10-21 23:03:27
|
-->
|
<template>
|
<div class="flex">
|
<div v-show="false">
|
<printTemplate1 :table-data="printData" :qrInstoreOrder="qrInstoreOrder"></printTemplate1>
|
</div>
|
<Suspense>
|
<div class="w-1/4 xl:w-4/5 h-full">
|
<mainTable />
|
</div>
|
</Suspense>
|
<Suspense>
|
<div class="w-1/4 xl:w-1/5 py-4 pr-4 h-full">
|
<div class="p-5 h-full" style="background-color: white">
|
<span class="mb-5 p-5" style="color: #0780b9; font-size: 16px">请扫码打印入库单</span>
|
<a-button type="primary" @click="ToPrint"> 打印 </a-button>
|
<QrCode
|
:value="qrCodeUrl"
|
:height="198"
|
:options="{ margin: 5 }"
|
ref="qrDiyRef"
|
:logo="LogoImg"
|
/>
|
</div>
|
<span class="mb-5 p-5" style="color: #0780b9">{{ tag }}</span>
|
</div>
|
</Suspense>
|
<Suspense>
|
<CustModal
|
@register="registerCust"
|
@success="custSuccess"
|
:type="cType"
|
:detailSlots="dtlSlots"
|
:entityName="entityName"
|
>
|
<!-- 用插槽自定义多表单 -->
|
<template #[item.name] v-for="item in dtlSlots" :key="item.name">
|
<BasicForm @register="useFormData[item.name][0]" v-if="useFormData[item.name]">
|
<!-- 用插槽自定义弹出选择框 -->
|
<template #[name]="{ field }" v-for="name in item.slots" :key="name">
|
<a-button
|
class="mt-1 ml-1"
|
size="small"
|
@click="handleCustClick(field)"
|
:preIcon="item.preIcons[name]"
|
/>
|
<GeneralModal
|
@register="useModalData[name][0]"
|
@success="(d, u) => handleEntSuccess(d, u, item.name)"
|
/>
|
</template>
|
</BasicForm>
|
<!-- 自定义内容 -->
|
</template>
|
</CustModal>
|
</Suspense>
|
</div>
|
</template>
|
<script lang="ts" setup>
|
import { useModal } from '@/components/Modal';
|
import GeneralModal from '/@/views/components/GeneralModal.vue';
|
import mainTable from './mainTable.vue';
|
import printTemplate1 from './printTemplate1.vue';
|
import CustModal from '/@/views/components/CustModal.vue';
|
import { custOnChange, goByParams, OpenCustModal } from '../data';
|
import { Ref, h, onMounted, onUnmounted, provide, ref, unref } from 'vue';
|
import { useRoute, useRouter } from 'vue-router';
|
import { BasicForm } from '/@/components/Form/index';
|
import { getEntity, GetEnum } from '/@/api/tigerapi/system';
|
import { isNullOrEmpty } from '/@/utils/is';
|
import { useLocale } from '/@/locales/useLocale';
|
import { Tag, Tooltip } from 'ant-design-vue';
|
import { getRoleButtons } from '/@/api/sys/menu';
|
import { QrCode } from '/@/components/Qrcode/index';
|
import LogoImg from '/@/assets/images/logo.png';
|
import printJS from 'print-js';
|
import { useWebSocketStore } from '/@/store/modules/websocket';
|
import { buildUUID } from '/@/utils/uuid';
|
|
defineOptions({ name: '工单工艺绑定' });
|
|
const usewebSocket = useWebSocketStore();
|
const { getLocale } = useLocale();
|
const route = useRoute();
|
const { currentRoute } = useRouter();
|
// const objParams = ref(JSON.parse(decodeURI(route.params?.id as string))); //ref(JSON.parse(history.state.obj))
|
const routeParams = ref(JSON.parse(decodeURI(route.params?.id as string)));
|
// 从sessionStorage中读取参数并转换回对象
|
const savedParams = sessionStorage.getItem(`${routeParams.value.sName}_params`);
|
const objParams = savedParams ? ref(JSON.parse(decodeURI(savedParams))) : ref({});
|
const entityName = ref(routeParams.value.Name);
|
const useModalData = ref({}); //表单中插槽渲染按钮打开模态框useModal方法
|
const useFormData = ref({});
|
const cType = ref('');
|
const dtlSlots = ref([] as any[]);
|
const otherSlots = ref<any[]>([]);
|
const selectVals = ref({});
|
const isMounted = ref(false);
|
const qrCodeUrl = ref(`PrintJS_${buildUUID()}`);
|
const tag = ref('');
|
const _columns = ref<any[]>([]);
|
const _searchFormSchema = ref<any[]>([]);
|
const _crudFormSchema = ref<any[]>([]);
|
const buttons = ref([]);
|
const printData = ref<any[]>([]);
|
const qrInstoreOrder = ref('YDRKD20241118001');
|
const AuthOption = ref({
|
BY_ORG: '',
|
BY_PROD: '',
|
BY_WH: '',
|
});
|
const keyFieldValues = ref<any>(null);
|
const custImport = ref<any>(null);
|
const [registerCust] = useModal();
|
provide<Ref<any>>('objParams', objParams);
|
provide<Ref<any>>('keyFieldValues', keyFieldValues);
|
provide<Ref<{}>>('AuthOption', AuthOption);
|
provide<Ref<any[]>>('_columns', _columns);
|
provide<Ref<any[]>>('_searchFormSchema', _searchFormSchema);
|
provide<Ref<any[]>>('_crudFormSchema', _crudFormSchema);
|
|
onMounted(async () => {
|
isMounted.value = false;
|
|
printData.value = [
|
{
|
id: '111',
|
Items: [
|
{
|
ID: 111,
|
SALES_ORDER: 'YDSO240400482',
|
ORDER_NO: 'YDRKD241000012',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 112,
|
SALES_ORDER: 'YDSO240400483',
|
ORDER_NO: 'YDRKD241000013',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 113,
|
SALES_ORDER: 'YDSO240400484',
|
ORDER_NO: 'YDRKD241000014',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 114,
|
ORDER_NO: 'YDRKD241000015',
|
SALES_ORDER: 'YDSO240400485',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 115,
|
ORDER_NO: 'YDRKD241000016',
|
SALES_ORDER: 'YDSO240400486',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 116,
|
ORDER_NO: 'YDRKD241000017',
|
SALES_ORDER: 'YDSO240400487',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 116,
|
ORDER_NO: 'YDRKD241000018',
|
SALES_ORDER: 'YDSO240400488',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 116,
|
ORDER_NO: 'YDRKD241000019',
|
SALES_ORDER: 'YDSO240400489',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 116,
|
ORDER_NO: 'YDRKD241000020',
|
SALES_ORDER: 'YDSO240400490',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
{
|
ID: 116,
|
ORDER_NO: 'YDRKD241000021',
|
SALES_ORDER: 'YDSO240400491',
|
WORK_ORDER: 'YDMOB241104737',
|
ITEM_CODE: '20100705.0102.00',
|
ITEM_NAME:
|
'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
PLAN_QTY: 100,
|
SCAN_QTY: 50,
|
STATUS: 'Y'
|
},
|
],
|
},
|
// {
|
// id: '112',
|
// Items: [
|
// {
|
// ID: 311,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// {
|
// ID: 312,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// {
|
// ID: 313,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// ],
|
// },
|
// {
|
// id: '113',
|
// Items: [
|
// {
|
// ID: 211,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// {
|
// ID: 212,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// {
|
// ID: 213,
|
// ORDER_NO: 'YDSO241101002',
|
// WORK_ORDER: 'YDMOB241104737',
|
// ITEM_CODE: '20100705.0102.00',
|
// ITEM_NAME:
|
// 'YM-DEMS-BD11Q48 AC0-300V AC20mA 电能1级 ',
|
// PLAN_QTY: 100,
|
// SCAN_QTY: 50,
|
// STATUS: 'Y'
|
// },
|
// ],
|
// },
|
];
|
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
custImport.value = await import(`../entityts/${entityName.value}.ts`);
|
if (custImport.value['default']) {
|
otherSlots.value = custImport.value['default']()[0]['GetSlots']();
|
}
|
isMounted.value = true;
|
|
const data = await getEntity({
|
sqlcmd: `ASSEMBLY_NAME ='${objParams.value.Name}'`,
|
entityName: 'SYS_LOW_CODE',
|
order: '',
|
});
|
AuthOption.value.BY_ORG = data.Data.Items[0].BY_ORG;
|
AuthOption.value.BY_PROD = data.Data.Items[0].BY_PROD;
|
AuthOption.value.BY_WH = data.Data.Items[0].BY_WH;
|
var searchForms = JSON.parse(data.Data.Items[0].SEARCH_FORM_JSON);
|
for (const i in searchForms) {
|
if (
|
!isNullOrEmpty(searchForms[i].componentProps) &&
|
!isNullOrEmpty(searchForms[i].componentProps.api) &&
|
searchForms[i].componentProps.api == 'GetEnum'
|
) {
|
searchForms[i].componentProps.api = GetEnum;
|
searchForms[i].componentProps.params.name =
|
`${objParams.value.ID}+${searchForms[i].field}s`;
|
searchForms[i].componentProps.labelField = unref(getLocale) == 'zh_CN' ? 'Desc' : 'Name';
|
}
|
if (
|
!isNullOrEmpty(searchForms[i].componentProps) &&
|
!isNullOrEmpty(searchForms[i].componentProps.api) &&
|
searchForms[i].componentProps.api == 'getEntity'
|
) {
|
searchForms[i].componentProps.api = getEntity;
|
searchForms[i].componentProps.resultField = 'Data.Items';
|
}
|
if (searchForms[i].component == 'RangePicker') {
|
}
|
onChangeConfig(searchForms[i]);
|
}
|
_searchFormSchema.value = searchForms;
|
|
var objs = JSON.parse(data.Data.Items[0].BASE_FORM_JSON);
|
for (const i in objs) {
|
if (!isNullOrEmpty(objs[i].customRender)) {
|
const func = new Function(objs[i].customRender)();
|
objs[i].customRender = ({ record }) => {
|
let texts = func(record);
|
/* 如果是链接就跳转并传入配置的参数 */
|
if (texts.isLink == 'Y') {
|
return h('a', [
|
h(
|
'span',
|
{
|
onClick: () => {
|
goByParams(texts.path, texts.params, go);
|
},
|
},
|
texts.text,
|
),
|
]);
|
} else {
|
return h(Tooltip, { title: texts.text }, () =>
|
h(Tag, { color: texts.color }, () => texts.text),
|
);
|
}
|
};
|
}
|
}
|
_columns.value = objs;
|
buttons.value = await getRoleButtons(currentRoute.value.meta.menuCode as string);
|
} catch (e) {
|
console.log(e);
|
}
|
});
|
|
/**
|
* @description: Select 自定义onChange方法
|
* @param {*} obj
|
* @return {*}
|
*/
|
function onChangeConfig(obj: any) {
|
if (obj.component == 'Select') {
|
var options = obj.componentProps.options;
|
var onChange = obj.componentProps.onChange;
|
obj.componentProps = ({ schema, tableAction, formActionType, formModel }) => {
|
return {
|
options: options,
|
onChange: (e) => custOnChange(e, onChange, objParams.value.ID),
|
};
|
};
|
}
|
}
|
|
/**
|
* @desc 生成QR完成
|
*/
|
function onQrcodeDone({ ctx }: any) {
|
if (ctx instanceof CanvasRenderingContext2D) {
|
// 额外绘制
|
ctx.fillStyle = 'black';
|
ctx.font = '16px "微软雅黑"';
|
ctx.textBaseline = 'bottom';
|
ctx.textAlign = 'center';
|
ctx.fillText('你帅你先扫', 200, 380, 600);
|
}
|
}
|
|
const unsubscribe = usewebSocket.$subscribe((mutation, state) => {
|
tag.value = `收到打印请求:${state.printTag}`;
|
if (state.printTag == qrCodeUrl.value) {
|
// printJS(state.printJson);
|
printData.value = state.printJson as unknown as any[];
|
usewebSocket.SetPrintTag('');
|
setTimeout(() => {
|
ToPrint();
|
}, 100);
|
}
|
});
|
|
// 当组件卸载时取消订阅
|
onUnmounted(() => {
|
unsubscribe();
|
});
|
|
function ToPrint() {
|
const _style = `
|
#print-area {
|
position: absolute;
|
inset: 0;
|
background-color: #fff;
|
|
.item {
|
display: flex;
|
flex-direction: column;
|
page-break-after: always;
|
height: 100%;
|
|
|
.head {
|
z-index: 1;
|
width: 100%;
|
background-color: azure;
|
font-size: 22px;
|
font-weight: bold;
|
line-height: 100px;
|
text-align: center;
|
}
|
|
.main {
|
display: flex;
|
flex: 1;
|
justify-content: center;
|
padding: 15px;
|
|
table {
|
border-collapse: collapse;
|
width: 100%;
|
}
|
|
table,
|
th,
|
td {
|
border: solid 1px black;
|
}
|
|
tr > th {
|
height: 60px;
|
}
|
.instore_td {
|
border: 1px solid #000;
|
font-size: 12px;
|
line-height: 20px;
|
text-align: center;
|
word-break: break-all;
|
}
|
|
.material_table_td {
|
border: 1px solid #000;
|
font-size: 14px;
|
line-height: 20px;
|
text-align: center;
|
word-break: break-all;
|
}
|
}
|
|
.footer {
|
display: flex;
|
margin-bottom: 15px;
|
background-color: #eee;
|
font-size: 12px;
|
line-height: 21px;
|
text-align: center;
|
}
|
}
|
}`;
|
|
printJS({
|
// 需要打印区域设置的Id
|
printable: 'print-area',
|
// 打印类型
|
type: 'html',
|
// 默认值为800,我们把把设置为100%
|
maxWidth: '100%',
|
// *代表应用所有样式,默认值为null,如果不设置,打印窗口则会忽略所有样式
|
targetStyles: ['*'],
|
// font_size: '9pt',
|
scanStyles: false,
|
style: `@page {size: auto; margin: 0mm;} html, ${_style}`,
|
});
|
}
|
|
/**
|
* @description: 弹出框确定返回
|
* @param {*} d
|
* @return {*}
|
*/
|
function custSuccess(d) {
|
// reload();
|
}
|
|
/**
|
* @description: 各表单内弹出选择框选择成功后方法
|
* @param {*} d
|
* @param {*} u
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleEntSuccess(d, u, item) {
|
/* 动态import实体名.ts的自定义方法 */
|
try {
|
import(`../entityts/${cType.value}.ts`).then((m) => {
|
const [{ GetSelectSuccess }] = m.default();
|
var values = GetSelectSuccess(d, u);
|
selectVals.value = values; //保存弹出框选择的结果
|
let _val = {};
|
d.returnFieldName.map((x) => {
|
_val[x] = values[x];
|
});
|
useFormData.value[item][1].setFieldsValue(_val);
|
});
|
} catch (e) {}
|
}
|
|
/**
|
* @description: 打开自定义模态框
|
* @param {*} item
|
* @return {*}
|
*/
|
function handleCustClick(item) {
|
OpenCustModal(
|
useModalData.value[item][1].openModal, //带入openModal方法
|
cType.value,
|
item,
|
[],
|
// selectVals.value['ROUTE_CODE'],
|
); //[openRvModal], selectVals.value['ID']这是自定义参数,按实际需求
|
}
|
</script>
|
<style lang="less">
|
.vben-page-wrapper .vben-page-wrapper-content {
|
margin: 1px;
|
}
|
</style>
|