UserManager.vue 33.2 KB
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
<template>
  <div style="    height: 100%;">
    <el-tabs type="card" @tab-click="tabClick" v-model="currentTabName">
      <el-tab-pane label="基本信息" name="basic">
        <form data-vv-scope="editUserForm" class="form">
          <table class="form-table" cellspacing="0" cellpadding="0" border="0">
            <tbody>
              <tr>
                <td class="is-required">姓名:</td>
                <td>
                  <ht-input
                    v-model="user.fullname"
                    style="width: 100%"
                    autocomplete="off"
                    :validate="{
                      required: true,
                      min: '1',
                      max: '20',
                      regex: {
                        exp: '^[\u4E00-\u9FA5A-Za-z0-9]+$',
                        message: '姓名不能包含特殊字符,请重新输入'
                      }
                    }"
                    :maxlength="20"
                    :showWordLimit="true"
                  ></ht-input>
                </td>
                <td class="is-required">账号:</td>
                <td>
                  <ht-input
                    v-model="user.account"
                    style="width: 100%"
                    autocomplete="off"
                    :disabled="account != ''"
                    v-pinyin:1="user.fullname"
                    :validate="{
                      regex: {
                        exp: '^[\u4E00-\u9FA5a-zA-Z0-9_-]{2,20}$',
                        message: '账号不能包含中文或特殊字符且字数不低于2'
                      }
                    }"
                    :maxlength="20"
                    :showWordLimit="true"
                  ></ht-input>
                </td>
                <td rowspan="4" align="center" valign="middle">
                  <!-- fit="scale-down" -->
                  <el-avatar :size="120" fit="scale-down" :src="photoUrl">
                    <img :src="photoUrl" />
                  </el-avatar>
                  <el-upload
                    action="string"
                    :http-request="updateUserImage"
                    :show-file-list="false"
                    :before-upload="beforeAvatarUpload"
                    accept=".jpg,.jpeg,.png,.gif,.ico"
                  >
                    <el-button size="small" type="primary">点击上传</el-button>
                  </el-upload>
                </td>
              </tr>
              <tr>
                <td v-if="account != ''">手机:</td>
                <td v-if="account != ''">
                  <ht-input
                    style="width: 100%"
                    v-model="user.mobile"
                    autocomplete="off"
                    validate="mobile"
                  ></ht-input>
                </td>
                <td v-if="account == ''" class="is-required">密码:</td>
                <td v-if="account == ''">
                  <ht-input
                    style="width: 100%"
                    v-model="user.password"
                    show-password
                    :validate="pwdValidate"
                  />
                </td>
                <td>邮箱:</td>
                <td>
                  <ht-input
                    style="width: 100%"
                    v-model="user.email"
                    autocomplete="off"
                  ></ht-input>
                </td>
              </tr>
              <tr>
                <td>性别:</td>
                <td>
                  <ht-select
                    v-model="user.sex"
                    :options="[
                      {key: '男', value: '男'},
                      {key: '女', value: '女'}
                    ]"
                  />
                </td>
                <td>地址:</td>
                <td>
                  <ht-input
                    style="width: 100%"
                    v-model="user.address"
                    autocomplete="off"
                    :validate="{
                      regex: {
                        exp: '^[\\s\\S]{0,100}$',
                        message: '内容超出输入限制'
                      }
                    }"
                  ></ht-input>
                </td>
              </tr>
              <tr>
                <td>状态:</td>
                <td>
                  <ht-select
                    v-model="user.status"
                    :validate="{required: true}"
                    :options="[
                      {key: 0, value: '禁用'},
                      {key: 1, value: '正常'},
                      {key: -2, value: '离职'}
                    ]"
                  />
                </td>
                <td v-if="account == ''">手机:</td>
                <td v-if="account == ''">
                  <ht-input
                    style="width: 100%"
                    v-model="user.mobile"
                    autocomplete="off"
                    validate="mobile"
                  ></ht-input>
                </td>
                <td v-if="account != ''" colspan="2"></td>
              </tr>
              <!-- <tr>
                <td colspan="5" align="center">

                </td>
              </tr> -->
            </tbody>
          </table>
        </form>
        <div class="button">
          <ht-submit-button
            :url="saveUserUrl"
            :model="user"
            :is-submit="isSubmit"
            scope-name="editUserForm"
            @before-save-data="beforeSaveData"
            @after-save-data="afterSaveData"
            @after-response-value = "afterResponseValue"
            :restoreUrl="restoreUrl"
            aliasProp="account"
            >{{ $t('eip.common.save') }}</ht-submit-button
          >
          <el-button @click="closeUserManager">{{
            $t('eip.common.cancel')
          }}</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="所属组织岗位"
        name="orgPost"
        :disabled="account == ''"
      >
        <ht-table
          @load="orgPostData"
          v-if="userOrgPostLoaded"
          :data="orgPostList"
          :pageResult="orgPostPageResult"
          :selection="true"
          :show-export="false"
          :show-custom-column="false"
          :default-querys="[{property: 'account', value: account}]"
          ref="orgPostTables"
        >
          <template v-slot:toolbar>
            <el-button
              size="small"
              @click="showEipOrgDialog"
              icon="el-icon-plus"
              >添加组织</el-button
            >
            <el-button
              size="small"
              @click="showEipPostDialog"
              icon="el-icon-plus"
              >添加岗位</el-button
            >
            <ht-delete-button
              :url="delOrgUser"
              :htTable="$refs.orgPostTables"
              @after-delete="afterDelOrgUser"
              pk="orgUserId"
              >删除</ht-delete-button
            >
          </template>
          <template>
            <ht-table-column
              type="index"
              width="50"
              align="center"
              label="序号"
            />
            <ht-table-column prop="demName" label="组织维度" width="160" />
            <ht-table-column prop="orgName" label="组织名称" />
            <ht-table-column prop="posName" label="岗位名称" />
            <ht-table-column prop="isMaster" label="主组织/主岗位" width="140">
              <template v-slot="{row}">
                <el-tag type="danger" v-if="row.isMaster == '0'">否</el-tag>
                <el-tag v-if="row.isMaster == '1'">是</el-tag>
              </template>
            </ht-table-column>
            <ht-table-column label="操作" width="300">
              <template v-slot="{row}">
                <el-button
                  type="primary"
                  icon="el-icon-edit-outline"
                  v-if="row.isMaster == 0 && row.posName"
                  @click="setMaster(row)"
                  >设置主岗位</el-button
                >
                <el-button
                  type="primary"
                  icon="el-icon-edit-outline"
                  v-if="row.isMaster == 1 && row.posName"
                  @click="setMaster(row)"
                  >取消主岗位</el-button
                >
                <el-button
                  type="primary"
                  icon="el-icon-edit-outline"
                  v-if="row.isMaster == 0 && !row.posName"
                  @click="setMaster(row)"
                  >设置主组织</el-button
                >
                <el-button
                  type="primary"
                  icon="el-icon-edit-outline"
                  v-if="row.isMaster == 1 && !row.posName"
                  @click="setMaster(row)"
                  >取消主组织</el-button
                >
              </template>
            </ht-table-column>
          </template>
        </ht-table>
      </el-tab-pane>
      <el-tab-pane label="所属角色" name="role" :disabled="account == ''">
        <ht-table
          @load="userRoleLoad"
          :data="userRoleList"
          v-if="userRoleLoaded"
          :pageResult="rolePageResult"
          :selectable="false"
          :show-export="false"
          :show-custom-column="false"
          :default-querys="[{property: 'u.account_', value: account}]"
          ref="userRoleTable"
        >
          <template v-slot:toolbar>
            <el-button-group>
              <el-button
                size="small"
                @click="showEipRoleDialog"
                icon="el-icon-plus"
                >添加角色</el-button
              >
            </el-button-group>
          </template>
          <template>
            <ht-table-column
              type="index"
              width="50"
              align="center"
              label="序号"
            />
            <ht-table-column prop="roleName" label="名称" />
            <ht-table-column prop="alias" label="编码" width="300" />
            <ht-table-column width="154" label="操作">
              <template v-slot="{row}">
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  @click="deleteUserRole(row.alias)"
                  >删除</el-button
                >
              </template>
            </ht-table-column>
          </template>
        </ht-table>
      </el-tab-pane>
      <el-tab-pane label="用户参数" name="param" :disabled="account == ''">
        <el-form v-model="userParam" class="user-param-form form">
          <template v-for="param in userParams">
            <ht-form-item
              :label="param.name"
              prop="name"
              label-width="100px"
              :key="param.name"
            >
              <el-date-picker
                v-model="userParam[param.code]"
                type="datetime"
                placeholder="选择日期时间"
                v-if="param.ctlType === 'date'"
              ></el-date-picker>
              <ht-input
                v-model="userParam[param.code]"
                v-if="param.ctlType === 'input'"
                validate="max:30"
                :maxlength="30"
              />
              <ht-input
                type="number"
                v-model="userParam[param.code]"
                v-if="param.ctlType === 'number'"
              />
              <ht-select
                v-model="userParam[param.code]"
                v-if="param.ctlType === 'select'"
                :options="JSON.parse(param.json)"
              />
              <ht-radio
                v-model="userParam[param.code]"
                v-if="param.ctlType === 'radio'"
                :options="JSON.parse(param.json)"
              />
              <ht-checkbox
                v-model="userParam[param.code]"
                v-if="param.ctlType === 'checkbox'"
                :options="JSON.parse(param.json)"
              />
            </ht-form-item>
          </template>
        </el-form>
        <div class="button" v-if="userParams.length">
          <el-button type="primary" @click="userParamSubmit">保存</el-button>
        </div>
      </el-tab-pane>
      <el-tab-pane
        label="签章管理"
        name="electronicSeal"
        :disabled="account == ''"
        lazy
      >
        <el-form data-vv-scope="electronicSealForm " class="form">
          <ht-form-item label="签章">
            <el-image
              class="el-image"
              v-bind:src="electronicSealPic"
              v-if="sealPicShow"
            />
            <el-upload
              action="string"
              accept=".png,.PNG"
              :http-request="updateElectronicSeal"
              :before-upload="beforeAvatarUpload2"
              :show-file-list="false"
            >
              <el-tooltip
                class="item"
                effect="light"
                content="图片格式:png 图片尺寸:250*70px"
                placement="right"
              >
                <el-button size="small" icon="el-icon-plus" round
                  >上传</el-button
                >
              </el-tooltip>
            </el-upload>
          </ht-form-item>
          <ht-form-item label="请输入密码" class="electronicSeal-Password">
            <ht-input
              show-password
              v-model="electronicSeal.password"
              type="password"
              placeholder="请输入密码"
              :validate="{
                required: true,
                max: 20,
                regex: {
                  exp: '^[a-zA-Z][a-zA-Z0-9_]*$',
                  message: '只能输入字母、数字、下划线,且以字母开头'
                }
              }"
            />
          </ht-form-item>
          <ht-form-item label="确认密码">
            <ht-input
              show-password
              v-model="confirmPwd"
              :validate="'confirmed:' + electronicSeal.password"
              type="password"
              placeholder="确认"
            />
          </ht-form-item>
        </el-form>
        <div class="dialog-footer electronic-style button">
          <ht-submit-button
            :url="ElectronicSealSubmitUrl"
            :model="electronicSealChange"
            :isSubmit="electronicSealFormSubmit"
            requestMethod="POST"
            scopeName="editForm"
            @before-save-data="electronicSaveData"
            @after-save-data="afterSaveData"
            >{{ $t('eip.common.save') }}</ht-submit-button
          >
        </div>
      </el-tab-pane>
    </el-tabs>
    <!-- 组织选择对话框  -->
    <ht-org-post-dialog
      ref="eipOrgDialog"
      @on-confirm="addUserOrg"
      append-to-body
    />
    <!-- 岗位选择对话框  -->
    <ht-post-dialog
      ref="eipPostDialog"
      @on-confirm="addUserPost"
      append-to-body
    />
    <!-- 角色选择对话框  -->
    <ht-role-dialog
      ref="eipRoleDialog"
      @on-confirm="addUserRole"
      append-to-body
    />
  </div>
</template>

<script>
import utils from '@/hotent-ui-util.js'
import uc from '@/api/uc.js'
import org from '@/api/org.js'
import sys from '@/api/portal.js'
import eipOrgDialog from '@/components/dialog/EipOrgDialog.vue'
import eipPostDialog from '@/components/dialog/EipPostDialog.vue'
const eipRoleDialog = () => import('@/components/dialog/EipRoleDialog.vue')

export default {
  name: 'UserManager',
  components: {
    eipOrgDialog,
    eipPostDialog,
    eipRoleDialog
  },
  computed: {
    saveUserUrl: function() {
      let preUrl = window.context.uc + '/api/user/v1/user'
      if (this.account) {
        preUrl += '/updateUser'
      } else {
        preUrl += '/addUser'
      }
      return preUrl
    },
    restoreUrl: function() {
      return window.context.uc + '/api/user/v1/restoreByAlias/'
    },
    delOrgUser: function() {
      return window.context.uc + '/api/org/v1/orgUser/delOrgUser'
    },
    ElectronicSealSubmitUrl: function() {
      return window.context.uc + '/uc/electronicSeal/v1/save'
    },
    electronicSealPicUrl: function() {
      return (
        window.context.uc +
        '/system/file/v1/preview?fileId=' +
        this.electronicSeal.fileId
      )
    }
  },
  data() {
    return {
      electronicSealChange: {},
      user: {
        id: '',
        account: '',
        address: '',
        email: '',
        fullname: '',
        mobile: '',
        password: '',
        photo: '',
        sex: '',
        status: 1
      },
      photoUrl: require('@/assets/img/defaultPhoto.jpg'),
      orgPostPageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      rolePageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      orgPostList: [], //组织岗位
      userRoleList: [], //用户角色,
      userParam: {}, //当前用户的用户参数值
      userParams: [], //系统的所有用户参数
      account: '',
      isSubmit: false,
      currentTabName: 'basic',
      userParamLoaded: false,
      userOrgPostLoaded: false,
      userRoleLoaded: false,
      pwdValidate: {
        required: true,
        min: 6,
        max: 30
      },
      electronicSeal: {
        fileId: '',
        password: '',
        picUrl: ''
      }, // 签章
      confirmPwd: '',
      electronicSealPic: '',
      sealPicShow: false,
      electronicSealFormSubmit: false
    }
  },
  props: ['userAccount', 'orgCode'],
  mounted() {
    this.account = this.userAccount
    // 用户参数是否已加载
    this.userParamLoaded = false
    // 是否显示用户所属组织岗位
    this.userOrgPostLoaded = false
    // 是否显示用户拥有的角色
    this.userRoleLoaded = false
    if (this.account) {
      uc.getUser(this.account).then(resp => {
        this.user = resp.user
        if (this.user.photo) {
          this.$store
            .dispatch('menu/downloadImg', this.user.photo)
            .then(res => {
              if (res != '') {
                this.photoUrl = res
              }
            })
        }
      })
    }
    //默认密码策略
    uc.getDefaultPwdStrategy().then(data => {
      if (data) {
        let form = data
        //默认初始化密码
        if (form.initPwd) {
          this.user.password = form.initPwd
        }
        if (form.enable == 1) {
          let pwdRule = form.pwdRule
          let pwdLength = form.pwdLength
          if (pwdRule == 1) {
            this.pwdValidate = {
              required: true,
              min: pwdLength
            }
          } else {
            let regex = {}
            if (pwdRule == 2) {
              regex = {
                exp: '^(?=.*[0-9])(?=.*[a-zA-Z]).{' + pwdLength + ',30}$',
                message: '密码必须包含字母、数字,至少' + pwdLength + '位'
              }
            } else if (pwdRule == 3) {
              regex = {
                exp:
                  '^(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{' +
                  pwdLength +
                  ',30}$',
                message:
                  '密码必须包含数字、字母、特殊字符,至少' + pwdLength + '位'
              }
            } else if (pwdRule == 4) {
              regex = {
                exp:
                  '^(?=.*[0-9])(?=.*[A-Z])(?=.*[a-z])(?=.*[^a-zA-Z0-9]).{' +
                  pwdLength +
                  ',30}$',
                message:
                  '密码必须包含数字、大小写字母、特殊字符,至少' +
                  pwdLength +
                  '位'
              }
            }
            this.pwdValidate = {
              required: true,
              regex: regex
            }
          }
        }
      }
    })
  },
  // watch: {
  //   electronicSeal: {
  //     handler(val) {
  //
  //       this.electronicSealChange = _.cloneDeep(val)
  //       delete this.electronicSealChange.picUrl
  //     },
  //     immediate: true,
  //     deep: true
  //   }
  // },
  methods: {
    phonoError(e) {
      // this.user.photo = "/img/defaultPhoto.jpg";
    },
    addOrg() {
      if (!this.orgCode || !this.user.account) {
        return false
      }
      //是否是编辑用户,是编辑用户就不要添加到组织下
      if (this.user.id) {
        return false
      }
      let param = [
        {
          code: this.orgCode
        }
      ]
      this.account = this.user.account
      this.addUserOrg(param)
    },
    async beforeSaveData() {
      if (this.photo) {
        this.user.photo = this.photo
      }
      this.isSubmit = true
    },
    afterSaveData() {
      this.addOrg()

      this.$confirm('操作成功,是否退出?', '提示', {
        confirmButtonText: '退出',
        cancelButtonText: '不退出',
        closeOnClickModal: false,
        type: 'warning'
      })
        .then(() => {
          //点击取消按钮
          this.$emit('handleCloseUserManager')
        })
        .catch(() => {
          this.account = this.user.account
          this.electronicSealFormSubmit = false
        })
    },
    afterResponseValue(response){
      if(response.userId){
        this.user.id = response.userId
      }
    },
    //头像上传
    updateUserImage(param) {
      const formData = new FormData()
      formData.append('files', param.file)
      uc.fileUpload(formData)
        .then(response => {
          this.photo = response.fileId
          this.user.photo = response.fileId
          this.$store
            .dispatch('menu/downloadImg', response.fileId)
            .then(res => {
              if (res != '') {
                this.photoUrl = res
              }
            })
          param.onSuccess() // 上传成功的图片会显示绿色的对勾
        })
        .catch(response => {
          param.onError()
        })
    },
    updateElectronicSeal(param) {
      const formData = new FormData()
      formData.append('files', param.file)
      uc.fileUpload(formData).then(response => {
        this.electronicSeal.fileId = response.fileId
        this.$store.dispatch('menu/downloadImg', response.fileId).then(res => {
          if (res != '') {
            this.electronicSealPic = res
            this.sealPicShow = true
          }
        })
        this.$message.success('上传成功')
      })
    },
    electronicSaveData() {
      let patt = new RegExp('^[a-zA-Z][a-zA-Z0-9_]{0,20}$')
      this.electronicSealFormSubmit = true
      if (!this.electronicSeal.fileId) {
        this.$message.error('请上传签章!')
        this.electronicSealFormSubmit = false
        return false
      }
      if (!this.electronicSeal.password) {
        this.$message.error('请输入密码!')
        this.electronicSealFormSubmit = false
        return false
      } else if (this.electronicSeal.password != this.confirmPwd) {
        this.$message.error('两次输入的密码不一致,请重新输入')
        this.electronicSealFormSubmit = false
        return false
      } else if (!patt.test(this.electronicSeal.password)) {
        this.$message.error(
          '密码只能输入字母、数字、下划线,且以字母开头,长度不能超过20'
        )
        this.electronicSealFormSubmit = false
        return false
      }
      this.electronicSeal.userId = this.user.id
      this.electronicSealChange = _.cloneDeep(this.electronicSeal)
      delete this.electronicSealChange.picUrl
    },
    orgPostData(param, cb) {
      uc.getUserOrgPage(param)
        .then(response => {
          this.orgPostList = response.rows
          this.orgPostPageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        })
        .finally(() => cb())
    },
    setMaster(row) {
      let flag = false
      let orgName = ''
      this.orgPostList.forEach(item => {
        if (item.isMaster === 1 && row.orgId !== item.orgId) {
          orgName = item.orgName
          flag = true
        }
      })
      if (flag) {
        this.$confirm(
          '该用户已设置主组织' + orgName + ',是否重新设置?',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'success'
          }
        )
          .then(() => {
            uc.setMasterById(row.orgUserId).then(resp => {
              if (resp.state) {
                this.$message.success(resp.message || '设置成功!')
                this.$refs.orgPostTables.load()
              } else {
                this.$message.error(resp.message || '设置失败!')
              }
            })
          })
          .catch(() => {})
      } else {
        uc.setMasterById(row.orgUserId).then(resp => {
          if (resp.state) {
            this.$message.success(resp.message || '设置成功!')
            this.$refs.orgPostTables.load()
          } else {
            this.$message.error(resp.message || '设置失败!')
          }
        })
      }
    },
    showEipOrgDialog() {
      this.$refs.eipOrgDialog.showDialog()
    },
    showEipPostDialog() {
      this.$refs.eipPostDialog.showDialog()
    },
    checkBeyondOrg(orgCodes, callback) {
      org.getOrgLimitByCodes(orgCodes.join(',')).then(resp => {
        let normalOrgCodes = []
        let beyondOrgs = []
        if (resp && resp.rows) {
          resp.rows.forEach(org => {
            if (org.exceedLimitNum === 1 && org.limitNum != 0) {
              if (org.limitNum > org.nowNum) {
                normalOrgCodes.push(org.code)
              } else {
                beyondOrgs.push(org)
              }
            } else {
              normalOrgCodes.push(org.code)
            }
          })
        }
        callback({normal: normalOrgCodes, beyond: beyondOrgs})
      })
    },
    addUserOrg(param) {
      param = param.map(param => {
        return param.code
      })
      let _this = this
      this.checkBeyondOrg(param, function(resp) {
        if (resp.beyond.length > 0) {
          let beyondOrgNames = resp.beyond.map(org => {
            return org.name
          })
          _this.$message.error(
            '添加失败:组织【' + beyondOrgNames.join(',') + '】超出限编'
          )
          return
        }
        var params = {
          account: _this.account,
          orgCode: resp.normal
        }
        setTimeout(() => {
          uc.saveUserOrgs(params).then(resp => {
            if (resp.state) {
              _this.$message.success(resp.message || '添加成功!')
              _this.$refs.orgPostTables.load()
            } else {
              _this.$message.error(resp.message || '操作失败!')
            }
          })
        }, 300)
      })
    },
    addUserPost(param) {
      param = param.map(param => {
        return param.code
      })
      var params = {
        account: this.account,
        Code: param
      }
      uc.saveUserPosts(params).then(resp => {
        if (resp.state) {
          this.$message.success(resp.message || '添加成功!')
          this.$refs.orgPostTables.load()
        } else {
          this.$message.error(resp.message || '操作失败!')
        }
      })
    },
    getOrg(_param) {
      org.getOrg(_param.orgCode).then(resp => {
        if (resp.exceedLimitNum === 1 && resp.limitNum != 0) {
          if (resp.limitNum > resp.nowNum + 1) {
            return _param.code
          } else {
            isBeyond = true
          }
        } else {
          return _param.code
        }
      })
    },
    showEipRoleDialog() {
      this.$refs.eipRoleDialog.showDialog()
    },
    deleteOrgPost(id) {
      uc.delOrgUser(id).then(() => {
        this.$refs.orgPostTables.load()
      })
    },
    userRoleLoad(param, cb) {
      uc.userRolePage(param)
        .then(response => {
          if (response) {
            this.userRoleList = response.rows
            this.rolePageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total
            }
          }
        })
        .finally(() => cb())
    },
    deleteUserRole(code) {
      var params = {
        account: this.account,
        codes: code
      }
      uc.delUserRole(params).then(resp => {
        if (resp.state) {
          this.$message.success(resp.message)
          this.$refs.userRoleTable.load()
        } else {
          this.$message.error(resp.message)
        }
      })
    },
    addUserRole(param) {
      param = param.map(param => {
        return param.code
      })
      var params = {
        account: this.account,
        codes: param
      }
      uc.saveUserRoles(params).then(resp => {
        if (resp.state) {
          this.$message.success(resp.message)
          this.$refs.userRoleTable.load()
        } else {
          this.$message.error(resp.message)
        }
      })
    },
    userParamSubmit() {
      var param = {
        account: this.user.account
      }
      var data = []
      let _this = this
      for (var _param in this.userParam) {
        for (let i = 0; i < _this.userParams.length; i++) {
          if (
            _this.userParams[i].ctlType === 'input' &&
            _this.userParam[_param].length > 30
          ) {
            this.$message({type: 'warning', message: '内容超出输入限制'})
            return false
          }
        }
        data.push({alias: _param, value: this.userParam[_param]})
      }
      uc.saveUserParams(data, param).then(resp => {
        this.$message({
          message: resp.message,
          type: 'success',
          showClose: true
        })
      })
    },
    closeUserManager() {
      // 调用父级方法关闭面板
      this.$emit('closeUserManeger')
    },
    // 点击某个tab页签时再加载该页签的数据
    tabClick() {
      switch (this.currentTabName) {
        case 'orgPost':
          this.userOrgPostLoaded = true
          break
        case 'role':
          this.userRoleLoaded = true
          break
        case 'param':
          // 获取用户参数
          if (!this.userParamLoaded && this.account) {
            uc.getUserParams()
              .then(resp => {
                this.userParamLoaded = true
                this.userParams = resp
                return resp
              })
              .then(params => {
                if (
                  !params ||
                  params.constructor != Array ||
                  params.length < 1
                ) {
                  return
                }
                uc.getUserParamsValue(this.account).then(response => {
                  if (response && response.constructor == Array) {
                    response.forEach(r => {
                      this.$set(this.userParam, r['alias'], r['value'])
                    })
                  }
                })
              })
          }
          break
        case 'electronicSeal':
          uc.getSealByUserId(this.user.id).then(resp => {
            if (resp) {
              this.electronicSeal = resp
              this.$store
                .dispatch('menu/downloadImg', this.electronicSeal.fileId)
                .then(res => {
                  if (res != '') {
                    this.electronicSealPic = res
                    this.sealPicShow = true
                  }
                })
            }
          })
          break
      }
    },
    afterDelOrgUser() {
      this.$refs.orgPostTables.load()
    },
    //头像上传
    beforeAvatarUpload(file) {
      var FileExt = file.name.replace(/.+\./, '')
      let arr = ['jpg', 'jepg', 'png', 'gif', 'ico']
      if (arr.indexOf(FileExt.toLowerCase()) === -1) {
        this.$message({
          type: 'warning',
          message: '请上传后缀名为jpg、png、gif、ico、jepg类型的图片'
        })
        return false
      }
    },
    //签章上传
    beforeAvatarUpload2(file) {
      var FileExt = file.name.replace(/.+\./, '')
      if (['png'].indexOf(FileExt.toLowerCase()) === -1) {
        this.$message({
          type: 'warning',
          message: '请上传后缀名为png类型的图片'
        })
        return false
      }
    },
    removeElectronicSealPic() {
      let me_ = this
      if (!this.electronicSeal.id) {
        return
      }
      this.$confirm('是否确认删除签章?', '提示', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          //点击取消按钮
          request
            .remove(
              '${uc}/uc/electronicSeal/v1/remove/?ids=' + this.electronicSeal.id
            )
            .then(rep => {
              if (rep.data.state) {
                me_.electronicSealPic = ''
                me_.electronicSeal.fileId = ''
                me_.electronicSeal.id
                me_.sealPicShow = false
                Message.success('删除成功')
              }
            })
        })
        .catch(() => {})
    }
  }
}
</script>
<style scoped lang="scss">
.user-param-form {
  min-height: 200px;
  max-height: 500px;
  overflow-y: auto;
}

.electronic-style {
  margin-left: 100px;
}

::v-deep .el-form-item__content .el-image {
  .el-image__inner {
    width: 40%;
  }
}

::v-deep.el-avatar {
  display: flex;
  align-items: center;
  justify-content: center;

  img {
    height: 100%;
    width: 100%;
  }
}

::v-deep {
  .el-tabs,
  .el-tab-pane {
    height: 100%;
  }

  .el-tabs__content {
    height: calc(100% - 56px);
  }
}
.form {
  height: calc(100% - 40px);
  overflow-y: auto;
  overflow-x: hidden;
}
.button {
  position: absolute;
  bottom: 0;
  text-align: center;

  left: 0;
  margin: auto;
  right: 0;
}

.electronicSeal-Password {
  margin-bottom: 25px;
}
</style>