package com.yem.wm.es.shippingdetails.form;

import com.yem.wm.es.Util.TotalUtil;
import com.yem.wm.es.Util.ZJUtils;
import com.yem.wm.im.clientdemand.utils.ClientUtils;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.IFormView;

import java.math.BigDecimal;
import java.util.EventObject;

/**
 * @author 张立攀
 * @version 1.0
 * @description    出运明细单-配件
 * @date 2023-08-16 17:51
 */
public class ShippingDetailsZJFormPlugin extends AbstractBillPlugIn {

    @Override
    public void afterBindData(EventObject e) {
        super.afterBindData(e);
        IDataModel model = this.getModel();
        OperationStatus status = this.getView().getFormShowParameter().getStatus();
        if(OperationStatus.ADDNEW == status){
            ZJUtils.setRandomDataTools(model);
        }
    }

    @Override
    public void propertyChanged(PropertyChangedArgs e) {
        IFormView view = this.getView();
        IDataModel model = this.getModel();
        ChangeData changeData = e.getChangeSet()[0];
        String name = e.getProperty().getName();
        int rowIndex = changeData.getRowIndex();
        DynamicObject dataEntity = model.getDataEntity();
        DynamicObjectCollection materialInfo = dataEntity.getDynamicObjectCollection("yem_es_materialinfo");
        switch (name) {
            case "yem_qty" :
                ZJUtils.setRandomDataTools(model);
                ZJUtils.countOrderSumNumberZJ(model);
                TotalUtil.setGiftGiving(model);
                ClientUtils.addSaAmountTk(model,rowIndex);//销售金额（价格条款）结算币别
                break;
            case "yem_lenghtunit" ://长度单位
            case "yem_vol" ://体积
                TotalUtil.countVolM3(model,rowIndex,"yem_lenghtunit","yem_vol","yem_volm3");;
                break;
        }
    }
}
