package nckd.jxccl.swc.hsas.formplugin.web.cal;

import kd.bos.base.AbstractBasePlugIn;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.IListView;

import java.util.*;

public class CalResultDetailPluginEx extends AbstractBasePlugIn {
    public CalResultDetailPluginEx() {
    }

    @Override
    public void beforeDoOperation(BeforeDoOperationEventArgs args) {
        super.beforeDoOperation(args);
        FormOperate formOperate = (FormOperate)args.getSource();
        String opKey = formOperate.getOperateKey();
        if (opKey.equals("donothing_openagencypaybill")) {
            this.openAgencyPayBill(args);
        }
    }


    public void openAgencyPayBill(BeforeDoOperationEventArgs args) {
        Map customParams = this.getView().getFormShowParameter().getCustomParams();
        // 构建参数
        Map formCustomParams = new HashMap();
        // 薪资核算组 核算期间 核算规则 归属日期 组织
        formCustomParams.put("payrollgroup", customParams.get("payrollgroup"));
        formCustomParams.put("calPeriodId", customParams.get("calPeriodId"));
        formCustomParams.put("calRuleId", customParams.get("calRuleId"));
        formCustomParams.put("startDate", customParams.get("startdate"));
        formCustomParams.put("org", customParams.get("org"));
        formCustomParams.put("source", "calPerson");
        // 当前页面选择的人
        IListView listview = (IListView) this.getView();
        ListSelectedRowCollection selectedRows = listview.getSelectedRows();
        Object[] calPersonIds = selectedRows.getPrimaryKeyValues();
        formCustomParams.put("calPersonIds", Arrays.asList(calPersonIds));
        FormShowParameter formShowParameter = new FormShowParameter();
        formShowParameter.setFormId("nckd_agencypaybill");
        formShowParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);
        formShowParameter.setCustomParams(formCustomParams);
        this.getView().showForm(formShowParameter);
    }

}
