index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <div>
  3. <!--顶级按钮-->
  4. <div class="btn-group mr-1"
  5. v-if="jiBie == 0"
  6. >
  7. <button
  8. type="button"
  9. @click="selectAgency"
  10. class="btn btn-sm btn-outline-secondary"
  11. >
  12. {{ $store.state.user.agentFlag ? $store.state.user.nickName : "智慧易加"}}
  13. </button>
  14. <button
  15. type="button"
  16. class="
  17. btn btn-sm btn-outline-secondary
  18. dropdown-toggle dropdown-toggle-split
  19. "
  20. data-toggle="dropdown"
  21. aria-expanded="false"
  22. >
  23. <span class="sr-only"></span>
  24. </button>
  25. <div
  26. class="dropdown-menu"
  27. style="overflow-y: auto; max-height: 400px; max-width: 280px"
  28. >
  29. <form class="px-4 py-3">
  30. <input
  31. type="email"
  32. class="form-control"
  33. id="exampleDropdownFormEmail1"
  34. placeholder=""
  35. autocomplete="off"
  36. @input="filterMethod"
  37. v-model="filterText"
  38. />
  39. </form>
  40. <div class="dropdown-divider"></div>
  41. <a
  42. class="dropdown-item"
  43. href="#"
  44. v-for="ele in filteredGroups"
  45. :key="ele.deptId"
  46. @click="selectGroup(ele)"
  47. >{{ ele.deptName }}</a
  48. >
  49. </div>
  50. </div>
  51. <!--集团按钮-->
  52. <div class="btn-group mr-1"
  53. v-show="!!currentGroup"
  54. v-if="jiBie == 0 || jiBie == 1 "
  55. >
  56. <button
  57. @click="selectGroup(currentGroup)"
  58. type="button"
  59. class="btn btn-sm btn-outline-secondary"
  60. >
  61. {{ (currentGroup||{}).deptName }}
  62. </button>
  63. <button
  64. type="button"
  65. class="
  66. btn btn-sm btn-outline-secondary
  67. dropdown-toggle dropdown-toggle-split
  68. "
  69. data-toggle="dropdown"
  70. aria-expanded="false"
  71. >
  72. <span class="sr-only"></span>
  73. </button>
  74. <div
  75. class="dropdown-menu"
  76. style="overflow-y: auto; max-height: 400px; max-width: 280px"
  77. >
  78. <form class="px-4 py-3">
  79. <input
  80. type="email"
  81. class="form-control"
  82. id="exampleDropdownFormEmail1"
  83. placeholder=""
  84. autocomplete="off"
  85. @input="filterMethod"
  86. v-model="filterText"
  87. />
  88. </form>
  89. <div class="dropdown-divider"></div>
  90. <a
  91. class="dropdown-item"
  92. href="#"
  93. v-for="ele in filteredStations"
  94. :key="ele.deptId"
  95. @click="selectStation(ele)"
  96. >{{ ele.deptName }}</a
  97. >
  98. </div>
  99. </div>
  100. <!--站点-->
  101. <button type="button" class="btn btn-sm btn-success" disabled>
  102. {{ tip + (jiBie !=2 ? ":" : "") + currentShow.deptName }}
  103. </button>
  104. </div>
  105. </template>
  106. <script>
  107. import { userdepttree, getGroups, getStations } from "@/api/system/dept";
  108. import { mapMutations } from 'vuex'
  109. import Treeselect from "@riophae/vue-treeselect";
  110. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  111. export default {
  112. components: { Treeselect },
  113. data() {
  114. return {
  115. value: null,
  116. options: [],
  117. Infinity: 2,
  118. num: 0,
  119. tip:'',
  120. Agency: {
  121. deptId: 1,
  122. deptName: this.$store.state.user.deptName,
  123. },
  124. groups: [
  125. {
  126. deptId: 3,
  127. deptName: "李哈哈的集团",
  128. },
  129. {
  130. deptId: 2,
  131. deptName: "李哈哈的顶级集团",
  132. },
  133. ],
  134. stations: [
  135. {
  136. deptId: 4,
  137. deptName: "李哈哈的站点1",
  138. },
  139. {
  140. deptId: 5,
  141. deptName: "李哈哈的站点2",
  142. },
  143. ],
  144. currentStation: undefined,
  145. currentGroup: undefined,
  146. filterText:"",
  147. filterStationText:"",
  148. filterTimer:null
  149. };
  150. },
  151. computed: {
  152. currentShow() {
  153. if (!!this.currentStation) {
  154. return this.currentStation;
  155. }
  156. if (!!this.currentGroup) {
  157. return this.currentGroup;
  158. }
  159. return this.Agency;
  160. },
  161. filteredGroups(){
  162. return this.groups.filter((ele)=>{
  163. return ele.deptId.toString().includes(this.filterText) || ele.deptName.includes(this.filterText)
  164. })
  165. },
  166. filteredStations(){
  167. return this.stations.filter((ele)=>{
  168. return ele.deptId.toString().includes(this.filterText) || ele.deptName.includes(this.filterText)
  169. })
  170. }
  171. },
  172. watch: {
  173. // 监听deptId
  174. value: "currDeptChange",
  175. },
  176. created() {
  177. this.init();
  178. },
  179. methods: {
  180. ...mapMutations({
  181. setLevelId:"SET_LEVELID"
  182. }),
  183. init() {
  184. if(this.jiBie == 0){
  185. this.tip = this.$store.state.user.agentFlag ? '代理' : "全站"
  186. this.setLevelId(undefined)
  187. this.selectAgency();
  188. }else if(this.jiBie == 1){
  189. this.tip = "集团"
  190. this.currentGroup = {
  191. deptId: undefined,
  192. deptName: this.$store.state.user.deptName
  193. }
  194. this.setLevelId(this.currentGroup.deptId)
  195. this.selectGroup(this.currentGroup);
  196. }else if(this.jiBie == 2){
  197. this.setLevelId(undefined)
  198. }
  199. },
  200. selectAgency() {
  201. this.tip = this.$store.state.user.agentFlag ? '代理' : "全站";
  202. this.filterText = "";
  203. this.currentGroup = undefined;
  204. this.currentStation = undefined;
  205. this.setLevelId(undefined)
  206. getGroups().then((res)=>{
  207. if(res.code == 200){
  208. this.groups = res.data
  209. }else{
  210. throw new Error("");
  211. }
  212. }).catch(()=>{
  213. this.msgError("拉取首页菜单的集团列表失败,请刷新网页")
  214. })
  215. this.refreshTagView();
  216. },
  217. selectGroup(group) {
  218. this.tip = "集团";
  219. this.filterText = "";
  220. this.currentGroup = group;
  221. this.currentStation = undefined;
  222. const id = this.jiBie==1 ? undefined : this.currentGroup.deptId;
  223. this.setLevelId(id);
  224. getStations({
  225. deptId: group.deptId
  226. }).then((res)=>{
  227. if(res.code == 200){
  228. this.stations = res.data
  229. }else{
  230. throw new Error("");
  231. }
  232. }).catch(()=>{
  233. this.msgError("拉取首页菜单的站点列表失败,请刷新网页")
  234. })
  235. this.refreshTagView();
  236. },
  237. selectStation(station) {
  238. this.tip = "站点";
  239. this.filterText = "";
  240. this.currentStation = station;
  241. const id = this.jiBie==2 ? undefined : this.currentStation.deptId;
  242. this.setLevelId(id)
  243. this.refreshTagView();
  244. },
  245. /** 查询部门下拉树结构 */
  246. // getTreeselect() {
  247. // userdepttree().then((response) => {
  248. // this.options = response.data;
  249. // if (response.data != null && response.data.length > 0) {
  250. // this.value = response.data[0].id;
  251. // this.$store.selectDeptName = response.data[0].label;
  252. // this.$store.selectDeptId = response.data[0].id;
  253. // }
  254. // });
  255. // },
  256. currDeptChange(val) {
  257. if (val) {
  258. this.$store.selectDeptId = val;
  259. if (this.num > 0) {
  260. let path = this.$route.path;
  261. let visitedViews = this.$store.state.tagsView.visitedViews;
  262. let stagpath = null;
  263. const proArr = [];
  264. for (let i = 0; i < visitedViews.length; i++) {
  265. let view = visitedViews[i];
  266. proArr.push(
  267. this.$store.dispatch("tagsView/delCachedView", view).then(() => {
  268. const { fullPath } = view;
  269. if (path === fullPath) {
  270. stagpath = view;
  271. } else {
  272. this.$nextTick(() => {
  273. this.$router.replace({
  274. path: "/redirect" + fullPath,
  275. });
  276. });
  277. }
  278. })
  279. );
  280. }
  281. Promise.all(proArr).then(() => {
  282. if (stagpath != null) {
  283. this.$store
  284. .dispatch("tagsView/delCachedView", stagpath)
  285. .then(() => {
  286. const { fullPath } = stagpath;
  287. this.$nextTick(() => {
  288. this.$router.replace({
  289. path: "/redirect" + fullPath,
  290. });
  291. });
  292. });
  293. }
  294. });
  295. }
  296. this.num = this.num + 1;
  297. }
  298. },
  299. refreshTagView() {
  300. const proArr = []
  301. this.$store.state.tagsView.visitedViews.map((view) => {
  302. proArr.push(this.$store.dispatch("tagsView/delCachedView", view))
  303. // this.$store.dispatch("tagsView/delCachedView", view).then(() => {
  304. // const { fullPath } = view;
  305. // console.log(fullPath);
  306. // // this.$nextTick(() => {
  307. // // this.$router.replace({
  308. // // path: "/redirect" + fullPath,
  309. // // });
  310. // // });
  311. // });
  312. });
  313. Promise.all(proArr).then(()=>{
  314. this.$nextTick(() => {
  315. this.$router.replace({
  316. path: "/redirect" + this.$route.path,
  317. });
  318. });
  319. })
  320. },
  321. filterMethod(e){
  322. clearTimeout(this.filterTimer);
  323. this.filterTimer = setTimeout(()=>{
  324. this.filterText = e.target.value
  325. }, 800)
  326. },
  327. },
  328. };
  329. </script>
  330. <style lang="scss">
  331. .vue-treeselect__control {
  332. height: 20px;
  333. line-height: 26px;
  334. font-size: 12px;
  335. text-indent: 4px;
  336. }
  337. .vue-treeselect__menu-container {
  338. position: absolute;
  339. left: 0;
  340. width: 100%;
  341. overflow: visible;
  342. transition: 0s;
  343. }
  344. .vue-treeselect__menu {
  345. font-size: 12px;
  346. }
  347. </style>