高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
public without sharing class eSignFormAttachmentController {
 
    //存放所有的附件
    public List<AccessoryData> acccData { get; set; } 
    //存放所有的附件的状态
    public eSignForm__c eSignForm { get; set; } 
    //区分医院经销商标识符
    public String identifier { get; set; }
    public String identifier2 { get; set; } 
    //附件表的parentId
    public String parentId;
    public eSignFormAttachmentController() {
      parentId = System.currentPageReference().getParameters().get('parentId');
      //parentId = 'a421000000367mz';
      acccData = new List<AccessoryData>();
      System.debug('tiaoshiListjiheparentId==='+parentId);
    }
    public void init() {
      getAccessory();
      String soql = 'SELECT agencyAutoSignUpStatus__c,id,HPSignUpStatus__c,Group_purchase_PCL__c,OCM_man_province_cus__c,agencySignUpDate__c,Sales_Root_Formula__c,HPSignUpDate__c from eSignForm__c where id = :parentId ';
      List<eSignForm__c> eSignFormData = Database.query(soql);
      if(eSignFormData!=null){
        eSignForm = eSignFormData[0];
      }
      System.debug('eSignForm==='+eSignForm);
    }
 
    public void getAccessory(){
      String soql = 'SELECT Name,id,parentId,ContentType from Attachment where parentId = :parentId order by createddate desc';
      List<Attachment> acc = Database.query(soql);
      Map<String,String> identifierMap = new Map<String,String>();
      if(acc != null && acc.size() > 0){
        for(Integer i = 0;i<acc.size();i++){
          if(acc[i].Name.substring(0,1)=='A'){
            acc[i].ContentType = '经销商';
            identifierMap.put(acc[i].ContentType,acc[i].ContentType);
          }else if(acc[i].Name.substring(0,1)=='H'){
            acc[i].ContentType = '医院';
            identifierMap.put(acc[i].ContentType,acc[i].ContentType);
          }else{
            acc[i].ContentType = '';
          }
          acccData.add(new AccessoryData(acc[i]));
        }
        if(identifierMap.containsKey('经销商') && !identifierMap.containsKey('医院')){
          identifier='经销商';
        }else if(identifierMap.containsKey('医院') && !identifierMap.containsKey('经销商') ){
            identifier2='医院';
        }else if(identifierMap.containsKey('医院') && identifierMap.containsKey('经销商')){
          identifier='经销商';
          identifier2='医院';
        }
      }
      System.debug('tiaoshiListjihe==='+acccData);
    }
 
    /**
     * 为了方便前端table获取值
     */
    class AccessoryData {
      public Attachment accessory { get; set; }
      public Boolean canEdit { get; private set; }
      public Boolean hasError { get; private set; }
      public Boolean hasFieldError { get; private set; }
      public Integer lineNo { get; private set; }
      public String changeFlg { get; set; }
      public String reasonFlg { get; set; }
      //复选框id值
      public String chk { get;set; }
      
      public AccessoryData(Attachment record) {
          accessory = record;
          canEdit = true;
          hasError = false;
          hasFieldError = false;
          lineNo = 0;
          changeFlg = '0';
          reasonFlg = '0';
          chk = 'chk'+lineNo;
      }
  }
}