buli
2023-06-05 3962c2bb0435484b60a3e408e4738d792e249a53
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
import { LightningElement,wire,api,track } from 'lwc';
import { CurrentPageReference } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { NavigationMixin } from 'lightning/navigation';
import initPage from '@salesforce/apex/LexConsumableController.init';
import categoryAllload from '@salesforce/apex/LexConsumableController.categoryAllload';
import categoryload from '@salesforce/apex/LexConsumableController.categoryload';
import searchConsumableorderdetails from '@salesforce/apex/LexConsumableController.searchConsumableorderdetails';
import searchorderdetails from '@salesforce/apex/LexConsumableController.searchorderdetails';
import save from '@salesforce/apex/LexConsumableController.save';
import ordrCopy from '@salesforce/apex/LexConsumableController.ordrCopy';
import setEditAble from '@salesforce/apex/LexConsumableController.setEditAble';
import backOrder from '@salesforce/apex/LexConsumableController.backOrder';
import delConsumable from '@salesforce/apex/LexConsumableController.delConsumable';
import sorder from '@salesforce/apex/LexConsumableController.sorder';
import filesUpload from '@salesforce/apex/LexConsumableController.filesUpload';
import initHospital from '@salesforce/apex/LexSearchHospitalController.init';
import searchHospital from '@salesforce/apex/LexSearchHospitalController.searchHospital';
import initContract from '@salesforce/apex/LexSearchContractController.init';
import searchContract from '@salesforce/apex/LexSearchContractController.searchContract';
import deleteAtt from '@salesforce/apex/LexConsumableController.deleteAtt';
//table css 
import { loadStyle } from "lightning/platformResourceLoader";
import WrappedHeaderTable from "@salesforce/resourceUrl/lexdatatable";
 
export default class LexConsumable extends NavigationMixin(LightningElement) {
   
   //页面基础数据
   @track editAble;
   @track pageType;
   @track esetId;
   @track keyWords;
   @track coc;
   @track cocId;
   @track userWorkLocation;
   @track accountName;
   @track accountid;
   @track specialCampaign = false;
   @track dealerProductId = [];
   @track category1;
   @track category3 = '';
   @track category4 = '';
   @track category5 = '';
   @track category_Goods;
   @track category3Option = [];
   @track category4Option = [];
   @track category5Option = [];
   @track consumableorderdetailsRecordsview = [];
   @track currentRecord = [];//分页
   @track selectRows = [];
   @track attachmentRecoeds = [];
   @track contactDealer = [];
   @track proLimitAndDate = [];
   @track agencyProType;
   @track agencyProType1;
   @track OSHFLG = false;
   @track bargainPrice;
   @track showOrderDate = false;
   @track showAttUploadDate = false;
   @track edoffersPrice = false;
   @track editDelCommitBtnDisabled = false;
   @track showEditBtn = false;
   @track disabledEditBtn = false;
   @track showPrintSheetBtn = false;
   @track showUploadSheetBtn = false;
   @track disabledUploadSheetBtn = false;
   @track showSubOrderbtn = false;
   @track disabledSubOrderbtn = false;
   @track showSaveOrderbtn1 = false;
   @track showSaveOrderbtn2 = false;
   @track showDeleteBtn = false;
   @track disabledDeleteBtn = false;
   @track showOfferPriceInputBtn = false;
   @track disabledOfferPriceInputBtn = false;
   @track showReapplyBtn = false;
   @track showHospital = false;
   @track showPage = false;
   @track cansee = false;
   @track showSpinner = true;
   @track showPopSpinner = false;
   stylesLoaded = false;
   //是否一直显示提示
   @track isNoteStay = true;
   //排序相关
   @track sortDirection = 'asc';
   @track sortedBy;
   //分页
   @track currentPage = 1;
   @track pageSize = 10;
   // @track totalPage = 0;
   @track pageSizeOptions = [10, 25, 50, 100];
   @track recordStart = 0;
   @track recordEnd = 0;
   //报错提醒
   // @track hasError = false;
   @track errorMsgs = [];
   // @track hasWarning = false;
   @track warningMsgs = [];
   //附件上传
   @track showAttPop = false;
   @track filesUploaded = [];
   @track fileName;
   file;
   fileContents;
   fileReader;
   content;
   //医院搜索
   @track showAttHosPop = false;
   @track hospitalList = [];
   @track searchNameHos;
   @track chooseHospital;
   @track chooseHospitalId;
   @track hospitalId;
   @track hospitalName;
   @track tempidHp;
   @track hosCols = [
      // {label:'医院名称',fieldName:'Name',type:'button',typeAttributes:{label:{fieldName:'Name'},variant:'base'}},
      {label:'',type:'button',typeAttributes:{label:'选择'},initialWidth:90,hideDefaultActions: true,wrapText:true},
      {label:'医院名称',fieldName:'Name',initialWidth:380,wrapText:true,hideDefaultActions: true},
      {label:'省份',fieldName:'StateMaster',initialWidth:80,hideDefaultActions: true,wrapText:true},
      {label:'地址',fieldName:'Address__c',hideDefaultActions: true,wrapText:true}
   ];
   //合同搜索
   @track contractLabel;
   @track showConPop = false;
   @track contractList = [];
   @track searchNameCon;
   @track chooseContract;
   @track chooseContractId; 
   @track contractId;
   @track contractName;
   @track tempidPp;
   @track conCols = [
      {label:'',type:'button',typeAttributes:{label:'选择'},initialWidth:90,hideDefaultActions: true,wrapText:true},
      {label:'合同名称',fieldName:'Name',wrapText:true,hideDefaultActions: true},
      {label:'省份',fieldName:'StateMaster',initialWidth:80,hideDefaultActions: true,wrapText:true},
      {label:'申请销售课',fieldName:'Sales_Section__c',initialWidth:160,hideDefaultActions: true,wrapText:true},
      {label:'允许报价期间(开始日)',fieldName:'Contract_Decide_Start_Date__c',initialWidth:175,hideDefaultActions: true,wrapText:true},
      {label:'允许报价期间(结束日)',fieldName:'Contract_Decide_End_Date__c',initialWidth:175,hideDefaultActions: true,wrapText:true}
   ];
 
   //消耗品数据col
   get cols(){
      var cols = [];
      cols.push({label:'消耗品名称',fieldName:'prodName',wrapText:true,hideDefaultActions: true,sortable: true});
      cols.push({label:'规格',fieldName:'packing_list',wrapText:true,hideDefaultActions: true,initialWidth:50,cellAttributes: { alignment: "right" }});
      cols.push({label:'CFDA状态',fieldName:'prodSFDAStatus',wrapText:true,hideDefaultActions: true,initialWidth:97});
      cols.push({label:'注册证编码号',fieldName:'approbation_No',wrapText:true,hideDefaultActions: true,initialWidth:120});
      cols.push({label:'注册证效期',fieldName:'expiration_Date',wrapText:true,hideDefaultActions: true,initialWidth:105});
      cols.push({label:'第3分类',fieldName:'prodCategory3',wrapText:true,hideDefaultActions: true,initialWidth:78,sortable: true});
      cols.push({label:'第4分类',fieldName:'prodCategory4',wrapText:true,hideDefaultActions: true,initialWidth:107,sortable: true});
      cols.push({label:'第5分类',fieldName:'prodCategory5',wrapText:true,hideDefaultActions: true,initialWidth:80,sortable: true});
      if(this.cansee){
         cols.push({label:'标准单价',type:'number',typeAttributes:{minimumFractionDigits: 2},fieldName:'prodIntraTradeList',hideDefaultActions: true,initialWidth:80});
      }
      if(this.editAble){
         cols.push(
            {label:'采购数量',
            type: "customTableInput",typeAttributes: {
               recordId: { fieldName: "recordId" },
               inputValue: { fieldName: "consumableCount" },
               upperLimit: { fieldName: "upperlimit" },
               lowerLimit: { fieldName: "lowerlimit" },
               allnumber: { fieldName: "allnumber" },
               valueType: 'Number'
            },
            hideDefaultActions: true,initialWidth:80});
      }else{
         cols.push({label:'采购数量',fieldName:'consumableCount',hideDefaultActions: true,initialWidth:80,cellAttributes: { alignment: "right" }});
      }
      cols.push({label:'在库数下限',fieldName:'lowerlimit',hideDefaultActions: true,initialWidth:100,cellAttributes: { alignment: "right" }});
      cols.push({label:'在库数上限',fieldName:'upperlimit',hideDefaultActions: true,initialWidth:100,cellAttributes: { alignment: "right" }});
      // cols.push({label:'有效期库存(盒)',fieldName:'allnumber',hideDefaultActions: true,initialWidth:105,sortable: true});
      cols.push(
         {label:'有效期库存(盒)',
         type: "customInventoryColor",
         typeAttributes: {
            value: { fieldName: "allnumber" },
            upperlimit: { fieldName: "upperlimit" },
            lowerlimit: { fieldName: "lowerlimit" },
            boxPrice: '盒'
         },
         hideDefaultActions: true,initialWidth:126});
      cols.push({label:'有效期库存(个)',fieldName:'allnumber_piece',hideDefaultActions: true,initialWidth:126,cellAttributes: { alignment: "right" }});
      return cols;
   }
 
   //附件cols
   @track attCols = [
      {label:'标题',fieldName:'attUrl',type:'url',typeAttributes:{label:{fieldName:'fileName'},target: "_blank"},hideDefaultActions: true},
      {label:'创建人',fieldName:'ownerUrl',type:'url',typeAttributes:{label:{fieldName:'ownerName'},target: "_blank"},hideDefaultActions: true},
      {label:'上传日期',fieldName:'updateDate',hideDefaultActions: true},
      {label:'',type:'tableCellIcon',typeAttributes:{iconName:'utility:delete',recordId:{fieldName : 'recordId'}},initialWidth:50,hideDefaultActions: true}
   ];
 
   //取得所有被勾选的产品id
   getAllChecked(){
      this.selectRows = [];
      for(var i in this.currentRecord){
         if(this.currentRecord[i].check){
            this.selectRows.push(this.currentRecord[i].recordId);
         }
      }
   }
 
   //勾选操作
   checkRows(event){
      this.selectRows = [];
      const selectedRows = event.detail.selectedRows;
      for(var i in this.consumableorderdetailsRecordsview){
         var count = 0;
         for(var j in selectedRows){
            if(this.consumableorderdetailsRecordsview[i].recordId == selectedRows[j].recordId){
               count++
               console.log("checkId:"+selectedRows[j].recordId+'---'+this.consumableorderdetailsRecordsview[i].prodName);
            }
         }
         if(count == 0){
            this.consumableorderdetailsRecordsview[i].check = false;
         }else{
            this.consumableorderdetailsRecordsview[i].check = true;
            this.selectRows.push(this.consumableorderdetailsRecordsview[i].recordId);
         }
      }
      for(var i in this.selectRows){
         console.log("checkId1:"+this.selectRows[i]);
         for(var i in this.currentRecord){
            if(this.currentRecord[i].recordId == this.selectRows[i]){
               console.log("currentRecord:"+this.selectRows[i]);
            }
         }
      }
   }
 
   //采购数量获取
   conCountChange(event){
      var recordId = event.detail.data.recordId;
      var conCount = event.detail.data.value;
      console.log('countChange:'+recordId+'---'+conCount);
      for(var i in this.consumableorderdetailsRecordsview){
         if(this.consumableorderdetailsRecordsview[i].recordId == recordId){
            this.consumableorderdetailsRecordsview[i].esd.Consumable_count__c = conCount;
            this.consumableorderdetailsRecordsview[i].consumableCount = conCount;
            if(conCount != null && conCount !=0 && conCount!=''){
               this.consumableorderdetailsRecordsview[i].check = true;
            }else{
               this.consumableorderdetailsRecordsview[i].check = false;
            }
         }
      }
      this.getAllChecked();
      for(var i in this.currentRecord){
         if(this.currentRecord[i].recordId == recordId){
            console.log("currentRecord1:"+this.currentRecord[i].esd.Consumable_count__c);
         }
      }
   }
 
   //采购数量失焦
   conCountBlur(event){
      var conCount = event.detail.data.value;
      var allnumber = event.detail.data.allnumber;
      var upperLimit = event.detail.data.upperLimit;
      var lowerLimit = event.detail.data.lowerLimit;
      console.log('limit:'+conCount+'---'+ allnumber+'---'+lowerLimit+'---'+allnumber);
      if(upperLimit != null && lowerLimit != null && conCount != null && allnumber != null){
         if(parseInt(allnumber) + parseInt(conCount) > upperLimit){
            // window.alert("该产品订购数量超出库存上限!");
            this.showMyToast('该产品订购数量超出库存上限!','','error');
         }
         if(parseInt(allnumber) + parseInt(conCount) < lowerLimit){
            // window.alert("该产品订购数量低于库存下限!");
            this.showMyToast('该产品订购数量低于库存下限!','','error');
         }
      }
   }
 
   @wire(CurrentPageReference)
   getStateParameters(currentPageReference) {
      console.log('CurrentPageReference');
      if (currentPageReference) {
         this.pageType = currentPageReference.state?.type;
         this.esetId = currentPageReference.state?.ESetid;
         this.keyWords = currentPageReference.state?.KeyWords;
         console.log('type:'+this.pageType);
         console.log('esetId:'+this.esetId);
         console.log('keyWords:'+this.keyWords);
      }
   }
 
   renderedCallback(){ 
      if (!this.stylesLoaded) {
          Promise.all([loadStyle(this, WrappedHeaderTable)])
              .then(() => {
                  console.log("Custom styles loaded");
                  this.stylesLoaded = true;
              })
              .catch((error) => {
                  console.error("Error loading custom styles");
              });
      }
   }
   
   //页面初始化
   connectedCallback(){
      this.showSpinner = true;
      initPage({type:this.pageType, esetId:this.esetId, keywordStr:this.keyWords})
         .then(result=>{
            this.isNoteStay = result.isNoteStay;
            if(result.result == 'Success'){
               this.editAble = result.editAble;
               this.edoffersPrice = result.edoffersPrice;
               this.cansee = result.cansee;
               this.editDelCommitBtnDisabled = result.editDelCommitBtnDisabled;
               this.category3Option = result.category3Option;
               this.category4Option = result.category4Option;
               this.category5Option = result.category5Option;
               this.agencyProType = result.agencyProType;
               this.agencyProType1 = result.agencyProType1;
               this.OSHFLG = result.OSHFLG;
               this.hospitalName = result.hospitalName;
               this.contractName = result.contractName;
               this.contractLabel = '经销商有效合同';
               this.consumableorderdetailsRecordsview = result.consumableorderdetailsRecordsview;
               this.currentPage = 1;
               this.showCurrentReocrd();
               this.getAllChecked();
               this.attachmentRecoeds = result.attachmentRecoeds;
               console.log("attSize:"+this.attachmentRecoeds.length);
               for(var i in this.attachmentRecoeds){
                  this.attachmentRecoeds[i]['recordId'] = this.attachmentRecoeds[i].Concc.Id;
                  this.attachmentRecoeds[i]['documentId'] = this.attachmentRecoeds[i].Concc.ContentDocumentId;
                  this.attachmentRecoeds[i]['fileFullName'] = this.attachmentRecoeds[i].Concc.Title;
                  var contractionName = this.attachmentRecoeds[i].Concc.Title;
                  // var contractionName = '长文件长文件长文件长文件';
                  if(contractionName.length > 25){
                     contractionName = contractionName.substr(0,21) + "...";
                  }
                  this.attachmentRecoeds[i]['fileName'] = contractionName;
                  this.attachmentRecoeds[i]['ownerName'] = this.attachmentRecoeds[i].Concc.Owner.Name;
                  this.attachmentRecoeds[i]['downloadUrl'] = '/sfc/servlet.shepherd/document/download/'+this.attachmentRecoeds[i].Concc.ContentDocumentId+'?operationContext=S1';
                  // var date = this.attachmentRecoeds[i].Concc.CreatedDate;
                  // var year = date.getFullYear();
                  // var month = date.getMonth();
                  // var day = date.getDay();
                  // console.log(year+'-'+month+'-'+day);
                  this.attachmentRecoeds[i]['updateDate'] = new Date(Date.parse(this.attachmentRecoeds[i].Concc.CreatedDate)).toLocaleString();
                  this.attachmentRecoeds[i]['attUrl'] = '/'+this.attachmentRecoeds[i].Concc.Id;
                  this.attachmentRecoeds[i]['ownerUrl'] = '/'+this.attachmentRecoeds[i].Concc.OwnerId;
               }
               this.errorMsgs = result.errorMsgList;
               this.warningMsgs = result.warningMsgList;
               this.userWorkLocation = result.userWorkLocation;
               this.accountName = result.accountName;
               this.accountid = result.accountid;
               this.hospitalId = result.hospitalId;
               this.contractId = result.contractId;
               this.category_Goods = result.category_Goods;
               this.specialCampaign = result.specialCampaign;
               this.dealerProductId = result.dealerProductId;
               this.contactDealer = result.contactDealer;
               this.pageType = result.methodType;
               this.proLimitAndDate = result.proLimitAndDate;
               console.log("proLimitAndDate:"+JSON.stringify(this.proLimitAndDate));
               this.coc = result.coc;
               this.cocId = this.coc.Id;
               if(this.pageType == 'hospitalorder' && this.agencyProType != 'ET'){
                  this.showHospital = true;
               }
               if(this.coc.Order_status__c == "已提交" || this.coc.Order_status__c == "批准"){
                  this.showOrderDate = true;
               }
               if(this.coc.Consumable_pdf_insert_day__c != null){
                  this.showAttUploadDate = true;
               }
               if(!(this.editAble || this.edoffersPrice)){
                  this.showEditBtn = true;
                  this.showOfferPriceInputBtn = true;
               }
               if(this.coc.Order_status__c == "已提交" || this.coc.Order_status__c == "批准" || this.coc.Order_status__c == "驳回"){
                  this.disabledEditBtn = true;
                  this.disabledUploadSheetBtn = true;
                  this.disabledSubOrderbtn = true;
                  this.disabledDeleteBtn = true;
                  this.disabledOfferPriceInputBtn = true;
               }
               if(!(this.editDelCommitBtnDisabled || this.editAble || this.edoffersPrice)){
                  this.showPrintSheetBtn = true;
                  this.showUploadSheetBtn = true;
                  this.showSubOrderbtn = true;
                  this.showDeleteBtn = true;
               }
               if((this.editDelCommitBtnDisabled || this.editAble || this.edoffersPrice) && this.coc.Order_status__c != "驳回"){
                  this.showSaveOrderbtn1 = true;
               }
               if(this.coc.Order_status__c == "驳回" && this.editAble){
                  this.showSaveOrderbtn2 = true;
               }
               if(this.coc.Order_status__c == "驳回" && !this.editAble){
                  this.showReapplyBtn = true;
               }
               this.showSpinner = false;
               this.showPage = true;
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('初始化页面失败',result.errorMsg,'error');
            }
         })
         .catch(error=>{
            this.showSpinner = false;
            console.log("error:"+error);
            this.showMyToast('初始化页面失败',error,'error');
         })
   }
 
   //排序
   onHandleSort(event){
      //将已经选好了的放到前面,不进行排序
      console.log('sort');
      if(this.editAble){
         const { fieldName: sortedBy, sortDirection } = event.detail;
         const cloneData = [...this.currentRecord];
         cloneData.sort(this.sortBy(sortedBy, sortDirection === 'asc' ? 1 : -1));
         let index = 0;
         let selectedRows = this.template.querySelector('c-lex-custom-lightning-datatable').getSelectedRows();
         let selectedRowsIds = [];
         for(var i in selectedRows){
            selectedRowsIds.push(selectedRows[i].recordId);
         }
         console.log('selectedRowsIds = ' + JSON.stringify(selectedRowsIds));
         for(var i = 0;i < cloneData.length ; i++){
            if(selectedRowsIds.indexOf(cloneData[i].recordId) != -1){
               if(i != 0){
                  let temp = cloneData[index];
                  cloneData[index] = cloneData[i];
                  cloneData[i] = temp;
               }
               index++;
            }
         }
         this.currentRecord = cloneData;
         this.sortDirection = sortDirection;
         this.sortedBy = sortedBy;
      }else{
         const { fieldName: sortedBy, sortDirection } = event.detail;
         const cloneData = [...this.currentRecord];
         cloneData.sort(this.sortBy(sortedBy, sortDirection === 'asc' ? 1 : -1));
         this.currentRecord = cloneData;
         this.sortDirection = sortDirection;
         this.sortedBy = sortedBy;
      }
   }
 
   sortBy(field, reverse, primer) {
      const key = primer
          ? function (x) {
                return primer(x[field]);
            }
          : function (x) {
                return x[field];
            };
 
      return function (a, b) {
          a = key(a);
          b = key(b);
          return reverse * ((a > b) - (b > a));
      };
   }
   
   //是否有警告
   get hasWarning(){
      if(this.warningMsgs == null || this.warningMsgs.length == 0){
         return false;
      }
      if(this.warningMsgs.length > 0){
         return true;
      }
   }
 
   //是否有错误
   get hasError(){
      if(this.errorMsgs == null || this.errorMsgs.length == 0){
         return false;
      }
      if(this.errorMsgs.length > 0){
         return true;
      }
   }
 
   //特价change事件
   offerPriceChange(event){
      this.coc.Offers_Price__c = event.detail.value;
   }
 
   //消耗品名称change事件
   category1Change(event){
      this.category1 = event.detail.value;
   }
 
   //第三分类change事件
   category3Change(event){
      this.showSpinner = true;
      this.category3 = event.detail.value;
      this.category4 = '';
      this.category5 = '';
      categoryAllload({agencyProTypeStr:this.agencyProType, category3Str:this.category3})
         .then(result=>{
            if(result.result == 'Success'){
               this.category4Option = result.category4Option;
               this.category5Option = result.category5Option;
               this.showSpinner = false;
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('加载分类失败',result.errorMsg,'error');
            }
         })
   }
 
   //第四分类change事件
   category4Change(event){
      this.showSpinner = true;
      this.category4 = event.detail.value;
      this.category5 = '';
      categoryload({agencyProTypeStr:this.agencyProType, category3Str:this.category3, category4Str:this.category4})
         .then(result=>{
            if(result.result == 'Success'){
               this.category4Option = result.category4Option;
               this.category5Option = result.category5Option;
               this.showSpinner = false;
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('加载分类失败',result.errorMsg,'error');
            }
         })
   }
 
   //第五分类change事件
   category5Change(event){
      this.category5 = event.detail.value;
   }
 
   //搜索产品
   searchProduct(event){
      this.showSpinner = true;
      searchConsumableorderdetails({userWorkLocationStr:this.userWorkLocation,
         agencyProTypeStr:this.agencyProType,
         accountNameStr:this.accountName,
         accountIdStr:this.accountid,
         contractIdStr:this.contractId,
         hospitalIdStr:this.hospitalId,
         category1Str:this.category1, 
         category3Str:this.category3, 
         category4Str:this.category4, 
         category5Str:this.category5, 
         category_GoodStr:this.category_Goods, 
         specialCampaignStr:this.specialCampaign, 
         dealerProductIdStr:JSON.stringify(this.dealerProductId), 
         methodTypeStr:this.pageType,
         editAbleStr:this.editAble,
         consumableorderdetailsRecordsviewStr:JSON.stringify(this.consumableorderdetailsRecordsview),
         proLimitAndDateList : this.proLimitAndDate
      })
            .then(result=>{
               if(result.result == 'Success'){
                  this.consumableorderdetailsRecordsview = result.consumableorderdetailsRecordsview;
                  this.currentPage = 1;
                  this.currentRecord = [];
                  this.showCurrentReocrd();
                  this.getAllChecked();
                  this.showSpinner = false;
                  this.errorMsgs = result.errorMsgList;
                  this.warningMsgs = result.warningMsgList;
                  // this.hasError = result.hasError;
                  // this.hasWarning = result.hasWarning;
                  this.showMyToast('搜索成功',result.errorMsg,'success');
               }else{
                  this.showSpinner = false;
                  console.log("Error:"+result.errorMsg);
                  if(result.errorMsg == '没有搜索到相关数据'){
                     this.showMyToast(result.errorMsg,'','error');
                  }else{
                     this.showMyToast('搜索失败',result.errorMsg,'error');
                  }
               }
            })
            .catch(error=>{
               console.log("Error:"+error);
            })
   }
 
   //清除搜索栏
   clear(event){
      this.category1 = '';
      this.category3 = '';
      this.category4 = '';
      this.category5 = '';
      this.showSpinner = true;
      searchConsumableorderdetails({
         userWorkLocationStr:this.userWorkLocation,
         agencyProTypeStr:this.agencyProType,
         accountNameStr:this.accountName,
         accountIdStr:this.accountid,
         contractIdStr:this.contractId,
         hospitalIdStr:this.hospitalId,
         category1Str:this.category1, 
         category3Str:this.category3, 
         category4Str:this.category4, 
         category5Str:this.category5, 
         category_GoodStr:this.category_Goods, 
         specialCampaignStr:this.specialCampaign, 
         dealerProductIdStr:JSON.stringify(this.dealerProductId), 
         methodTypeStr:this.pageType,
         editAbleStr:this.editAble,
         consumableorderdetailsRecordsviewStr:JSON.stringify(this.consumableorderdetailsRecordsview),
         proLimitAndDateList : this.proLimitAndDate
      }).then(result=>{
            if(result.result == 'Success'){
               this.consumableorderdetailsRecordsview = result.consumableorderdetailsRecordsview;
               this.currentPage = 1;
               this.currentRecord = [];
               this.showCurrentReocrd();
               this.getAllChecked();
               this.showSpinner = false;
               this.showMyToast('搜索成功',result.errorMsg,'success');
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               if(result.errorMsg == '没有搜索到相关数据'){
                  this.showMyToast(result.errorMsg,'','error');
               }else{
                  this.showMyToast('搜索失败',result.errorMsg,'error');
               }
            }
         })
   }
 
   //选择所有
   checkAll(event){
      for(let i=0, len=this.consumableorderdetailsRecordsview.length; i < len ;i++){
         this.consumableorderdetailsRecordsview[i].check = event.target.checked;
      }
   }
 
   //选择
   check(event){
      let index = event.target.getAttribute("data-index");
      this.consumableorderdetailsRecordsview[index].check = event.target.checked;
   }
 
   //采购数量change事件
   // consumableCountChange(event){
   //    let index = event.target.getAttribute("data-index");
   //    var value = event.target.value;
   //    this.consumableorderdetailsRecordsview[index].esd.Consumable_count__c = value;
   //    if(isNaN(value)){
   //       value=0.00;
   //    }
   //    if(value != null && value !=0 && value!=''){
   //       this.consumableorderdetailsRecordsview[index].check = true;
   //    }else{
   //       this.consumableorderdetailsRecordsview[index].check = false;
   //    }
   // }
 
   //保存订单
   saveOrder(event){
      this.showSpinner = true;
      console.log('start save');
      save({
         contractNameStr:this.contractName,
         cocStr:JSON.stringify(this.coc),
         agencyProTypeStr:this.agencyProType,
         accountidStr:this.accountid,
         consumableorderdetailsRecordsviewStr:JSON.stringify(this.consumableorderdetailsRecordsview),
         contactDealerStr:JSON.stringify(this.contactDealer),
         methodTypeStr:this.pageType,
         eSetIdStr:this.esetId,
         hospitalIdStr : this.hospitalId,
         contractIdStr : this.contractId,
         agencyProType1Str : this.agencyProType1,
         OSHFLGStr : this.OSHFLG
      }).then(result=>{
         this.showSpinner = false;
         if(result.result == 'Success'){
            this.esetId = result.eSetId;
            const config = {
               type: 'standard__webPage',
               attributes: {
                  url: '/lexconsumable?ESetid=' + this.esetId + '&type=' + this.pageType
               }
           };
           this[NavigationMixin.Navigate](config);
         }else{
            this.showSpinner = false;
            console.log("Error:"+result.errorMsg);
            this.showMyToast('保存失败',result.errorMsg,'error');
         }
      })
   }
 
   //保存订单(驳回)
   orderCopy(event){
      this.showSpinner = true;
      ordrCopy({
         contractNameStr:this.contractName,
         cocStr:JSON.stringify(this.coc),
         agencyProTypeStr:this.agencyProType,
         accountidStr:this.accountid,
         consumableorderdetailsRecordsviewStr:JSON.stringify(this.consumableorderdetailsRecordsview),
         contactDealerStr:JSON.stringify(this.contactDealer),
         methodTypeStr:this.pageType,
         hospitalIdStr:this.hospitalId,
         contractIdStr : this.contractId,
         agencyProType1Str : this.agencyProType1,
         OSHFLGStr : this.OSHFLG
      }).then(result=>{
         this.showSpinner = false;
         if(result.result == 'Success'){
            this.esetId = result.eSetId;
            const config = {
               type: 'standard__webPage',
               attributes: {
                   url: '/lexconsumable?ESetid=' + this.esetId + '&type=' + this.pageType
               }
           };
           this[NavigationMixin.Navigate](config);
         }else{
            this.showSpinner = false;
            console.log("Error:"+result.errorMsg);
            this.showMyToast('保存失败',result.errorMsg,'error');
         }
      })
   }
 
   //编辑
   editOrder(event){
      setEditAble({eSetidStr:this.esetId})
         .then(result=>{
            if(result.result == 'Success'){
               const config = {
                  type: 'standard__webPage',
                  attributes: {
                      url: result.url
                  }
               };
              this[NavigationMixin.Navigate](config);
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('编辑失败',result.errorMsg,'error');
            }
         })
   }
 
   //打印配置单
   printOrder(event){
      var site = window.location.origin;
      const config = {
         type: 'standard__webPage',
         attributes: {
            url: site+'/consumable/PrintConsumblePDF?ESetid='+this.esetId
         }
      };
      this[NavigationMixin.Navigate](config);
   }
 
   //上传配置单
   uploadOrder(event){
      this.showAttPop = true;
   }
 
   //提交订单
   submitOrder(event){
      sorder({eSetidStr:this.esetId,accountidStr:this.accountid})
         .then(result=>{
            if(result.result == 'Success'){
               const config = {
                  type: 'standard__webPage',
                  attributes: {
                     url: result.url
                  }
               };
               this[NavigationMixin.Navigate](config);
            }else{
               this.showSpinner = false;
               this.errorMsgs = result.errorMsgList;
               this.warningMsgs = result.warningMsgList;
               console.log("Error:"+result.errorMsg);
               if(result.errorMsg.indexOf("请上传订货配置单附件") != -1){
                  result.errorMsg = '请上传订货配置单附件';
               }
               this.showMyToast('提交失败',result.errorMsg,'error');
            }
         })
         .catch(error=>{
            console.log("Error:"+error);
         })
   }
 
   //删除订单
   deleteOrder(event){
      if(!window.confirm('删除是不可恢复的,你确认要删除吗?')){
         return;
      }
      delConsumable({eSetidStr:this.esetId})
         .then(result=>{
            if(result.result == 'Success'){
               const config = {
                  type: 'standard__webPage',
                  attributes: {
                     url: result.url
                  }
            };
            this[NavigationMixin.Navigate](config);
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('删除失败',result.errorMsg,'error');
            }
         })
   }
 
   //特价金额录入
   inputOfferPrice(event){
      this.edoffersPrice = true;
      if(!(this.editAble || this.edoffersPrice)){
         this.showEditBtn = true;
         this.showOfferPriceInputBtn = true;
      }else{
         this.showEditBtn = false;
         this.showOfferPriceInputBtn = false;
      }
      if(!(this.editDelCommitBtnDisabled || this.editAble || this.edoffersPrice)){
         this.showPrintSheetBtn = true;
         this.showUploadSheetBtn = true;
         this.showSubOrderbtn = true;
         this.showDeleteBtn = true;
      }else{
         this.showPrintSheetBtn = false;
         this.showUploadSheetBtn = false;
         this.showSubOrderbtn = false;
         this.showDeleteBtn = false;
      }
      if((this.editDelCommitBtnDisabled || this.editAble || this.edoffersPrice) && this.coc.Order_status__c != "驳回"){
         this.showSaveOrderbtn1 = true;
      }else{
         this.showSaveOrderbtn1 = false;
      }
   }
 
   //再申请
   reapplyOrder(event){
      backOrder({eSetidStr:this.esetId})
         .then(result=>{
            if(result.result == 'Success'){
               const config = {
                  type: 'standard__webPage',
                  attributes: {
                     url: result.url
                  }
            };
            this[NavigationMixin.Navigate](config);
            }else{
               this.showSpinner = false;
               console.log("Error:"+result.errorMsg);
               this.showMyToast('再申请失败',result.errorMsg,'error');
            }
         })
   }
 
   //附件change事件
   attChange(event){
      if(event.target.files.length > 0) {
         this.filesUploaded = event.target.files;
         this.fileName = event.target.files[0].name;
         console.log('this.fileName:'+this.fileName);
      }
   }
 
   //是否显示附件移除
   get attDelBtn(){
      if(this.fileName != '' && this.fileName != null && this.fileName != '请选择一个文件上传'){
         return true;
      }else{
         return false;
      }
   }
 
   //关闭附件弹窗
   closePop(){
      this.showAttPop = false;
      this.filesUploaded = [];
      this.fileName = null;
   }
 
   //移除附件
   removeAtt(){
      this.filesUploaded = [];
      this.fileName = '';
   }
 
   //上传附件
   uploadAtt(event){
      if(this.filesUploaded.length > 0) {
         this.file = this.filesUploaded[0];
         if (this.file.size > this.MAX_FILE_SIZE) {
            window.console.log('文件过大');
            return ;
         }
         this.fileReader= new FileReader();
 
         this.fileReader.onloadend = (() => {
            this.fileContents = this.fileReader.result;
            let base64 = 'base64,';
            this.content = this.fileContents.indexOf(base64) + base64.length;
            this.fileContents = this.fileContents.substring(this.content);
            this.saveToFile();
         });
         this.fileReader.readAsDataURL(this.file);
      }
      else {
         this.fileName = '请选择一个文件上传';
      }
   }
 
   //调用上传附件后台方法
   saveToFile() {
      this.showPopSpinner = true;
      filesUpload({pId:this.esetId, fileName: this.file.name, base64Data: encodeURIComponent(this.fileContents)})
         .then(result => {
            this.showPopSpinner = false;
            if(result.result == 'Success'){
               this.closePop();
               window.location.reload();
            }else{
               console.log("Error:"+result.errorMsg);
               this.showMyToast('上传失败',result.errorMsg,'error');
            }
         })
         .catch(error => {
            this.showPopSpinner = false;
            this.showMyToast('上传失败',error,'error');
         });
   }
 
   //删除附件
   deleteAtt(event){
      this.showSpinner = true;
      var recordId = event.target.getAttribute("data-fileid");
      console.log('attid:'+recordId);
      deleteAtt({contentVersionId : recordId})
      .then(result=>{
         this.showSpinner = false;
         if(result.result == 'Success'){
            window.location.reload();
         }else{
            console.log("Error:"+result.errorMsg);
            this.showMyToast('删除失败',result.errorMsg,'error');
         }
      })
      .catch(error=>{
         this.showSpinner = false;
         console.log("Error:"+error);
         this.showMyToast('删除失败',JSON.stringify(error),'error');
      })
   }
 
   //预览附件
   previweAtt(event){
      var recordId = event.target.getAttribute("data-fileid");
      console.log(recordId);
      this[NavigationMixin.Navigate]({ 
         type:'standard__namedPage',
         attributes:{ 
            pageName:'filePreview'
         },
         state:{ 
            recordIds: recordId,
            selectedRecordId: recordId
         }
      });
   }
 
   //打开搜索弹窗,并初始化弹窗
   showSearchHos(event){
      initHospital()
         .then(result=>{
            if(result.result == 'Success'){
               this.showAttHosPop = true;
               this.hospitalList = result.attList;
               for(var i in this.hospitalList){
                  if(this.hospitalList[i].State_Master__c){
                     this.hospitalList[i]['StateMaster'] = this.hospitalList[i].State_Master__r.Name;
                  }
               }
            }else{
               console.log("Error:"+result.errorMsg);
               this.showMyToast('初始化检索医院页面失败',result.errorMsg,'error');
            }
         })
         .catch(error=>{
            console.log("Error:"+error);
            this.showMyToast('初始化检索医院页面失败',error,'error');
         })
   }
 
   //检索医院
   searchHos(event){
      searchHospital({searchName:this.searchNameHos, accountId:this.accountid})
         .then(result=>{
            if(result.result == 'Success'){
               this.hospitalList = result.attList;
               for(var i in this.hospitalList){
                  if(this.hospitalList[i].State_Master__c){
                     this.hospitalList[i]['StateMaster'] = this.hospitalList[i].State_Master__r.Name;
                  }
               }
            }else{
               console.log("Error:"+result.errorMsg);
               this.showMyToast('搜索失败',result.errorMsg,'error');
            }
         })
         .catch(error=>{
            console.log("Error:"+error);
            this.showMyToast('搜索失败',error,'error');
         })
   }
 
   //医院名称change
   searchNameHosChange(event){
      this.searchNameHos = event.detail.value;
   }
 
   //关闭弹窗
   closeHospitalPop(){
      this.showAttHosPop = false;
      this.chooseHospital = '';
      this.chooseHospitalId = '';
   }
 
   // //选择医院
   // chooseHos(event){
   //    var hosName = event.target.getAttribute("data-name");
   //    var hosid = event.target.getAttribute("data-hosid");
   //    console.log('hos:'+hosName+'---'+hosid);
   //    this.chooseHospital = hosName;
   //    this.chooseHospitalId = hosid;
   // }
 
   changeHos(event){
      this.hospitalName = event.detail.value;
   }
 
   changeCon(event){
      this.contractName = event.detail.value;
   }
 
   chooseHos(event){
      const row = event.detail.row;
      this.chooseHospitalId = row.Id;
      this.chooseHospital = row.Name;
      console.log('row.Id:'+row.Id);
      console.log('row.Name:'+row.Name);
      this.confirmHospital();
   }
 
   //确认选择医院
   confirmHospital(){
      if(this.chooseHospital != '' && this.chooseHospital != null){
         this.hospitalId = this.chooseHospitalId;
         this.tempidHp = this.chooseHospitalId;
         this.hospitalName = this.chooseHospital;
         this.closeHospitalPop();
         //消除警告
         var arr = [];
         for(var i in this.warningMsgs){
            if(this.warningMsgs[i] != '请选择医院'){
               arr.push(this.warningMsgs[i]);
            }
         }
         this.warningMsgs = arr;
         if(this.tempidHp != 'tempId' && this.tempidHp != ''){
            searchorderdetails({
               methodTypeStr : this.pageType,
               accountIdStr : this.accountid,
               hospitalIdStr : this.hospitalId,
               contractIdStr : this.contractId,
               userWorkLocationStr : this.userWorkLocation,
               accountNameStr : this.accountName,
               proLimitAndDateList : this.proLimitAndDate,
               editAbleStr : this.editAble
            }).then(result=>{
               if(result.result == 'Success'){
                  this.consumableorderdetailsRecordsview = result.consumableorderdetailsRecordsview;
                  this.currentPage = 1;
                  this.currentRecord = [];
                  this.showCurrentReocrd();
                  this.getAllChecked();
                  this.showMyToast('搜索成功',result.errorMsg,'success');
               }else{
                  console.log("Error:"+result.errorMsg);
                  if(result.errorMsg == '没有搜索到相关数据'){
                     this.showMyToast(result.errorMsg,'','error');
                  }else{
                     this.showMyToast('搜索产品失败',result.errorMsg,'error');
                  }
               }
            })
            .catch(error=>{
               console.log("Error:"+error);
               this.showMyToast('搜索产品失败',error,'error');
            })
            this.tempidHp = 'tempId';
         }
      }else{
         this.showMyToast('请选择医院','','error');
      }
   }
 
   //打开合同检索弹窗并初始化
   showSearchCon(){
      initContract({ctype:this.agencyProType1})
      .then(result=>{
         if(result.result == 'Success'){
            this.showConPop = true;
            this.contractList = result.attList;
            for(var i in this.contractList){
               if(this.contractList[i].State_Master__c){
                  this.contractList[i]['StateMaster'] = this.contractList[i].State_Master__r.Name;
               }
            }
         }else{
            console.log("Error:"+result.errorMsg);
            this.showMyToast('初始化检索合同页面失败',result.errorMsg,'error');
         }
      })
      .catch(error=>{
         console.log("Error:"+error);
         this.showMyToast('初始化检索合同页面失败',error,'error');
      })
   }
 
   //检索合同
   searchCon(){
      searchContract({searchName:this.searchNameCon, accountId:this.accountid, ctype:this.agencyProType1,OSHFLGStr : this.OSHFLG})
      .then(result=>{
         if(result.result == 'Success'){
            this.contractList = result.attList;
            for(var i in this.contractList){
               if(this.contractList[i].State_Master__c){
                  this.contractList[i]['StateMaster'] = this.contractList[i].State_Master__r.Name;
               }
            }
         }else{
            console.log("Error:"+result.errorMsg);
            this.showMyToast('搜索失败',result.errorMsg,'error');
         }
      })
      .catch(error=>{
         console.log("Error:"+error);
         this.showMyToast('搜索失败',error,'error');
      })
   }
 
   searchNameConChange(event){
      this.searchNameCon = event.detail.value;
   }
 
   //关闭弹窗
   closeContractPop(){
      this.showConPop = false;
      this.chooseContract = '';
      this.chooseContractId = '';
   }
 
   //选择合同
   // chooseCon(event){
   //    var conName = event.target.getAttribute("data-name");
   //    var conid = event.target.getAttribute("data-hosid");
   //    console.log('hos:'+conName+'---'+conid);
   //    this.chooseContract = conName;
   //    this.chooseContractId = conid;
   // }
 
   chooseCon(event){
      const row = event.detail.row;
      this.chooseContractId = row.Id;
      this.chooseContract = row.Name;
      console.log('row.Id:'+row.Id);
      console.log('row.Name:'+row.Name);
      this.confirmContract();
   }
 
   //确认选择合同
   confirmContract(){
      if(this.chooseContract != '' && this.chooseContract != null){
         this.contractId = this.chooseContractId;
         this.tempidPp = this.chooseContractId;
         this.contractName = this.chooseContract;
         this.closeContractPop();
         if(this.tempidPp != 'tempId' && this.tempidPp != '' && this.contractId != '' && this.pageType == 'promotionorder'){
            searchorderdetails({
               methodTypeStr : this.pageType,
               accountIdStr : this.accountid,
               hospitalIdStr : this.hospitalId,
               contractIdStr : this.contractId,
               userWorkLocationStr : this.userWorkLocation,
               accountNameStr : this.accountName,
               proLimitAndDateList : this.proLimitAndDate,
               editAbleStr : this.editAble
            }).then(result=>{
               if(result.result == 'Success'){
                  this.consumableorderdetailsRecordsview = result.consumableorderdetailsRecordsview;
                  this.currentPage = 1;
                  this.currentRecord = [];
                  this.showCurrentReocrd();
                  this.getAllChecked();
                  this.showMyToast('搜索成功',result.errorMsg,'success');
               }else{
                  console.log("Error:"+result.errorMsg);
                  if(result.errorMsg == '没有搜索到相关数据'){
                     this.showMyToast(result.errorMsg,'','error');
                  }else{
                     this.showMyToast('搜索产品失败',result.errorMsg,'error');
                  }
               }
            })
            .catch(error=>{
               console.log("Error:"+error);
               this.showMyToast('搜索产品失败',error,'error');
            })
            this.tempidPp = 'tempId';
         }
      }else{
         this.showMyToast('请选择合同','','error');
      }
   }
 
   showMyToast(title, message, variant) {
      console.log('show custom message');
      var iconName = '';
      var content = '';
      if(variant == 'success'){
         iconName = 'utility:check';
      }else{
         iconName = 'utility:error';
      }
      if(message != ''){
         content = '<h2><strong>'+title+'<strong/></h2><h5>'+message+'</h5>';
      }else{
         content = '<h2><strong>'+title+'<strong/></h2>';
      }
      this.template.querySelector('c-common-toast').
      showToast(variant,content,iconName,10000);
      // var mode;
      // if(this.isNoteStay){
      //     mode ='sticky';
      // }else{
      //     mode = 'dismissable';
      // }
      // const evt = new ShowToastEvent({
      //     title: title,
      //     message: message,
      //     variant: variant,
      //     mode: mode
      // });
      // this.dispatchEvent(evt);
   }
 
   //分页
   showCurrentReocrd(){
      var startIndex = 0;
      var endIndex = 0;
      console.log('len:'+this.consumableorderdetailsRecordsview.length);
      if(this.consumableorderdetailsRecordsview != null && this.consumableorderdetailsRecordsview.length > 0){
         var currentRecord = [];
         var currentCount = 0;
         var mu = this.consumableorderdetailsRecordsview.length % this.pageSize;
         if(this.currentPage == this.totalPage){
            if(mu != 0){
               currentCount = mu;
            }else{
               currentCount = this.pageSize;
            }
         }else{
            currentCount = this.pageSize;
         }
         console.log('this.totalPage:'+this.totalPage);
         console.log('this.pageSize:'+this.pageSize);
         console.log('mu:'+mu);
         console.log('currentCount:'+currentCount);
         startIndex = (this.currentPage - 1) * this.pageSize;
         endIndex = parseInt(startIndex) + parseInt(currentCount) - 1;
         console.log('startIndex:'+startIndex);
         console.log('endIndex:'+endIndex);
         if(this.editAble){
            for(var i in this.currentRecord){
               if(this.currentRecord[i].check){
                  currentRecord.push(this.currentRecord[i]);
               }
            }
         }
         for(var i = startIndex; i <= endIndex; i++){
            var count  = 0;
            for(var j in this.currentRecord){
               if(this.consumableorderdetailsRecordsview[i].recordId == this.currentRecord[j].recordId){
                  count++;
               }
            }
            if(count == 0){
               currentRecord.push(this.consumableorderdetailsRecordsview[i]);
            }
         }
         this.recordStart = startIndex + 1;
         this.recordEnd = endIndex + 1;
         this.currentRecord = currentRecord;
      }else{
         this.currentPage = 0;
         this.currentRecord = [];
      }
   }
 
   get prePage(){
      return this.currentPage - 1;
   }
 
   get nextPage(){
      return this.currentPage + 1;
   }
 
   get totalPage(){
      if(this.consumableorderdetailsRecordsview.length % this.pageSize == 0){
         return Math.trunc(this.consumableorderdetailsRecordsview.length / this.pageSize);
      }else{
         return Math.trunc(this.consumableorderdetailsRecordsview.length / this.pageSize) + 1;
      }
   }
 
   get totalRecords(){
      return this.consumableorderdetailsRecordsview.length;
   }
 
   //第一页
   goFirstPage(){
      this.currentPage = 1;
      this.showCurrentReocrd();
   }
 
   //最后一页
   goLastPage(){
      this.currentPage = this.totalPage;
      this.showCurrentReocrd();
   }
 
   //上一页
   prePageClick(){
      this.currentPage = this.currentPage - 1;
      this.showCurrentReocrd();
   }
 
   //下一页
   nextPageClick(){
      this.currentPage = this.currentPage + 1;
      this.showCurrentReocrd();
   }
 
   //page size change
   pageSizeChange(event){
      console.log('pagesize:'+event.detail);
      this.pageSize = event.detail;
      this.currentPage = 1;
      this.currentRecord = [];
      this.showCurrentReocrd();
   }
 
   //上一页按钮是否disable
   get previousButtonDisabled() {
      return this.currentPage == 1 || this.currentPage == 0;
   }
 
   //下一页按钮是否disable
   get nextButtonDisabled() {
      return this.currentPage == this.totalPage;
   }
}