Пример #1
0
        public static void SetAreaId(this IViewModelField v, int areaId, IArea?area, bool isSetProperty)
        {
            if (areaId == PleaseSelect.Id)
            {
                return;
            }
            area ??= Res.GetAll().FirstOrDefault(x => x.Id == areaId);
            if (area == null)
            {
                return;
            }
            if (!isSetProperty && area.Up.HasValue)
            {
                v.SetAreaId(area.Up.Value, null, isSetProperty);
            }
            switch (area.Level)
            {
            case AreaLevel.省或直辖市或特别行政区:
                v.SetAreaItems3(GetAreasByLevel(AreaLevel.市_不包括直辖市, areaId), isSetProperty);
                v.SetAreaNotVisible3(v.AreaItems3 == GroupEmpty, isSetProperty);
                v.SetAreaItems4(v.AreaNotVisible3 ? GetAreasByLevel(AreaLevel.区县_县级市, areaId) : GroupEmpty, isSetProperty);
                v.SetAreaNotVisible4(v.AreaNotVisible3 && v.AreaItems4 == GroupEmpty, isSetProperty);
                if (!isSetProperty)
                {
                    v.SetAreaSelectItem2(area, isSetProperty);
                }
                v.SetAreaSelectItem3(v.AreaSelectItem4 = PleaseSelect, isSetProperty);
                break;

            case AreaLevel.市_不包括直辖市:
                v.SetAreaItems4(GetAreasByLevel(AreaLevel.区县_县级市, areaId), isSetProperty);
                v.SetAreaNotVisible4(v.AreaItems4 == GroupEmpty, isSetProperty);
                if (!isSetProperty)
                {
                    v.SetAreaSelectItem3(area, isSetProperty);
                }
                v.SetAreaSelectItem4(PleaseSelect, isSetProperty);
                break;

            case AreaLevel.区县_县级市:
                if (!isSetProperty)
                {
                    v.SetAreaSelectItem4(area, isSetProperty);
                }
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// 初始化视图模型中的地区数据
        /// </summary>
        /// <param name="v"></param>
        public static void InitAreas(this IViewModelField v)
        {
            v.AreaItems2 = Group2;
            v.AreaItems3 = v.AreaItems4 = GroupEmpty;
            v.SetAreaSelectItem4(PleaseSelect, false);
            v.SetAreaSelectItem3(PleaseSelect, false);
            v.SetAreaSelectItem2(PleaseSelect, false);

            void SubscribeAreaSelectItem(IArea?area)
            {
                if (area != null)
                {
                    v.SelectArea(area);
                }
            }

            v.WhenAnyValue(x => x.AreaSelectItem2).Subscribe(SubscribeAreaSelectItem).AddTo(v);
            v.WhenAnyValue(x => x.AreaSelectItem3).Subscribe(SubscribeAreaSelectItem).AddTo(v);
        }