// // RQUserInfoViewModel.m // SDJK // // Created by 张嵘 on 2021/8/3. // #import "RQUserInfoViewModel.h" @interface RQUserInfoViewModel () @end @implementation RQUserInfoViewModel - (instancetype)initWithServices:(id)services params:(NSDictionary *)params{ if (self = [super initWithServices:services params:params]) { } return self; } - (void)initialize{ [super initialize]; self.title = @"个人信息"; ///配置数据 [self rq_configureData]; } #pragma mark - PrivateMethod - (void)rq_configureData { // @weakify(self); /// 第一组 RQCommonGroupViewModel *group0 = [RQCommonGroupViewModel groupViewModel]; group0.headerHeight = CGFLOAT_MIN; group0.footerHeight = 10; /// 头像 RQCommonAvatarItemViewModel *avatar = [RQCommonAvatarItemViewModel itemViewModelWithTitle:@"头像"]; RAC(avatar, avatar) = RACObserve(RQ_USER_MANAGER, headImage); avatar.rowHeight = RQ_FIT_HORIZONTAL(64.0f); /// 用户名 RQCommonArrowItemViewModel *nickname = [RQCommonArrowItemViewModel itemViewModelWithTitle:@"用户名"]; nickname.rowHeight = RQ_FIT_HORIZONTAL(54.0f); RAC(nickname, subtitle) = RACObserve(RQ_USER_MANAGER, nickName); // @weakify(nickname); // nickname.operation = ^{ // @strongify(self); // @strongify(nickname); // NSString *value = RQStringIsNotEmpty(self.user.screenName)?self.user.screenName:@""; // RQModifyNicknameViewModel *viewModel = [[RQModifyNicknameViewModel alloc] initWithServices:self.services params:@{RQViewModelUtilKey:value}]; // [self.services presentViewModel:viewModel animated:YES completion:NULL]; // // /// 设置block // @weakify(self); // @weakify(nickname); // viewModel.callback = ^(NSString *screenName) { // @strongify(self); // @strongify(nickname); // self.user.screenName = screenName; // [[self.services client] saveUser:self.user]; // nickname.subtitle = screenName; // // // “手动触发self.dataSource的KVO”,必写。 // [self willChangeValueForKey:@"dataSource"]; // // “手动触发self.now的KVO”,必写。 // [self didChangeValueForKey:@"dataSource"]; // }; // }; group0.itemViewModels = @[avatar, nickname]; /// 第二组 RQCommonGroupViewModel *group1 = [RQCommonGroupViewModel groupViewModel]; group1.headerHeight = CGFLOAT_MIN; RQProfileLogouItemViewModel *profileLogouItemViewModel = [[RQProfileLogouItemViewModel alloc] initWithTitle:@"注销账号"]; group1.itemViewModels = @[profileLogouItemViewModel]; group1.footerHeight = group1.itemViewModels.count > 0? 10 : CGFLOAT_MIN; self.dataSource = @[group0 , group1]; } @end