TopPurchaseView.m 11.9 KB
Newer Older
n22's avatar
n22 committed
1 2 3 4 5 6 7 8 9 10 11
//
//  TopPurchaseView.m
//  XFFruit
//
//  Created by n22 on 15/8/21.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "TopPurchaseView.h"

#import "SurveyCell.h"
陈俊俊's avatar
陈俊俊 committed
12
#import "ChooseVendorViewController.h"
n22's avatar
n22 committed
13 14
#import "ChooseTypeViewController.h"
#import "ChooseWarehouseViewController.h"
15
#import "ChosePersonViewController.h"
陈俊俊's avatar
陈俊俊 committed
16
#import "Vendor.h"
17
#import "SurveyUser.h"
n22's avatar
n22 committed
18 19 20
#define LeftMargin 15
#define LeftWidth 80
#define SpaceHeight 10
陈俊俊's avatar
陈俊俊 committed
21 22
#define TopMargin 10
#define TableHeight 44
n22's avatar
n22 committed
23 24 25 26 27
@interface TopPurchaseView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
陈俊俊's avatar
陈俊俊 committed
28 29 30 31
//选择的项目
@property (nonatomic,strong)NSString *selectType;
@property (nonatomic,strong)NSString *selectVendor;
@property (nonatomic,strong)NSString *selectWarehouse;
n22's avatar
n22 committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
@end


@implementation TopPurchaseView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        //界面
        [self bulidLayout];
    }
    return self;
}

#pragma mark - 布局
- (void)bulidLayout
{
    self.backgroundColor  = XXFBgColor;
    _dataArr = [NSMutableArray array];
50
    NSArray *arr = @[@"采购员:",@"类型:",@"供应商:",@"收货仓库:",@"其他费用:",@"总金额:",@"备注:"];
n22's avatar
n22 committed
51 52 53 54 55 56 57 58 59 60
    [_dataArr addObjectsFromArray:arr];
    
    _tableView = [[UITableView alloc]initWithFrame:(CGRectMake(0, TopMargin,self.frame.size.width, self.frame.size.height - TopMargin)) style:(UITableViewStylePlain)];
    _tableView.backgroundColor = [UIColor whiteColor];
    _tableView.bounces = NO;
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self addSubview:_tableView];
}
#pragma mark - 协议方法
61 62 63 64 65 66 67
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 4) {
        return 0.01;
    }
    return 44;
}

n22's avatar
n22 committed
68 69 70 71 72 73 74 75 76 77 78 79 80
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *cellID = @"cellID";
    SurveyCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[SurveyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
81
        if (indexPath.row >= 0 && indexPath.row < 4) {
n22's avatar
n22 committed
82 83 84 85 86 87 88 89 90
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        }
        [self createViewInCell:cell indexPath:indexPath];
    }
    [cell setTitleStr:_dataArr[indexPath.row]];
    return cell;
}
-  (void)createViewInCell:(SurveyCell *)cell indexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 4 ) {
n22's avatar
n22 committed
91
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
n22's avatar
n22 committed
92
        textField.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
93 94
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
95
        textField.keyboardType = UIKeyboardTypeDecimalPad;
n22's avatar
n22 committed
96 97 98
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
n22's avatar
n22 committed
99
        self.otherPriceFiled = textField;
100 101
        self.otherPriceFiled.placeholder = @"其他费用";
        self.otherPriceFiled.enabled = NO;
陈俊俊's avatar
陈俊俊 committed
102
        [self.otherPriceFiled addTarget:self action:@selector(boxValueChanged:) forControlEvents:UIControlEventEditingChanged];
n22's avatar
n22 committed
103 104
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame) + 5, 0, 20, TableHeight)];
        label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
105
        label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
106
        label.font = GXF_FIFTEENTEN_SIZE;
107
        [cell.contentView removeAllSubViews];
n22's avatar
n22 committed
108
        [cell.contentView addSubview:label];
109
        cell.alpha = 0;
n22's avatar
n22 committed
110 111
        
    }else if (indexPath.row == _dataArr.count -1){
陈俊俊's avatar
陈俊俊 committed
112
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
n22's avatar
n22 committed
113 114
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
115
        self.remarkTextView.maxNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
116
        self.remarkTextView.isScrollable = YES;
陈俊俊's avatar
陈俊俊 committed
117
        self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
118
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
119
        self.remarkTextView.delegate = self;
n22's avatar
n22 committed
120 121
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
122
        
n22's avatar
n22 committed
123 124
        [cell.contentView addSubview:self.remarkTextView];
    }else{
n22's avatar
n22 committed
125
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
n22's avatar
n22 committed
126
        contentLabel.textAlignment= NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
127
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
陈俊俊's avatar
陈俊俊 committed
128
        contentLabel.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
129 130
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 0) {
131
            contentLabel.text = @"选择采购员";
n22's avatar
n22 committed
132 133 134 135 136 137 138 139 140 141 142 143 144
            self.purchaseNoticeLabel = contentLabel;
            
        }else if(indexPath.row == 1){
            contentLabel.text = @"选择类型";
            self.purchaseTypeLabel = contentLabel;
            
        }else if(indexPath.row == 2){
            contentLabel.text = @"选择供应商";
            self.purchaseSupplierLabel = contentLabel;
            
        }else if(indexPath.row == 3){
            contentLabel.text = @"选择收货仓库";
            self.purchaseStoreLabel = contentLabel;
n22's avatar
n22 committed
145 146 147
        }else if(indexPath.row == 5){
            contentLabel.text = @"0";
            contentLabel.frame = CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight);
陈俊俊's avatar
陈俊俊 committed
148
            contentLabel.textColor = GXF_NAVIGAYION_COLOR;
n22's avatar
n22 committed
149 150 151
            self.purchasePriceLabel = contentLabel;
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+ 5, 0, 20, TableHeight)];
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
152
            label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
153
            label.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
154
            [cell.contentView addSubview:label];
155
            
n22's avatar
n22 committed
156 157
        }
    }
陈俊俊's avatar
陈俊俊 committed
158 159
    [self prepareDataInCell];
}
陈俊俊's avatar
陈俊俊 committed
160 161 162 163 164 165 166 167 168 169 170 171
//赋值
- (void)setBill:(PurchaseBill *)bill{
    if (bill) {
        if (bill.noticeUuid.length > 0) {
            self.purchaseNoticeLabel.text = bill.noticeNumber;
            self.purchaseNoticeLabel.textColor = GXF_CONTENT_COLOR;
        }
        if (bill.type.length > 0) {
            NSString *type = [bill.type isEqualToString:GXF_Critical] ? @"紧急" : @"普通";
            self.purchaseTypeLabel.text = type;
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
            self.type = bill.type;
陈俊俊's avatar
陈俊俊 committed
172 173
            self.selectType = type;
            
陈俊俊's avatar
陈俊俊 committed
174 175 176 177 178 179 180
        }
        if (bill.vendor_name.length > 0) {
            self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",bill.vendor_name,bill.vendor_code];
            self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
            self.vendor_uuid = bill.uuid;
            self.vendor_code = bill.vendor_code;
            self.vendor_name = bill.vendor_name;
陈俊俊's avatar
陈俊俊 committed
181
            self.selectVendor = bill.vendor_uuid;
陈俊俊's avatar
陈俊俊 committed
182 183 184 185
        }
        if (bill.receiveWrh_name.length > 0) {
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",bill.receiveWrh_name,bill.receiveWrh_code];
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
186

陈俊俊's avatar
陈俊俊 committed
187 188 189
            self.receiveWrh_uuid = bill.receiveWrh_uuid;
            self.receiveWrh_code = bill.receiveWrh_code;
            self.receiveWrh_name = bill.receiveWrh_name;
陈俊俊's avatar
陈俊俊 committed
190 191
            self.selectWarehouse = bill.receiveWrh_uuid;

陈俊俊's avatar
陈俊俊 committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
        }
        if (bill.charge) {
            self.otherPriceFiled.text = [bill.charge stringValue];
            self.chargePurchase = bill.charge;
        }
        if (bill.total) {
            self.purchasePriceLabel.text = [bill.total stringValue];
            self.total = bill.total;
        }
        if (bill.remark.length > 0) {
            self.remarkTextView.text = bill.remark;
            self.remark = bill.remark;
        }
    }
}
陈俊俊's avatar
陈俊俊 committed
207 208 209 210
- (void)prepareDataInCell{
    if (self.total) {
        self.purchasePriceLabel.text = [self.total stringValue];
    }
陈俊俊's avatar
陈俊俊 committed
211 212 213 214
    if (self.noticeNumber.length > 0) {
        self.purchaseNoticeLabel.text = self.noticeNumber;
        self.purchaseNoticeLabel.textColor = GXF_CONTENT_COLOR;
    }
n22's avatar
n22 committed
215
}
陈俊俊's avatar
陈俊俊 committed
216 217 218
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 2){
        ChooseVendorViewController *cvc = [ChooseVendorViewController new];
陈俊俊's avatar
陈俊俊 committed
219 220 221
        if (self.selectVendor.length > 0) {
            cvc.selectStr = self.selectVendor;
        }
陈俊俊's avatar
陈俊俊 committed
222
        cvc.choseBaseInfo = ^(NSArray *vendors){
陈俊俊's avatar
陈俊俊 committed
223 224
            if (vendors.count > 0) {
                Vendor *vendor = vendors[0];
n22's avatar
n22 committed
225
                self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
陈俊俊's avatar
陈俊俊 committed
226
                self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
227 228 229
                self.vendor_uuid = vendor.uuid;
                self.vendor_code = vendor.code;
                self.vendor_name = vendor.name;
陈俊俊's avatar
陈俊俊 committed
230
                self.selectVendor = vendor.uuid;
陈俊俊's avatar
陈俊俊 committed
231 232 233 234 235
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
n22's avatar
n22 committed
236 237
    }else if(indexPath.row == 1){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
238 239 240
        if (self.selectType.length > 0) {
            tvc.selectStr = self.selectType;
        }
陈俊俊's avatar
陈俊俊 committed
241 242
        tvc.choseBaseInfo = ^(NSArray *types){
            NSString *type = types[0];
n22's avatar
n22 committed
243
            self.purchaseTypeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
244
            self.selectType = type;
陈俊俊's avatar
陈俊俊 committed
245
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
246 247 248 249 250
            if ([type isEqualToString:@"紧急"]) {
                self.type = GXF_Critical;
            }else{
                self.type = GXF_Normal;
            }
n22's avatar
n22 committed
251 252 253 254
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 3){
        ChooseWarehouseViewController *wvc = [[ChooseWarehouseViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
255 256 257
        if (self.selectWarehouse.length > 0) {
            wvc.selectStr = self.selectWarehouse;
        }
陈俊俊's avatar
陈俊俊 committed
258 259
        wvc.choseBaseInfo = ^(NSArray *warehouses){
            Warehouse *warehouse = warehouses[0];
n22's avatar
n22 committed
260
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
陈俊俊's avatar
陈俊俊 committed
261
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
262 263 264
            self.receiveWrh_uuid = warehouse.uuid;
            self.receiveWrh_code = warehouse.code;
            self.receiveWrh_name = warehouse.name;
陈俊俊's avatar
陈俊俊 committed
265
            self.selectWarehouse = self.receiveWrh_uuid;
n22's avatar
n22 committed
266 267
        };
        [self.delegate pushNextViewController:wvc];
268 269 270 271 272 273 274 275 276 277 278 279 280
    }else if (indexPath.row == 0){
        
        ChosePersonViewController *cvc = [ChosePersonViewController new];
        cvc.choseBaseInfo = ^(NSArray *users){
            if(users.count == 1){
                self.selectPerson = users[0];
                self.purchaseNoticeLabel.text = _selectPerson.userName;
                self.purchaseNoticeLabel.textColor = GXF_CONTENT_COLOR;
            }
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];

陈俊俊's avatar
陈俊俊 committed
281 282
    }
}
n22's avatar
n22 committed
283 284 285 286 287 288 289 290
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}
n22's avatar
n22 committed
291 292 293
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.delegate hiddenKeyBoard];
}
陈俊俊's avatar
陈俊俊 committed
294 295 296

- (void)boxValueChanged:(UITextField *)textFiled{
        [[NSNotificationCenter defaultCenter] postNotificationName:SetProductTotalPrice object:nil];
n22's avatar
n22 committed
297
}
n22's avatar
n22 committed
298 299


n22's avatar
n22 committed
300
@end