TopPurchaseView.m 10.2 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"
陈俊俊's avatar
陈俊俊 committed
15
#import "Vendor.h"
n22's avatar
n22 committed
16 17 18
#define LeftMargin 15
#define LeftWidth 80
#define SpaceHeight 10
陈俊俊's avatar
陈俊俊 committed
19 20
#define TopMargin 10
#define TableHeight 44
n22's avatar
n22 committed
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
@interface TopPurchaseView ()<UITableViewDataSource,UITableViewDelegate,HPGrowingTextViewDelegate,UITextFieldDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArr;
}
@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];
n22's avatar
n22 committed
44
    NSArray *arr = @[@"采购通知:",@"类型:",@"供应商:",@"收货仓库:",@"其他费用:",@"总金额:",@"备注:"];
n22's avatar
n22 committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
    [_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 - 协议方法
- (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;
n22's avatar
n22 committed
68
        if (indexPath.row > 0 && indexPath.row < 4) {
n22's avatar
n22 committed
69 70 71 72 73 74 75 76 77
            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
78
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight)];
n22's avatar
n22 committed
79
        textField.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
80 81
        textField.textColor = GXF_CONTENT_COLOR;
        textField.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
82
        textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
n22's avatar
n22 committed
83 84 85
        textField.returnKeyType = UIReturnKeyDone;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
n22's avatar
n22 committed
86 87
        self.otherPriceFiled = textField;
        self.otherPriceFiled.placeholder = @"请输入其他费用";
陈俊俊's avatar
陈俊俊 committed
88
        [self.otherPriceFiled addTarget:self action:@selector(boxValueChanged:) forControlEvents:UIControlEventEditingChanged];
n22's avatar
n22 committed
89 90
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(textField.frame) + 5, 0, 20, TableHeight)];
        label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
91
        label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
92
        label.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
93
        [cell.contentView addSubview:label];
n22's avatar
n22 committed
94 95
        
    }else if (indexPath.row == _dataArr.count -1){
陈俊俊's avatar
陈俊俊 committed
96
        self.remarkTextView = [[HPGrowingTextView alloc] initWithFrame:CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight)];
n22's avatar
n22 committed
97 98
        self.remarkTextView.contentInset = UIEdgeInsetsMake(5, 5, 5, 0);
        self.remarkTextView.minNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
99
        self.remarkTextView.maxNumberOfLines = 1;
陈俊俊's avatar
陈俊俊 committed
100
        self.remarkTextView.isScrollable = YES;
陈俊俊's avatar
陈俊俊 committed
101
        self.remarkTextView.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
102
        self.remarkTextView.textAlignment = NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
103
        self.remarkTextView.delegate = self;   
n22's avatar
n22 committed
104 105
        self.remarkTextView.returnKeyType = UIReturnKeyDone;
        self.remarkTextView.placeholder = @"输入备注内容";
陈俊俊's avatar
陈俊俊 committed
106

n22's avatar
n22 committed
107 108
        [cell.contentView addSubview:self.remarkTextView];
    }else{
n22's avatar
n22 committed
109
        UILabel *contentLabel = [[UILabel alloc]initWithFrame:(CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-15, TableHeight))];
n22's avatar
n22 committed
110
        contentLabel.textAlignment= NSTextAlignmentRight;
陈俊俊's avatar
陈俊俊 committed
111
        contentLabel.textColor = GXF_PLACEHOLDER_COLOR;
陈俊俊's avatar
陈俊俊 committed
112
        contentLabel.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
113 114
        [cell.contentView addSubview:contentLabel];
        if (indexPath.row == 0) {
n22's avatar
n22 committed
115
            contentLabel.text = @"采购通知单号";
n22's avatar
n22 committed
116 117 118 119 120 121 122 123 124 125 126 127 128
            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
129 130 131 132 133 134 135
        }else if(indexPath.row == 5){
            contentLabel.text = @"0";
            contentLabel.frame = CGRectMake(100+LeftMargin, 0, ScreenSize.width - 100 - LeftMargin*2-30, TableHeight);
            contentLabel.textColor = [UIColor redColor];
            self.purchasePriceLabel = contentLabel;
            UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(contentLabel.frame)+ 5, 0, 20, TableHeight)];
            label.text = @"元";
陈俊俊's avatar
陈俊俊 committed
136
            label.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
137
            label.font = GXF_FIFTEENTEN_SIZE;
n22's avatar
n22 committed
138 139
            [cell.contentView addSubview:label];

n22's avatar
n22 committed
140 141
        }
    }
陈俊俊's avatar
陈俊俊 committed
142 143
    [self prepareDataInCell];
}
陈俊俊's avatar
陈俊俊 committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
//赋值
- (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;
        }
        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;
        }
        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
167

陈俊俊's avatar
陈俊俊 committed
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
            self.receiveWrh_uuid = bill.receiveWrh_uuid;
            self.receiveWrh_code = bill.receiveWrh_code;
            self.receiveWrh_name = bill.receiveWrh_name;
        }
        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
186
#warning  有点问题
陈俊俊's avatar
陈俊俊 committed
187 188 189 190
- (void)prepareDataInCell{
    if (self.total) {
        self.purchasePriceLabel.text = [self.total stringValue];
    }
n22's avatar
n22 committed
191
}
陈俊俊's avatar
陈俊俊 committed
192 193 194
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.row == 2){
        ChooseVendorViewController *cvc = [ChooseVendorViewController new];
陈俊俊's avatar
陈俊俊 committed
195
        cvc.choseBaseInfo = ^(NSArray *vendors){
陈俊俊's avatar
陈俊俊 committed
196 197
            if (vendors.count > 0) {
                Vendor *vendor = vendors[0];
n22's avatar
n22 committed
198
                self.purchaseSupplierLabel.text = [NSString stringWithFormat:@"%@[%@]",vendor.name,vendor.code];
陈俊俊's avatar
陈俊俊 committed
199
                self.purchaseSupplierLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
200 201 202
                self.vendor_uuid = vendor.uuid;
                self.vendor_code = vendor.code;
                self.vendor_name = vendor.name;
陈俊俊's avatar
陈俊俊 committed
203 204 205 206 207
            }
            
        };
        cvc.isMoreChose = NO;
        [self.delegate pushNextViewController:cvc];
n22's avatar
n22 committed
208 209
    }else if(indexPath.row == 1){
        ChooseTypeViewController *tvc = [[ChooseTypeViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
210 211
        tvc.choseBaseInfo = ^(NSArray *types){
            NSString *type = types[0];
n22's avatar
n22 committed
212
            self.purchaseTypeLabel.text = type;
陈俊俊's avatar
陈俊俊 committed
213
            self.purchaseTypeLabel.textColor = GXF_CONTENT_COLOR;
陈俊俊's avatar
陈俊俊 committed
214 215 216 217 218
            if ([type isEqualToString:@"紧急"]) {
                self.type = GXF_Critical;
            }else{
                self.type = GXF_Normal;
            }
n22's avatar
n22 committed
219 220 221 222
        };
        [self.delegate pushNextViewController:tvc];
    }else if(indexPath.row == 3){
        ChooseWarehouseViewController *wvc = [[ChooseWarehouseViewController alloc]init];
陈俊俊's avatar
陈俊俊 committed
223 224
        wvc.choseBaseInfo = ^(NSArray *warehouses){
            Warehouse *warehouse = warehouses[0];
n22's avatar
n22 committed
225
            self.purchaseStoreLabel.text = [NSString stringWithFormat:@"%@[%@]",warehouse.name,warehouse.code];
陈俊俊's avatar
陈俊俊 committed
226
            self.purchaseStoreLabel.textColor = GXF_CONTENT_COLOR;
n22's avatar
n22 committed
227 228 229
            self.receiveWrh_uuid = warehouse.uuid;
            self.receiveWrh_code = warehouse.code;
            self.receiveWrh_name = warehouse.name;
n22's avatar
n22 committed
230 231
        };
        [self.delegate pushNextViewController:wvc];
陈俊俊's avatar
陈俊俊 committed
232 233
    }
}
n22's avatar
n22 committed
234 235 236 237 238 239 240 241
- (BOOL)growingTextViewShouldReturn:(HPGrowingTextView *)growingTextView{
    [self.remarkTextView resignFirstResponder];
    return YES;
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [self.delegate hiddenKeyBoard];
    return YES;
}
n22's avatar
n22 committed
242 243 244
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.delegate hiddenKeyBoard];
}
陈俊俊's avatar
陈俊俊 committed
245 246 247

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


n22's avatar
n22 committed
251
@end