<template>
    <div class="content">
        <pro-form ref="formRef_form" :model="formData" :rules="formRules_form" label-width="120px">
            <div id="toolbar_1474186599741" class="datagrid-toolbar">
                <pro-button id="64C2FDE9-F8B9-47B9-B315-9CDB352874D8" size="small" :icon="h(SaveOutlined)"
                    @beforeSubmit="validates">保存</pro-button>
                <pro-button id="C1DBA8AE-B768-439F-801D-F833B1AE1F6D" size="small"
                    :icon="h(PoweroffOutlined)">关闭</pro-button>
            </div>
            <pro-tabs type="editable-card" v-model:activeKey="proTabActice_tab_1489386174777" :hideAdd="true"
                id="tab_1489386174777" class="easyui-tabs"
                data-options='width:800,height:600,fit:true,border:false,toolPosition:"left",tabPosition:"top"'>
                <pro-tab-pane label="年结参数基本信息" name="年结参数基本信息" :closable="false">
                    <pro-form-grid>
                        <table-select @bindSqlByJs="queryUpbrSql" @selectAfter="dcUpBrNoSeleAfter"
                            ref="formItemRef_leg_no_zh" :formItemProps="{ label: '配置法人', prop: 'leg_no_zh' }"
                            v-model:value="formData.leg_no_zh" size="small" lableKey="name" valueKey="no"
                            :tableAttr="tableAttr"></table-select>
                        <pro-select-tree ref="formItemRef_sob_no" :formItemProps="{ label: '账套', prop: 'sob_no' }"
                            v-model:value="formData.sob_no" size="small" type="sob_tree"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectAcc" ref="formItemRef_bnlr_acc_no"
                            :formItemProps="{ label: '本年利润科目', prop: 'bnlr_acc_no' }"
                            v-model:value="formData.bnlr_acc_no" size="small" type="tree"
                            :props="{ key: 'no', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectwfplr" ref="formItemRef_wfplr_acc_no"
                            :formItemProps="{ label: '未分配利润科目', prop: 'wfplr_acc_no' }"
                            v-model:value="formData.wfplr_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectyqndsytzld" ref="formItemRef_yqndsytzld_acc_no"
                            :formItemProps="{ label: '以前年度损益调整利得科目', prop: 'yqndsytzld_acc_no' }"
                            v-model:value="formData.yqndsytzld_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectyqndsytzss" ref="formItemRef_yqndsytzss_acc_no"
                            :formItemProps="{ label: '以前年度损益调整损失科目', prop: 'yqndsytzss_acc_no' }"
                            v-model:value="formData.yqndsytzss_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selecttqfdyygj" ref="formItemRef_tqfdyygj_acc_no"
                            :formItemProps="{ label: '提取法定盈余公积科目', prop: 'tqfdyygj_acc_no' }"
                            v-model:value="formData.tqfdyygj_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectfdyygj" ref="formItemRef_fdyygj_acc_no"
                            :formItemProps="{ label: '法定盈余公积科目', prop: 'fdyygj_acc_no' }"
                            v-model:value="formData.fdyygj_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selecttqryyygj" ref="formItemRef_tqryyygj_acc_no"
                            :formItemProps="{ label: '提取任意盈余公积科目', prop: 'tqryyygj_acc_no' }"
                            v-model:value="formData.tqryyygj_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectryyygj" ref="formItemRef_ryyygj_acc_no"
                            :formItemProps="{ label: '任意盈余公积科目', prop: 'ryyygj_acc_no' }"
                            v-model:value="formData.ryyygj_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selecttqybzb" ref="formItemRef_tqybzb_acc_no"
                            :formItemProps="{ label: '提取一般风险准备科目', prop: 'tqybzb_acc_no' }"
                            v-model:value="formData.tqybzb_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectybzb" ref="formItemRef_ybzb_acc_no"
                            :formItemProps="{ label: '一般准备科目', prop: 'ybzb_acc_no' }"
                            v-model:value="formData.ybzb_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectlrfpyfgl" ref="formItemRef_lrfp_yfgl_acc_no"
                            :formItemProps="{ label: '利润分配应付股利科目', prop: 'lrfp_yfgl_acc_no' }"
                            v-model:value="formData.lrfp_yfgl_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectyfgl" ref="formItemRef_yfgl_acc_no"
                            :formItemProps="{ label: '应付股利科目', prop: 'yfgl_acc_no' }"
                            v-model:value="formData.yfgl_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree ref="formItemRef_gbze_acc_no"
                            :formItemProps="{ label: '实时股本总额科目', prop: 'gbze_acc_no' }"
                            v-model:value="formData.gbze_acc_no" size="small" :props="{ key: 'id', title: 'name' }"
                            :showCheckbox="true"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectzzgb" ref="formItemRef_zzgb_acc_no"
                            :formItemProps="{ label: '转增股本科目', prop: 'zzgb_acc_no' }"
                            v-model:value="formData.zzgb_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-select-tree @selectAfter="selectlrfbyygjbk" ref="formItemRef_yygjbk_acc_no"
                            :formItemProps="{ label: '利润分配盈余公积补亏', prop: 'yygjbk_acc_no' }"
                            v-model:value="formData.yygjbk_acc_no" size="small"
                            :props="{ key: 'id', title: 'name' }"></pro-select-tree>
                        <pro-input @change="gettqfd" ref="formItemRef_tqfdyygjjbl"
                            :formItemProps="{ label: '提取法定盈余公积金比例(%)', prop: 'tqfdyygjjbl' }"
                            v-model:value="formData.tqfdyygjjbl" size="small"></pro-input>
                        <pro-input @change="gettqry" ref="formItemRef_tqryyygjjbl"
                            :formItemProps="{ label: '提取任意盈余公积金比例(%)', prop: 'tqryyygjjbl' }"
                            v-model:value="formData.tqryyygjjbl" size="small"></pro-input>
                        <pro-input-number ref="formItemRef_right_year_times"
                            :formItemProps="{ label: '确权数据历史年数', prop: 'right_year_times' }"
                            v-model:value="formData.right_year_times" size="small" type=""
                            :precision="2"></pro-input-number>
                        <pro-input v-show="false" ref="formItemRef_leg_no"
                            :formItemProps="{ label: '隐藏所属法人编号', prop: 'leg_no' }" v-model:value="formData.leg_no"
                            size="small"></pro-input>
                        <pro-input v-show="false" ref="formItemRef_stdd_no"
                            :formItemProps="{ label: '隐藏准则', prop: 'stdd_no' }" v-model:value="formData.stdd_no"
                            size="small"></pro-input>
                    </pro-form-grid>
                </pro-tab-pane>
                <pro-tab-pane label="确权数据信息" name="确权数据信息" :closable="false">
                    <pro-form-grid>
                        <pro-date-picker ref="formItemRef_right_date"
                            :formItemProps="{ label: '确权日期', prop: 'right_date' }" v-model:value="formData.right_date"
                            size="small" type="daterange" range-separator="至" start-placeholder="开始日期"
                            end-placeholder="结束日期"></pro-date-picker>
                        <pro-input ref="formItemRef_stock_bal" :formItemProps="{ label: '股本总额', prop: 'stock_bal' }"
                            v-model:value="formData.stock_bal" size="small"></pro-input>
                        <pro-select ref="formItemRef_sts" :formItemProps="{ label: '状态', prop: 'sts' }"
                            v-model:value="formData.sts" size="small" tableName="gls_right_data_info"
                            colName="sts"></pro-select>
                        <pro-input v-show="false" ref="formItemRef_up_br_no"
                            :formItemProps="{ label: '隐藏所属法人机构', prop: 'up_br_no' }" v-model:value="formData.up_br_no"
                            size="small"></pro-input>
                    </pro-form-grid>
                    <pro-table ref="tableRef_grid1487658622829" :queryRule="queryRule_grid1487658622829"
                        :columns="columns_grid1487658622829" :singleSelect="true" :stripe="true">
                        <template v-slot:header="">
                            <pro-button id="29A42A6D-D824-4785-832C-753532206D65" size="small"
                                :icon="h(SearchOutlined)">查询</pro-button>
                            <pro-button id="766EA769-DC5C-4CCE-8CCA-B7188BA6F580" size="small"
                                :icon="h(PlusOutlined)">新增</pro-button>
                        </template>
                    </pro-table>
                </pro-tab-pane>
            </pro-tabs>
        </pro-form>
    </div>
</template>

<script setup>
import { ref, onMounted, h } from 'vue';
import { getFoundationsController, userDataLevelQueryController, getRecursionSqlResultPublicMethod } from '@/api/endYear_manager'
import { message } from 'ant-design-vue';
import { PoweroffOutlined, SaveOutlined } from '@ant-design/icons-vue';
const singleSelect = undefined // 不显示选择列
const tableAttr = ref({
    //唯一标识
    rowKey: "key",
    //是否展示复选框
    isSelection: false,
    //边框
    border: true,
    //每页条数
    pageSize: 10,
    pagination: true,
    columns: [
        {
            prop: "key",
            label: "机构号",
            isbind: true,
            bindname: "key",
            visable: true,
            issearch: true,
        }, {
            prop: "name",
            label: "机构名称",
            isbind: true,
            bindname: "name",
            visable: true,
            issearch: true,
        }, {
            prop: "no",
            label: "显示名",
            isbind: true,
            bindname: "no",
            visable: false,
            issearch: false,
        }
    ]
})
const dataSource = ref([
    {
        key: "152000",
        name: "xxxx"
    }
    ,
    {
        key: "152001",
        name: "yyyy"
    }
])
const formData = ref({
    sob_no: ['10'],
    leg_no_zh: '',
    leg_no: '',
});
const rules = {
    depNo: [
        { required: true, message: '请选择所属机构', trigger: 'blur' },
    ],
    key: [
        { required: true, message: '请输入用户编号', trigger: 'blur' },
    ],
};
onMounted(() => {
    getcorpOrgan()
})

const getcorpOrgan = async () => {
    await getFoundationsController().then(res => {
        if (res[0].ITEM_NO == -1) {
            message.error("当前用户岗位权限下，没有查到法人机构！");
        } else {
            dataSource.value = []
            for (var i = 0; i < res.length; i++) {
                dataSource.value.push({
                    key: res[i].item_no,
                    name: res[i].item_name
                })
                if ("152000" == res[i].item_no) {
                    formData.value.leg_no_zh = res[i].item_name
                    formData.value.leg_no = res[i].item_no;
                }
            }

            console.log("xxx", dataSource.value);
        }
    })
}


const queryUpbrSql = async (sql) => {
    var dep_no = getUpDepNo();
    var sql = '';
    //设置数据权限的情况判断
    await userDataLevelQueryController().then(function (level) {
        if (level != undefined && level != '') {
            /*sql = "SELECT * FROM (SELECT DISTINCT NO, DEP_NO, DC_IND, KEY, NAME FROM (SELECT K.NO, T.DEP_NO, T.DISP_SEQN,T.UP_NO,K.KEY,"+
            "K.NAME,K.IS_GATHER,K.DC_IND ,K.BL_CORP FROM COM_DEPART_RELATION_DEF T, COM_DEPARTMENT K WHERE T.DEP_NO = K.NO AND T.DEP_REL_IND = '1'"+
            "AND T.STS = '1' AND K.USE_STS = '1' AND K.DEP_STS = '1' AND T.FLOOR>="+level+" AND T.RELATION_INFO_NO = 'AAAAAA')  C WHERE  C.BL_CORP='Y'"+
            "START WITH C.NO='"+dep_no+"' CONNECT BY NOCYCLE PRIOR C.DEP_NO = C.UP_NO ORDER BY C.KEY) Z";*/
            var paramMap = {};
            paramMap.extralSql1 = 'SELECT K.NO,K.NO DEP_NO,K.DC_IND,K.KEY,K.NAME FROM COM_DEPARTMENT K WHERE NO IN (';
            paramMap.extralSql2 = ') ORDER BY K.KEY';
            paramMap.str = 'DEP_NO';
            paramMap.iniNodeAttr = 'DEP_NO,UP_NO,BL_CORP';
            paramMap.tableName = 'COM_DEPART_RELATION_DEF T, COM_DEPARTMENT K';
            paramMap.whereSql = " T.DEP_NO = K.NO AND T.DEP_REL_IND = '1' AND T.STS = '1' AND K.USE_STS = '1' AND K.DEP_STS = '1' AND T.FLOOR>=" + level + " AND T.RELATION_INFO_NO = 'AAAAAA' ";
            paramMap.beforeWhere = "BL_CORP='Y'";
            paramMap.afterWhere = "DEP_NO='" + dep_no + "' ";
            paramMap.idColumn = 'DEP_NO';
            paramMap.pidColumn = 'UP_NO';
            sql = loadGridDataMysql(paramMap, 'leg_no_zh');
        } else {
            /*sql = "SELECT * FROM (SELECT DISTINCT NO, DEP_NO, DC_IND, KEY, NAME FROM (SELECT K.NO, T.DEP_NO, T.DISP_SEQN,T.UP_NO,K.KEY,"+
            "K.NAME,K.IS_GATHER,K.DC_IND,K.BL_CORP FROM COM_DEPART_RELATION_DEF T, COM_DEPARTMENT K WHERE T.DEP_NO = K.NO AND T.DEP_REL_IND = '1'"+
            "AND T.STS = '1' AND K.USE_STS = '1' AND K.DEP_STS = '1' AND T.RELATION_INFO_NO = 'AAAAAA')  C WHERE  C.BL_CORP='Y'"+
            "START WITH C.NO='"+dep_no+"' CONNECT BY NOCYCLE PRIOR C.DEP_NO = C.UP_NO ORDER BY C.KEY) Z";*/
            var paramMap = {};
            paramMap.extralSql1 = 'SELECT K.NO,K.NO DEP_NO,K.DC_IND,K.KEY,K.NAME FROM COM_DEPARTMENT K WHERE NO IN (';
            paramMap.extralSql2 = ') ORDER BY K.KEY';
            paramMap.str = 'DEP_NO';
            paramMap.iniNodeAttr = 'DEP_NO,UP_NO,BL_CORP';
            paramMap.tableName = 'COM_DEPART_RELATION_DEF T, COM_DEPARTMENT K';
            paramMap.whereSql = " T.DEP_NO = K.NO AND T.DEP_REL_IND = '1' AND T.STS = '1' AND K.USE_STS = '1' AND K.DEP_STS = '1' AND T.RELATION_INFO_NO = 'AAAAAA' ";
            paramMap.beforeWhere = "BL_CORP='Y'";
            paramMap.afterWhere = "DEP_NO='" + dep_no + "' ";
            paramMap.idColumn = 'DEP_NO';
            paramMap.pidColumn = 'UP_NO';
            sql = loadGridDataMysql(paramMap, 'leg_no_zh');
        }
    });;
    return sql;
}

const loadGridDataMysql = async (paramMap, id) => {
    var sql = "";
    await getRecursionSqlResultPublicMethod(paramMap).then(function (rs) {
        sql = rs.sql;
    });;
    return sql;
}
</script>

<style scoped>
.content {
    padding: 20px;
    background-color: white;
}
</style>
