赞
踩
let paymentTypeList = ref<Array<any>>([]);
此时 forEach 里面调很多次接口 不知道paymentTypeList什么时候获取到
所以 await initUiData(); 异步执行完获取不到paymentTypeList
回显的时候detailData方法里面没有这个数据
- const initUiData = async () => {
- const allGroupUi = allUiViews.value?.uiViews;
- allGroupUi?.forEach((uiView: UiView, index: number) => {
- // viewOptionData[uiView.id] = {};
- let _uiClumns = uiView.uiClumns ? uiView.uiClumns : [];
-
- _uiClumns.forEach(async (column: UiClumn, cindex: number) => {
- if (column.ele_code) {
- const res: any = await getBaseInfoList({
- eleCode: column.ele_code,
- });
- if (res.status_code === '0000') {
- if (column.data_type == '5' || column.data_type == '18') {
- if (column.field_code == 'payment_type') {
- paymentTypeList.value = res.data;
- }
- }
- }
- });
- });
- };
- onMounted(async () => {
- if (billFormId && billFormId !== 'undefined') {
- await getUiData();
- } else {
- allUiViews.value = SessionStorageService.get('contractFormUiDataChange') as any as UiData;
- await initUiData();
- }
-
- if (billId && billId !== 'undefined') {
- detailData();
- } else {
- getBillInfo();
- }
-
- });
解决方案是用watch监听
之前定义paymentTypeList是reactive方式,但是监听不到
就换成了ref定义 不知道为啥
- watch([paymentTypeList], async (oldval, newVal) => {
- //阶段描述
- let id = '';
- paymentTypeList.value.forEach((item: any) => {
- if (contractData.formData.pmContract.payment_type == item.code) {
- id = item.id;
- }
- });
- if (contractData.formData.pmContract.payment_type) {
- const res: any = await getRelation({
- primary_code: 'APM_PAY_MODE',
- priElementId: id,
- });
- if (res.status_code == '0000') {
- res.data.data.forEach((item: any) => {
- item.value = item.code;
- item.label = item.name;
- });
- custableConfigDatas.pmContractPayPlanList.cusColumnObj.stage_msg.options = res.data
- .data as any;
- }
- }
- });
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。