掌上报销移动端二开新增单据体

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-23浏览:1

掌上报销移动端二开新增单据体

【应用场景】

客户在PC端二开新增单据体,需要在移动端也能支持相关二开单据体的展示与录入、删除


【注意事项】

移动端二开方案基于移动列表实现,目前移动列表无法支持自定义字段,所以移动列表展示的字段需要到移动表单里面固定写死,分录录单需要额外新增移动表单录入(2023.06.08补丁,标准产品有预置空白移动表单供二开使用ER_MBReimb_EntityEditV3


【案例演示】

以费用报销单为例


【实现步骤】

<1>在PC端费用报销单新增单据体

<2>单据体分录增加新增、删除按钮(此知识贴只有新增、删除相关功能,至于复制等其他操作,参考现有操作即可),绑定新增操作,删除操作

<3>拓展ER_MBReimb_ExpReimbV3(掌上报销V3_费用报销单)移动表单,新增移动列表布局,添加移动列表需要展示的字段

勾选新增时不删除默认分录行,不然分录录单触发值更新以后会提示寻找实体上对应的属性描述符失败

表单插件代码如下:

using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.FormElement;
using Kingdee.BOS.Mobile;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using Kingdee.K3.Core.Mobile.Const;
using Kingdee.K3.Core.Mobile.Objects;
using Kingdee.K3.Core.Mobile.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3.AddEntityTest
{
    [Description("掌上报销V3_费用报销单新增单据体测试")]
    public class MBReimbAddEntityTest : MBReimbExpReimbEdit
    {
        public MBReimbAddEntityTest()
        {
            _commandMethods = new Dictionary<string, Action<MobEventArgs>>(StringComparer.OrdinalIgnoreCase);
            _commandMethods["FMobileListViewEntity"] = LinkToEditEntry;
            _commandMethods["FButtonAdd"] = LinkToAddEntry;
            _commandMethods["FButtonDel"] = LinkToDelete;
        }

        public override void EntityRowDoubleClick(EntityRowClickEventArgs e)
        {
            if (_commandMethods.ContainsKey(e.Key))
            {
                _commandMethods[e.Key](new MobEventArgs(e.Key, e.Row - 1));
            }
        }

        public override void ButtonClick(ButtonClickEventArgs e)
        {
            if (_commandMethods.ContainsKey(e.Key))
            {
                _commandMethods[e.Key](new MobEventArgs(e.Key, e.MenuKey.TryPareValue<int>()));
            }
        }

        /// <summary>
        /// 通用方法
        /// </summary>
        protected Dictionary<string, Action<MobEventArgs>> _commandMethods;

        /// <summary>
        /// 编辑分录
        /// </summary>
        /// <param name="e"></param>
        protected void LinkToEditEntry(MobEventArgs e)
        {
            var showParameter = GetShowChildParameter("MobAddEntity_Test", Convert.ToString(e.Row), "FEntity1");
            showParameter.OpenStyle.ShowType = ShowType.Modal;
            showParameter.Status = BOS.Core.Metadata.OperationStatus.EDIT;
            this.View.ShowForm(showParameter, x =>
            {
                if (x.ReturnData != null && Convert.ToBoolean(x.ReturnData))
                {
                    UpdateSingleEntry(e.Row);
                }
            });
        }

        /// <summary>
        /// 新增分录
        /// </summary>
        /// <param name="e"></param>
        protected void LinkToAddEntry(MobEventArgs e)
        {
            var op = BillView.BusinessInfo.GetForm().FormOperations.FirstOrDefault(x => x.OperationId == FormOperation.Operation_NewEntry && x.Parmeter != null && !x.Parmeter.OperationObjectKey.IsNullOrEmptyOrWhiteSpace() && x.Parmeter.OperationObjectKey.EqualsIgnoreCase("FEntity1"));
            if (op == null)
            {
                this.View.ShowMessage("找不到新增分录的操作,请检查BOS配置");
                return;
            }

            var opResult = BillView.InvokeFormOperation(op.Operation);
            if (!opResult)
                return;

            var addRow = BillView.Model.GetEntryRowCount("FEntity1") - 1;
            if (addRow < 0)
                return;

            var showParameter = GetShowChildParameter("MobAddEntity_Test", Convert.ToString(addRow), "FEntity1");
            showParameter.OpenStyle.ShowType = ShowType.Modal;
            this.View.ShowForm(showParameter, x =>
            {
                if (x.ReturnData != null && Convert.ToBoolean(x.ReturnData))
                {
                    FillEntryData();
                }
            });
        }

        protected void LinkToDelete(MobEventArgs e)
        {
            this.View.ShowMessage(Kingdee.BOS.Resource.ResManager.LoadKDString("是否删除此行明细", "00444575000020654", Kingdee.BOS.Resource.SubSystemType.SCM), MessageBoxOptions.YesNo, x =>
            {
                if (x != MessageBoxResult.Yes)
                    return;

                BillView.SetEntityFocusRow("FEntity1", e.Row);
                var opResult = BillView.InvokeFormOperation("DeleteEntryTest");
                if (!opResult)
                    return;
                this.View.Model.DeleteEntryRow("FMobileListViewEntity", e.Row);
                UpdateControlState();
            });
        }

         public override void OnSetLayoutInfo(SetLayoutInfoArgs e)
        {
            base.OnSetLayoutInfo(e);
            var entityAppearaces = _myLayoutInfo.GetEntityAppearances();
            var entityDict = _myBusinessInfo.Entrys.ToDictionary(x => x.Key, x => x);
            if (entityAppearaces != null && entityAppearaces.Count > 0 && entityDict.Count > 0)
            {
                foreach (var item in entityAppearaces.Where(item => entityDict.ContainsKey(item.Key)))
                {
                    item.Entity = entityDict[item.Key];
                }
            }

            var fieldAppearances = _myLayoutInfo.GetFieldAppearances();
            var fieldDict = _myBusinessInfo.GetFieldList().ToDictionary(x => x.Key, x => x);
            if (fieldAppearances != null && fieldAppearances.Count > 0 && fieldDict.Count > 0)
            {
                foreach (var item in fieldAppearances.Where(item => item.Field != null && fieldDict.ContainsKey(item.Key)))
                {
                    item.Field.Entity = fieldDict[item.Key].Entity;
                }
            }
        }

        protected override void FillData()
        {
            base.FillData();
            FillEntryData();
           
        }

        protected void FillEntryData()
        {
            //填充移动列表
            var localEntryData = this.View.Model.GetEntityDataObject(this.View.BusinessInfo.GetEntryEntity("FMobileListViewEntity"));
            localEntryData.Clear();

            var billEntryData = BillView.Model.GetEntityDataObject(BillView.BusinessInfo.GetEntryEntity("FEntity1"));
            if (billEntryData == null)
                return;

            //全部展开
            if (billEntryData != null && billEntryData.Any())
            {
                this.View.Model.BatchCreateNewEntryRow("FMobileListViewEntity", billEntryData.Count);
                for (var i = 0; i < billEntryData.Count; i++)
                {
                    FillSingleEntry(billEntryData, localEntryData, i);
                }
                this.View.UpdateView("FMobileListViewEntity");
            }
        }

        /// <summary>
        /// 填充单一分录数据
        /// </summary>
        /// <param name="billEntryData"></param>
        /// <param name="localEntryData"></param>
        /// <param name="row"></param>
        protected void FillSingleEntry(DynamicObjectCollection billEntryData, DynamicObjectCollection localEntryData, int row)
        {
            if (billEntryData.Count <= row || localEntryData.Count <= row)
                return;

            this.View.SetEntityFocusRow("FMobileListViewEntity", row);

            //var billEntry = billEntryData[row];
            var localEntry = localEntryData[row];
            var billEntry = billEntryData[row];
            localEntry["Text4"] = "费用" + Convert.ToString(row + 1);
            localEntry["Text2"] = billEntry.GetPropertyValue<string>("Decimal"); ;//小数
            localEntry["Text3"] = billEntry.GetPropertyValue<string>("Date1");//日期
            localEntry["Text"] = billEntry.GetPropertyValue<string>("Text");//文本
            localEntry["Text1"] = (billEntry["Base"] as DynamicObject).GetPropertyValue<string>("Name");//基础资料
        }

        /// <summary>
        /// 更新分录信息
        /// </summary>
        /// <param name="row"></param>
        protected void UpdateSingleEntry(int row)
        {
            var localEntryData = this.View.Model.GetEntityDataObject(this.View.BusinessInfo.GetEntryEntity("FMobileListViewEntity"));
            var billEntity = BillView.BusinessInfo.GetEntryEntity("FEntity1");
            var billEntryData = BillView.Model.GetEntityDataObject(billEntity);
            this.View.Model.BeginIniti();
            FillSingleEntry(billEntryData, localEntryData, row);
            this.View.Model.EndIniti();
            this.View.UpdateView("FMobileListViewEntity", row);
        }
    }
}


<4>新增移动表单用于承载单据体分录的录入,移动表单展示的字段插件动态处理:MBReimbEditEntryTest

底部菜单参考如下配置:

表单插件代码如下:

using Kingdee.BOS;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.ControlElement;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Util;
using Kingdee.K3.BD.Common.Business.PlugIn.Mobile;
using Kingdee.K3.BD.Common.Business.PlugIn.Mobile.Provider;
using Kingdee.K3.Core.Mobile.Const;
using Kingdee.K3.Core.Mobile.Objects;
using Kingdee.K3.Core.Mobile.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace Kingdee.K3.FIN.ER.Mobile.Business.PlugIn.MobileReimbV3.AddEntityTest
{
    [Description("掌上报销V3_费用报销单编辑分录测试")]
    public class MBReimbEditEntryTest : AbstractLightAppEdit
    {
        public MBReimbEditEntryTest()
        {
            _commandMethods = new Dictionary<string, Action<MobEventArgs>>(StringComparer.OrdinalIgnoreCase);
            _commandMethods["FBtnConfirm"] = LinkToConfirm;
        }

        /// <summary>
        /// 通用方法
        /// </summary>
        protected Dictionary<string, Action<MobEventArgs>> _commandMethods;

        /// <summary>
        /// 自定义字段提供者,处理 加载、放置 那些用户自定义的显示字段
        /// </summary>
        protected DynamicFieldProvider FieldProvider { get; set; }

        protected List<string> _exceptVisibleKey = new List<string>() { "FText", "FBase", "FDecimal", "FDate1" };

        public override void ButtonClick(ButtonClickEventArgs e)
        {
            if (_commandMethods.ContainsKey(e.Key))
            {
                _commandMethods[e.Key](new MobEventArgs(e.Key, e.MenuKey.TryPareValue<int>()));
            }
        }

        public override void OnSetBusinessInfo(SetBusinessInfoArgs e)
        {
            base.OnSetBusinessInfo(e);

            FieldProvider = InitFieldProvider();
            FieldProvider.SetBusinessInfo(e, new HashSet<string>(_exceptVisibleKey));
        }

        public override void OnSetLayoutInfo(SetLayoutInfoArgs e)
        {
            base.OnSetLayoutInfo(e);
            FieldProvider.ClearLastChildContainerStyle();
            FieldProvider.SetLayoutInfo(e);
        }

        protected override void AddControls()
        {
            base.AddControls();
            FieldProvider.AddControls("FFlowLayout");
        }

        protected override void SetVisible(string key, bool value)
        {
            if (!FieldProvider.SetVisible(key, value))
                base.SetVisible(key, value);
        }

        protected override void SetMustInput(string key, bool value)
        {
            if (!FieldProvider.SetMustInput(key, value))
                base.SetMustInput(key, value);
        }

        /// <summary>
        /// 初始化动态字段提供者
        /// </summary>
        /// <returns></returns>
        protected virtual DynamicFieldProvider InitFieldProvider()
        {
            var fieldProvider = new DynamicFieldProvider(this.View, "ER_ExpReimbursement") 
            {
                ResetContainerStyle = ResetContainerStyle
            };
            return fieldProvider;
        }

        /// <summary>
        /// 重置流式布局样式
        /// </summary>
        /// <param name="app"></param>
        /// <param name="container"></param>
        /// <returns></returns>
        protected virtual ContainerAppearance ResetContainerStyle(FieldAppearance app, ContainerAppearance container)
        {
            return container;
        }

        public override void AfterBindData(EventArgs e)
        {
            base.AfterBindData(e);
            BindTitle();
        }

        /// <summary>
        /// 确认
        /// </summary>
        /// <param name="e"></param>
        protected virtual void LinkToConfirm(MobEventArgs e)
        {
            this.View.ReturnToParentWindow(new FormResult(true));
            this.View.Close();
        }

        /// <summary>
        /// 设置标题
        /// </summary>
        protected virtual void BindTitle()
        {
            this.View.SetFormTitle(new LocaleValue(BillView.BusinessInfo.GetForm().Name));
        }
    }
}

<5>其他单据与上面费用报销单单据类似,具体表单映射关系参考:

https://vip.kingdee.com/article/439370655386174720?productLineId=1&isKnowledge=2




【功能验证】

在电脑端调试移动端轻应用参考帖子:https://vip.kingdee.com/article/343300265727936512



【金蝶云星空BOS二次开发案例演示】

https://vip.kingdee.com/article/94751030918525696



掌上报销移动端二开新增单据体

【应用场景】客户在PC端二开新增单据体,需要在移动端也能支持相关二开单据体的展示与录入、删除【注意事项】移动端二开方案基于移动列表实...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息