/**
 * Created by 1 at 2023-12-20 17:03:56
 * 注册事件类【机构数据填报编辑】，参看event.defaultEvent.js
 */
window.$swEvent.setup("mztb.base.partyDataFill.partyDataFillCard", {
    setup(page) {
        const {$params, $refs, $widgets, $model, $utils, $tabRouter, $api, $lifecycle, $engine, $parent} = page || {};
        const {$$message, $$http, $$sys, $$UtilPub} = $utils || {};

        // 示例
        const demoFunc = () => {

        };

        $lifecycle.onLoad = () => {
            if (!$params.id) {
                $model.card.setFormVal("fo_type", Number($params.type))
                $model.card.setFormVal("fo_task", Number($params.type) === 2 ? Number($params.task + "99") : Number($params.task)) //如果是年报 年份后面添加标识 99
                $model.card.setFormVal("fo_task_text", $params.task_text)
            }
            $api.loadOne("partyForm")
            if (Number($model.card.getFormVal("fo_state") === 2) || Number($model.card.getFormVal("fo_state") === 1)) {
                $refs.saveButton.hide()
            }
            if (Number($model.card.getFormVal("fo_type")) === 1) { // 月报
                $refs.yearEnd.hide()
            }
        }

        $lifecycle.onLoadOne = (dataSet) => {
            // 加载机构后 通过不同的登记部门 对字段进行禁用处理
            if (dataSet === "partyForm") {
                // 不同登记部门 可填写字段不同
                withRegisterDeptTypeDisable($model.partyForm.getFormVal("pi_reg_dept"));
            }
        }

        // 聚合数据集操作
        Object.assign($engine, {
            buildSaveParams(params) {// 将需要保存的数据集 构建到参数里面
                if (Number($model.card.getFormVal("fo_type")) === 2) { // 年报
                    params.yearEndPersonsForm = {
                        form: $model.yearEndPersonsForm.data.form
                    }
                }
                params.financeForm = {
                    form: $model.financeForm.data.form
                }
                params.businessForm = {
                    form: $model.businessForm.data.form
                }
                params.partyForm = {
                    form: $model.partyForm.data.form
                }
            }
        })

        const withRegisterDeptTypeDisable = (type) => {
            console.log("登记部门类型： ", type)
            switch (Number(type)) {
                case 1 : // 字典值 市场监管部门
                    oneHide();
                    break;
                case 2 : // 民政部门登记
                    twoHide();
                    break;
                case 3 : // 编制部门登记
                    threeHide();
                    break;
            }
        }

        const twoHide = () => { // 民政部门登记禁用
            $api.widgetDisable({
                financeForm: [
                    "fi_grand_total_depr", "fi_gtd_year", "fi_operation_revenue", "fi_operating_costs"
                    , "fi_taxes", "fi_sell_cost", "fi_manage_cost", "fi_mc_taxes"
                    , "fi_mc_travel", "fi_finance_cost", "fi_fc_interests", "fi_asset_loss"
                    , "fi_fair_value_chanage", "fi_income_from_investment", "fi_operating_profit", "fi_nonbusiness_income"
                    , "fi_ni_public_subsidy", "fi_base_pay", "fi_payable_money_year"
                    ,  "fi_mf_assets", "fi_bf_tax", "fi_ysf_menage_fee"
                    , "fi_mf_staff_costs", "fi_mf_every_day_fee", "fi_mf_assets", "fi_mf_tax"
                    , "fi_change_in_not_assets","fi_yit_enterpricse","fi_yit_business"]
            })
        }
        const threeHide = () => { // 编制部门登记禁用
            $api.widgetDisable({
                financeForm: [
                    "fi_grand_total_depr", "fi_gtd_year", "fi_operation_revenue", "fi_operating_costs"
                    , "fi_taxes", "fi_sell_cost", "fi_manage_cost", "fi_mc_taxes"
                    , "fi_mc_travel", "fi_finance_cost", "fi_fc_interests", "fi_asset_loss"
                    , "fi_fair_value_chanage", "fi_income_from_investment", "fi_operating_profit", "fi_nonbusiness_income"
                    , "fi_ni_public_subsidy", "fi_base_pay", "fi_payable_money_year", ""
                    , "fi_payable_money_year", "fi_year_expend", "fi_ycs_salary", "fi_ye_commodity_service"
                    , "fi_cs_heating_fee", "fi_cs_travel_expense", "fi_cs_go_abroad", "fi_cs_service_fee"
                    , "fi_cs_expend", "fi_cs_weal", "fi_ycs_personage_family_fee", "fi_pff_fuxue"
                    , "fi_pff_living_subsidy", "fi_pff_relief", "fi_pff_student_grent", "fi_pff_subsidy"
                    ,  "fi_year_sum_fee", "fi_ysf_business_fee", "fi_bf_staff_costs","fi_bf_every_day_fee"
                    , "fi_ycs_operating_expense", "fi_sell_fee", "fi_taxes","fi_yit_donation","fi_yit_membershiop_fees"]
            })
        }
        const oneHide = () => { // 市场监管部门登记禁用
            $api.widgetDisable({
                financeForm: [
                    "fi_year_income_total", "fi_yit_enterpricse", "fi_operation_revenue", "fi_yit_business"
                    , "fi_yit_donation", "fi_yit_membershiop_fees", "fi_yit_subsidy", "fi_year_expend"
                    , "fi_ycs_salary", "fi_ye_commodity_service", "fi_cs_heating_fee", "fi_cs_travel_expense"
                    , "fi_cs_go_abroad", "fi_cs_service_fee", "fi_cs_expend", "fi_cs_travel_expense"
                    , "fi_cs_weal", "fi_ycs_personage_family_fee", "fi_pff_fuxue", "fi_pff_living_subsidy"
                    , "fi_pff_relief", "fi_pff_student_grent", "fi_pff_bounty", "fi_ycs_operating_expense"
                    , "fi_sell_fee", "fi_year_sum_fee", "fi_ysf_business_fee", "fi_bf_staff_costs"
                    , "fi_bf_every_day_fee", "fi_mf_assets", "fi_bf_tax", "fi_ysf_menage_fee"
                    , "fi_mf_staff_costs", "fi_mf_every_day_fee", "fi_mf_assets", "fi_mf_tax"
                    , "fi_change_in_not_assets"]
            })
        }


        const loadPageCard = () => {
            // $api.loadCard()
        }


        return {
            demoFunc, loadPageCard
        }
    }
});
