"use strict";
import { base } from './base.js'
import { util } from '../../util/util.js'
import { tree } from '../page/query/tree.js'
import {khcModal} from '../alert/khcModal.js'
import {config} from "../../config.js";
import {page} from "../page/page.js";
import {fullMap} from "../../fullMap.js";
import {pageInfoMap} from "../../pageInfoMap.js";
import {httpUtil} from "../../util/httpUtil.js";
/**
 * 页面（子表（vChildPage）有 page_parent_uuid 关联，页面（vPage）则没有）
 * vPage不强制是虚拟字段，虚拟字段和实体字段都可以使用
 */
class vPage extends base {
    constructor(data) {
        super(data);
        this.type='page';
        this.isValue=true;
        this.pageObj=null;
    }
    render(parentObjID) {
        let that=this;
        let data = this.data
        let pageCode=data.dict_code.code;
        let code = { pageCode: pageCode }
        let obj={url:config.getConfigJson().pageInfoUrl,params:code,isClientCache:true}
        httpUtil.post(obj, (response)=>{
            let pageType = response.data.data.page_type;
            if (pageType == 'ordinary') {
                let componentArray = response.data.data.componentData;
                for (let i = 0; i < componentArray.length; i++) {
                    let componentInfo = componentArray[i];
                    let code={ version: '1.0.0', dsCode: componentInfo.ds_code, formCode: componentInfo.form_code,queryCode: componentInfo.query_code };
                    let formCode = { parentObjID: util.getUUID() + 'div', type: 'form', code: code }
                    let queryCode = { parentObjID: util.getUUID() + 'div', type: 'query', code: code };
                    let formPageData = { parentObjID: parentObjID };
                    formPageData['parentFormObjID'] = data.formObjID;
                    formPageData['pageCode'] = pageCode;
                    formPageData['formCode'] = formCode;

                    formPageData['queryCode'] = queryCode;
                    formPageData['pkFieldName'] = 'id';
                    obj={url:config.getConfigJson().metaUrl,params:code,isClientCache:true}
                    httpUtil.post(obj, (response)=>{
                        let thisFormPage = new page(formPageData);
                        thisFormPage.render();
                        fullMap.push(thisFormPage.objID, thisFormPage);
                        that.pageObj=thisFormPage;
                    });
                }
            }
        });
    }
    setDisabled(){

    }
    removeDisabled(){

    }
    hide(){
        //document.getElementById(this.parentObjID).setAttribute('style', 'display:none');//隐藏
    }
    show(){
        //document.getElementById(this.parentObjID).setAttribute('style', '');//展示
    }
    getValue() {
        let that=this;
        let tableView=that.pageObj.queryComponent.tableView
        if(tableView.queryIds!=undefined&&tableView.queryIds.length>0){
            return tableView.queryIds;
        }
        if (tableView.queryInfo.is_checkbox == 'Y') {
            console.log(1111)
            let ids=tableView.getCheckedDataPkCode();
            if(ids.length>0){
                return ids;
            }else{
                return '';
            }
        }
        return '';
    }
    setValue(value){
        let that=this;
        let timeout=0;
        if(that.pageObj==null){//如果子表对象为空是因为子表还没渲染就调用formEdit,设置一个延迟时间
            timeout=2000
        }
        setTimeout( ()=>{
            let tableView=that.pageObj.queryComponent.tableView
            if(!util.isNull(value)){
                tableView.queryIds=value;
                tableView.refresh();
            }
        },timeout)
    }
    hideDiv(){

    }
    showDiv(){

    }
    refreshCanNull(){

    }

}
export { vPage }