|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <template>
-
- <div class="top_main">
-
- <el-dropdown trigger="click" placement="bottom-start">
- <div class="select_address el-dropdown-link">
- <span class="sanjiao-right"></span>
- <p>{{cityName}}</p>
- </div>
- <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
- <el-dropdown-item v-for="(item,index) in deptOptions" :command="item.orgCode">
- <div class="selected" @click="chooseCity(item.orgCode)">
- <p>{{item.deptName}}</p>
- </div>
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
-
- <el-dropdown trigger="click" placement="bottom-start" v-if="!hideTown">
- <div class="select_address el-dropdown-link">
- <span class="sanjiao-right"></span>
- <p>{{townName}}</p>
- </div>
- <el-dropdown-menu slot="dropdown" style="width: 8vw;text-align: center;">
- <el-dropdown-item v-for="(item,index) in townList" :command="item.orgCode">
- <div class="selected" @click="chooseTown(item.orgCode)">
- <p>{{item.deptName}}</p>
- </div>
- </el-dropdown-item>
- </el-dropdown-menu>
- </el-dropdown>
-
- <slot></slot>
- </div>
-
- </template>
-
- <script>
- import {cityTree} from "@/api/misc/misc_dept";
-
- export default {
- name: 'TopDeptChooser',
- props: {
- countyCode: String,
- townCode: String,
- rootId: [String, Number],
- allTown: {
- type: Boolean,
- default: false,
- },
- hideTown: {
- type: Boolean,
- default: false,
- },
- },
- created() {
- this.getDeptTree();
- },
- data() {
- return {
- deptOptions: [],
- icountyCode: this.countyCode || null,
- itownCode: this.townCode || null,
- };
- },
- methods: {
- getDeptTree() {
- cityTree({rootId: this.rootId}).then((resp) => {
- this.deptOptions = resp.data;
- if(this.deptOptions.length)
- {
- this.icountyCode = this.deptOptions[0].orgCode;
- this.emitUpdate(1);
- }
- });
- },
- chooseCity(cmd) {
- this.icountyCode = cmd;
- this.itownCode = null;
- this.emitUpdate(1 | 2);
- },
- chooseTown(cmd) {
- this.itownCode = cmd;
- this.emitUpdate(2);
- },
- emitUpdate(w) {
- if(w & 1)
- {
- this.$emit('update:countyCode', this.icountyCode);
- }
- if((w & 2) && !this.hideTown)
- {
- this.$emit('update:townCode', this.itownCode);
- }
- if(w & 1)
- {
- this.$emit('countyChanged', this.icountyCode, null);
- }
- if((w & 2) && !this.hideTown)
- {
- this.$emit('townChanged', this.itownCode, this.icountyCode);
- }
- if((w & 1) || ((w & 2) && !this.hideTown))
- {
- this.$emit('dataChanged', this.icountyCode, this.itownCode, w);
- }
- },
- },
- watch: {
- rootId(newVal) {
- this.getDeptTree();
- },
- countyCode(newVal) {
- if(this.icountyCode != newVal)
- {
- this.icountyCode = newVal;
- //this.emitUpdate(1);
- }
- },
- townCode(newVal) {
- if(this.itownCode != newVal)
- {
- this.itownCode = newVal;
- //this.emitUpdate(2);
- }
- },
- /* icountyCode(newVal) {
- if(this.countyCode != newVal)
- {
- this.emitUpdate(1);
- }
- },
- itownCode(newVal) {
- if(this.townCode != newVal)
- {
- this.emitUpdate(2);
- }
- },*/
- },
- computed: {
- cityName() {
- if(!this.deptOptions.length)
- return '';
- let dept = this.deptOptions.find((x) => x.orgCode === this.icountyCode);
- return dept ? dept.deptName : '';
- },
- townList() {
- if(!this.deptOptions.length)
- return [];
- let dept = this.deptOptions.find((x) => x.orgCode === this.icountyCode);
- let arr = [];
- if(this.allTown)
- arr.push({orgCode: '', deptName: '全部'});
- arr.push(...(dept ? dept.children || [] : []));
- return arr;
- },
- townName() {
- if(!this.townList.length)
- return '';
- if(this.allTown)
- {
- if(!this.itownCode)
- return '全部';
- }
- let dept = this.townList.find((x) => x.orgCode === this.itownCode);
- return dept ? dept.deptName : '';
- },
- },
- }
- </script>
-
- <style scoped lang="scss">
- .el-dropdown-link {
- cursor: pointer;
- }
- .selected{
- display: flex;
- height: 4vh;
- p{
- width: 8vw;
- line-height: 4vh;
- text-align: center;
- }
- }
- p{margin: 0;line-height: 1;}
- .top_main{
- display: flex;
- align-items: center;
- position: relative;
- .selected{
- width: 16vw;
- background-color: #ffffff;
- position: absolute;
- top: 4vh;
- left: 10vw;
- z-index: 9;
- border-radius: 8px;
- box-shadow: 0 10px 10px #dedfe1;
- padding: 1vh 0;
- div{
- display: flex;
- height: 4vh;
- p{
- width: 8vw;
- line-height: 4vh;
- text-align: center;
- }
- }
- }
- .select_address{
- display: flex;
- align-items: center;
- justify-content: center;
- margin-right: 2vw;
- background-color: #ffffff;
- padding: 0px 0px;
- border-radius: 8px;
- box-shadow: 0 0 10px #dedfe1;
- width: 8vw;
- height: 4vh;
- overflow: hidden;
- &:nth-child(2){
- margin-right: 0vw;
- }
- &:nth-child(3){
- margin-right: 0vw;
- border-top-left-radius: initial;
- border-bottom-left-radius: initial;
- }
- .sanjiao-right {
- display: inline-block;
- border-left: 8px solid #000;
- border-left-color: initial;
- border-top: 5px solid transparent;
- border-bottom: 5px solid transparent;
- margin-right: 5px;
- }
- .select_time{
- text-align: center;
- width: 100%;
- height: 4vh;
- line-height: 4vh;
- background-color: #3976ff;
- color: #ffffff;
- }
- }
- }
- </style>
|