cloud-web-corejs 1.0.54-dev.783 → 1.0.54-dev.785

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cloud-web-corejs",
3
3
  "private": false,
4
- "version": "1.0.54-dev.783",
4
+ "version": "1.0.54-dev.785",
5
5
  "scripts": {
6
6
  "dev": "vue-cli-service serve",
7
7
  "dev:micro": "vue-cli-service serve --port 17527",
@@ -1,10 +1,10 @@
1
- import {getToken} from "../../utils/auth";
2
- import {openCnPrint} from "../../components/cnPrint/index";
3
- import {openHiPrint} from "../../components/hiprint/index";
4
- import {openJdPrint} from "../../components/jdPrint/index";
5
- import {openPddPrint} from "../../components/pddPrint/index";
6
- import {openVipPrint} from "../../components/vipPrint/index";
7
- import {openXhsPrint} from "../../components/xhsPrint/index";
1
+ import { getToken } from "../../utils/auth";
2
+ import { openCnPrint } from "../../components/cnPrint/index";
3
+ import { openHiPrint } from "../../components/hiprint/index";
4
+ import { openJdPrint } from "../../components/jdPrint/index";
5
+ import { openPddPrint } from "../../components/pddPrint/index";
6
+ import { openVipPrint } from "../../components/vipPrint/index";
7
+ import { openXhsPrint } from "../../components/xhsPrint/index";
8
8
 
9
9
  let modules;
10
10
  let configUtil = {
@@ -29,7 +29,7 @@ modules = {
29
29
  },
30
30
  computed: {
31
31
  buttonName() {
32
- if(this.option.label){
32
+ if (this.option.label) {
33
33
  return this.option.label;
34
34
  }
35
35
  let exportTemplates = this.exportTemplates;
@@ -143,14 +143,13 @@ modules = {
143
143
  },
144
144
  getTableGrid() {
145
145
  let grid = null;
146
- let tableTarget = this.option.tableTarget
146
+ let tableTarget = this.option.tableTarget;
147
147
  if (tableTarget) {
148
148
  if (typeof tableTarget === "function") {
149
149
  grid = tableTarget();
150
150
  } else {
151
151
  grid = tableTarget;
152
152
  }
153
-
154
153
  } else if (this.option.tableRef) {
155
154
  grid = this.parentTarget.$refs[this.option.tableRef];
156
155
  }
@@ -160,23 +159,22 @@ modules = {
160
159
  let checkRows = [];
161
160
  let $grid = this.getTableGrid();
162
161
 
163
-
164
162
  let condition = null;
165
- if(this.option.customCondition){
163
+ if (this.option.customCondition) {
166
164
  let condition1 = this.option.customCondition(item);
167
- if(condition1)condition = condition1;
165
+ if (condition1) condition = condition1;
168
166
  }
169
- if(!condition){
167
+ if (!condition) {
170
168
  if ($grid) {
171
169
  checkRows = $grid.getCheckboxRecords(true);
172
170
  } else {
173
- checkRows
174
- = typeof this.option.param === "function"
175
- ? this.option.param(item)
176
- : this.option.param;
171
+ checkRows =
172
+ typeof this.option.param === "function"
173
+ ? this.option.param(item)
174
+ : this.option.param;
177
175
  }
178
176
  let ids = checkRows ? checkRows.map((row) => row.id) : [];
179
- condition = ids.length ? {id: ids} : null;
177
+ condition = ids.length ? { id: ids } : null;
180
178
  }
181
179
  return condition;
182
180
 
@@ -222,7 +220,12 @@ modules = {
222
220
  if ($grid) {
223
221
  checkRows = $grid.getCheckboxRecords(true);
224
222
  if (!checkRows.length) {
225
- this.$baseAlert(this.$t2("请选择需要导出/打印的数据", "components.baseInputExport.selectDataTip"));
223
+ this.$baseAlert(
224
+ this.$t2(
225
+ "请选择需要导出/打印的数据",
226
+ "components.baseInputExport.selectDataTip"
227
+ )
228
+ );
226
229
  return;
227
230
  }
228
231
  }
@@ -238,7 +241,9 @@ modules = {
238
241
  } else if (this.exportTypes.includes(etType)) {
239
242
  //导出excel
240
243
  let conditions = this.tableDefalutHandle(exportTemplate) || [];
241
- this.$baseConfirm(this.$t2("您确定要导出吗?", "components.baseInputExport.exportTip")).then(() => {
244
+ this.$baseConfirm(
245
+ this.$t2("您确定要导出吗?", "components.baseInputExport.exportTip")
246
+ ).then(() => {
242
247
  let condition = $grid
243
248
  ? this.tableDefalutHandle(exportTemplate)
244
249
  : this.tableDefalutHandle(exportTemplate);
@@ -371,16 +376,17 @@ modules = {
371
376
  }
372
377
 
373
378
  function downLoadFile(row, that) {
374
- let realFileName = fileName ? fileName + "-" + row.uuid : row.uuid;
375
- let fileUrl
376
- = configUtil.baseUrl
377
- + that.option.prefix
378
- + "/export_ins/download?uuid="
379
- + row.uuid
380
- + "&ippaaapp="
381
- + row.ippaaapp
382
- + "&n="
383
- + realFileName;
379
+ let filename = row.filename || fileName;
380
+ let realFileName = filename ? filename + "-" + row.uuid : row.uuid;
381
+ let fileUrl =
382
+ configUtil.baseUrl +
383
+ that.option.prefix +
384
+ "/export_ins/download?uuid=" +
385
+ row.uuid +
386
+ "&ippaaapp=" +
387
+ row.ippaaapp +
388
+ "&n=" +
389
+ realFileName;
384
390
  var params = {};
385
391
  that.parentTarget.$http({
386
392
  method: "post",
@@ -430,7 +430,7 @@
430
430
  <div
431
431
  class="d-item"
432
432
  v-for="(item, index1) in user.userCompanyInfoDTOs"
433
- :key="index1"
433
+ :key="item.companyCode"
434
434
  >
435
435
  <div class="title">
436
436
  <b>{{ item.companyName }}</b>
@@ -438,7 +438,7 @@
438
438
  class="button-sty"
439
439
  icon="el-icon-delete"
440
440
  v-if="isCurrentCompany(item.companyCode)"
441
- @click="deleteCompany(item, index1)"
441
+ @click="deleteCompany(item)"
442
442
  >{{ $t1("删除") }}
443
443
  </el-button>
444
444
  </div>
@@ -490,24 +490,19 @@
490
490
  @resizable-change="$vxeTableUtil.onColumnWitchChange"
491
491
  @custom="$vxeTableUtil.customHandle"
492
492
  >
493
- <template #position="{ row, rowIndex, $table }">
493
+ <template #position="{ row }">
494
494
  <el-input
495
495
  class="search-input"
496
496
  :value="getSelectPositionName(row)"
497
497
  clearable
498
- @clear="
499
- row.userSaleOrgPositionDTOs = [];
500
- $forceUpdate();
501
- "
498
+ @clear="clearSaleOrgPosition(row)"
502
499
  v-el-readonly
503
500
  v-if="companyInfo.companyCode == row.companyCode"
504
501
  >
505
502
  <i
506
503
  slot="suffix"
507
504
  class="el-input__icon el-icon-search"
508
- @click="
509
- openSelectPositionDialog(row, rowIndex, $table)
510
- "
505
+ @click="openSelectPositionDialog(row)"
511
506
  ></i>
512
507
  </el-input>
513
508
  <template v-else>
@@ -551,11 +546,6 @@
551
546
  @confirm="confirmRole"
552
547
  :param="roleDialogParam"
553
548
  />
554
- <companyDialog
555
- v-if="showCompanyDialog"
556
- :visiable.sync="showCompanyDialog"
557
- @confirm="confirmInsertCompany"
558
- />
559
549
  <saleOrgDialog
560
550
  v-if="showSaleOrgDialog"
561
551
  :visiable.sync="showSaleOrgDialog"
@@ -585,14 +575,12 @@
585
575
  </template>
586
576
 
587
577
  <script>
588
- import xeUtils from "xe-utils";
589
578
  import tempStorageButton from "@base/components/tempStorage/index.vue";
590
579
 
591
580
  export default {
592
581
  name: "UserEdit",
593
582
  components: {
594
583
  roleDialog: () => import("../../../views/user/role/dialog.vue"),
595
- companyDialog: () => import("../../../views/user/company_info/dialog.vue"),
596
584
  saleOrgDialog: () => import("../../../views/user/sale_org/dialog.vue"),
597
585
  positionDialog: () => import("../../../views/user/position/dialog.vue"),
598
586
  countryDialog: () => import("../../../views/user/country/dialog.vue"),
@@ -627,7 +615,7 @@ export default {
627
615
 
628
616
  return {
629
617
  dataId: "",
630
- hBtn: true,
618
+ isEdit: false,
631
619
  user: {
632
620
  userCompanyInfoDTOs: [],
633
621
  userSaleOrgDTOs: [],
@@ -640,27 +628,17 @@ export default {
640
628
  areaName: null,
641
629
  areaId: null,
642
630
  },
643
- companyTableData: [],
644
- vxeOption: {},
645
- companyInfoOption: {},
646
- userRoleOption: {},
647
631
  showRoleDialog: false,
648
- showCompanyDialog: false,
649
632
  showSaleOrgDialog: false,
650
633
  showPositionDialog: false,
651
- saleOrgPositionIndex: 0,
634
+ positionDialogDatas: [],
635
+ positionDialogRow: null,
652
636
  passRules: [
653
637
  { validator: validatePass, trigger: "blur", required: false },
654
638
  ],
655
639
  pass2Rules: [
656
640
  { validator: validatePass2, trigger: "blur", required: false },
657
641
  ],
658
- activeName: "first",
659
- userCustomerListDTO: {
660
- userCustomerDTOs: [],
661
- },
662
- customerOption: {},
663
- showCustomerDialog: false,
664
642
  exportOption: {
665
643
  prefix: USER_PREFIX,
666
644
  title: this.$t1("用户"),
@@ -669,11 +647,9 @@ export default {
669
647
  return [{ id: this.dataId }];
670
648
  },
671
649
  },
672
- showExtendedProperties: false,
673
- radio1: "0",
674
650
  companyInfo: {},
675
- distributorCode: "distributor",
676
651
  distributorRole: null,
652
+ unassignedTipShown: false,
677
653
  outUserCodes: [],
678
654
  roleDialogParam: { queryAll: true },
679
655
  tempStorageOption: {
@@ -684,11 +660,9 @@ export default {
684
660
  },
685
661
  chooseConfirm: (tempStorageData) => {
686
662
  this.user = tempStorageData;
687
- let map = xeUtils.groupBy(this.user.userRoleDTOs, "companyCode");
688
- Object.keys(map).forEach((key) => {
689
- let comapnyDTO = this.getCompanyDTO(key);
690
- comapnyDTO.roleData = map[key];
691
- });
663
+ // 暂存时 getReqFormData 把表格数据和表格配置都置空了,这里必须整体还原,
664
+ // 否则机构信息丢失、表格无列,且保存时 handleData 展开 null 会直接报错
665
+ this.restoreCompanyGrids();
692
666
  },
693
667
  saveConfirm: () => {},
694
668
  },
@@ -734,14 +708,11 @@ export default {
734
708
  user.userRoleDTOs = this.user.userRoleDTOs;
735
709
  this.user = user;
736
710
  this.user.password = "";
737
-
738
- this.showExtendedProperties = true;
739
711
  },
740
712
  });
741
713
  } else {
742
714
  this.user.gender = 1;
743
715
  this.isEdit = false;
744
- this.showExtendedProperties = true;
745
716
  }
746
717
  },
747
718
  getReqFormData() {
@@ -758,6 +729,11 @@ export default {
758
729
  ...this.user,
759
730
  userCompanyInfoDTOs,
760
731
  };
732
+ //编辑态不修改密码时不下发密码字段,避免被空值覆盖
733
+ if (this.isEdit && !formData.password) {
734
+ delete formData.password;
735
+ delete formData.rePassword;
736
+ }
761
737
  return formData;
762
738
  },
763
739
  saveData() {
@@ -821,16 +797,8 @@ export default {
821
797
  isLoading: true,
822
798
  modalStrictly: true,
823
799
  success: (res) => {
824
- // this.$refs.saleOrgGrid.loadData(res.objx || []);
825
- let rows = res.objx || [];
826
- if (rows.length) {
827
- let map = xeUtils.groupBy(rows, "companyCode");
828
- Object.keys(map).forEach((key) => {
829
- let companyDTO = this.getCompanyDTO(key);
830
- companyDTO.saleOrgData = map[key];
831
- });
832
- }
833
- this.user.userSaleOrgDTOs = rows;
800
+ this.user.userSaleOrgDTOs = res.objx || [];
801
+ this.initCompanyGrids(this.syncCompanyGrids());
834
802
  },
835
803
  });
836
804
  }
@@ -844,21 +812,20 @@ export default {
844
812
  isLoading: true,
845
813
  modalStrictly: true,
846
814
  success: (res) => {
847
- let rows = res.objx || [];
848
- if (rows.length) {
849
- let map = xeUtils.groupBy(rows, "companyCode");
850
- Object.keys(map).forEach((key) => {
851
- let companyDTO = this.getCompanyDTO(key);
852
- companyDTO.roleData = map[key];
853
- });
854
- }
855
- this.user.userRoleDTOs = rows;
815
+ this.user.userRoleDTOs = res.objx || [];
816
+ this.initCompanyGrids(this.syncCompanyGrids());
856
817
  },
857
818
  });
858
819
  }
859
820
  },
860
- deleteSaleOrgItem(row, index, $table) {
861
- this.getCompanyDTO(row.companyCode).saleOrgData.splice(index, 1);
821
+ deleteSaleOrgItem(row) {
822
+ const companyDTO = this.getCompanyDTO(row.companyCode);
823
+ const rows = (companyDTO && companyDTO.saleOrgData) || [];
824
+ // 用行对象定位,rowIndex 是渲染序,排序/过滤后会删错行
825
+ const index = rows.indexOf(row);
826
+ if (index > -1) {
827
+ rows.splice(index, 1);
828
+ }
862
829
  },
863
830
  getCompanyInfoData(callback) {
864
831
  if (this.dataId) {
@@ -870,7 +837,6 @@ export default {
870
837
  modalStrictly: true,
871
838
  success: (res) => {
872
839
  let rows = res.objx || [];
873
- let companyTableData = [];
874
840
  rows.forEach((row) => {
875
841
  Object.assign(row, {
876
842
  saleOrgGridOption: {},
@@ -888,7 +854,10 @@ export default {
888
854
  },
889
855
  initSaleOrg(companyCode) {
890
856
  let companyDTO = this.getCompanyDTO(companyCode);
891
- if (Object.keys(companyDTO.saleOrgGridOption).length) {
857
+ if (!companyDTO) {
858
+ return;
859
+ }
860
+ if (Object.keys(companyDTO.saleOrgGridOption || {}).length) {
892
861
  return;
893
862
  }
894
863
  let tableRef = "saleOrgGrid-" + companyCode;
@@ -914,23 +883,14 @@ export default {
914
883
  field: "defaults",
915
884
  width: 120,
916
885
  slots: {
917
- default: ({ row, $table, rowIndex }) => {
918
- var isDefault = row.defaults || false;
886
+ default: ({ row }) => {
919
887
  let disabled = this.companyInfo.companyCode != row.companyCode;
920
888
  return [
921
889
  <el-checkbox
922
- v-model={isDefault}
890
+ value={!!row.defaults}
923
891
  disabled={disabled}
924
- onchange={() => {
925
- let companyDTO = this.getCompanyDTO(row.companyCode);
926
- companyDTO.saleOrgData.forEach((item, index) => {
927
- if (index !== rowIndex) {
928
- item.defaults = false;
929
- }
930
- });
931
- this.$nextTick(() => {
932
- row.defaults = true;
933
- });
892
+ onchange={(checked) => {
893
+ this.changeSaleOrgDefault(row, checked);
934
894
  }}
935
895
  />,
936
896
  ];
@@ -943,14 +903,14 @@ export default {
943
903
  title: "",
944
904
  sortable: false,
945
905
  slots: {
946
- default: ({ row, rowIndex, $table }) => {
906
+ default: ({ row }) => {
947
907
  if (this.companyInfo.companyCode == row.companyCode) {
948
908
  return [
949
909
  <a
950
910
  href="javascript:void(0);"
951
911
  class="a-link"
952
912
  onclick={() => {
953
- this.deleteSaleOrgItem(row, rowIndex, $table);
913
+ this.deleteSaleOrgItem(row);
954
914
  }}
955
915
  >
956
916
  <el-tooltip
@@ -976,10 +936,12 @@ export default {
976
936
  },
977
937
  initUserRole(companyCode) {
978
938
  let companyDTO = this.getCompanyDTO(companyCode);
979
- if (Object.keys(companyDTO.roleGridOption).length) {
939
+ if (!companyDTO) {
940
+ return;
941
+ }
942
+ if (Object.keys(companyDTO.roleGridOption || {}).length) {
980
943
  return;
981
944
  }
982
- let userType = this.userType;
983
945
  const tableOption = {
984
946
  vue: this,
985
947
  tableRef: "userRoleGrid-" + companyCode,
@@ -991,13 +953,7 @@ export default {
991
953
  field: "name",
992
954
  width: 200,
993
955
  slots: {
994
- default: ({ row }) => {
995
- if (!row.isAdd) {
996
- return row.roleName;
997
- } else {
998
- return row.name;
999
- }
1000
- },
956
+ default: ({ row }) => row.roleName || row.name,
1001
957
  },
1002
958
  },
1003
959
  {
@@ -1006,14 +962,14 @@ export default {
1006
962
  title: "",
1007
963
  sortable: false,
1008
964
  slots: {
1009
- default: ({ row, rowIndex, $table }) => {
965
+ default: ({ row }) => {
1010
966
  if (this.companyInfo.companyCode == row.companyCode) {
1011
967
  return [
1012
968
  <a
1013
969
  href="javascript:void(0);"
1014
970
  class="a-link"
1015
971
  onclick={() => {
1016
- this.deleteRoleItem(row, rowIndex, $table);
972
+ this.deleteRoleItem(row);
1017
973
  }}
1018
974
  >
1019
975
  <el-tooltip
@@ -1041,17 +997,24 @@ export default {
1041
997
  if (rows.length > 0) {
1042
998
  let companyCode = this.companyInfo.companyCode;
1043
999
  let companyDTO = this.getCompanyDTO(companyCode);
1000
+ if (!companyDTO) {
1001
+ return;
1002
+ }
1044
1003
  let outUserCodes = this.outUserCodes;
1045
- if (this.userType === 1) {
1004
+ // 由机构带出的角色没有 code,不参与内外部过滤,否则会被整批丢弃
1005
+ if (this.userType == 1) {
1046
1006
  //组织用户
1047
- rows = rows.filter((row) => !outUserCodes.includes(row.code));
1048
- } else if (this.userType === 2) {
1007
+ rows = rows.filter(
1008
+ (row) => !row.code || !outUserCodes.includes(row.code)
1009
+ );
1010
+ } else if (this.userType == 2) {
1049
1011
  //外部用户
1050
- rows = rows.filter((row) => outUserCodes.includes(row.code));
1012
+ rows = rows.filter(
1013
+ (row) => !row.code || outUserCodes.includes(row.code)
1014
+ );
1051
1015
  }
1052
1016
 
1053
- const $grid = this.$refs["userRoleGrid-" + companyCode][0];
1054
- const tableData = companyDTO.roleData;
1017
+ const tableData = companyDTO.roleData || [];
1055
1018
  const map = {};
1056
1019
  tableData.forEach(function (item) {
1057
1020
  map[item.roleId] = 1;
@@ -1069,22 +1032,26 @@ export default {
1069
1032
  }
1070
1033
  });
1071
1034
 
1072
- companyDTO.roleData.push(...items);
1035
+ tableData.push(...items);
1036
+ companyDTO.roleData = tableData;
1073
1037
  }
1074
1038
  },
1075
- deleteRoleItem(row, index, $table) {
1076
- let companyDTO = this.getCompanyDTO(row.companyCode);
1077
- $table.remove(row);
1078
- companyDTO.roleData.splice(index, 1);
1039
+ deleteRoleItem(row) {
1040
+ const companyDTO = this.getCompanyDTO(row.companyCode);
1041
+ const rows = (companyDTO && companyDTO.roleData) || [];
1042
+ const index = rows.indexOf(row);
1043
+ if (index > -1) {
1044
+ rows.splice(index, 1);
1045
+ }
1079
1046
  },
1080
1047
  confirmInsertCompany(rows, callback) {
1048
+ const items = [];
1081
1049
  if (rows.length > 0) {
1082
1050
  const tableData = this.user.userCompanyInfoDTOs;
1083
1051
  const map = {};
1084
1052
  tableData.forEach(function (item) {
1085
1053
  map[item.companyCode] = 1;
1086
1054
  });
1087
- var items = [];
1088
1055
  rows.forEach((row) => {
1089
1056
  const item = {
1090
1057
  companyCode: row.companyCode,
@@ -1100,25 +1067,29 @@ export default {
1100
1067
  items.push(item);
1101
1068
  }
1102
1069
  });
1103
- // $grid.insertAt(items, -1);
1104
1070
  this.user.userCompanyInfoDTOs.splice(0, 0, ...items);
1105
1071
  if (this.user.userCompanyInfoDTOs.length == 1) {
1106
1072
  this.user.userCompanyInfoDTOs[0].defaults = true;
1107
1073
  }
1108
- // this.user.userCompanyInfoDTOs = this.user.userCompanyInfoDTOs.concat(items);
1074
+ // 该企业可能已经加载过角色/机构(组织数据缺失时尤其如此),需要回填,
1075
+ // 否则新建的卡片是两张空表,保存时 handleData 会把已有数据清掉
1076
+ items.forEach((item) => this.fillCompanyGrids(item));
1109
1077
  }
1110
1078
  callback && callback();
1079
+ return items;
1111
1080
  },
1112
- deleteCompany(row, index) {
1081
+ deleteCompany(row) {
1113
1082
  let companyCode = row.companyCode;
1114
- let companyDTO = this.getCompanyDTO(companyCode);
1115
- this.user.userCompanyInfoDTOs.splice(index, 1);
1116
- companyDTO.roleData = [];
1117
- companyDTO.saleOrgData = [];
1118
- this.user.userSaleOrgDTOs = this.user.userSaleOrgDTOs.filter(
1083
+ let index = this.user.userCompanyInfoDTOs.indexOf(row);
1084
+ if (index > -1) {
1085
+ this.user.userCompanyInfoDTOs.splice(index, 1);
1086
+ }
1087
+ row.roleData = [];
1088
+ row.saleOrgData = [];
1089
+ this.user.userSaleOrgDTOs = (this.user.userSaleOrgDTOs || []).filter(
1119
1090
  (item) => item.companyCode != companyCode
1120
1091
  );
1121
- this.user.userRoleDTOs = this.user.userRoleDTOs.filter(
1092
+ this.user.userRoleDTOs = (this.user.userRoleDTOs || []).filter(
1122
1093
  (item) => item.companyCode != companyCode
1123
1094
  );
1124
1095
  },
@@ -1126,7 +1097,9 @@ export default {
1126
1097
  if (rows.length > 0) {
1127
1098
  let companyCode = this.companyInfo.companyCode;
1128
1099
  let companyDTO = this.getCompanyDTO(companyCode);
1129
- const $grid = this.$refs["saleOrgGrid-" + companyCode][0];
1100
+ if (!companyDTO) {
1101
+ return;
1102
+ }
1130
1103
  const tableData = companyDTO.saleOrgData || [];
1131
1104
  const map = {};
1132
1105
  tableData.forEach(function (item) {
@@ -1137,7 +1110,7 @@ export default {
1137
1110
  let newUserRoleDTOs = [];
1138
1111
  var items = [];
1139
1112
 
1140
- rows.forEach((row, index) => {
1113
+ rows.forEach((row) => {
1141
1114
  const item = {
1142
1115
  companyCode: companyCode,
1143
1116
  companyName: row.companyName,
@@ -1167,11 +1140,12 @@ export default {
1167
1140
  items[0].defaults = true;
1168
1141
  }
1169
1142
 
1170
- companyDTO.saleOrgData.push(...items);
1143
+ tableData.push(...items);
1144
+ companyDTO.saleOrgData = tableData;
1171
1145
  this.confirmRole(newUserRoleDTOs);
1172
1146
  }
1173
1147
  },
1174
- openSelectPositionDialog(row, rowIndex, $table) {
1148
+ openSelectPositionDialog(row) {
1175
1149
  const userSaleOrgPositionDTOs = row.userSaleOrgPositionDTOs || [];
1176
1150
  const items = [];
1177
1151
  userSaleOrgPositionDTOs.forEach((userSaleOrgPositionDTO) => {
@@ -1186,17 +1160,17 @@ export default {
1186
1160
  });
1187
1161
 
1188
1162
  this.positionDialogDatas = items;
1189
- this.saleOrgPositionIndex = rowIndex;
1163
+ // 保存行对象而不是 rowIndex,避免排序/过滤后岗位写到别的机构上
1164
+ this.positionDialogRow = row;
1190
1165
  this.showPositionDialog = true;
1191
1166
  },
1192
1167
  confirmInsertPosition(rows) {
1193
- let companyCode = this.companyInfo.companyCode;
1194
- const saleOrgPositionIndex = this.saleOrgPositionIndex;
1195
- let companyDTO = this.getCompanyDTO(companyCode);
1196
- const tableData = companyDTO.saleOrgData || [];
1168
+ const saleOrgRow = this.positionDialogRow;
1169
+ if (!saleOrgRow) {
1170
+ return;
1171
+ }
1197
1172
  if (rows.length > 0) {
1198
- const oldPositions =
1199
- tableData[saleOrgPositionIndex].userSaleOrgPositionDTOs || [];
1173
+ const oldPositions = saleOrgRow.userSaleOrgPositionDTOs || [];
1200
1174
  const map = {};
1201
1175
  oldPositions.forEach(function (item) {
1202
1176
  map[item.positionId] = item;
@@ -1218,23 +1192,15 @@ export default {
1218
1192
  oItems.push(map[item.positionId]);
1219
1193
  }
1220
1194
  });
1221
- tableData[saleOrgPositionIndex].userSaleOrgPositionDTOs =
1222
- oItems.concat(items);
1195
+ this.$set(saleOrgRow, "userSaleOrgPositionDTOs", oItems.concat(items));
1223
1196
  } else {
1224
- tableData[saleOrgPositionIndex].userSaleOrgPositionDTOs = [];
1197
+ this.$set(saleOrgRow, "userSaleOrgPositionDTOs", []);
1225
1198
  }
1226
1199
  this.$forceUpdate();
1227
1200
  },
1228
1201
  getSelectPositionName(row) {
1229
- var userSaleOrgPositions = row.userSaleOrgPositionDTOs || [];
1230
- var allName = "";
1231
- userSaleOrgPositions.forEach(function (pItem, pIndex) {
1232
- allName = allName + "," + pItem.positionName;
1233
- });
1234
- if (allName) {
1235
- allName = allName.substr(1);
1236
- }
1237
- return allName;
1202
+ const userSaleOrgPositions = row.userSaleOrgPositionDTOs || [];
1203
+ return userSaleOrgPositions.map((item) => item.positionName).join(",");
1238
1204
  },
1239
1205
  getConpanyInfo() {
1240
1206
  this.$http({
@@ -1243,19 +1209,13 @@ export default {
1243
1209
  isLoading: true,
1244
1210
  success: (res) => {
1245
1211
  this.companyInfo = res.objx || {};
1246
- let companyCode = this.companyInfo.companyCode;
1247
1212
  if (!this.isEdit) {
1248
1213
  this.addCurrentCompany();
1249
1214
  } else {
1250
1215
  this.getCompanyInfoData(() => {
1251
1216
  this.getUserRoleData();
1252
1217
  this.getSaleOrgData();
1253
- setTimeout(() => {
1254
- this.user.userCompanyInfoDTOs.forEach((userCompanyInfoDTO) => {
1255
- this.initSaleOrg(userCompanyInfoDTO.companyCode);
1256
- this.initUserRole(userCompanyInfoDTO.companyCode);
1257
- });
1258
- }, 100);
1218
+ this.initCompanyGrids(this.user.userCompanyInfoDTOs);
1259
1219
  });
1260
1220
  }
1261
1221
  },
@@ -1265,26 +1225,19 @@ export default {
1265
1225
  return this.companyInfo.companyCode == companyCode;
1266
1226
  },
1267
1227
  addCurrentCompany(callback) {
1268
- this.confirmInsertCompany([this.companyInfo], callback);
1269
- setTimeout(() => {
1270
- this.initSaleOrg(this.companyInfo.companyCode);
1271
- this.initUserRole(this.companyInfo.companyCode);
1272
- setTimeout(() => {
1273
- if (this.userType === 2) {
1274
- //经销商
1275
- if (this.distributorRole) {
1276
- this.confirmRole([this.distributorRole]);
1277
- }
1278
- }
1279
- }, 100);
1280
- }, 100);
1228
+ const items = this.confirmInsertCompany([this.companyInfo], callback);
1229
+ if (this.userType == 2 && this.distributorRole) {
1230
+ //经销商,默认带出经销商角色
1231
+ this.confirmRole([this.distributorRole]);
1232
+ }
1233
+ this.initCompanyGrids(items);
1281
1234
  },
1282
1235
  handleData() {
1283
1236
  let saleOrgs = [];
1284
1237
  let roles = [];
1285
1238
  this.user.userCompanyInfoDTOs.forEach((companyDTO) => {
1286
- saleOrgs.push(...companyDTO.saleOrgData);
1287
- roles.push(...companyDTO.roleData);
1239
+ saleOrgs.push(...(companyDTO.saleOrgData || []));
1240
+ roles.push(...(companyDTO.roleData || []));
1288
1241
  });
1289
1242
 
1290
1243
  this.user.userRoleDTOs = roles;
@@ -1372,7 +1325,148 @@ export default {
1372
1325
  this.user.userCompanyInfoDTOs.forEach((row) => {
1373
1326
  row.defaults = row.companyCode == companyCode;
1374
1327
  });
1328
+ } else {
1329
+ // 至少保留一个默认组织,取消唯一的默认项时回填
1330
+ let hasDefault = this.user.userCompanyInfoDTOs.some(
1331
+ (row) => row.defaults
1332
+ );
1333
+ if (!hasDefault) {
1334
+ item.defaults = true;
1335
+ }
1336
+ }
1337
+ },
1338
+ changeSaleOrgDefault(row, checked) {
1339
+ const companyDTO = this.getCompanyDTO(row.companyCode);
1340
+ const rows = (companyDTO && companyDTO.saleOrgData) || [];
1341
+ rows.forEach((item) => {
1342
+ if (item === row) {
1343
+ this.$set(item, "defaults", !!checked);
1344
+ } else if (checked) {
1345
+ this.$set(item, "defaults", false);
1346
+ }
1347
+ });
1348
+ },
1349
+ clearSaleOrgPosition(row) {
1350
+ this.$set(row, "userSaleOrgPositionDTOs", []);
1351
+ this.$forceUpdate();
1352
+ },
1353
+ normalizeSaleOrgRow(row) {
1354
+ //后端返回的机构行可能缺字段,先补齐保证响应式
1355
+ if (row.defaults === undefined) {
1356
+ this.$set(row, "defaults", false);
1357
+ }
1358
+ if (!row.userSaleOrgPositionDTOs) {
1359
+ this.$set(row, "userSaleOrgPositionDTOs", []);
1360
+ }
1361
+ return row;
1362
+ },
1363
+ // userRoleDTOs / userSaleOrgDTOs 是唯一事实源,这里统一分发到各组织卡片。
1364
+ // handleData 保存时只认组织卡片里的数据,所以任何没有归属组织的行都必须
1365
+ // 补出一张组织卡片,否则用户点一次保存就被静默删掉了。
1366
+ // 返回本次补建的组织卡片,交给调用方决定何时初始化表格。
1367
+ syncCompanyGrids() {
1368
+ this.dropUnassignedRows();
1369
+ const items = this.getLackCompanyCodes().map((companyCode) => {
1370
+ return {
1371
+ companyCode: companyCode,
1372
+ companyName: this.getRowCompanyName(companyCode),
1373
+ guid: null,
1374
+ defaults: false,
1375
+ saleOrgGridOption: {},
1376
+ roleGridOption: {},
1377
+ saleOrgData: [],
1378
+ roleData: [],
1379
+ };
1380
+ });
1381
+ if (items.length) {
1382
+ this.user.userCompanyInfoDTOs.push(...items);
1383
+ }
1384
+ this.user.userCompanyInfoDTOs.forEach((companyDTO) =>
1385
+ this.fillCompanyGrids(companyDTO)
1386
+ );
1387
+ return items;
1388
+ },
1389
+ fillCompanyGrids(companyDTO) {
1390
+ const companyCode = companyDTO.companyCode;
1391
+ const saleOrgData = (this.user.userSaleOrgDTOs || []).filter(
1392
+ (row) => row.companyCode == companyCode
1393
+ );
1394
+ saleOrgData.forEach((row) => this.normalizeSaleOrgRow(row));
1395
+ this.$set(companyDTO, "saleOrgData", saleOrgData);
1396
+ this.$set(
1397
+ companyDTO,
1398
+ "roleData",
1399
+ (this.user.userRoleDTOs || []).filter(
1400
+ (row) => row.companyCode == companyCode
1401
+ )
1402
+ );
1403
+ },
1404
+ getLackCompanyCodes() {
1405
+ //有角色/机构数据、但没有对应组织的企业编码
1406
+ const rows = (this.user.userSaleOrgDTOs || []).concat(
1407
+ this.user.userRoleDTOs || []
1408
+ );
1409
+ const codes = [];
1410
+ rows.forEach((row) => {
1411
+ const companyCode = row.companyCode;
1412
+ if (codes.includes(companyCode) || this.getCompanyDTO(companyCode)) {
1413
+ return;
1414
+ }
1415
+ codes.push(companyCode);
1416
+ });
1417
+ return codes;
1418
+ },
1419
+ getRowCompanyName(companyCode) {
1420
+ const rows = (this.user.userSaleOrgDTOs || []).concat(
1421
+ this.user.userRoleDTOs || []
1422
+ );
1423
+ const row = rows.find(
1424
+ (item) => item.companyCode == companyCode && item.companyName
1425
+ );
1426
+ return row ? row.companyName : companyCode;
1427
+ },
1428
+ dropUnassignedRows() {
1429
+ //companyCode 为空的行补不出有效组织,保留会往提交体里塞一条空组织关系
1430
+ const isUnassigned = (row) => {
1431
+ const code = row.companyCode;
1432
+ return code === null || code === undefined || code === "";
1433
+ };
1434
+ const roles = this.user.userRoleDTOs || [];
1435
+ const saleOrgs = this.user.userSaleOrgDTOs || [];
1436
+ const badRows = roles.filter(isUnassigned).concat(
1437
+ saleOrgs.filter(isUnassigned)
1438
+ );
1439
+ if (!badRows.length) {
1440
+ return;
1441
+ }
1442
+ this.user.userRoleDTOs = roles.filter((row) => !isUnassigned(row));
1443
+ this.user.userSaleOrgDTOs = saleOrgs.filter((row) => !isUnassigned(row));
1444
+ console.warn("[UserEdit] 忽略未归属组织的角色/机构数据", badRows);
1445
+ if (this.unassignedTipShown) {
1446
+ return;
1447
+ }
1448
+ this.unassignedTipShown = true;
1449
+ this.$baseAlert(this.$t1("存在未归属组织的角色/机构数据,已忽略"));
1450
+ },
1451
+ initCompanyGrids(companyDTOs) {
1452
+ if (!companyDTOs || !companyDTOs.length) {
1453
+ return;
1375
1454
  }
1455
+ this.$nextTick(() => {
1456
+ companyDTOs.forEach((companyDTO) => {
1457
+ this.initSaleOrg(companyDTO.companyCode);
1458
+ this.initUserRole(companyDTO.companyCode);
1459
+ });
1460
+ });
1461
+ },
1462
+ restoreCompanyGrids() {
1463
+ //暂存恢复:表格配置被置空过,需要连同表格一起重建
1464
+ (this.user.userCompanyInfoDTOs || []).forEach((companyDTO) => {
1465
+ this.$set(companyDTO, "saleOrgGridOption", {});
1466
+ this.$set(companyDTO, "roleGridOption", {});
1467
+ });
1468
+ this.syncCompanyGrids();
1469
+ this.initCompanyGrids(this.user.userCompanyInfoDTOs);
1376
1470
  },
1377
1471
  getCompanyDTO(companyCode) {
1378
1472
  return this.user.userCompanyInfoDTOs.find(