123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- <template>
- <div>
- <!--顶级按钮-->
- <div class="btn-group mr-1"
- v-if="jiBie == 0"
- >
- <button
- type="button"
- @click="selectAgency"
- class="btn btn-sm btn-outline-secondary"
- >
- {{ $store.state.user.agentFlag ? $store.state.user.nickName : "智慧易加"}}
- </button>
- <button
- type="button"
- class="
- btn btn-sm btn-outline-secondary
- dropdown-toggle dropdown-toggle-split
- "
- data-toggle="dropdown"
- aria-expanded="false"
- >
- <span class="sr-only"></span>
- </button>
- <div
- class="dropdown-menu"
- style="overflow-y: auto; max-height: 400px; max-width: 280px"
- >
- <form class="px-4 py-3">
- <input
- type="email"
- class="form-control"
- id="exampleDropdownFormEmail1"
- placeholder=""
- autocomplete="off"
- @input="filterMethod"
- v-model="filterText"
- />
- </form>
- <div class="dropdown-divider"></div>
- <a
- class="dropdown-item"
- href="#"
- v-for="ele in filteredGroups"
- :key="ele.deptId"
- @click="selectGroup(ele)"
- >{{ ele.deptName }}</a
- >
- </div>
- </div>
- <!--集团按钮-->
- <div class="btn-group mr-1"
- v-show="!!currentGroup"
- v-if="jiBie == 0 || jiBie == 1 "
- >
- <button
- @click="selectGroup(currentGroup)"
- type="button"
- class="btn btn-sm btn-outline-secondary"
- >
- {{ (currentGroup||{}).deptName }}
- </button>
- <button
- type="button"
- class="
- btn btn-sm btn-outline-secondary
- dropdown-toggle dropdown-toggle-split
- "
- data-toggle="dropdown"
- aria-expanded="false"
- >
- <span class="sr-only"></span>
- </button>
- <div
- class="dropdown-menu"
- style="overflow-y: auto; max-height: 400px; max-width: 280px"
- >
- <form class="px-4 py-3">
- <input
- type="email"
- class="form-control"
- id="exampleDropdownFormEmail1"
- placeholder=""
- autocomplete="off"
- @input="filterMethod"
- v-model="filterText"
- />
- </form>
- <div class="dropdown-divider"></div>
- <a
- class="dropdown-item"
- href="#"
- v-for="ele in filteredStations"
- :key="ele.deptId"
- @click="selectStation(ele)"
- >{{ ele.deptName }}</a
- >
- </div>
- </div>
- <!--站点-->
- <button type="button" class="btn btn-sm btn-success" disabled>
- {{ tip + (jiBie !=2 ? ":" : "") + currentShow.deptName }}
- </button>
- </div>
- </template>
- <script>
- import { userdepttree, getGroups, getStations } from "@/api/system/dept";
- import { mapMutations } from 'vuex'
- import Treeselect from "@riophae/vue-treeselect";
- import "@riophae/vue-treeselect/dist/vue-treeselect.css";
- export default {
- components: { Treeselect },
- data() {
- return {
- value: null,
- options: [],
- Infinity: 2,
- num: 0,
- tip:'',
- Agency: {
- deptId: 1,
- deptName: this.$store.state.user.deptName,
- },
- groups: [
- {
- deptId: 3,
- deptName: "李哈哈的集团",
- },
- {
- deptId: 2,
- deptName: "李哈哈的顶级集团",
- },
- ],
- stations: [
- {
- deptId: 4,
- deptName: "李哈哈的站点1",
- },
- {
- deptId: 5,
- deptName: "李哈哈的站点2",
- },
- ],
- currentStation: undefined,
- currentGroup: undefined,
- filterText:"",
- filterStationText:"",
- filterTimer:null
- };
- },
- computed: {
- currentShow() {
- if (!!this.currentStation) {
- return this.currentStation;
- }
- if (!!this.currentGroup) {
- return this.currentGroup;
- }
- return this.Agency;
- },
- filteredGroups(){
- return this.groups.filter((ele)=>{
- return ele.deptId.toString().includes(this.filterText) || ele.deptName.includes(this.filterText)
- })
- },
- filteredStations(){
- return this.stations.filter((ele)=>{
- return ele.deptId.toString().includes(this.filterText) || ele.deptName.includes(this.filterText)
- })
- }
- },
- watch: {
- // 监听deptId
- value: "currDeptChange",
- },
- created() {
- this.init();
- },
- methods: {
- ...mapMutations({
- setLevelId:"SET_LEVELID"
- }),
- init() {
- if(this.jiBie == 0){
- this.tip = this.$store.state.user.agentFlag ? '代理' : "全站"
- this.setLevelId(undefined)
- this.selectAgency();
- }else if(this.jiBie == 1){
- this.tip = "集团"
- this.currentGroup = {
- deptId: undefined,
- deptName: this.$store.state.user.deptName
- }
- this.setLevelId(this.currentGroup.deptId)
- this.selectGroup(this.currentGroup);
- }else if(this.jiBie == 2){
- this.setLevelId(undefined)
- }
- },
- selectAgency() {
- this.tip = this.$store.state.user.agentFlag ? '代理' : "全站";
- this.filterText = "";
- this.currentGroup = undefined;
- this.currentStation = undefined;
- this.setLevelId(undefined)
- getGroups().then((res)=>{
- if(res.code == 200){
- this.groups = res.data
- }else{
- throw new Error("");
- }
- }).catch(()=>{
- this.msgError("拉取首页菜单的集团列表失败,请刷新网页")
- })
- this.refreshTagView();
- },
- selectGroup(group) {
- this.tip = "集团";
- this.filterText = "";
- this.currentGroup = group;
- this.currentStation = undefined;
- const id = this.jiBie==1 ? undefined : this.currentGroup.deptId;
- this.setLevelId(id);
- getStations({
- deptId: group.deptId
- }).then((res)=>{
- if(res.code == 200){
- this.stations = res.data
- }else{
- throw new Error("");
- }
- }).catch(()=>{
- this.msgError("拉取首页菜单的站点列表失败,请刷新网页")
- })
- this.refreshTagView();
- },
- selectStation(station) {
- this.tip = "站点";
- this.filterText = "";
- this.currentStation = station;
- const id = this.jiBie==2 ? undefined : this.currentStation.deptId;
- this.setLevelId(id)
- this.refreshTagView();
- },
- /** 查询部门下拉树结构 */
- // getTreeselect() {
- // userdepttree().then((response) => {
- // this.options = response.data;
- // if (response.data != null && response.data.length > 0) {
- // this.value = response.data[0].id;
- // this.$store.selectDeptName = response.data[0].label;
- // this.$store.selectDeptId = response.data[0].id;
- // }
- // });
- // },
- currDeptChange(val) {
- if (val) {
- this.$store.selectDeptId = val;
- if (this.num > 0) {
- let path = this.$route.path;
- let visitedViews = this.$store.state.tagsView.visitedViews;
- let stagpath = null;
- const proArr = [];
- for (let i = 0; i < visitedViews.length; i++) {
- let view = visitedViews[i];
- proArr.push(
- this.$store.dispatch("tagsView/delCachedView", view).then(() => {
- const { fullPath } = view;
- if (path === fullPath) {
- stagpath = view;
- } else {
- this.$nextTick(() => {
- this.$router.replace({
- path: "/redirect" + fullPath,
- });
- });
- }
- })
- );
- }
- Promise.all(proArr).then(() => {
- if (stagpath != null) {
- this.$store
- .dispatch("tagsView/delCachedView", stagpath)
- .then(() => {
- const { fullPath } = stagpath;
- this.$nextTick(() => {
- this.$router.replace({
- path: "/redirect" + fullPath,
- });
- });
- });
- }
- });
- }
- this.num = this.num + 1;
- }
- },
- refreshTagView() {
- const proArr = []
- this.$store.state.tagsView.visitedViews.map((view) => {
- proArr.push(this.$store.dispatch("tagsView/delCachedView", view))
- // this.$store.dispatch("tagsView/delCachedView", view).then(() => {
- // const { fullPath } = view;
- // console.log(fullPath);
- // // this.$nextTick(() => {
- // // this.$router.replace({
- // // path: "/redirect" + fullPath,
- // // });
- // // });
- // });
- });
- Promise.all(proArr).then(()=>{
- this.$nextTick(() => {
- this.$router.replace({
- path: "/redirect" + this.$route.path,
- });
- });
- })
- },
- filterMethod(e){
- clearTimeout(this.filterTimer);
- this.filterTimer = setTimeout(()=>{
- this.filterText = e.target.value
- }, 800)
- },
- },
- };
- </script>
- <style lang="scss">
- .vue-treeselect__control {
- height: 20px;
- line-height: 26px;
- font-size: 12px;
- text-indent: 4px;
- }
- .vue-treeselect__menu-container {
- position: absolute;
- left: 0;
- width: 100%;
- overflow: visible;
- transition: 0s;
- }
- .vue-treeselect__menu {
- font-size: 12px;
- }
- </style>
|