package nckd.jimin.jyyy.fi.plugin.form;

import kd.bos.bill.BillOperationStatus;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.ext.fi.plugin.ArApConvert.util.EmptyUtils;
import kd.bos.form.ShowType;
import kd.bos.form.events.BillListHyperLinkClickEvent;
import kd.bos.form.events.HyperLinkClickArgs;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;

/**
 * 标准单据列表插件
 */
public class GetPrepayParameterBillListPlugin extends AbstractListPlugin implements Plugin {
    public void billListHyperLinkClick(HyperLinkClickArgs args) {
        if ("billno".equals(args.getFieldName())) {
            //取消标准的打开界面
            args.setCancel(true);

            //获取当前数据行
            BillListHyperLinkClickEvent evt = (BillListHyperLinkClickEvent) args.getHyperLinkClickEvent();
            ListSelectedRow currentRow = evt.getCurrentRow();
            Long billId = (Long) currentRow.getPrimaryKeyValue();
            String billStatus = currentRow.getBillStatus();

            String formId = "er_prepaybill";

            //跳转到指定PC布局
            BillShowParameter showParameter = new BillShowParameter();
            QFilter qf = new QFilter("id", QCP.equals, billId);
            //跳转到指定PC布局
            DynamicObject billDyn = BusinessDataServiceHelper.loadSingle("er_prepaybill", new QFilter[]{qf});
            if (billDyn != null) {
                if (EmptyUtils.isNotEmpty(billDyn.getString("nckd_pageid"))) {
                    formId = billDyn.getString("nckd_pageid");
                }

            }
            showParameter.setFormId(formId);
            showParameter.setPkId(billId);
            showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage);

            if("A".equals(billStatus) || "D".equals(billStatus)) {
                showParameter.setStatus(OperationStatus.EDIT);
                showParameter.setBillStatus(BillOperationStatus.EDIT);
            } else {
                showParameter.setStatus(OperationStatus.VIEW);
                showParameter.setBillStatus(BillOperationStatus.VIEW);
            }

            this.getView().showForm(showParameter);
        }
    }
}