organization-manage.vue 24.7 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
<!-- 机构管理 -->
<template>
  <div
    class="organization-manage org log-list customer-list-box dashboard-container"
  >
    <div class="test">
      <!-- 左侧树形结构树 -->
      <div class="log-list-left">
        <el-scrollbar
          style="width: 100%;margin-bottom:50px"
        >
          <el-card
            class="box-card"
            shadow="never"
          >
            <div class="app-container">
              <el-tree
                ref="orgTree"
                style="font-size: 12px display: none;"
                :props="defaultProps"
                :check-strictly="true"
                :data="orgTree"
                :indent="22"
                :filter-node-method="filterNode"
                highlight-current
                node-key="id"
                :expand-on-click-node="false"
                class="filter-tree customer-tree-box"
                :default-expanded-keys="treeExpandData"
                @node-click="nodeClick"
              />
            </div>
          </el-card>
        </el-scrollbar>
      </div>
      <!-- 右侧结构树对应的内容 -->
      <div
        class="log-list-right"
      >
        <el-card
          class="box-card"
          shadow="always"
        >
          <div
            slot="header"
            class="clearfix"
          >
            <span>机构信息</span>
          </div>
          <div>
            <el-form
              ref="form"
              :model="org"
              label-position="right"
              label-width="120px"
              style="width: 90%; text-align: center"
              class="form-bottom"
            >
              <el-row>
                <el-col :span="8">
                  <el-form-item label="机构编号">
                    <el-input
                      v-model="org.id"
                      disabled
                    /> </el-form-item></el-col>
                <el-col :span="8">
                  <el-form-item
                    label="机构名称"
                    prop="parentId"
                    disabled
                  >
                    <el-input
                      v-model="org.name"
                      disabled
                    /> </el-form-item></el-col>
                <el-col :span="8">
                  <!-- 组织类型 -->
                  <el-form-item
                    label="机构类型"
                    prop="orgType"
                    disabled
                  >
                    <el-select
                      v-model="org.type"
                      disabled
                      clearable
                      placeholder="请选择"
                      style="width: 100%"
                    >
                      <el-option
                        v-for="item in orgTypeOptions"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
                      />
                    </el-select> </el-form-item></el-col>
              </el-row>
              <el-row>
                <el-col :span="24">
                  <!-- 地址 -->
                  <el-form-item
                    label="机构地址"
                    prop="describe"
                  >
                    <el-row
                      :gutter="24"
                      style="margin: 0"
                    >
                      <el-col
                        :span="8"
                        style="padding: 0"
                      >
                        <el-select
                          :value="org.province !== null ? org.province.id : ''"
                          placeholder="请选择省"
                          value-key="id"
                          clearable
                          :disabled="!isCanSubmit"
                          @change="getCity($event, true)"
                        >
                          <el-option
                            v-for="item in provinceList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          />
                        </el-select>
                      </el-col>
                      <el-col
                        :span="8"
                        style="padding: 0 4px"
                      >
                        <el-select
                          :value="org.city !== null ? org.city.id : ''"
                          value-key="id"
                          clearable
                          placeholder="请选择市"
                          :disabled="!isCanSubmit ||!org.province.id"
                          @change="getCounty($event, true)"
                        >
                          <el-option
                            v-for="item in cityList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          />
                        </el-select>
                      </el-col>
                      <el-col
                        :span="8"
                        style="padding: 0"
                      >
                        <el-select
                          :value="countyId"
                          value-key="id"
                          clearable
                          placeholder="请选择县/区"
                          :disabled="!isCanSubmit||!org.city.id"
                          @change="getCurrent"
                        >
                          <el-option
                            v-for="item in countryList"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id"
                          />
                        </el-select>
                      </el-col>
                    </el-row> </el-form-item></el-col>
                <el-col :span="8">
                  <!-- 机构负责人 -->
                  <el-form-item
                    label="详细地址"
                    prop="address"
                  >
                    <el-input
                      v-model="org.address"
                      maxlength="20"
                      :disabled="!isCanSubmit"
                    /> </el-form-item></el-col>
                <el-col :span="8">
                  <!-- 经度 -->
                  <el-form-item
                    label="经度"
                    prop="longitude"
                  >
                    <el-input
                      v-model="org.longitude"
                      disabled
                      maxlength="20"
                    >
                      <span
                        slot="suffix"
                        style="
                          color: #20232a;
                          font-weight: 400;
                          font-size: 14px;
                          font-family: PingFangSC, PingFangSC-Regular;
                          margin-right: 14px;
                          line-height: 40px;
                        "
                      >E</span></el-input>
                  </el-form-item></el-col>
                <el-col :span="8">
                  <!-- 纬度 -->
                  <el-form-item
                    label="纬度"
                    prop="latitude"
                  >
                    <el-input
                      v-model="org.latitude"
                      disabled
                      maxlength="20"
                    >
                      <span
                        slot="suffix"
                        style="
                          color: #20232a;
                          font-weight: 400;
                          font-size: 14px;
                          font-family: PingFangSC, PingFangSC-Regular;
                          margin-right: 14px;
                          line-height: 40px;
                        "
                      >N</span></el-input>
                  </el-form-item></el-col>
                <el-col :span="8">
                  <!-- 机构负责人 -->
                  <el-form-item
                    label="机构负责人"
                    prop="contractNumber"
                  >
                    <el-input
                      v-model="org.managerName"
                      maxlength="20"
                      :disabled="!isCanSubmit"
                    /> </el-form-item></el-col>
                <el-col :span="8">
                  <el-form-item
                    label="机构电话"
                    prop="abbreviation"
                  >
                    <el-input
                      v-model="org.phone"
                      maxlength="200"
                      :disabled="!isCanSubmit"
                    /> </el-form-item></el-col>
              </el-row>
              <el-button
                v-if="org.id"
                type="warning"
                style="width: 89px; height: 36px; padding: 10px 20px"
                @click="submit"
              >{{ isCanSubmit ? '保存' : '编辑' }}</el-button>
            </el-form>
          </div>
        </el-card>
        <el-card
          class="box-card org-index"
          style="margin-top: 20px; box-shadow: none"
        >
          <div
            slot="header"
            class="clearfix"
          >
            <span>员工信息</span>
          </div>
          <el-table
            v-if="dataList && dataList.length > 0"
            ref="multipleTable"
            :data="dataList"
            fit
            style="width: 100%"
            stripe
            :header-cell-style="{ background: 'rgba(250,252,255,1)' }"
          >
            <el-table-column
              type="index"
              label="序号"
              width="60"
            />
            <el-table-column
              align="left"
              label="员工编号"
              min-width="150"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.userId }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="员工姓名"
              min-width="100"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.name }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="手机号"
              min-width="100"
            >
              <template slot-scope="scope">
                <span>{{ scope.row.mobile }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="所属机构"
              min-width="140"
              show-overflow-tooltip
            >
              <template slot-scope="scope">
                <span>{{
                  scope.row.agency === null ? '' : scope.row.agency.name
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="系统账户"
              min-width="100"
              prop="account"
            >
            </el-table-column>
            <el-table-column
              align="left"
              label="系统角色"
              min-width="100"
              prop="stationName"
            >
              <template slot-scope="scope">
                <span>{{
                  scope.row.roleNames && scope.row.roleNames.join(',')
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              align="left"
              label="账号状态"
            >
              <template slot-scope="scope">
                <div
                  v-if="scope.row.status !== null"
                  class="tableColumn-status"
                  :class="{ 'stop-use': String(scope.row.status) === '0' }"
                >
                  {{ String(scope.row.status) === '1' ? '正常' : '禁用' }}
                </div>
                <div v-else></div>
              </template>
            </el-table-column>
          </el-table>
          <empty
            v-else
            src="../../assets/empty.png"
            desc="这里空空如也~"
          ></empty>
          <!-- end -->
          <!-- 分页 -->
          <div
            v-show="total > 5"
            class="pagination"
          >
            <div class="pages">
              <el-pagination
                :current-page="Number(requestParameters.page)"
                :total="Number(total)"
                :page-size="Number(requestParameters.pageSize)"
                :page-sizes="[5, 10, 20, 40]"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
              />
            </div>
          </div>
        </el-card>
      </div>
    </div>
  </div>
</template>
<script>
import options from '@/api/OrgType.json' // 机构类型
import { areaList } from '@/api/common' // 地区
import { agencyList, detail, update, getuserByAgency } from '@/api/institutions'
export default {
  name: 'OrgManager',
  data() {
    return {
      total: 0,
      requestParameters: {
        page: 1, // 当前页
        pageSize: 5, // 每页条数
        agencyId: '' // 机构id
      },
      dataList: [],
      defaultProps: {
        children: 'children', // 子节点
        label: 'name' // 显示的名称
      },
      treeExpandData: [], // 树形展开的数据
      treeExpandData2: [], // 树形默认展开的数据
      provincialCenterId: '', // 省级中心id
      provincialCenterId2: [], // 省级树形默认展开中心id
      countyId: '', // 城市id
      name: '', // 机构名称
      orgTypeOptions: '', // 机构类型
      orgTree: [], // 树形数据
      parentName: '无上级',
      provinceList: [], // 省列表
      cityList: [], // 市列表
      countryList: [], // 县区列表
      isCanSubmit: false, // 是否处于编辑状态
      org: this.initOrg() // 机构信息数据
    }
  },
  mounted() {
    this.orgTypeOptions = options
    this.initOrgTree()
  },
  methods: {
    // 初始化
    initOrg() {
      this.countyId = ''
      return {
        id: '',
        name: '',
        type: '',
        address: '',
        managerName: '',
        provinceId: '',
        cityId: '',
        countyId: '',
        phone: '',
        parentId: 0,
        latitude: '',
        longitude: '',
        county: {
          id: ''
        },
        province: {
          id: ''
        },
        city: {
          id: ''
        }
      }
    },
    // 提交修改当前数据
    submit() {
      const data = this.org
      // 当前数据
      const params = {
        id: data.id,
        name: data.name,
        type: data.type,
        provinceId: data.province ? data.province.id : '',
        cityId: data.province ? data.city.id : '',
        countyId: data.county ? data.county.id : '',
        address: data.address,
        managerName: data.managerName,
        phone: data.phone
      }
      // 判断是否可以提交
      if (!this.isCanSubmit) {
        return (this.isCanSubmit = !this.isCanSubmit)
      }
      if (!data.address) {
        return this.$message.error('请填写详细地址')
      } else if (!data.province.id || !data.city.id || !this.countyId) {
        return this.$message.error('请选择机构地址')
      }
      update(params)
        .then((res) => {
          if (Number(res.code) === 200) {
            this.$message.success('机构信息保存成功')
            this.isCanSubmit = false
          } else {
            this.$message.error(res.msg || '机构信息保存失败')
          }
        })
        .catch((err) => {
          this.$message.error(err.msg || '机构信息保存失败')
        })
    },
    // 获取省信息
    getProvince(val) {
      areaList({ parentId: val }).then((response) => {
        this.provinceList = response.data
      })
    },
    // 获取市信息,获取到省的信息后才能进行,因此需要绑定在省上
    getCity(val, isClear) {
      areaList({ parentId: val }).then((response) => {
        this.cityList = response.data
        this.org.province.id = val
        if (isClear) {
          this.org.city.id = ''
          this.countyId = ''
        }
      })
    },
    // 获取县区信息,获取到市之后才能够继续进行,因此事件需要绑定在市上
    getCounty(val, isClear) {
      areaList({ parentId: val }).then((response) => {
        this.countryList = response.data
        this.org.city.id = val
        if (isClear) {
          this.countyId = ''
        }
      })
    },
    // 获取当前的数据id
    getCurrent(val) {
      this.org.county.id = val
      this.countyId = val
    },
    // 获取树形结构默认展开节点
    getExpandData(provincialCenterId) {
      // 将传入的数据转换为数组
      const provincialCenterIdArr = provincialCenterId.split(',')
      // 循环数组,将数组中的数据添加到treeExpandData中
      provincialCenterIdArr.forEach((item) => {
        this.treeExpandData.push(item)
      })
    },
    getExpandData2(provincialCenterId2) {
      // 将传入的数据添加到treeExpandData2中
      this.treeExpandData2 = [provincialCenterId2]
      const _this = this
      // 加入延时函数是因为需要等待页面数据加载完毕
      setTimeout(() => {
        _this.nodeClick(provincialCenterId2)
      }, 50)
    },
    // 初始化机构数
    initOrgTree() {
      agencyList({}).then((response) => {
        const res = response.data
        this.orgTree = JSON.parse(res)
        this.provincialCenterId = this.orgTree[0].children[0].id // 默认展开第一个节点下的第一个节点
        this.provincialCenterId2 = this.orgTree[0].children[0].children[0]
        this.$nextTick(function () {
          this.$refs['orgTree'].setCurrentKey(
            this.orgTree[0].children[0].children[0].id
          )
        })
        this.getExpandData2(this.provincialCenterId2)
        this.getExpandData(this.provincialCenterId)
      })
    },
    // 过滤器,过滤出空数据和不存在的数据
    filterNode(value, data) {
      if (!value) return true
      return data.name.indexOf(value) !== -1
    },
    // 树形点击事件
    nodeClick(data) {
      this.requestParameters.agencyId = data.id
      this.isCanSubmit = false
      this.showEdit = true
      this.showSave = false
      // 获取机构详情
      detail(data.id)
        .then((response) => {
          this.org = response.data
          this.countyId = ''
          if (response.data.province === null) this.org.province = {}
          if (response.data.city === null) this.org.city = {}
          if (response.data.county === null) this.org.county = {}
          this.getProvince()
          if (response.data.city !== null && response.data.city.id) {
            this.getCity(response.data.province.id, false)
            this.getCounty(response.data.city.id, false)
          }
          if (response.data.county !== null && response.data.county.id) {
            this.countyId = response.data.county.id
          }
        })
        .catch(() => {
          this.$message.error('获取机构详情失败')
          this.org = this.initOrg()
        })
      this.getList()
    },
    getList() {
      // 获取机构下的员工列表数据
      getuserByAgency(this.requestParameters).then((res) => {
        this.dataList = res.data.items
        this.total = res.data.counts
      })
    },
    // 每页显示信息条数
    handleSizeChange(val) {
      this.requestParameters.pageSize = val
      if (this.requestParameters.page === 1) {
        this.getList(this.requestParameters)
      }
    },
    // 进入某一页
    handleCurrentChange(val) {
      this.requestParameters.page = val
      this.getList()
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/ .customer-tree-box {
  .el-tree-node {
    margin: 2px 0 !important;
    .is-focusable {
      position: relative;
      &::before {
        content: '';
        display: inline-block;
        position: absolute;
        left: 6px;
        // width: 1px;
        border-left: #e5e7ec solid 1px;
        height: calc(100% + 3px);
        // 将此类名的最后一项样式设置为none
        &:last-child {
          border-left: none !important;
        }
      }
      margin: 2px 0 !important;
      .el-tree-node {
        .el-tree-node__children {
          margin: 2px 0 !important;
          .el-tree-node {
            .el-tree-node__content {
              .el-tree-node__expand-icon {
                display: none;
              }
              .el-tree-node__label {
                margin-left: 0px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                width: 131px;
              }
            }
          }
        }
      }
    }
  }
  .el-tree-node {
    .el-tree-node {
      .el-tree-node {
        position: relative;
        &::before {
          content: '';
          display: inline-block;
          position: absolute;
          left: 26px;
          // width: 1px;
          border-left: #e5e7ec solid 1px;
          height: calc(100% + 3px);
        }
        // 将此类名的最后一项样式设置为none
      }
    }
  }
}
</style>
<style lang="scss" scoped>
.organization-manage {
  // overflow-x: scroll;
  min-height: 870px;
  padding-top: 23px !important;
  .log-list-left {
    height: auto !important;
    border-radius: 4px;
    width: 214px;
    // 设置内边距
    padding-left: 9px;
    /deep/ .customer-tree-box {
      .el-tree-node {
        margin: 5px 0 !important;
        .el-tree-node__children {
          margin: 2px 0 !important;
          .el-tree-node {
            .el-tree-node__children {
              margin: 2px 0 !important;
              .el-tree-node {
                .el-tree-node__content {
                  .el-tree-node__expand-icon {
                    display: none;
                  }
                  .el-tree-node__label {
                    margin-left: 0px;
                    white-space: nowrap;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    width: 131px;
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  .log-list-right {
    /deep/ .el-card__header {
      color: #2a2929;
      font-weight: bold;
      font-size: 16px;
    }
  }
  .el-tree {
    padding-left: 10px;
    margin-top: 5px;
  }
  .app-container {
    background-color: white;
  }
  .pagination {
    text-align: center;
    margin-top: 26px;
    padding-bottom: 40px;
  }
  /deep/ .el-card__body {
    padding: 0;
    padding-top: 10px;
    .app-container {
      padding: 0;
    }
  }

  .el-form--label-right {
    padding: 20px 0;
    width: 100% !important;
    padding-right: 37px;
  }

  /deep/ .el-tree-node__content {
    margin-right: 20px;
  }
}

.addEdit {
  background-color: #e05635;
  color: #fff;
  border-radius: 5px;
  &:hover {
    background-color: #e05635;
    color: #fff;
    border-color: #dcdfe6;
  }
}
.org {
  .app-container {
    margin: 0 0 10px 0 !important;
  }
}
.el-card {
  border-radius: 8px;
  border: none;
  .el-card__header {
    background: #f8faff;
    border-bottom: 0px solid #e6ebf5;
  }
}

.log-list {
  width: 100%;
  padding: 20px;
  padding-top: 0;
  .test {
    width: 100%;
    display: -webkit-box;
    // display: flex;
    /deep/ .el-row {
      width: 100%;
    }
    .log-list-right {
      flex: 1;
      // 新添加的
      margin-left: 20px;

      .log-list-right-table {
        min-height: calc(75vh - 0px);
      }
      /deep/ .el-card__header {
        background-color: #fafafa;
        // border-radius: 8px 8px 0 0;
      }
      /deep/ .el-card.is-always-shadow {
        border-radius: 4px !important;
        box-shadow: none;
      }
      /deep/ .el-select {
        width: 100%;
      }
      // 新添加的
      /deep/ .custom-theme .el-input.is-disabled .el-input__inner {
        background-color: #fafafa !important;
        color: red;
      }
    }
    .log-list-left,
    .log-list-right {
      // height: 870px;

      background-color: #fff;
      border-radius: 4px;
      /deep/ .el-scrollbar {
        border-radius: 8px;
      }
    }
    .log-list-right{
      background-color: #f3f4f7;
    }
  }

  /deep/ .org-index {
    .el-card__body {
      // border-top: 1px solid #e5e7ec;
      // margin: 0px 60px;
      box-sizing: border-box;
      padding-top: 20px !important;
      padding: 0 28px;
      padding-bottom: 20px;
    }
  }
}
/deep/ .el-pager li.active {
  color: #e15536;
}
/deep/ .el-pagination__total {
  color: #20232a;
}
/deep/ .el-pagination button:hover {
  color: #e15536;
}
/deep/ .el-pagination__sizes .el-input .el-input__inner:hover {
  border-color: #e15536;
}
</style>